refactor: move wlr_layershell to its own subdirectory

This commit is contained in:
outfoxxed 2024-02-26 03:13:55 -08:00
parent 4ae7ff8c72
commit cfd9a27619
Signed by untrusted user: outfoxxed
GPG key ID: 4C88A185FB89301E
13 changed files with 95 additions and 79 deletions

View file

@ -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) find_package(PkgConfig REQUIRED)
pkg_check_modules(wayland REQUIRED IMPORTED_TARGET wayland-client wayland-protocols) pkg_check_modules(wayland REQUIRED IMPORTED_TARGET wayland-client wayland-protocols)
find_package(Qt6 REQUIRED COMPONENTS WaylandClient) 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 # wayland protocols
if (DEFINED ENV{QTWAYLANDSCANNER}) if (DEFINED ENV{QTWAYLANDSCANNER})
@ -45,20 +28,33 @@ execute_process(
message(STATUS "Found wayland-protocols at ${WAYLAND_PROTOCOLS_DIR}") message(STATUS "Found wayland-protocols at ${WAYLAND_PROTOCOLS_DIR}")
set(PROTO_SRC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/wl-proto) function (wl_proto target name path)
set(PROTO_BUILD_PATH ${CMAKE_CURRENT_BINARY_DIR}/wl-proto) set(PROTO_BUILD_PATH ${CMAKE_CURRENT_BINARY_DIR}/wl-proto/${name})
make_directory(${PROTO_BUILD_PATH}) 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} 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 ${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-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) 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(${target} 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}/qwayland-${name}.cpp)
target_include_directories(${target} PRIVATE ${PROTO_BUILD_PATH})
endfunction() 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)

View file

@ -2,7 +2,7 @@
#include <qqml.h> #include <qqml.h>
#include "../core/plugin.hpp" #include "../core/plugin.hpp"
#include "waylandlayershell.hpp" #include "wlr_layershell.hpp"
namespace { 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 // 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 // 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. // the QML_ELMENT module import the old register-type style module.
qmlRegisterModuleImport(
"Quickshell.Wayland",
QQmlModuleImportModuleAny,
"Quickshell.Wayland._WlrLayerShell",
QQmlModuleImportLatest
);
qmlRegisterModuleImport( qmlRegisterModuleImport(
"Quickshell", "Quickshell",
QQmlModuleImportModuleAny, QQmlModuleImportModuleAny,

View file

@ -1,7 +1,7 @@
name = "Quickshell.Wayland" name = "Quickshell.Wayland"
description = "Wayland specific Quickshell types" description = "Wayland specific Quickshell types"
headers = [ headers = [
"layershell.hpp", "wlr_layershell/window.hpp",
"waylandlayershell.hpp", "wlr_layershell.hpp",
] ]
----- -----

View file

@ -1,4 +1,4 @@
#include "waylandlayershell.hpp" #include "wlr_layershell.hpp"
#include <utility> #include <utility>
#include <qlogging.h> #include <qlogging.h>
@ -12,14 +12,14 @@
#include "../core/panelinterface.hpp" #include "../core/panelinterface.hpp"
#include "../core/proxywindow.hpp" #include "../core/proxywindow.hpp"
#include "../core/qmlscreen.hpp" #include "../core/qmlscreen.hpp"
#include "layershell.hpp" #include "wlr_layershell/window.hpp"
WaylandLayershell::WaylandLayershell(QObject* parent) WlrLayershell::WlrLayershell(QObject* parent)
: ProxyWindowBase(parent) : ProxyWindowBase(parent)
, ext(new LayershellWindowExtension(this)) {} , ext(new LayershellWindowExtension(this)) {}
QQuickWindow* WaylandLayershell::createWindow(QObject* oldInstance) { QQuickWindow* WlrLayershell::createWindow(QObject* oldInstance) {
auto* old = qobject_cast<WaylandLayershell*>(oldInstance); auto* old = qobject_cast<WlrLayershell*>(oldInstance);
QQuickWindow* window = nullptr; QQuickWindow* window = nullptr;
if (old == nullptr || old->window == nullptr) { if (old == nullptr || old->window == nullptr) {
@ -43,25 +43,25 @@ QQuickWindow* WaylandLayershell::createWindow(QObject* oldInstance) {
return window; return window;
} }
void WaylandLayershell::setupWindow() { void WlrLayershell::setupWindow() {
this->ProxyWindowBase::setupWindow(); this->ProxyWindowBase::setupWindow();
// clang-format off // clang-format off
QObject::connect(this->ext, &LayershellWindowExtension::layerChanged, this, &WaylandLayershell::layerChanged); QObject::connect(this->ext, &LayershellWindowExtension::layerChanged, this, &WlrLayershell::layerChanged);
QObject::connect(this->ext, &LayershellWindowExtension::keyboardFocusChanged, this, &WaylandLayershell::keyboardFocusChanged); QObject::connect(this->ext, &LayershellWindowExtension::keyboardFocusChanged, this, &WlrLayershell::keyboardFocusChanged);
QObject::connect(this->ext, &LayershellWindowExtension::anchorsChanged, this, &WaylandLayershell::anchorsChanged); QObject::connect(this->ext, &LayershellWindowExtension::anchorsChanged, this, &WlrLayershell::anchorsChanged);
QObject::connect(this->ext, &LayershellWindowExtension::exclusiveZoneChanged, this, &WaylandLayershell::exclusiveZoneChanged); QObject::connect(this->ext, &LayershellWindowExtension::exclusiveZoneChanged, this, &WlrLayershell::exclusiveZoneChanged);
QObject::connect(this->ext, &LayershellWindowExtension::marginsChanged, this, &WaylandLayershell::marginsChanged); QObject::connect(this->ext, &LayershellWindowExtension::marginsChanged, this, &WlrLayershell::marginsChanged);
QObject::connect(this, &ProxyWindowBase::widthChanged, this, &WaylandLayershell::updateAutoExclusion); QObject::connect(this, &ProxyWindowBase::widthChanged, this, &WlrLayershell::updateAutoExclusion);
QObject::connect(this, &ProxyWindowBase::heightChanged, this, &WaylandLayershell::updateAutoExclusion); QObject::connect(this, &ProxyWindowBase::heightChanged, this, &WlrLayershell::updateAutoExclusion);
QObject::connect(this, &WaylandLayershell::anchorsChanged, this, &WaylandLayershell::updateAutoExclusion); QObject::connect(this, &WlrLayershell::anchorsChanged, this, &WlrLayershell::updateAutoExclusion);
// clang-format on // clang-format on
this->updateAutoExclusion(); this->updateAutoExclusion();
} }
void WaylandLayershell::setWidth(qint32 width) { void WlrLayershell::setWidth(qint32 width) {
this->mWidth = width; this->mWidth = width;
// only update the actual size if not blocked by anchors // 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; this->mHeight = height;
// only update the actual size if not blocked by anchors // 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->ProxyWindowBase::setScreen(screen);
this->ext->setUseWindowScreen(screen != nullptr); this->ext->setUseWindowScreen(screen != nullptr);
} }
// NOLINTBEGIN // NOLINTBEGIN
#define extPair(type, get, set) \ #define extPair(type, get, set) \
type WaylandLayershell::get() const { return this->ext->get(); } \ type WlrLayershell::get() const { return this->ext->get(); } \
void WaylandLayershell::set(type value) { this->ext->set(value); } void WlrLayershell::set(type value) { this->ext->set(value); }
extPair(Layer::Enum, layer, setLayer); extPair(Layer::Enum, layer, setLayer);
extPair(KeyboardFocus::Enum, keyboardFocus, setKeyboardFocus); extPair(KeyboardFocus::Enum, keyboardFocus, setKeyboardFocus);
extPair(Margins, margins, setMargins); extPair(Margins, margins, setMargins);
// NOLINTEND // 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); this->ext->setAnchors(anchors);
// explicitly set width values are tracked so the entire screen isn't covered if an anchor is removed. // 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); 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)); this->ext->setNamespace(std::move(ns));
emit this->namespaceChanged(); 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->mExclusiveZone = exclusiveZone;
this->setExclusionMode(ExclusionMode::Normal); this->setExclusionMode(ExclusionMode::Normal);
this->ext->setExclusiveZone(exclusiveZone); 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; this->mExclusionMode = exclusionMode;
if (exclusionMode == this->mExclusionMode) return; 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(); const auto anchors = this->anchors();
auto zone = 0; auto zone = 0;
@ -144,13 +144,13 @@ void WaylandLayershell::setAutoExclusion() {
this->ext->setExclusiveZone(zone); this->ext->setExclusiveZone(zone);
} }
void WaylandLayershell::updateAutoExclusion() { void WlrLayershell::updateAutoExclusion() {
if (this->mExclusionMode == ExclusionMode::Auto) { if (this->mExclusionMode == ExclusionMode::Auto) {
this->setAutoExclusion(); this->setAutoExclusion();
} }
} }
WaylandLayershell* WaylandLayershell::qmlAttachedProperties(QObject* object) { WlrLayershell* WlrLayershell::qmlAttachedProperties(QObject* object) {
if (auto* obj = qobject_cast<WaylandPanelInterface*>(object)) { if (auto* obj = qobject_cast<WaylandPanelInterface*>(object)) {
return obj->layer; return obj->layer;
} else { } else {
@ -162,7 +162,7 @@ WaylandLayershell* WaylandLayershell::qmlAttachedProperties(QObject* object) {
WaylandPanelInterface::WaylandPanelInterface(QObject* parent) WaylandPanelInterface::WaylandPanelInterface(QObject* parent)
: PanelWindowInterface(parent) : PanelWindowInterface(parent)
, layer(new WaylandLayershell(this)) { , layer(new WlrLayershell(this)) {
// clang-format off // clang-format off
QObject::connect(this->layer, &ProxyWindowBase::windowConnected, this, &WaylandPanelInterface::windowConnected); 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); QObject::connect(this->layer, &ProxyWindowBase::maskChanged, this, &WaylandPanelInterface::maskChanged);
// panel specific // panel specific
QObject::connect(this->layer, &WaylandLayershell::anchorsChanged, this, &WaylandPanelInterface::anchorsChanged); QObject::connect(this->layer, &WlrLayershell::anchorsChanged, this, &WaylandPanelInterface::anchorsChanged);
QObject::connect(this->layer, &WaylandLayershell::marginsChanged, this, &WaylandPanelInterface::marginsChanged); QObject::connect(this->layer, &WlrLayershell::marginsChanged, this, &WaylandPanelInterface::marginsChanged);
QObject::connect(this->layer, &WaylandLayershell::exclusiveZoneChanged, this, &WaylandPanelInterface::exclusiveZoneChanged); QObject::connect(this->layer, &WlrLayershell::exclusiveZoneChanged, this, &WaylandPanelInterface::exclusiveZoneChanged);
QObject::connect(this->layer, &WaylandLayershell::exclusionModeChanged, this, &WaylandPanelInterface::exclusionModeChanged); QObject::connect(this->layer, &WlrLayershell::exclusionModeChanged, this, &WaylandPanelInterface::exclusionModeChanged);
// clang-format on // clang-format on
} }

View file

@ -9,9 +9,9 @@
#include "../core/doc.hpp" #include "../core/doc.hpp"
#include "../core/proxywindow.hpp" #include "../core/proxywindow.hpp"
#include "layershell.hpp" #include "wlr_layershell/window.hpp"
class WaylandLayershell: public ProxyWindowBase { class WlrLayershell: public ProxyWindowBase {
QSDOC_BASECLASS(PanelWindowInterface); QSDOC_BASECLASS(PanelWindowInterface);
// clang-format off // clang-format off
Q_OBJECT; 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(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(ExclusionMode::Enum exclusionMode READ exclusionMode WRITE setExclusionMode NOTIFY exclusionModeChanged);
QSDOC_HIDE Q_PROPERTY(Margins margins READ margins WRITE setMargins NOTIFY marginsChanged); QSDOC_HIDE Q_PROPERTY(Margins margins READ margins WRITE setMargins NOTIFY marginsChanged);
QML_ATTACHED(WaylandLayershell); QML_ATTACHED(WlrLayershell);
QML_ELEMENT; QML_ELEMENT;
// clang-format on // clang-format on
public: public:
explicit WaylandLayershell(QObject* parent = nullptr); explicit WlrLayershell(QObject* parent = nullptr);
QQuickWindow* createWindow(QObject* oldInstance) override; QQuickWindow* createWindow(QObject* oldInstance) override;
void setupWindow() override; void setupWindow() override;
@ -64,7 +64,7 @@ public:
[[nodiscard]] Margins margins() const; [[nodiscard]] Margins margins() const;
void setMargins(Margins margins); // NOLINT void setMargins(Margins margins); // NOLINT
static WaylandLayershell* qmlAttachedProperties(QObject* object); static WlrLayershell* qmlAttachedProperties(QObject* object);
signals: signals:
void layerChanged(); void layerChanged();
@ -134,7 +134,7 @@ public:
// NOLINTEND // NOLINTEND
private: private:
WaylandLayershell* layer; WlrLayershell* layer;
friend class WaylandLayershell; friend class WlrLayershell;
}; };

View file

@ -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)

View file

@ -4,7 +4,7 @@
#include <private/qwaylandshellsurface_p.h> #include <private/qwaylandshellsurface_p.h>
#include <private/qwaylandwindow_p.h> #include <private/qwaylandwindow_p.h>
#include "layer_surface.hpp" #include "surface.hpp"
#include "wayland-wlr-layer-shell-unstable-v1-client-protocol.h" #include "wayland-wlr-layer-shell-unstable-v1-client-protocol.h"
QSWaylandLayerShellIntegration::QSWaylandLayerShellIntegration() QSWaylandLayerShellIntegration::QSWaylandLayerShellIntegration()

View file

@ -1,4 +1,4 @@
#include "layer_surface.hpp" #include "surface.hpp"
#include <private/qwaylanddisplay_p.h> #include <private/qwaylanddisplay_p.h>
#include <private/qwaylandscreen_p.h> #include <private/qwaylandscreen_p.h>
@ -12,9 +12,9 @@
#include <qtypes.h> #include <qtypes.h>
#include <qwayland-wlr-layer-shell-unstable-v1.h> #include <qwayland-wlr-layer-shell-unstable-v1.h>
#include "../core/panelinterface.hpp" #include "../../core/panelinterface.hpp"
#include "layershell.hpp"
#include "shell_integration.hpp" #include "shell_integration.hpp"
#include "window.hpp"
// clang-format off // clang-format off
[[nodiscard]] QtWayland::zwlr_layer_shell_v1::layer toWaylandLayer(const Layer::Enum& layer) noexcept; [[nodiscard]] QtWayland::zwlr_layer_shell_v1::layer toWaylandLayer(const Layer::Enum& layer) noexcept;

View file

@ -7,8 +7,8 @@
#include <qwayland-wlr-layer-shell-unstable-v1.h> #include <qwayland-wlr-layer-shell-unstable-v1.h>
#include <qwindow.h> #include <qwindow.h>
#include "layershell.hpp"
#include "shell_integration.hpp" #include "shell_integration.hpp"
#include "window.hpp"
class QSWaylandLayerSurface class QSWaylandLayerSurface
: public QtWaylandClient::QWaylandShellSurface : public QtWaylandClient::QWaylandShellSurface

View file

@ -1,4 +1,4 @@
#include "layershell.hpp" #include "window.hpp"
#include <utility> #include <utility>
#include <private/qwaylandwindow_p.h> #include <private/qwaylandwindow_p.h>
@ -9,9 +9,9 @@
#include <qvariant.h> #include <qvariant.h>
#include <qwindow.h> #include <qwindow.h>
#include "../core/panelinterface.hpp" #include "../../core/panelinterface.hpp"
#include "layer_surface.hpp"
#include "shell_integration.hpp" #include "shell_integration.hpp"
#include "surface.hpp"
LayershellWindowExtension* LayershellWindowExtension::get(QWindow* window) { LayershellWindowExtension* LayershellWindowExtension::get(QWindow* window) {
auto v = window->property("layershell_ext"); auto v = window->property("layershell_ext");

View file

@ -6,7 +6,7 @@
#include <qtypes.h> #include <qtypes.h>
#include <qwindow.h> #include <qwindow.h>
#include "../core/panelinterface.hpp" #include "../../core/panelinterface.hpp"
namespace Layer { // NOLINT namespace Layer { // NOLINT
Q_NAMESPACE; Q_NAMESPACE;