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

View file

@ -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

View file

@ -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);

View file

@ -246,7 +246,7 @@ void Application::createWorkspace()
void Application::createInput()
{
#if KWIN_BUILD_SCREENLOCKER
ScreenLockerWatcher::create(this);
m_screenLockerWatcher = std::make_unique<ScreenLockerWatcher>();
#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

View file

@ -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<PluginManager> m_pluginManager;
std::unique_ptr<InputMethod> m_inputMethod;
std::unique_ptr<ColorManager> m_colorManager;
#if KWIN_BUILD_SCREENLOCKER
std::unique_ptr<ScreenLockerWatcher> m_screenLockerWatcher;
#endif
};
inline static Application *kwinApp()

View file

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

View file

@ -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;
}
}

View file

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