Compare commits

...

3 commits

Author SHA1 Message Date
3789709820
screens: make screen list changes not recreate QuickshellScreenInfos
Fixes Variants recreating windows on existing screens and causing flickering.
2024-03-09 02:39:15 -08:00
15cd78e30c
screens: add qDebug<< impl to QuickshellScreenInfo 2024-03-09 02:35:48 -08:00
fc93591cab
variants: fix onReload not being called after variant updates 2024-03-09 02:35:07 -08:00
5 changed files with 53 additions and 6 deletions

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();
}

View file

@ -109,3 +109,21 @@ void QuickshellScreenInfo::screenDestroyed() {
this->screen = nullptr;
this->dangling = true;
}
QDebug operator<<(QDebug debug, const QuickshellScreenInfo* screen) {
if (screen == nullptr) {
debug.nospace() << "QuickshellScreenInfo(nullptr)";
return debug;
}
debug.nospace() << screen->metaObject()->className() << '(' << static_cast<const void*>(screen)
<< ", screen=" << screen->screen << ')';
return debug;
}
QString QuickshellScreenInfo::toString() const {
QString str;
QDebug(&str) << this;
return str;
}

View file

@ -1,9 +1,12 @@
#pragma once
#include <qdebug.h>
#include <qnamespace.h>
#include <qobject.h>
#include <qqmlinfo.h>
#include <qqmlintegration.h>
#include <qscreen.h>
#include <qtclasshelpermacros.h>
#include <qtmetamacros.h>
#include <qtypes.h>
@ -55,6 +58,8 @@ public:
[[nodiscard]] Qt::ScreenOrientation orientation() const;
[[nodiscard]] Qt::ScreenOrientation primaryOrientation() const;
[[nodiscard]] Q_INVOKABLE QString toString() const;
QScreen* screen;
private:
@ -71,3 +76,5 @@ signals:
private slots:
void screenDestroyed();
};
QDebug operator<<(QDebug debug, const QuickshellScreenInfo* screen);

View file

@ -46,6 +46,8 @@ void Variants::onReload(QObject* oldInstance) {
if (instance != nullptr) instance->onReload(oldInstance);
else Reloadable::reloadChildrenRecursive(instanceObj, oldInstance);
}
this->loaded = true;
}
void Variants::setVariants(QVariantList variants) {
@ -108,6 +110,11 @@ void Variants::updateVariants() {
instance->setParent(this);
this->instances.insert(variant, instance);
if (this->loaded) {
if (auto* reloadable = qobject_cast<Reloadable*>(instance)) reloadable->onReload(nullptr);
else Reloadable::reloadChildrenRecursive(instance, nullptr);
}
}
outer:;

View file

@ -53,4 +53,5 @@ private:
QQmlComponent* mComponent = nullptr;
QVariantList mVariants;
AwfulMap<QVariantMap, QObject*> instances;
bool loaded = false;
};