From 76fbffb40b0bdef8e6dd66fb865edd0946497ad2 Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Sun, 31 Jul 2022 14:40:08 +0200 Subject: [PATCH] screenlockerwatcher: move singleton to Application --- autotests/integration/test_helpers.cpp | 12 ++++++------ src/effects.cpp | 6 +++--- src/inputmethod.cpp | 2 +- src/main.cpp | 9 ++++++++- src/main.h | 7 +++++++ src/modifier_only_shortcuts.cpp | 4 ++-- src/screenlockerwatcher.cpp | 15 ++++++--------- src/screenlockerwatcher.h | 10 +++------- 8 files changed, 36 insertions(+), 29 deletions(-) diff --git a/autotests/integration/test_helpers.cpp b/autotests/integration/test_helpers.cpp index 832a7ca355..3c349c0858 100644 --- a/autotests/integration/test_helpers.cpp +++ b/autotests/integration/test_helpers.cpp @@ -917,15 +917,15 @@ bool lockScreen() if (!waylandServer()->isScreenLocked()) { return false; } - if (!ScreenLockerWatcher::self()->isLocked()) { - QSignalSpy lockedSpy(ScreenLockerWatcher::self(), &ScreenLockerWatcher::locked); + if (!kwinApp()->screenLockerWatcher()->isLocked()) { + QSignalSpy lockedSpy(kwinApp()->screenLockerWatcher(), &ScreenLockerWatcher::locked); if (!lockedSpy.isValid()) { return false; } if (!lockedSpy.wait()) { return false; } - if (!ScreenLockerWatcher::self()->isLocked()) { + if (!kwinApp()->screenLockerWatcher()->isLocked()) { return false; } } @@ -953,15 +953,15 @@ bool unlockScreen() if (waylandServer()->isScreenLocked()) { return true; } - if (ScreenLockerWatcher::self()->isLocked()) { - QSignalSpy lockedSpy(ScreenLockerWatcher::self(), &ScreenLockerWatcher::locked); + if (kwinApp()->screenLockerWatcher()->isLocked()) { + QSignalSpy lockedSpy(kwinApp()->screenLockerWatcher(), &ScreenLockerWatcher::locked); if (!lockedSpy.isValid()) { return false; } if (!lockedSpy.wait()) { return false; } - if (ScreenLockerWatcher::self()->isLocked()) { + if (kwinApp()->screenLockerWatcher()->isLocked()) { return false; } } diff --git a/src/effects.cpp b/src/effects.cpp index fc0c3b4524..18d6516853 100644 --- a/src/effects.cpp +++ b/src/effects.cpp @@ -214,8 +214,8 @@ EffectsHandlerImpl::EffectsHandlerImpl(Compositor *compositor, Scene *scene) #endif connect(workspace()->screenEdges(), &ScreenEdges::approaching, this, &EffectsHandler::screenEdgeApproaching); #if KWIN_BUILD_SCREENLOCKER - connect(ScreenLockerWatcher::self(), &ScreenLockerWatcher::locked, this, &EffectsHandler::screenLockingChanged); - connect(ScreenLockerWatcher::self(), &ScreenLockerWatcher::aboutToLock, this, &EffectsHandler::screenAboutToLock); + connect(kwinApp()->screenLockerWatcher(), &ScreenLockerWatcher::locked, this, &EffectsHandler::screenLockingChanged); + connect(kwinApp()->screenLockerWatcher(), &ScreenLockerWatcher::aboutToLock, this, &EffectsHandler::screenAboutToLock); #endif connect(kwinApp(), &Application::x11ConnectionChanged, this, [this]() { @@ -1631,7 +1631,7 @@ QString EffectsHandlerImpl::supportInformation(const QString &name) const bool EffectsHandlerImpl::isScreenLocked() const { #if KWIN_BUILD_SCREENLOCKER - return ScreenLockerWatcher::self()->isLocked(); + return kwinApp()->screenLockerWatcher()->isLocked(); #else return false; #endif diff --git a/src/inputmethod.cpp b/src/inputmethod.cpp index 8f55dec951..c25d5c9f02 100644 --- a/src/inputmethod.cpp +++ b/src/inputmethod.cpp @@ -76,7 +76,7 @@ void InputMethod::init() m_inputMethodCrashes = 0; }); #if KWIN_BUILD_SCREENLOCKER - connect(ScreenLockerWatcher::self(), &ScreenLockerWatcher::aboutToLock, this, &InputMethod::hide); + connect(kwinApp()->screenLockerWatcher(), &ScreenLockerWatcher::aboutToLock, this, &InputMethod::hide); #endif new VirtualKeyboardDBus(this); diff --git a/src/main.cpp b/src/main.cpp index c13ddc85a3..68ae4d7431 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -246,7 +246,7 @@ void Application::createWorkspace() void Application::createInput() { #if KWIN_BUILD_SCREENLOCKER - ScreenLockerWatcher::create(this); + m_screenLockerWatcher = std::make_unique(); #endif auto input = InputRedirection::create(this); input->init(); @@ -576,4 +576,11 @@ ColorManager *Application::colorManager() const return m_colorManager.get(); } +#if KWIN_BUILD_SCREENLOCKER +ScreenLockerWatcher *Application::screenLockerWatcher() const +{ + return m_screenLockerWatcher.get(); +} +#endif + } // namespace diff --git a/src/main.h b/src/main.h index 95a9d44e14..ff11a7ee35 100644 --- a/src/main.h +++ b/src/main.h @@ -33,6 +33,7 @@ class X11EventFilter; class PluginManager; class InputMethod; class ColorManager; +class ScreenLockerWatcher; class XcbEventFilter : public QAbstractNativeEventFilter { @@ -236,6 +237,9 @@ public: PluginManager *pluginManager() const; InputMethod *inputMethod() const; ColorManager *colorManager() const; +#if KWIN_BUILD_SCREENLOCKER + ScreenLockerWatcher *screenLockerWatcher() const; +#endif Q_SIGNALS: void x11ConnectionChanged(); @@ -295,6 +299,9 @@ private: std::unique_ptr m_pluginManager; std::unique_ptr m_inputMethod; std::unique_ptr m_colorManager; +#if KWIN_BUILD_SCREENLOCKER + std::unique_ptr m_screenLockerWatcher; +#endif }; inline static Application *kwinApp() diff --git a/src/modifier_only_shortcuts.cpp b/src/modifier_only_shortcuts.cpp index 1820ffcdff..32c8a85d9c 100644 --- a/src/modifier_only_shortcuts.cpp +++ b/src/modifier_only_shortcuts.cpp @@ -30,7 +30,7 @@ ModifierOnlyShortcuts::ModifierOnlyShortcuts() , InputEventSpy() { #if KWIN_BUILD_SCREENLOCKER - connect(ScreenLockerWatcher::self(), &ScreenLockerWatcher::locked, this, &ModifierOnlyShortcuts::reset); + connect(kwinApp()->screenLockerWatcher(), &ScreenLockerWatcher::locked, this, &ModifierOnlyShortcuts::reset); #endif } @@ -46,7 +46,7 @@ void ModifierOnlyShortcuts::keyEvent(KeyEvent *event) m_pressedKeys.insert(event->nativeScanCode()); if (wasEmpty && m_pressedKeys.size() == 1 && #if KWIN_BUILD_SCREENLOCKER - !ScreenLockerWatcher::self()->isLocked() && + !kwinApp()->screenLockerWatcher()->isLocked() && #endif m_pressedButtons == Qt::NoButton && m_cachedMods == Qt::NoModifier) { m_modifier = Qt::KeyboardModifier(int(event->modifiersRelevantForGlobalShortcuts())); diff --git a/src/screenlockerwatcher.cpp b/src/screenlockerwatcher.cpp index 42fd71d69f..03fc16546a 100644 --- a/src/screenlockerwatcher.cpp +++ b/src/screenlockerwatcher.cpp @@ -16,13 +16,10 @@ namespace KWin { -KWIN_SINGLETON_FACTORY(ScreenLockerWatcher) - static const QString SCREEN_LOCKER_SERVICE_NAME = QStringLiteral("org.freedesktop.ScreenSaver"); -ScreenLockerWatcher::ScreenLockerWatcher(QObject *parent) - : QObject(parent) - , m_serviceWatcher(new QDBusServiceWatcher(this)) +ScreenLockerWatcher::ScreenLockerWatcher() + : m_serviceWatcher(new QDBusServiceWatcher(this)) , m_locked(false) { if (waylandServer() && waylandServer()->hasScreenLockerIntegration()) { @@ -32,10 +29,6 @@ ScreenLockerWatcher::ScreenLockerWatcher(QObject *parent) } } -ScreenLockerWatcher::~ScreenLockerWatcher() -{ -} - void ScreenLockerWatcher::initialize() { connect(m_serviceWatcher, &QDBusServiceWatcher::serviceOwnerChanged, this, &ScreenLockerWatcher::serviceOwnerChanged); @@ -88,4 +81,8 @@ void ScreenLockerWatcher::setLocked(bool activated) Q_EMIT locked(m_locked); } +bool ScreenLockerWatcher::isLocked() const +{ + return m_locked; +} } diff --git a/src/screenlockerwatcher.h b/src/screenlockerwatcher.h index 7b8da1685d..f1b5129164 100644 --- a/src/screenlockerwatcher.h +++ b/src/screenlockerwatcher.h @@ -25,11 +25,9 @@ class KWIN_EXPORT ScreenLockerWatcher : public QObject { Q_OBJECT public: - ~ScreenLockerWatcher() override; - bool isLocked() const - { - return m_locked; - } + explicit ScreenLockerWatcher(); + + bool isLocked() const; Q_SIGNALS: void locked(bool locked); void aboutToLock(); @@ -45,8 +43,6 @@ private: OrgKdeScreensaverInterface *m_kdeInterface = nullptr; QDBusServiceWatcher *m_serviceWatcher; bool m_locked; - - KWIN_SINGLETON(ScreenLockerWatcher) }; }