Skip to content

Commit

Permalink
Successful build on Plasma 6
Browse files Browse the repository at this point in the history
  • Loading branch information
matinlotfali committed Jan 9, 2024
1 parent f34b777 commit 64fef43
Show file tree
Hide file tree
Showing 14 changed files with 172 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/glslangValidator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
run: sudo apt update && sudo apt install -y glslang-tools

- name: Validate Shaders
run: glslangValidator src/shaders_110/shapecorners.frag src/shaders_140/shapecorners.frag
run: glslangValidator src/shaders/shapecorners.frag src/shaders/shapecorners_core.frag
11 changes: 9 additions & 2 deletions .github/workflows/neon-unstable.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
name: KDE Neon (Unstable)

on:
workflow_dispatch:
push:
branches: [ master ]
paths-ignore: [ '**.md', '**.png' ]
pull_request:
branches: [ master ]
paths-ignore: [ '**.md', '**.png' ]
schedule:
- cron: "0 0 * * *"

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
Expand All @@ -27,7 +34,7 @@ jobs:
continue-on-error: true

- name: Install Dependencies
run: apt -y install cmake g++ gettext extra-cmake-modules qttools5-dev libqt5x11extras5-dev libkf5configwidgets-dev libkf5globalaccel-dev libkf5notifications-dev kwin-dev
run: apt -y install cmake g++ gettext extra-cmake-modules qt6-base-dev-tools libkf6-kcmutils-dev kwin-dev

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
Expand Down
35 changes: 26 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@ cmake_minimum_required(VERSION 3.20)

project(kwin4_effect_shapecorners)

set(KF_MIN_VERSION "5.240.0")
set(QT_MIN_VERSION "6.4.0")
# kwin-dev qt6-base-dev-tools libkf6-kcmutils-dev

find_package(QT NAMES Qt5 Qt6 REQUIRED)
if(${QT_VERSION_MAJOR} EQUAL 6)
set(KF_MIN_VERSION "5.240.0")
set(QT_MIN_VERSION "6.4.0")
else()
set(KF_MIN_VERSION "5.78.0")
set(QT_MIN_VERSION "5.15.0")
endif()

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand All @@ -26,7 +34,7 @@ include(KDEInstallDirs)
include(KDECMakeSettings)
include(KDECompilerSettings NO_POLICY_SCOPE)

find_package(Qt6 ${QT_MIN_VERSION} REQUIRED COMPONENTS
find_package(Qt${QT_VERSION_MAJOR} ${QT_MIN_VERSION} REQUIRED COMPONENTS
Core
Gui
DBus
Expand All @@ -37,22 +45,31 @@ find_package(Qt6 ${QT_MIN_VERSION} REQUIRED COMPONENTS
)

# required frameworks by Core
find_package(KF6 ${KF_MIN_VERSION} REQUIRED COMPONENTS
find_package(KF${QT_VERSION_MAJOR} ${KF_MIN_VERSION} REQUIRED COMPONENTS
Config
ConfigWidgets
CoreAddons
GlobalAccel
WindowSystem
KCMUtils
)
if(${QT_VERSION_MAJOR} EQUAL 6)
find_package(KF${QT_VERSION_MAJOR} ${KF_MIN_VERSION} REQUIRED COMPONENTS
KCMUtils
)

find_package(KWin REQUIRED COMPONENTS
kwineffects
)
else()
find_package(KWinEffects REQUIRED COMPONENTS
kwineffects
kwinglutils
)
endif ()

find_package(epoxy REQUIRED)
find_package(XCB REQUIRED COMPONENTS XCB)

find_package(KWin REQUIRED COMPONENTS
kwineffects
)

find_package(KWinDBusInterface CONFIG REQUIRED)

add_subdirectory(src)
Expand Down
33 changes: 21 additions & 12 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,29 @@ kconfig_add_kcfg_files(effect_SRCS ShapeCornersConfig.kcfgc)
add_library(kwin4_effect_shapecorners SHARED ${effect_SRCS})

target_link_libraries(kwin4_effect_shapecorners
Qt6::Core
Qt6::CorePrivate
Qt6::Gui
Qt6::DBus
KWin::kwin
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::DBus
epoxy::epoxy
KF6::ConfigCore
KF6::ConfigGui
KF6::CoreAddons
KF6::WindowSystem
KF${QT_VERSION_MAJOR}::ConfigCore
KF${QT_VERSION_MAJOR}::ConfigGui
KF${QT_VERSION_MAJOR}::CoreAddons
KF${QT_VERSION_MAJOR}::WindowSystem
)
if(${QT_VERSION_MAJOR} EQUAL 6)
target_link_libraries(kwin4_effect_shapecorners
KWin::kwin
Qt${QT_VERSION_MAJOR}::CorePrivate
)
else()
target_link_libraries(kwin4_effect_shapecorners
KWinEffects::kwineffects
KWinEffects::kwinglutils
)
endif()

install(TARGETS kwin4_effect_shapecorners DESTINATION ${PLUGIN_INSTALL_DIR}/kwin/effects/plugins/)

execute_process(COMMAND kf5-config --install data OUTPUT_VARIABLE DATAPATH OUTPUT_STRIP_TRAILING_WHITESPACE)
install(FILES shaders_140/shapecorners.frag DESTINATION ${DATAPATH}/kwin/shaders/1.40)
install(FILES shaders_110/shapecorners.frag DESTINATION ${DATAPATH}/kwin/shaders/1.10)
execute_process(COMMAND kf${QT_VERSION_MAJOR}-config --install data OUTPUT_VARIABLE DATAPATH OUTPUT_STRIP_TRAILING_WHITESPACE)
install(FILES shaders/shapecorners_core.frag DESTINATION ${DATAPATH}/kwin/shaders)
install(FILES shaders/shapecorners.frag DESTINATION ${DATAPATH}/kwin/shaders)
45 changes: 31 additions & 14 deletions src/ShapeCornersEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,23 @@
* Boston, MA 02110-1301, USA.
*/

#include <QtDBus/QDBusConnection>
#include <QDBusError>
#include <opengl/glutils.h>
#include <effect/effecthandler.h>
#include <core/output.h>
#include "ShapeCornersEffect.h"
#include "ShapeCornersConfig.h"
#include <QtDBus/QDBusConnection>
#include <QDBusError>

#if QT_VERSION_MAJOR >= 6
#include <opengl/glutils.h>
#include <effect/effecthandler.h>
#include <core/output.h>
#else
#include <kwinglutils.h>
#endif

#if KWIN_EFFECT_API_VERSION >= 235
#include <KX11Extras>
#include <KX11Extras>
#else
#include <kwindowsystem.h>
#include <kwindowsystem.h>
#endif

ShapeCornersEffect::ShapeCornersEffect()
Expand All @@ -45,11 +50,11 @@ ShapeCornersEffect::ShapeCornersEffect()
qWarning("ShapeCorners: Cannot connect to the D-Bus session bus.\n");
}
else {
if (!connection.registerService("org.kde.ShapeCorners")) {
if (!connection.registerService(QStringLiteral("org.kde.ShapeCorners"))) {
qWarning("%s\n", qPrintable(connection.lastError().message()));
}
else {
if (!connection.registerObject("/ShapeCornersEffect", this, QDBusConnection::ExportAllSlots)) {
if (!connection.registerObject(QStringLiteral("/ShapeCornersEffect"), this, QDBusConnection::ExportAllSlots)) {
qWarning("%s\n", qPrintable(connection.lastError().message()));
}
}
Expand Down Expand Up @@ -115,7 +120,10 @@ void ShapeCornersEffect::prePaintWindow(KWin::EffectWindow *w, KWin::WindowPrePa

const auto size = isWindowActive(w) ? ShapeCornersConfig::size(): ShapeCornersConfig::inactiveCornerRadius();

#if KWIN_EFFECT_API_VERSION >= 234
#if QT_VERSION_MAJOR >= 6
const auto geo = w->frameGeometry() * w->screen()->scale();
data.setTranslucent();
#elif KWIN_EFFECT_API_VERSION >= 234
const auto geo = w->frameGeometry() * KWin::effects->renderTargetScale();
data.setTranslucent();
#else
Expand Down Expand Up @@ -143,14 +151,21 @@ bool ShapeCornersEffect::supported()
return KWin::effects->isOpenGLCompositing();
}

#if QT_VERSION_MAJOR >= 6
void ShapeCornersEffect::drawWindow(const KWin::RenderTarget &renderTarget, const KWin::RenderViewport &viewport,
KWin::EffectWindow *w, int mask, const QRegion &region,
KWin::WindowPaintData &data) {
#else
void ShapeCornersEffect::drawWindow(KWin::EffectWindow *w, int mask, const QRegion &region,
KWin::WindowPaintData &data) {
#endif
if (!hasEffect(w))
{
unredirect(w);
#if KWIN_EFFECT_API_VERSION >= 236
#if QT_VERSION_MAJOR >= 6
OffscreenEffect::drawWindow(renderTarget, viewport, w, mask, region, data);
#elif KWIN_EFFECT_API_VERSION >= 236
OffscreenEffect::drawWindow(w, mask, region, data);
#else
DeformEffect::drawWindow(w, mask, region, data);
#endif
Expand All @@ -162,8 +177,10 @@ void ShapeCornersEffect::drawWindow(const KWin::RenderTarget &renderTarget, cons
m_shaderManager.Bind(w);
glActiveTexture(GL_TEXTURE0);

#if KWIN_EFFECT_API_VERSION >= 236
#if QT_VERSION_MAJOR >= 6
OffscreenEffect::drawWindow(renderTarget, viewport, w, mask, region, data);
#elif KWIN_EFFECT_API_VERSION >= 236
OffscreenEffect::drawWindow(w, mask, region, data);
#else
DeformEffect::drawWindow(w, mask, region, data);
#endif
Expand All @@ -183,9 +200,9 @@ QString ShapeCornersEffect::get_window_titles() const {
QSet<QString> response;
for (const auto& win: m_managed) {
const auto name = win->windowClass().split(QChar::Space).first();
if (name == "plasmashell")
if (name == QStringLiteral("plasmashell"))
continue;
response.insert(name);
}
return response.values().join("\n");
return response.values().join(QStringLiteral("\n"));
}
18 changes: 13 additions & 5 deletions src/ShapeCornersEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,23 @@

#pragma once

#include <effect/effecthandler.h>
#include <set>
#include "ShapeCornersShader.h"
#include <set>

#if QT_VERSION_MAJOR >= 6
#include <effect/effecthandler.h>
#include <effect/offscreeneffect.h>
#elif KWIN_EFFECT_API_VERSION >= 236
#include <kwineffects.h>
#include <kwinoffscreeneffect.h>
#else
#include <kwineffects.h>
#include <kwindeformeffect.h>
#endif

#if KWIN_EFFECT_API_VERSION >= 236
#include <effect/offscreeneffect.h>
class ShapeCornersEffect final: public KWin::OffscreenEffect
#else
#include <kwindeformeffect.h>
class ShapeCornersEffect final: public KWin::DeformEffect
#endif
{
Expand All @@ -44,7 +52,7 @@ class ShapeCornersEffect final: public KWin::DeformEffect
void reconfigure(ReconfigureFlags flags) override;

void prePaintWindow(KWin::EffectWindow *w, KWin::WindowPrePaintData &data, std::chrono::milliseconds time) override;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#if QT_VERSION_MAJOR >= 6
void drawWindow(const KWin::RenderTarget &RenderTarget, const KWin::RenderViewport& viewport,
KWin::EffectWindow *w, int mask, const QRegion &region, KWin::WindowPaintData &data) override;
#else
Expand Down
29 changes: 11 additions & 18 deletions src/ShapeCornersShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,30 @@
// Created by matin on 20/07/22.
//

#include <QFile>
#include <QWidget>
#include <opengl/glplatform.h>
#include <effect/effect.h>
#include <opengl/glutils.h>
#include "ShapeCornersShader.h"
#include "ShapeCornersEffect.h"
#include "ShapeCornersConfig.h"
#include "ShapeCornersShader.h"
#include <QFile>
#include <QWidget>

#if QT_VERSION_MAJOR >= 6
#include <opengl/glutils.h>
#else
#include <kwinglutils.h>
#endif

ShapeCornersShader::ShapeCornersShader():
m_manager(KWin::ShaderManager::instance()),
m_widget(new QWidget)
{
const QString shadersDir = IsLegacy()? "kwin/shaders/1.10/": "kwin/shaders/1.40/";
const QString fragmentshader = QStandardPaths::locate(QStandardPaths::GenericDataLocation, shadersDir + QStringLiteral("shapecorners.frag"));
const QString fragmentshader = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kwin/shaders/shapecorners.frag"));
// m_shader = KWin::ShaderManager::instance()->loadFragmentShader(KWin::ShaderManager::GenericShader, fragmentshader);
QFile file(fragmentshader);
if (!file.open(QFile::ReadOnly))
qCritical() << "ShapeCorners: no shaders found! Exiting...";

const QByteArray frag = file.readAll();
auto shader = m_manager->generateCustomShader(KWin::ShaderTrait::MapTexture, QByteArray(), frag);
auto shader = m_manager->generateShaderFromFile(KWin::ShaderTrait::MapTexture, QStringLiteral(""), fragmentshader);
#if KWIN_EFFECT_API_VERSION >= 235
m_shader = std::move(shader);
#else
Expand Down Expand Up @@ -105,12 +107,3 @@ ShapeCornersShader::Bind(const QMatrix4x4& mvp, KWin::EffectWindow *w) const {
void ShapeCornersShader::Unbind() const {
m_manager->popShader();
}

bool ShapeCornersShader::IsLegacy() {
#ifdef KWIN_HAVE_OPENGLES
const qint64 version = KWin::kVersionNumber(3, 0);
#else
const qint64 version = KWin::kVersionNumber(1, 40);
#endif
return KWin::GLPlatform::instance()->glslVersion() < version;
}
14 changes: 8 additions & 6 deletions src/ShapeCornersShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@
#ifndef KWIN4_SHAPECORNERS_CONFIG_SHADERMANAGER_H
#define KWIN4_SHAPECORNERS_CONFIG_SHADERMANAGER_H

#include <qconfig.h>
#if QT_VERSION_MAJOR >= 6
#include <effect/effect.h>
#else
#include <kwineffects.h>
#endif

namespace KWin {
class GLShader;
class ShaderManager;
}

struct QVector2DSize final: QVector2D {
struct QVector2DSize final: public QVector2D {
explicit QVector2DSize(const QSizeF s):
QVector2D(static_cast<float>(s.width()), static_cast<float>(s.height())) {}
};
Expand All @@ -23,11 +30,6 @@ class ShapeCornersShader {
*/
explicit ShapeCornersShader();

/**
* \return True if the GL platform version used in KWin is older than 1.40.
*/
static bool IsLegacy();

/**
* \return True if the shader is valid and loaded
*/
Expand Down
Loading

0 comments on commit 64fef43

Please sign in to comment.