From 3026d3400a60c1cf28a6c7ae79166f6440649c52 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Wed, 27 Mar 2024 02:43:14 -0700 Subject: [PATCH] all/window: use global screeninfo pool for screen getter --- src/core/proxywindow.cpp | 8 ++++---- src/core/qmlglobal.cpp | 9 +++++++++ src/core/qmlglobal.hpp | 2 ++ src/wayland/session_lock.cpp | 6 ++---- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/core/proxywindow.cpp b/src/core/proxywindow.cpp index f798ed6..285375b 100644 --- a/src/core/proxywindow.cpp +++ b/src/core/proxywindow.cpp @@ -13,6 +13,7 @@ #include #include "generation.hpp" +#include "qmlglobal.hpp" #include "qmlscreen.hpp" #include "region.hpp" #include "reload.hpp" @@ -231,6 +232,8 @@ void ProxyWindowBase::setScreen(QuickshellScreenInfo* screen) { } auto* qscreen = screen == nullptr ? nullptr : screen->screen; + if (qscreen == this->mScreen) return; + if (qscreen != nullptr) { QObject::connect(qscreen, &QObject::destroyed, this, &ProxyWindowBase::onScreenDestroyed); } @@ -257,10 +260,7 @@ QuickshellScreenInfo* ProxyWindowBase::screen() const { qscreen = this->window->screen(); } - return new QuickshellScreenInfo( - const_cast(this), // NOLINT - qscreen - ); + return QuickshellTracked::instance()->screenInfo(qscreen); } QColor ProxyWindowBase::color() const { diff --git a/src/core/qmlglobal.cpp b/src/core/qmlglobal.cpp index 2beee36..70d7b41 100644 --- a/src/core/qmlglobal.cpp +++ b/src/core/qmlglobal.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -73,6 +74,14 @@ QuickshellTracked::QuickshellTracked() { } } +QuickshellScreenInfo* QuickshellTracked::screenInfo(QScreen* screen) const { + for (auto* info: this->screens) { + if (info->screen == screen) return info; + } + + return nullptr; +} + QuickshellTracked* QuickshellTracked::instance() { static QuickshellTracked* instance = nullptr; // NOLINT if (instance == nullptr) { diff --git a/src/core/qmlglobal.hpp b/src/core/qmlglobal.hpp index 8d43bb8..83ef68d 100644 --- a/src/core/qmlglobal.hpp +++ b/src/core/qmlglobal.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -60,6 +61,7 @@ public: QuickshellTracked(); QVector screens; + QuickshellScreenInfo* screenInfo(QScreen* screen) const; static QuickshellTracked* instance(); diff --git a/src/wayland/session_lock.cpp b/src/wayland/session_lock.cpp index 73967c9..a99ed25 100644 --- a/src/wayland/session_lock.cpp +++ b/src/wayland/session_lock.cpp @@ -14,6 +14,7 @@ #include #include +#include "../core/qmlglobal.hpp" #include "../core/qmlscreen.hpp" #include "../core/reload.hpp" #include "session_lock/session_lock.hpp" @@ -243,10 +244,7 @@ QuickshellScreenInfo* WlSessionLockSurface::screen() const { qscreen = this->window->screen(); } - return new QuickshellScreenInfo( - const_cast(this), // NOLINT - qscreen - ); + return QuickshellTracked::instance()->screenInfo(qscreen); } void WlSessionLockSurface::setScreen(QScreen* qscreen) {