Commit 76fbffb4 authored by Xaver Hugl's avatar Xaver Hugl
Browse files

screenlockerwatcher: move singleton to Application

parent 497a78b7
Pipeline #212076 passed with stage
in 28 minutes and 4 seconds
......@@ -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;
}
}
......
......@@ -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
......
......@@ -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);
......
......@@ -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
......@@ -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()
......
......@@ -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()));
......
......@@ -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;
}
}
......@@ -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)
};
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment