mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-26 14:23:09 +00:00
64 lines
2.6 KiB
C++
64 lines
2.6 KiB
C++
// SPDX-FileCopyrightText: 2023 Devin Lin <devin@kde.org>
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#include "lockscreendbusclient.h"
|
|
|
|
#include <QDBusConnection>
|
|
#include <QDBusMessage>
|
|
#include <QDBusReply>
|
|
#include <QTimer>
|
|
|
|
LockscreenDBusClient::LockscreenDBusClient(QObject *parent)
|
|
: QObject{parent}
|
|
{
|
|
QDBusMessage request = QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.ScreenSaver"),
|
|
QStringLiteral("/ScreenSaver"),
|
|
QStringLiteral("org.freedesktop.ScreenSaver"),
|
|
QStringLiteral("GetActive"));
|
|
|
|
const QDBusReply<bool> response = QDBusConnection::sessionBus().call(request);
|
|
|
|
QDBusConnection::sessionBus().callWithCallback(request, this, SLOT(slotLockscreenActiveChanged(bool)), SLOT(dbusError(QDBusError)));
|
|
|
|
QDBusConnection::sessionBus().connect(QStringLiteral("org.freedesktop.ScreenSaver"),
|
|
QStringLiteral("/ScreenSaver"),
|
|
QStringLiteral("org.freedesktop.ScreenSaver"),
|
|
QStringLiteral("ActiveChanged"),
|
|
this,
|
|
SLOT(slotLockscreenActiveChanged(bool)));
|
|
}
|
|
|
|
bool LockscreenDBusClient::lockscreenActive() const
|
|
{
|
|
return m_lockscreenActive;
|
|
}
|
|
|
|
void LockscreenDBusClient::lockScreen()
|
|
{
|
|
QDBusMessage request = QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.ScreenSaver"),
|
|
QStringLiteral("/ScreenSaver"),
|
|
QStringLiteral("org.freedesktop.ScreenSaver"),
|
|
QStringLiteral("Lock"));
|
|
QDBusConnection::sessionBus().call(request);
|
|
}
|
|
|
|
void LockscreenDBusClient::slotLockscreenActiveChanged(bool active)
|
|
{
|
|
if (active != m_lockscreenActive) {
|
|
m_lockscreenActive = active;
|
|
|
|
Q_EMIT lockscreenActiveChanged();
|
|
|
|
// we don't want to trigger a lockscreen changing signal for the first property fetch (in constructor),
|
|
// since it's just getting the current state
|
|
if (m_firstPropertySet) {
|
|
m_lockscreenActive ? Q_EMIT lockscreenLocked() : Q_EMIT lockscreenUnlocked();
|
|
}
|
|
m_firstPropertySet = true;
|
|
}
|
|
}
|
|
|
|
void LockscreenDBusClient::dbusError(QDBusError error)
|
|
{
|
|
qDebug() << "Error fetching lockscreen state using DBus:" << error.message();
|
|
}
|