screens: make screen list changes not recreate QuickshellScreenInfos

Fixes Variants recreating windows on existing screens and causing flickering.
This commit is contained in:
outfoxxed 2024-03-09 02:39:15 -08:00
parent 15cd78e30c
commit 3789709820
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E

View file

@ -120,17 +120,31 @@ void QuickshellGlobal::setWatchFiles(bool watchFiles) { // NOLINT
void QuickshellGlobal::updateScreens() { void QuickshellGlobal::updateScreens() {
auto screens = QGuiApplication::screens(); auto screens = QGuiApplication::screens();
this->mScreens.resize(screens.size()); auto newScreens = QList<QuickshellScreenInfo*>();
for (auto i = 0; i < screens.size(); i++) { for (auto* newScreen: screens) {
if (this->mScreens[i] != nullptr) { for (auto i = 0; i < this->mScreens.length(); i++) {
this->mScreens[i]->screen = nullptr; auto* oldScreen = this->mScreens[i];
this->mScreens[i]->setParent(nullptr); // delete if not owned by the js engine 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(); emit this->screensChanged();
} }