Compare commits
3 commits
a35d3f9584
...
3789709820
Author | SHA1 | Date | |
---|---|---|---|
3789709820 | |||
15cd78e30c | |||
fc93591cab |
5 changed files with 53 additions and 6 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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:;
|
||||
|
|
|
@ -53,4 +53,5 @@ private:
|
|||
QQmlComponent* mComponent = nullptr;
|
||||
QVariantList mVariants;
|
||||
AwfulMap<QVariantMap, QObject*> instances;
|
||||
bool loaded = false;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue