From 3789709820fc7212d269ec6a8af18544743e7d27 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Sat, 9 Mar 2024 02:39:15 -0800 Subject: [PATCH] screens: make screen list changes not recreate QuickshellScreenInfos Fixes Variants recreating windows on existing screens and causing flickering. --- src/core/qmlglobal.cpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/core/qmlglobal.cpp b/src/core/qmlglobal.cpp index 99f25631..fc452171 100644 --- a/src/core/qmlglobal.cpp +++ b/src/core/qmlglobal.cpp @@ -120,17 +120,31 @@ void QuickshellGlobal::setWatchFiles(bool watchFiles) { // NOLINT void QuickshellGlobal::updateScreens() { auto screens = QGuiApplication::screens(); - this->mScreens.resize(screens.size()); + auto newScreens = QList(); - for (auto i = 0; i < screens.size(); i++) { - if (this->mScreens[i] != nullptr) { - this->mScreens[i]->screen = nullptr; - this->mScreens[i]->setParent(nullptr); // delete if not owned by the js engine + for (auto* newScreen: screens) { + for (auto i = 0; i < this->mScreens.length(); i++) { + auto* oldScreen = this->mScreens[i]; + if (newScreen == oldScreen->screen) { + newScreens.push_back(oldScreen); + this->mScreens.remove(i); + goto next; + } } - this->mScreens[i] = new QuickshellScreenInfo(this, screens[i]); + { + auto* si = new QuickshellScreenInfo(this, newScreen); + QQmlEngine::setObjectOwnership(si, QQmlEngine::CppOwnership); + newScreens.push_back(si); + } + next:; } + for (auto* oldScreen: this->mScreens) { + oldScreen->deleteLater(); + } + + this->mScreens = newScreens; emit this->screensChanged(); }