diff --git a/changelog/next.md b/changelog/next.md index fbd1c02..3e76558 100644 --- a/changelog/next.md +++ b/changelog/next.md @@ -4,3 +4,4 @@ - Fixed crashes when attempting to create or modify session locks reentrantly. - Fixed networking state breaking after restarting NetworkManager. - Fixed accessibility information not being provided for Quickshell windows. +- Fixed `WlSessionLockSurface.screen` being null and never updating with a real screen on monitor plug. diff --git a/src/core/qmlglobal.cpp b/src/core/qmlglobal.cpp index 0bee314..14991be 100644 --- a/src/core/qmlglobal.cpp +++ b/src/core/qmlglobal.cpp @@ -88,6 +88,8 @@ QuickshellTracked::QuickshellTracked() { } } +// FIXME: Some callers can potentially pass a freed QScreen here which is why we don't init a new one. +// The QuickshellTracked::init() in launch.cpp makes sure our screenAdded handler runs first for now. QuickshellScreenInfo* QuickshellTracked::screenInfo(QScreen* screen) const { for (auto* info: this->screens) { if (info->screen == screen) return info; @@ -96,13 +98,19 @@ QuickshellScreenInfo* QuickshellTracked::screenInfo(QScreen* screen) const { return nullptr; } +namespace { +static QuickshellTracked* qsTrackedInstance = nullptr; // NOLINT +} + +void QuickshellTracked::init() { + if (qsTrackedInstance) qFatal() << "Tried to reinitialize QuickshellTracked"; + qsTrackedInstance = new QuickshellTracked(); + QJSEngine::setObjectOwnership(qsTrackedInstance, QJSEngine::CppOwnership); +} + QuickshellTracked* QuickshellTracked::instance() { - static QuickshellTracked* instance = nullptr; // NOLINT - if (instance == nullptr) { - QJSEngine::setObjectOwnership(instance, QJSEngine::CppOwnership); - instance = new QuickshellTracked(); - } - return instance; + if (!qsTrackedInstance) qFatal() << "Tried to get QuickshellTracked instance before init"; + return qsTrackedInstance; } void QuickshellTracked::updateScreens() { diff --git a/src/core/qmlglobal.hpp b/src/core/qmlglobal.hpp index 2887a93..5fe2aa9 100644 --- a/src/core/qmlglobal.hpp +++ b/src/core/qmlglobal.hpp @@ -70,6 +70,7 @@ public: QVector screens; QuickshellScreenInfo* screenInfo(QScreen* screen) const; + static void init(); static QuickshellTracked* instance(); private slots: diff --git a/src/launch/launch.cpp b/src/launch/launch.cpp index 13e6b27..1edd60c 100644 --- a/src/launch/launch.cpp +++ b/src/launch/launch.cpp @@ -22,6 +22,7 @@ #include "../core/logging.hpp" #include "../core/paths.hpp" #include "../core/plugin.hpp" +#include "../core/qmlglobal.hpp" #include "../core/rootwrapper.hpp" #include "../ipc/ipc.hpp" #include "build.hpp" @@ -299,6 +300,10 @@ int launch(const LaunchArgs& args, char** argv) { QQmlDebuggingEnabler::startTcpDebugServer(args.debugPort, wait); } + // This needs to run early to get the first connection to QGuiApplication::screenAdded() in Qs. + // If we don't do that, attempts to get a QuickshellScreenInfo from a QScreen will fail in screenAdded bindings. + QuickshellTracked::init(); + QsEnginePlugin::initPlugins(); // Base window transparency appears to be additive.