From cfd9a27619c8b2deeb7009ee75e6a854d752cc45 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Mon, 26 Feb 2024 03:13:55 -0800 Subject: [PATCH] refactor: move wlr_layershell to its own subdirectory --- src/wayland/CMakeLists.txt | 46 ++++++------ src/wayland/init.cpp | 10 ++- src/wayland/module.md | 4 +- ...ylandlayershell.cpp => wlr_layershell.cpp} | 70 +++++++++---------- ...ylandlayershell.hpp => wlr_layershell.hpp} | 14 ++-- src/wayland/wlr_layershell/CMakeLists.txt | 12 ++++ .../shell_integration.cpp | 2 +- .../shell_integration.hpp | 0 .../surface.cpp} | 6 +- .../surface.hpp} | 2 +- .../window.cpp} | 6 +- .../window.hpp} | 2 +- .../wlr-layer-shell-unstable-v1.xml | 0 13 files changed, 95 insertions(+), 79 deletions(-) rename src/wayland/{waylandlayershell.cpp => wlr_layershell.cpp} (70%) rename src/wayland/{waylandlayershell.hpp => wlr_layershell.hpp} (93%) create mode 100644 src/wayland/wlr_layershell/CMakeLists.txt rename src/wayland/{ => wlr_layershell}/shell_integration.cpp (96%) rename src/wayland/{ => wlr_layershell}/shell_integration.hpp (100%) rename src/wayland/{layer_surface.cpp => wlr_layershell/surface.cpp} (98%) rename src/wayland/{layer_surface.hpp => wlr_layershell/surface.hpp} (98%) rename src/wayland/{layershell.cpp => wlr_layershell/window.cpp} (97%) rename src/wayland/{layershell.hpp => wlr_layershell/window.hpp} (98%) rename src/wayland/{wl-proto => wlr_layershell}/wlr-layer-shell-unstable-v1.xml (100%) diff --git a/src/wayland/CMakeLists.txt b/src/wayland/CMakeLists.txt index d527c056..7f93c5e3 100644 --- a/src/wayland/CMakeLists.txt +++ b/src/wayland/CMakeLists.txt @@ -1,25 +1,8 @@ -qt_add_library(quickshell-wayland STATIC - shell_integration.cpp - layer_surface.cpp - layershell.cpp - waylandlayershell.cpp -) - -# required to make sure the constructor is linked -add_library(quickshell-wayland-init OBJECT init.cpp) - -target_link_libraries(quickshell PRIVATE ${QT_DEPS} quickshell-waylandplugin quickshell-wayland-init) - -qt_add_qml_module(quickshell-wayland URI Quickshell.Wayland) - find_package(PkgConfig REQUIRED) pkg_check_modules(wayland REQUIRED IMPORTED_TARGET wayland-client wayland-protocols) find_package(Qt6 REQUIRED COMPONENTS WaylandClient) -target_link_libraries(quickshell-wayland PRIVATE ${QT_DEPS} wayland-client) -target_link_libraries(quickshell-wayland-init PRIVATE ${QT_DEPS} wayland-client) - # wayland protocols if (DEFINED ENV{QTWAYLANDSCANNER}) @@ -45,20 +28,33 @@ execute_process( message(STATUS "Found wayland-protocols at ${WAYLAND_PROTOCOLS_DIR}") -set(PROTO_SRC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/wl-proto) -set(PROTO_BUILD_PATH ${CMAKE_CURRENT_BINARY_DIR}/wl-proto) -make_directory(${PROTO_BUILD_PATH}) +function (wl_proto target name path) + set(PROTO_BUILD_PATH ${CMAKE_CURRENT_BINARY_DIR}/wl-proto/${name}) + make_directory(${PROTO_BUILD_PATH}) -function (wl_proto name path) execute_process(COMMAND ${waylandscanner} client-header ${path} ${PROTO_BUILD_PATH}/wayland-${name}-client-protocol.h) execute_process(COMMAND ${waylandscanner} private-code ${path} ${PROTO_BUILD_PATH}/wayland-${name}.c) execute_process(COMMAND ${qtwaylandscanner} client-header ${path} OUTPUT_FILE ${PROTO_BUILD_PATH}/qwayland-${name}.h) execute_process(COMMAND ${qtwaylandscanner} client-code ${path} OUTPUT_FILE ${PROTO_BUILD_PATH}/qwayland-${name}.cpp) - target_sources(quickshell-wayland PRIVATE ${PROTO_BUILD_PATH}/wayland-${name}.c) - target_sources(quickshell-wayland PRIVATE ${PROTO_BUILD_PATH}/qwayland-${name}.cpp) + target_sources(${target} PRIVATE ${PROTO_BUILD_PATH}/wayland-${name}.c) + target_sources(${target} PRIVATE ${PROTO_BUILD_PATH}/qwayland-${name}.cpp) + target_include_directories(${target} PRIVATE ${PROTO_BUILD_PATH}) endfunction() -wl_proto("wlr-layer-shell-unstable-v1" "${PROTO_SRC_PATH}/wlr-layer-shell-unstable-v1.xml") +# ----- -target_include_directories(quickshell-wayland PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/wl-proto) +qt_add_library(quickshell-wayland STATIC + wlr_layershell.cpp +) + +qt_add_qml_module(quickshell-wayland URI Quickshell.Wayland) + +# required to make sure the constructor is linked +add_library(quickshell-wayland-init OBJECT init.cpp) + +add_subdirectory(wlr_layershell) +target_link_libraries(quickshell-wayland PRIVATE ${QT_DEPS}) +target_link_libraries(quickshell-wayland-init PRIVATE ${QT_DEPS}) + +target_link_libraries(quickshell PRIVATE ${QT_DEPS} quickshell-waylandplugin quickshell-wayland-init) diff --git a/src/wayland/init.cpp b/src/wayland/init.cpp index b70b1d2a..6e964fa0 100644 --- a/src/wayland/init.cpp +++ b/src/wayland/init.cpp @@ -2,7 +2,7 @@ #include #include "../core/plugin.hpp" -#include "waylandlayershell.hpp" +#include "wlr_layershell.hpp" namespace { @@ -15,6 +15,14 @@ class WaylandPlugin: public QuickshellPlugin { // If any types are defined inside a module using QML_ELEMENT then all QML_ELEMENT types // will not be registered. This can be worked around with a module import which makes // the QML_ELMENT module import the old register-type style module. + + qmlRegisterModuleImport( + "Quickshell.Wayland", + QQmlModuleImportModuleAny, + "Quickshell.Wayland._WlrLayerShell", + QQmlModuleImportLatest + ); + qmlRegisterModuleImport( "Quickshell", QQmlModuleImportModuleAny, diff --git a/src/wayland/module.md b/src/wayland/module.md index ab6af64c..45194137 100644 --- a/src/wayland/module.md +++ b/src/wayland/module.md @@ -1,7 +1,7 @@ name = "Quickshell.Wayland" description = "Wayland specific Quickshell types" headers = [ - "layershell.hpp", - "waylandlayershell.hpp", + "wlr_layershell/window.hpp", + "wlr_layershell.hpp", ] ----- diff --git a/src/wayland/waylandlayershell.cpp b/src/wayland/wlr_layershell.cpp similarity index 70% rename from src/wayland/waylandlayershell.cpp rename to src/wayland/wlr_layershell.cpp index 91dfa5cb..3f73622e 100644 --- a/src/wayland/waylandlayershell.cpp +++ b/src/wayland/wlr_layershell.cpp @@ -1,4 +1,4 @@ -#include "waylandlayershell.hpp" +#include "wlr_layershell.hpp" #include #include @@ -12,14 +12,14 @@ #include "../core/panelinterface.hpp" #include "../core/proxywindow.hpp" #include "../core/qmlscreen.hpp" -#include "layershell.hpp" +#include "wlr_layershell/window.hpp" -WaylandLayershell::WaylandLayershell(QObject* parent) +WlrLayershell::WlrLayershell(QObject* parent) : ProxyWindowBase(parent) , ext(new LayershellWindowExtension(this)) {} -QQuickWindow* WaylandLayershell::createWindow(QObject* oldInstance) { - auto* old = qobject_cast(oldInstance); +QQuickWindow* WlrLayershell::createWindow(QObject* oldInstance) { + auto* old = qobject_cast(oldInstance); QQuickWindow* window = nullptr; if (old == nullptr || old->window == nullptr) { @@ -43,25 +43,25 @@ QQuickWindow* WaylandLayershell::createWindow(QObject* oldInstance) { return window; } -void WaylandLayershell::setupWindow() { +void WlrLayershell::setupWindow() { this->ProxyWindowBase::setupWindow(); // clang-format off - QObject::connect(this->ext, &LayershellWindowExtension::layerChanged, this, &WaylandLayershell::layerChanged); - QObject::connect(this->ext, &LayershellWindowExtension::keyboardFocusChanged, this, &WaylandLayershell::keyboardFocusChanged); - QObject::connect(this->ext, &LayershellWindowExtension::anchorsChanged, this, &WaylandLayershell::anchorsChanged); - QObject::connect(this->ext, &LayershellWindowExtension::exclusiveZoneChanged, this, &WaylandLayershell::exclusiveZoneChanged); - QObject::connect(this->ext, &LayershellWindowExtension::marginsChanged, this, &WaylandLayershell::marginsChanged); + QObject::connect(this->ext, &LayershellWindowExtension::layerChanged, this, &WlrLayershell::layerChanged); + QObject::connect(this->ext, &LayershellWindowExtension::keyboardFocusChanged, this, &WlrLayershell::keyboardFocusChanged); + QObject::connect(this->ext, &LayershellWindowExtension::anchorsChanged, this, &WlrLayershell::anchorsChanged); + QObject::connect(this->ext, &LayershellWindowExtension::exclusiveZoneChanged, this, &WlrLayershell::exclusiveZoneChanged); + QObject::connect(this->ext, &LayershellWindowExtension::marginsChanged, this, &WlrLayershell::marginsChanged); - QObject::connect(this, &ProxyWindowBase::widthChanged, this, &WaylandLayershell::updateAutoExclusion); - QObject::connect(this, &ProxyWindowBase::heightChanged, this, &WaylandLayershell::updateAutoExclusion); - QObject::connect(this, &WaylandLayershell::anchorsChanged, this, &WaylandLayershell::updateAutoExclusion); + QObject::connect(this, &ProxyWindowBase::widthChanged, this, &WlrLayershell::updateAutoExclusion); + QObject::connect(this, &ProxyWindowBase::heightChanged, this, &WlrLayershell::updateAutoExclusion); + QObject::connect(this, &WlrLayershell::anchorsChanged, this, &WlrLayershell::updateAutoExclusion); // clang-format on this->updateAutoExclusion(); } -void WaylandLayershell::setWidth(qint32 width) { +void WlrLayershell::setWidth(qint32 width) { this->mWidth = width; // only update the actual size if not blocked by anchors @@ -70,7 +70,7 @@ void WaylandLayershell::setWidth(qint32 width) { } } -void WaylandLayershell::setHeight(qint32 height) { +void WlrLayershell::setHeight(qint32 height) { this->mHeight = height; // only update the actual size if not blocked by anchors @@ -79,24 +79,24 @@ void WaylandLayershell::setHeight(qint32 height) { } } -void WaylandLayershell::setScreen(QuickshellScreenInfo* screen) { +void WlrLayershell::setScreen(QuickshellScreenInfo* screen) { this->ProxyWindowBase::setScreen(screen); this->ext->setUseWindowScreen(screen != nullptr); } // NOLINTBEGIN #define extPair(type, get, set) \ - type WaylandLayershell::get() const { return this->ext->get(); } \ - void WaylandLayershell::set(type value) { this->ext->set(value); } + type WlrLayershell::get() const { return this->ext->get(); } \ + void WlrLayershell::set(type value) { this->ext->set(value); } extPair(Layer::Enum, layer, setLayer); extPair(KeyboardFocus::Enum, keyboardFocus, setKeyboardFocus); extPair(Margins, margins, setMargins); // NOLINTEND -Anchors WaylandLayershell::anchors() const { return this->ext->anchors(); } +Anchors WlrLayershell::anchors() const { return this->ext->anchors(); } -void WaylandLayershell::setAnchors(Anchors anchors) { +void WlrLayershell::setAnchors(Anchors anchors) { this->ext->setAnchors(anchors); // explicitly set width values are tracked so the entire screen isn't covered if an anchor is removed. @@ -104,24 +104,24 @@ void WaylandLayershell::setAnchors(Anchors anchors) { if (!anchors.verticalConstraint()) this->ProxyWindowBase::setHeight(this->mHeight); } -QString WaylandLayershell::ns() const { return this->ext->ns(); } +QString WlrLayershell::ns() const { return this->ext->ns(); } -void WaylandLayershell::setNamespace(QString ns) { +void WlrLayershell::setNamespace(QString ns) { this->ext->setNamespace(std::move(ns)); emit this->namespaceChanged(); } -qint32 WaylandLayershell::exclusiveZone() const { return this->ext->exclusiveZone(); } +qint32 WlrLayershell::exclusiveZone() const { return this->ext->exclusiveZone(); } -void WaylandLayershell::setExclusiveZone(qint32 exclusiveZone) { +void WlrLayershell::setExclusiveZone(qint32 exclusiveZone) { this->mExclusiveZone = exclusiveZone; this->setExclusionMode(ExclusionMode::Normal); this->ext->setExclusiveZone(exclusiveZone); } -ExclusionMode::Enum WaylandLayershell::exclusionMode() const { return this->mExclusionMode; } +ExclusionMode::Enum WlrLayershell::exclusionMode() const { return this->mExclusionMode; } -void WaylandLayershell::setExclusionMode(ExclusionMode::Enum exclusionMode) { +void WlrLayershell::setExclusionMode(ExclusionMode::Enum exclusionMode) { this->mExclusionMode = exclusionMode; if (exclusionMode == this->mExclusionMode) return; @@ -134,7 +134,7 @@ void WaylandLayershell::setExclusionMode(ExclusionMode::Enum exclusionMode) { } } -void WaylandLayershell::setAutoExclusion() { +void WlrLayershell::setAutoExclusion() { const auto anchors = this->anchors(); auto zone = 0; @@ -144,13 +144,13 @@ void WaylandLayershell::setAutoExclusion() { this->ext->setExclusiveZone(zone); } -void WaylandLayershell::updateAutoExclusion() { +void WlrLayershell::updateAutoExclusion() { if (this->mExclusionMode == ExclusionMode::Auto) { this->setAutoExclusion(); } } -WaylandLayershell* WaylandLayershell::qmlAttachedProperties(QObject* object) { +WlrLayershell* WlrLayershell::qmlAttachedProperties(QObject* object) { if (auto* obj = qobject_cast(object)) { return obj->layer; } else { @@ -162,7 +162,7 @@ WaylandLayershell* WaylandLayershell::qmlAttachedProperties(QObject* object) { WaylandPanelInterface::WaylandPanelInterface(QObject* parent) : PanelWindowInterface(parent) - , layer(new WaylandLayershell(this)) { + , layer(new WlrLayershell(this)) { // clang-format off QObject::connect(this->layer, &ProxyWindowBase::windowConnected, this, &WaylandPanelInterface::windowConnected); @@ -174,10 +174,10 @@ WaylandPanelInterface::WaylandPanelInterface(QObject* parent) QObject::connect(this->layer, &ProxyWindowBase::maskChanged, this, &WaylandPanelInterface::maskChanged); // panel specific - QObject::connect(this->layer, &WaylandLayershell::anchorsChanged, this, &WaylandPanelInterface::anchorsChanged); - QObject::connect(this->layer, &WaylandLayershell::marginsChanged, this, &WaylandPanelInterface::marginsChanged); - QObject::connect(this->layer, &WaylandLayershell::exclusiveZoneChanged, this, &WaylandPanelInterface::exclusiveZoneChanged); - QObject::connect(this->layer, &WaylandLayershell::exclusionModeChanged, this, &WaylandPanelInterface::exclusionModeChanged); + QObject::connect(this->layer, &WlrLayershell::anchorsChanged, this, &WaylandPanelInterface::anchorsChanged); + QObject::connect(this->layer, &WlrLayershell::marginsChanged, this, &WaylandPanelInterface::marginsChanged); + QObject::connect(this->layer, &WlrLayershell::exclusiveZoneChanged, this, &WaylandPanelInterface::exclusiveZoneChanged); + QObject::connect(this->layer, &WlrLayershell::exclusionModeChanged, this, &WaylandPanelInterface::exclusionModeChanged); // clang-format on } diff --git a/src/wayland/waylandlayershell.hpp b/src/wayland/wlr_layershell.hpp similarity index 93% rename from src/wayland/waylandlayershell.hpp rename to src/wayland/wlr_layershell.hpp index e0df09ce..b96baf79 100644 --- a/src/wayland/waylandlayershell.hpp +++ b/src/wayland/wlr_layershell.hpp @@ -9,9 +9,9 @@ #include "../core/doc.hpp" #include "../core/proxywindow.hpp" -#include "layershell.hpp" +#include "wlr_layershell/window.hpp" -class WaylandLayershell: public ProxyWindowBase { +class WlrLayershell: public ProxyWindowBase { QSDOC_BASECLASS(PanelWindowInterface); // clang-format off Q_OBJECT; @@ -28,12 +28,12 @@ class WaylandLayershell: public ProxyWindowBase { QSDOC_HIDE Q_PROPERTY(qint32 exclusiveZone READ exclusiveZone WRITE setExclusiveZone NOTIFY exclusiveZoneChanged); QSDOC_HIDE Q_PROPERTY(ExclusionMode::Enum exclusionMode READ exclusionMode WRITE setExclusionMode NOTIFY exclusionModeChanged); QSDOC_HIDE Q_PROPERTY(Margins margins READ margins WRITE setMargins NOTIFY marginsChanged); - QML_ATTACHED(WaylandLayershell); + QML_ATTACHED(WlrLayershell); QML_ELEMENT; // clang-format on public: - explicit WaylandLayershell(QObject* parent = nullptr); + explicit WlrLayershell(QObject* parent = nullptr); QQuickWindow* createWindow(QObject* oldInstance) override; void setupWindow() override; @@ -64,7 +64,7 @@ public: [[nodiscard]] Margins margins() const; void setMargins(Margins margins); // NOLINT - static WaylandLayershell* qmlAttachedProperties(QObject* object); + static WlrLayershell* qmlAttachedProperties(QObject* object); signals: void layerChanged(); @@ -134,7 +134,7 @@ public: // NOLINTEND private: - WaylandLayershell* layer; + WlrLayershell* layer; - friend class WaylandLayershell; + friend class WlrLayershell; }; diff --git a/src/wayland/wlr_layershell/CMakeLists.txt b/src/wayland/wlr_layershell/CMakeLists.txt new file mode 100644 index 00000000..87bc0445 --- /dev/null +++ b/src/wayland/wlr_layershell/CMakeLists.txt @@ -0,0 +1,12 @@ +qt_add_library(quickshell-wayland-layershell STATIC + shell_integration.cpp + surface.cpp + window.cpp +) + +qt_add_qml_module(quickshell-wayland-layershell URI Quickshell.Wayland._WlrLayerShell) + +wl_proto(quickshell-wayland-layershell wlr-layer-shell-unstable-v1 "${CMAKE_CURRENT_SOURCE_DIR}/wlr-layer-shell-unstable-v1.xml") +target_link_libraries(quickshell-wayland-layershell PRIVATE ${QT_DEPS} wayland-client) + +target_link_libraries(quickshell-wayland PRIVATE quickshell-wayland-layershellplugin) diff --git a/src/wayland/shell_integration.cpp b/src/wayland/wlr_layershell/shell_integration.cpp similarity index 96% rename from src/wayland/shell_integration.cpp rename to src/wayland/wlr_layershell/shell_integration.cpp index 134d14dc..2939f5cd 100644 --- a/src/wayland/shell_integration.cpp +++ b/src/wayland/wlr_layershell/shell_integration.cpp @@ -4,7 +4,7 @@ #include #include -#include "layer_surface.hpp" +#include "surface.hpp" #include "wayland-wlr-layer-shell-unstable-v1-client-protocol.h" QSWaylandLayerShellIntegration::QSWaylandLayerShellIntegration() diff --git a/src/wayland/shell_integration.hpp b/src/wayland/wlr_layershell/shell_integration.hpp similarity index 100% rename from src/wayland/shell_integration.hpp rename to src/wayland/wlr_layershell/shell_integration.hpp diff --git a/src/wayland/layer_surface.cpp b/src/wayland/wlr_layershell/surface.cpp similarity index 98% rename from src/wayland/layer_surface.cpp rename to src/wayland/wlr_layershell/surface.cpp index 777a38f6..4da24510 100644 --- a/src/wayland/layer_surface.cpp +++ b/src/wayland/wlr_layershell/surface.cpp @@ -1,4 +1,4 @@ -#include "layer_surface.hpp" +#include "surface.hpp" #include #include @@ -12,9 +12,9 @@ #include #include -#include "../core/panelinterface.hpp" -#include "layershell.hpp" +#include "../../core/panelinterface.hpp" #include "shell_integration.hpp" +#include "window.hpp" // clang-format off [[nodiscard]] QtWayland::zwlr_layer_shell_v1::layer toWaylandLayer(const Layer::Enum& layer) noexcept; diff --git a/src/wayland/layer_surface.hpp b/src/wayland/wlr_layershell/surface.hpp similarity index 98% rename from src/wayland/layer_surface.hpp rename to src/wayland/wlr_layershell/surface.hpp index 2518e74b..beb86a55 100644 --- a/src/wayland/layer_surface.hpp +++ b/src/wayland/wlr_layershell/surface.hpp @@ -7,8 +7,8 @@ #include #include -#include "layershell.hpp" #include "shell_integration.hpp" +#include "window.hpp" class QSWaylandLayerSurface : public QtWaylandClient::QWaylandShellSurface diff --git a/src/wayland/layershell.cpp b/src/wayland/wlr_layershell/window.cpp similarity index 97% rename from src/wayland/layershell.cpp rename to src/wayland/wlr_layershell/window.cpp index 1fa9711a..7c51aa92 100644 --- a/src/wayland/layershell.cpp +++ b/src/wayland/wlr_layershell/window.cpp @@ -1,4 +1,4 @@ -#include "layershell.hpp" +#include "window.hpp" #include #include @@ -9,9 +9,9 @@ #include #include -#include "../core/panelinterface.hpp" -#include "layer_surface.hpp" +#include "../../core/panelinterface.hpp" #include "shell_integration.hpp" +#include "surface.hpp" LayershellWindowExtension* LayershellWindowExtension::get(QWindow* window) { auto v = window->property("layershell_ext"); diff --git a/src/wayland/layershell.hpp b/src/wayland/wlr_layershell/window.hpp similarity index 98% rename from src/wayland/layershell.hpp rename to src/wayland/wlr_layershell/window.hpp index 5ff1c62b..73c3f4f8 100644 --- a/src/wayland/layershell.hpp +++ b/src/wayland/wlr_layershell/window.hpp @@ -6,7 +6,7 @@ #include #include -#include "../core/panelinterface.hpp" +#include "../../core/panelinterface.hpp" namespace Layer { // NOLINT Q_NAMESPACE; diff --git a/src/wayland/wl-proto/wlr-layer-shell-unstable-v1.xml b/src/wayland/wlr_layershell/wlr-layer-shell-unstable-v1.xml similarity index 100% rename from src/wayland/wl-proto/wlr-layer-shell-unstable-v1.xml rename to src/wayland/wlr_layershell/wlr-layer-shell-unstable-v1.xml