screenlockerwatcher: move singleton to Application

This commit is contained in:
Xaver Hugl 2022-07-31 14:40:08 +02:00
parent 497a78b7cf
commit 76fbffb40b
8 changed files with 36 additions and 29 deletions

View file

@ -917,15 +917,15 @@ bool lockScreen()
if (!waylandServer()->isScreenLocked()) { if (!waylandServer()->isScreenLocked()) {
return false; return false;
} }
if (!ScreenLockerWatcher::self()->isLocked()) { if (!kwinApp()->screenLockerWatcher()->isLocked()) {
QSignalSpy lockedSpy(ScreenLockerWatcher::self(), &ScreenLockerWatcher::locked); QSignalSpy lockedSpy(kwinApp()->screenLockerWatcher(), &ScreenLockerWatcher::locked);
if (!lockedSpy.isValid()) { if (!lockedSpy.isValid()) {
return false; return false;
} }
if (!lockedSpy.wait()) { if (!lockedSpy.wait()) {
return false; return false;
} }
if (!ScreenLockerWatcher::self()->isLocked()) { if (!kwinApp()->screenLockerWatcher()->isLocked()) {
return false; return false;
} }
} }
@ -953,15 +953,15 @@ bool unlockScreen()
if (waylandServer()->isScreenLocked()) { if (waylandServer()->isScreenLocked()) {
return true; return true;
} }
if (ScreenLockerWatcher::self()->isLocked()) { if (kwinApp()->screenLockerWatcher()->isLocked()) {
QSignalSpy lockedSpy(ScreenLockerWatcher::self(), &ScreenLockerWatcher::locked); QSignalSpy lockedSpy(kwinApp()->screenLockerWatcher(), &ScreenLockerWatcher::locked);
if (!lockedSpy.isValid()) { if (!lockedSpy.isValid()) {
return false; return false;
} }
if (!lockedSpy.wait()) { if (!lockedSpy.wait()) {
return false; return false;
} }
if (ScreenLockerWatcher::self()->isLocked()) { if (kwinApp()->screenLockerWatcher()->isLocked()) {
return false; return false;
} }
} }

View file

@ -214,8 +214,8 @@ EffectsHandlerImpl::EffectsHandlerImpl(Compositor *compositor, Scene *scene)
#endif #endif
connect(workspace()->screenEdges(), &ScreenEdges::approaching, this, &EffectsHandler::screenEdgeApproaching); connect(workspace()->screenEdges(), &ScreenEdges::approaching, this, &EffectsHandler::screenEdgeApproaching);
#if KWIN_BUILD_SCREENLOCKER #if KWIN_BUILD_SCREENLOCKER
connect(ScreenLockerWatcher::self(), &ScreenLockerWatcher::locked, this, &EffectsHandler::screenLockingChanged); connect(kwinApp()->screenLockerWatcher(), &ScreenLockerWatcher::locked, this, &EffectsHandler::screenLockingChanged);
connect(ScreenLockerWatcher::self(), &ScreenLockerWatcher::aboutToLock, this, &EffectsHandler::screenAboutToLock); connect(kwinApp()->screenLockerWatcher(), &ScreenLockerWatcher::aboutToLock, this, &EffectsHandler::screenAboutToLock);
#endif #endif
connect(kwinApp(), &Application::x11ConnectionChanged, this, [this]() { connect(kwinApp(), &Application::x11ConnectionChanged, this, [this]() {
@ -1631,7 +1631,7 @@ QString EffectsHandlerImpl::supportInformation(const QString &name) const
bool EffectsHandlerImpl::isScreenLocked() const bool EffectsHandlerImpl::isScreenLocked() const
{ {
#if KWIN_BUILD_SCREENLOCKER #if KWIN_BUILD_SCREENLOCKER
return ScreenLockerWatcher::self()->isLocked(); return kwinApp()->screenLockerWatcher()->isLocked();
#else #else
return false; return false;
#endif #endif

View file

@ -76,7 +76,7 @@ void InputMethod::init()
m_inputMethodCrashes = 0; m_inputMethodCrashes = 0;
}); });
#if KWIN_BUILD_SCREENLOCKER #if KWIN_BUILD_SCREENLOCKER
connect(ScreenLockerWatcher::self(), &ScreenLockerWatcher::aboutToLock, this, &InputMethod::hide); connect(kwinApp()->screenLockerWatcher(), &ScreenLockerWatcher::aboutToLock, this, &InputMethod::hide);
#endif #endif
new VirtualKeyboardDBus(this); new VirtualKeyboardDBus(this);

View file

@ -246,7 +246,7 @@ void Application::createWorkspace()
void Application::createInput() void Application::createInput()
{ {
#if KWIN_BUILD_SCREENLOCKER #if KWIN_BUILD_SCREENLOCKER
ScreenLockerWatcher::create(this); m_screenLockerWatcher = std::make_unique<ScreenLockerWatcher>();
#endif #endif
auto input = InputRedirection::create(this); auto input = InputRedirection::create(this);
input->init(); input->init();
@ -576,4 +576,11 @@ ColorManager *Application::colorManager() const
return m_colorManager.get(); return m_colorManager.get();
} }
#if KWIN_BUILD_SCREENLOCKER
ScreenLockerWatcher *Application::screenLockerWatcher() const
{
return m_screenLockerWatcher.get();
}
#endif
} // namespace } // namespace

View file

@ -33,6 +33,7 @@ class X11EventFilter;
class PluginManager; class PluginManager;
class InputMethod; class InputMethod;
class ColorManager; class ColorManager;
class ScreenLockerWatcher;
class XcbEventFilter : public QAbstractNativeEventFilter class XcbEventFilter : public QAbstractNativeEventFilter
{ {
@ -236,6 +237,9 @@ public:
PluginManager *pluginManager() const; PluginManager *pluginManager() const;
InputMethod *inputMethod() const; InputMethod *inputMethod() const;
ColorManager *colorManager() const; ColorManager *colorManager() const;
#if KWIN_BUILD_SCREENLOCKER
ScreenLockerWatcher *screenLockerWatcher() const;
#endif
Q_SIGNALS: Q_SIGNALS:
void x11ConnectionChanged(); void x11ConnectionChanged();
@ -295,6 +299,9 @@ private:
std::unique_ptr<PluginManager> m_pluginManager; std::unique_ptr<PluginManager> m_pluginManager;
std::unique_ptr<InputMethod> m_inputMethod; std::unique_ptr<InputMethod> m_inputMethod;
std::unique_ptr<ColorManager> m_colorManager; std::unique_ptr<ColorManager> m_colorManager;
#if KWIN_BUILD_SCREENLOCKER
std::unique_ptr<ScreenLockerWatcher> m_screenLockerWatcher;
#endif
}; };
inline static Application *kwinApp() inline static Application *kwinApp()

View file

@ -30,7 +30,7 @@ ModifierOnlyShortcuts::ModifierOnlyShortcuts()
, InputEventSpy() , InputEventSpy()
{ {
#if KWIN_BUILD_SCREENLOCKER #if KWIN_BUILD_SCREENLOCKER
connect(ScreenLockerWatcher::self(), &ScreenLockerWatcher::locked, this, &ModifierOnlyShortcuts::reset); connect(kwinApp()->screenLockerWatcher(), &ScreenLockerWatcher::locked, this, &ModifierOnlyShortcuts::reset);
#endif #endif
} }
@ -46,7 +46,7 @@ void ModifierOnlyShortcuts::keyEvent(KeyEvent *event)
m_pressedKeys.insert(event->nativeScanCode()); m_pressedKeys.insert(event->nativeScanCode());
if (wasEmpty && m_pressedKeys.size() == 1 && if (wasEmpty && m_pressedKeys.size() == 1 &&
#if KWIN_BUILD_SCREENLOCKER #if KWIN_BUILD_SCREENLOCKER
!ScreenLockerWatcher::self()->isLocked() && !kwinApp()->screenLockerWatcher()->isLocked() &&
#endif #endif
m_pressedButtons == Qt::NoButton && m_cachedMods == Qt::NoModifier) { m_pressedButtons == Qt::NoButton && m_cachedMods == Qt::NoModifier) {
m_modifier = Qt::KeyboardModifier(int(event->modifiersRelevantForGlobalShortcuts())); m_modifier = Qt::KeyboardModifier(int(event->modifiersRelevantForGlobalShortcuts()));

View file

@ -16,13 +16,10 @@
namespace KWin namespace KWin
{ {
KWIN_SINGLETON_FACTORY(ScreenLockerWatcher)
static const QString SCREEN_LOCKER_SERVICE_NAME = QStringLiteral("org.freedesktop.ScreenSaver"); static const QString SCREEN_LOCKER_SERVICE_NAME = QStringLiteral("org.freedesktop.ScreenSaver");
ScreenLockerWatcher::ScreenLockerWatcher(QObject *parent) ScreenLockerWatcher::ScreenLockerWatcher()
: QObject(parent) : m_serviceWatcher(new QDBusServiceWatcher(this))
, m_serviceWatcher(new QDBusServiceWatcher(this))
, m_locked(false) , m_locked(false)
{ {
if (waylandServer() && waylandServer()->hasScreenLockerIntegration()) { if (waylandServer() && waylandServer()->hasScreenLockerIntegration()) {
@ -32,10 +29,6 @@ ScreenLockerWatcher::ScreenLockerWatcher(QObject *parent)
} }
} }
ScreenLockerWatcher::~ScreenLockerWatcher()
{
}
void ScreenLockerWatcher::initialize() void ScreenLockerWatcher::initialize()
{ {
connect(m_serviceWatcher, &QDBusServiceWatcher::serviceOwnerChanged, this, &ScreenLockerWatcher::serviceOwnerChanged); connect(m_serviceWatcher, &QDBusServiceWatcher::serviceOwnerChanged, this, &ScreenLockerWatcher::serviceOwnerChanged);
@ -88,4 +81,8 @@ void ScreenLockerWatcher::setLocked(bool activated)
Q_EMIT locked(m_locked); Q_EMIT locked(m_locked);
} }
bool ScreenLockerWatcher::isLocked() const
{
return m_locked;
}
} }

View file

@ -25,11 +25,9 @@ class KWIN_EXPORT ScreenLockerWatcher : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
~ScreenLockerWatcher() override; explicit ScreenLockerWatcher();
bool isLocked() const
{ bool isLocked() const;
return m_locked;
}
Q_SIGNALS: Q_SIGNALS:
void locked(bool locked); void locked(bool locked);
void aboutToLock(); void aboutToLock();
@ -45,8 +43,6 @@ private:
OrgKdeScreensaverInterface *m_kdeInterface = nullptr; OrgKdeScreensaverInterface *m_kdeInterface = nullptr;
QDBusServiceWatcher *m_serviceWatcher; QDBusServiceWatcher *m_serviceWatcher;
bool m_locked; bool m_locked;
KWIN_SINGLETON(ScreenLockerWatcher)
}; };
} }