From a361930865cde56b3001f5205e672e3dab141324 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Sun, 18 Feb 2024 19:23:20 -0800 Subject: [PATCH] feat: expose ProxyWindowBase.screen --- src/cpp/layershell.cpp | 34 ---------------------------------- src/cpp/layershell.hpp | 11 ----------- src/cpp/proxywindow.cpp | 34 ++++++++++++++++++++++++++++++++++ src/cpp/proxywindow.hpp | 11 +++++++++++ 4 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/cpp/layershell.cpp b/src/cpp/layershell.cpp index 922f7427..9a4a99ec 100644 --- a/src/cpp/layershell.cpp +++ b/src/cpp/layershell.cpp @@ -12,10 +12,8 @@ #include #include "proxywindow.hpp" -#include "qmlscreen.hpp" void ProxyShellWindow::setupWindow() { - QObject::connect(this->window, &QWindow::screenChanged, this, &ProxyShellWindow::screenChanged); this->shellWindow = LayerShellQt::Window::get(this->window); this->ProxyWindowBase::setupWindow(); @@ -32,7 +30,6 @@ void ProxyShellWindow::setupWindow() { QObject::connect(this, &ProxyShellWindow::marginsChanged, this, &ProxyShellWindow::updateExclusionZone); // clang-format on - this->window->setScreen(this->mScreen); this->setAnchors(this->mAnchors); this->setMargins(this->mMargins); this->setExclusionMode(this->mExclusionMode); // also sets exclusion zone @@ -64,37 +61,6 @@ void ProxyShellWindow::setHeight(qint32 height) { if (!anchors.mTop || !anchors.mBottom) this->ProxyWindowBase::setHeight(height); } -void ProxyShellWindow::setScreen(QuickShellScreenInfo* screen) { - if (this->mScreen != nullptr) { - QObject::disconnect(this->mScreen, nullptr, this, nullptr); - } - - auto* qscreen = screen == nullptr ? nullptr : screen->screen; - if (qscreen != nullptr) { - QObject::connect(qscreen, &QObject::destroyed, this, &ProxyShellWindow::onScreenDestroyed); - } - - if (this->window == nullptr) this->mScreen = qscreen; - else this->window->setScreen(qscreen); -} - -void ProxyShellWindow::onScreenDestroyed() { this->mScreen = nullptr; } - -QuickShellScreenInfo* ProxyShellWindow::screen() const { - QScreen* qscreen = nullptr; - - if (this->window == nullptr) { - if (this->mScreen != nullptr) qscreen = this->mScreen; - } else { - qscreen = this->window->screen(); - } - - return new QuickShellScreenInfo( - const_cast(this), // NOLINT - qscreen - ); -} - void ProxyShellWindow::setAnchors(Anchors anchors) { if (this->window == nullptr) { this->mAnchors = anchors; diff --git a/src/cpp/layershell.hpp b/src/cpp/layershell.hpp index 8aeeaee1..182dabf9 100644 --- a/src/cpp/layershell.hpp +++ b/src/cpp/layershell.hpp @@ -12,7 +12,6 @@ #include #include "proxywindow.hpp" -#include "qmlscreen.hpp" class Anchors { Q_GADGET; @@ -134,10 +133,6 @@ Q_ENUM_NS(Enum); class ProxyShellWindow: public ProxyWindowBase { // clang-format off Q_OBJECT; - /// The screen that the shell window currently occupies. - /// - /// > [!INFO] This cannot be changed while the shell window is visible. - Q_PROPERTY(QuickShellScreenInfo* screen READ screen WRITE setScreen NOTIFY screenChanged); /// Anchors attach a shell window to the sides of the screen. /// By default all anchors are disabled to avoid blocking the entire screen due to a misconfiguration. /// @@ -175,9 +170,6 @@ public: void setHeight(qint32 height) override; - void setScreen(QuickShellScreenInfo* screen); - [[nodiscard]] QuickShellScreenInfo* screen() const; - void setAnchors(Anchors anchors); [[nodiscard]] Anchors anchors() const; @@ -203,7 +195,6 @@ public: [[nodiscard]] ScreenConfiguration::Enum screenConfiguration() const; signals: - void screenChanged(); void anchorsChanged(); void marginsChanged(); void exclusionZoneChanged(); @@ -213,11 +204,9 @@ signals: private slots: void updateExclusionZone(); - void onScreenDestroyed(); private: LayerShellQt::Window* shellWindow = nullptr; - QScreen* mScreen = nullptr; ExclusionMode::Enum mExclusionMode = ExclusionMode::Normal; qint32 mExclusionZone = 0; Anchors mAnchors; diff --git a/src/cpp/proxywindow.cpp b/src/cpp/proxywindow.cpp index 53ddbe8d..b06717c3 100644 --- a/src/cpp/proxywindow.cpp +++ b/src/cpp/proxywindow.cpp @@ -9,6 +9,7 @@ #include #include +#include "qmlscreen.hpp" #include "region.hpp" #include "reload.hpp" @@ -53,6 +54,7 @@ void ProxyWindowBase::setupWindow() { QObject::connect(this->window, &QWindow::visibilityChanged, this, &ProxyWindowBase::visibleChanged); QObject::connect(this->window, &QWindow::widthChanged, this, &ProxyWindowBase::widthChanged); QObject::connect(this->window, &QWindow::heightChanged, this, &ProxyWindowBase::heightChanged); + QObject::connect(this->window, &QWindow::screenChanged, this, &ProxyWindowBase::screenChanged); QObject::connect(this->window, &QQuickWindow::colorChanged, this, &ProxyWindowBase::colorChanged); QObject::connect(this, &ProxyWindowBase::maskChanged, this, &ProxyWindowBase::onMaskChanged); @@ -60,6 +62,7 @@ void ProxyWindowBase::setupWindow() { QObject::connect(this, &ProxyWindowBase::heightChanged, this, &ProxyWindowBase::onMaskChanged); // clang-format on + this->window->setScreen(this->mScreen); this->setWidth(this->mWidth); this->setHeight(this->mHeight); this->setColor(this->mColor); @@ -115,6 +118,37 @@ void ProxyWindowBase::setHeight(qint32 height) { } else this->window->setHeight(height); } +void ProxyWindowBase::setScreen(QuickShellScreenInfo* screen) { + if (this->mScreen != nullptr) { + QObject::disconnect(this->mScreen, nullptr, this, nullptr); + } + + auto* qscreen = screen == nullptr ? nullptr : screen->screen; + if (qscreen != nullptr) { + QObject::connect(qscreen, &QObject::destroyed, this, &ProxyWindowBase::onScreenDestroyed); + } + + if (this->window == nullptr) this->mScreen = qscreen; + else this->window->setScreen(qscreen); +} + +void ProxyWindowBase::onScreenDestroyed() { this->mScreen = nullptr; } + +QuickShellScreenInfo* ProxyWindowBase::screen() const { + QScreen* qscreen = nullptr; + + if (this->window == nullptr) { + if (this->mScreen != nullptr) qscreen = this->mScreen; + } else { + qscreen = this->window->screen(); + } + + return new QuickShellScreenInfo( + const_cast(this), // NOLINT + qscreen + ); +} + QColor ProxyWindowBase::color() const { if (this->window == nullptr) return this->mColor; else return this->window->color(); diff --git a/src/cpp/proxywindow.hpp b/src/cpp/proxywindow.hpp index c2e08d9a..e28311ef 100644 --- a/src/cpp/proxywindow.hpp +++ b/src/cpp/proxywindow.hpp @@ -12,6 +12,7 @@ #include #include +#include "qmlscreen.hpp" #include "region.hpp" #include "reload.hpp" @@ -38,6 +39,10 @@ class ProxyWindowBase: public Reloadable { Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged); Q_PROPERTY(qint32 width READ width WRITE setWidth NOTIFY widthChanged); Q_PROPERTY(qint32 height READ height WRITE setHeight NOTIFY heightChanged); + /// The screen that the window currently occupies. + /// + /// > [!INFO] This cannot be changed while the window is visible. + Q_PROPERTY(QuickShellScreenInfo* screen READ screen WRITE setScreen NOTIFY screenChanged); /// The background color of the window. Defaults to white. /// /// > [!WARNING] This seems to behave weirdly when using transparent colors on some systems. @@ -129,6 +134,9 @@ public: [[nodiscard]] virtual qint32 height() const; virtual void setHeight(qint32 height); + virtual void setScreen(QuickShellScreenInfo* screen); + [[nodiscard]] QuickShellScreenInfo* screen() const; + [[nodiscard]] QColor color() const; void setColor(QColor color); @@ -142,6 +150,7 @@ signals: void visibleChanged(); void widthChanged(); void heightChanged(); + void screenChanged(); void colorChanged(); void maskChanged(); @@ -149,11 +158,13 @@ private slots: void onMaskChanged(); void onWidthChanged(); void onHeightChanged(); + void onScreenDestroyed(); protected: bool mVisible = true; qint32 mWidth = 100; qint32 mHeight = 100; + QScreen* mScreen = nullptr; QColor mColor = Qt::white; PendingRegion* mMask = nullptr; QQuickWindow* window = nullptr;