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() {
auto screens = QGuiApplication::screens();
this->mScreens.resize(screens.size());
auto newScreens = QList<QuickshellScreenInfo*>();
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();
}