2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2016-08-15 06:16:33 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2013 Martin Gräßlin <mgraesslin@kde.org>
|
2016-08-15 06:16:33 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2016-08-15 06:16:33 +00:00
|
|
|
#include "screenlockerwatcher.h"
|
2016-08-16 07:26:17 +00:00
|
|
|
#include "wayland_server.h"
|
2016-08-15 06:16:33 +00:00
|
|
|
|
|
|
|
// dbus generated
|
2019-06-23 15:59:44 +00:00
|
|
|
#include "kscreenlocker_interface.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
#include "screenlocker_interface.h"
|
2016-08-15 06:16:33 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2016-08-15 06:37:24 +00:00
|
|
|
KWIN_SINGLETON_FACTORY(ScreenLockerWatcher)
|
|
|
|
|
2016-08-15 06:16:33 +00:00
|
|
|
static const QString SCREEN_LOCKER_SERVICE_NAME = QStringLiteral("org.freedesktop.ScreenSaver");
|
|
|
|
|
|
|
|
ScreenLockerWatcher::ScreenLockerWatcher(QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, m_serviceWatcher(new QDBusServiceWatcher(this))
|
|
|
|
, m_locked(false)
|
2016-08-16 07:26:17 +00:00
|
|
|
{
|
|
|
|
if (waylandServer() && waylandServer()->hasScreenLockerIntegration()) {
|
|
|
|
connect(waylandServer(), &WaylandServer::initialized, this, &ScreenLockerWatcher::initialize);
|
|
|
|
} else {
|
|
|
|
initialize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ScreenLockerWatcher::~ScreenLockerWatcher()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenLockerWatcher::initialize()
|
2016-08-15 06:16:33 +00:00
|
|
|
{
|
2020-09-23 18:39:59 +00:00
|
|
|
connect(m_serviceWatcher, &QDBusServiceWatcher::serviceOwnerChanged, this, &ScreenLockerWatcher::serviceOwnerChanged);
|
2016-08-15 06:16:33 +00:00
|
|
|
m_serviceWatcher->setWatchMode(QDBusServiceWatcher::WatchForOwnerChange);
|
|
|
|
m_serviceWatcher->addWatchedService(SCREEN_LOCKER_SERVICE_NAME);
|
2022-03-17 14:05:01 +00:00
|
|
|
|
|
|
|
m_interface = new OrgFreedesktopScreenSaverInterface(SCREEN_LOCKER_SERVICE_NAME, QStringLiteral("/ScreenSaver"), QDBusConnection::sessionBus(), this);
|
|
|
|
m_kdeInterface = new OrgKdeScreensaverInterface(SCREEN_LOCKER_SERVICE_NAME, QStringLiteral("/ScreenSaver"), QDBusConnection::sessionBus(), this);
|
|
|
|
connect(m_interface, &OrgFreedesktopScreenSaverInterface::ActiveChanged,
|
|
|
|
this, &ScreenLockerWatcher::setLocked);
|
|
|
|
connect(m_kdeInterface, &OrgKdeScreensaverInterface::AboutToLock, this, &ScreenLockerWatcher::aboutToLock);
|
|
|
|
|
|
|
|
queryActive();
|
2016-08-15 06:16:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenLockerWatcher::serviceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner)
|
|
|
|
{
|
|
|
|
Q_UNUSED(oldOwner)
|
2022-03-17 14:05:01 +00:00
|
|
|
Q_UNUSED(serviceName)
|
2019-06-23 15:59:44 +00:00
|
|
|
|
2016-08-15 06:16:33 +00:00
|
|
|
m_locked = false;
|
|
|
|
|
2022-03-17 14:05:01 +00:00
|
|
|
if (!newOwner.isEmpty()) {
|
|
|
|
queryActive();
|
2016-08-15 06:16:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-17 14:05:01 +00:00
|
|
|
void ScreenLockerWatcher::queryActive()
|
2016-08-15 06:16:33 +00:00
|
|
|
{
|
2022-03-17 14:05:01 +00:00
|
|
|
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(m_interface->GetActive(), this);
|
|
|
|
connect(watcher, &QDBusPendingCallWatcher::finished,
|
|
|
|
this, &ScreenLockerWatcher::activeQueried);
|
2016-08-15 06:16:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenLockerWatcher::activeQueried(QDBusPendingCallWatcher *watcher)
|
|
|
|
{
|
|
|
|
QDBusPendingReply<bool> reply = *watcher;
|
|
|
|
if (!reply.isError()) {
|
|
|
|
setLocked(reply.value());
|
|
|
|
}
|
|
|
|
watcher->deleteLater();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenLockerWatcher::setLocked(bool activated)
|
|
|
|
{
|
|
|
|
if (m_locked == activated) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_locked = activated;
|
2021-06-08 07:02:14 +00:00
|
|
|
Q_EMIT locked(m_locked);
|
2016-08-15 06:16:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|