diff --git a/src/wayland/wlr_layershell.cpp b/src/wayland/wlr_layershell.cpp index 1a338522..a649603c 100644 --- a/src/wayland/wlr_layershell.cpp +++ b/src/wayland/wlr_layershell.cpp @@ -90,8 +90,8 @@ void WlrLayershell::setHeight(qint32 height) { } void WlrLayershell::setScreen(QuickshellScreenInfo* screen) { - this->ProxyWindowBase::setScreen(screen); this->ext->setUseWindowScreen(screen != nullptr); + this->ProxyWindowBase::setScreen(screen); } // NOLINTBEGIN diff --git a/src/window/proxywindow.cpp b/src/window/proxywindow.cpp index f75fc641..8ce80c20 100644 --- a/src/window/proxywindow.cpp +++ b/src/window/proxywindow.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -200,9 +201,6 @@ void ProxyWindowBase::completeWindow() { if (this->mScreen != nullptr && this->window->screen() != this->mScreen) { if (this->window->isVisible()) this->window->setVisible(false); this->window->setScreen(this->mScreen); - } else if (this->mScreen == nullptr) { - this->mScreen = this->window->screen(); - QObject::connect(this->mScreen, &QObject::destroyed, this, &ProxyWindowBase::onScreenDestroyed); } this->setWidth(this->mWidth); @@ -327,39 +325,39 @@ void ProxyWindowBase::setHeight(qint32 height) { void ProxyWindowBase::setScreen(QuickshellScreenInfo* screen) { auto* qscreen = screen == nullptr ? nullptr : screen->screen; - if (qscreen == this->mScreen) return; + auto newMScreen = this->mScreen != qscreen; - if (this->mScreen != nullptr) { + if (this->mScreen && newMScreen) { QObject::disconnect(this->mScreen, nullptr, this, nullptr); } - if (this->window == nullptr) { - emit this->screenChanged(); - } else { - auto reshow = this->isVisibleDirect(); - if (reshow) this->setVisibleDirect(false); - if (this->window != nullptr) this->window->setScreen(qscreen); - if (reshow) this->setVisibleDirect(true); + if (this->qscreen() != qscreen) { + this->mScreen = qscreen; + if (this->window == nullptr) { + emit this->screenChanged(); + } else if (qscreen) { + auto reshow = this->isVisibleDirect(); + if (reshow) this->setVisibleDirect(false); + if (this->window != nullptr) this->window->setScreen(qscreen); + if (reshow) this->setVisibleDirect(true); + } } - if (qscreen) this->mScreen = qscreen; - else this->mScreen = this->window->screen(); - - QObject::connect(this->mScreen, &QObject::destroyed, this, &ProxyWindowBase::onScreenDestroyed); + if (qscreen && newMScreen) { + QObject::connect(this->mScreen, &QObject::destroyed, this, &ProxyWindowBase::onScreenDestroyed); + } } void ProxyWindowBase::onScreenDestroyed() { this->mScreen = nullptr; } +QScreen* ProxyWindowBase::qscreen() const { + if (this->window) return this->window->screen(); + if (this->mScreen) return this->mScreen; + return QGuiApplication::primaryScreen(); +} + QuickshellScreenInfo* ProxyWindowBase::screen() const { - QScreen* qscreen = nullptr; - - if (this->window == nullptr) { - if (this->mScreen != nullptr) qscreen = this->mScreen; - } else { - qscreen = this->window->screen(); - } - - return QuickshellTracked::instance()->screenInfo(qscreen); + return QuickshellTracked::instance()->screenInfo(this->qscreen()); } QColor ProxyWindowBase::color() const { return this->mColor; } diff --git a/src/window/proxywindow.hpp b/src/window/proxywindow.hpp index 6f02e05a..92a85f4f 100644 --- a/src/window/proxywindow.hpp +++ b/src/window/proxywindow.hpp @@ -100,7 +100,8 @@ public: [[nodiscard]] qreal devicePixelRatio() const; - [[nodiscard]] virtual QuickshellScreenInfo* screen() const; + [[nodiscard]] QScreen* qscreen() const; + [[nodiscard]] QuickshellScreenInfo* screen() const; virtual void setScreen(QuickshellScreenInfo* screen); [[nodiscard]] QColor color() const;