From d4dde2c02de48a0a8d89662519f0bf22bdd570e1 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Sat, 27 Sep 2025 15:13:49 +1000 Subject: idlemonitor: handle logind lock/unlock Fixes #705 --- plugin/src/Caelestia/Internal/CMakeLists.txt | 2 +- plugin/src/Caelestia/Internal/logindmanager.cpp | 65 +++++++++++++++++++++++++ plugin/src/Caelestia/Internal/logindmanager.hpp | 27 ++++++++++ plugin/src/Caelestia/Internal/sleepnotifier.cpp | 32 ------------ plugin/src/Caelestia/Internal/sleepnotifier.hpp | 23 --------- 5 files changed, 93 insertions(+), 56 deletions(-) create mode 100644 plugin/src/Caelestia/Internal/logindmanager.cpp create mode 100644 plugin/src/Caelestia/Internal/logindmanager.hpp delete mode 100644 plugin/src/Caelestia/Internal/sleepnotifier.cpp delete mode 100644 plugin/src/Caelestia/Internal/sleepnotifier.hpp (limited to 'plugin/src/Caelestia') diff --git a/plugin/src/Caelestia/Internal/CMakeLists.txt b/plugin/src/Caelestia/Internal/CMakeLists.txt index 3a49d5a..bdc58db 100644 --- a/plugin/src/Caelestia/Internal/CMakeLists.txt +++ b/plugin/src/Caelestia/Internal/CMakeLists.txt @@ -5,7 +5,7 @@ qml_module(caelestia-internal circularindicatormanager.hpp circularindicatormanager.cpp hyprdevices.hpp hyprdevices.cpp hyprextras.hpp hyprextras.cpp - sleepnotifier.hpp sleepnotifier.cpp + logindmanager.hpp logindmanager.cpp LIBRARIES Qt::Gui Qt::Quick diff --git a/plugin/src/Caelestia/Internal/logindmanager.cpp b/plugin/src/Caelestia/Internal/logindmanager.cpp new file mode 100644 index 0000000..4194ee1 --- /dev/null +++ b/plugin/src/Caelestia/Internal/logindmanager.cpp @@ -0,0 +1,65 @@ +#include "logindmanager.hpp" + +#include +#include +#include +#include + +namespace caelestia::internal { + +LogindManager::LogindManager(QObject* parent) + : QObject(parent) { + auto bus = QDBusConnection::systemBus(); + if (!bus.isConnected()) { + qWarning() << "LogindManager::LogindManager: failed to connect to system bus:" << bus.lastError().message(); + return; + } + + bool ok = bus.connect("org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", + "PrepareForSleep", this, SLOT(handlePrepareForSleep(bool))); + + if (!ok) { + qWarning() << "LogindManager::LogindManager: failed to connect to PrepareForSleep signal:" + << bus.lastError().message(); + } + + QDBusInterface login1("org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", bus); + const QDBusReply reply = login1.call("GetSession", "auto"); + if (!reply.isValid()) { + qWarning() << "LogindManager::LogindManager: failed to get session path"; + return; + } + const auto sessionPath = reply.value().path(); + + ok = bus.connect("org.freedesktop.login1", sessionPath, "org.freedesktop.login1.Session", "Lock", this, + SLOT(handleLockRequested())); + + if (!ok) { + qWarning() << "LogindManager::LogindManager: failed to connect to Lock signal:" << bus.lastError().message(); + } + + ok = bus.connect("org.freedesktop.login1", sessionPath, "org.freedesktop.login1.Session", "Unlock", this, + SLOT(handleUnlockRequested())); + + if (!ok) { + qWarning() << "LogindManager::LogindManager: failed to connect to Unlock signal:" << bus.lastError().message(); + } +} + +void LogindManager::handlePrepareForSleep(bool sleep) { + if (sleep) { + emit aboutToSleep(); + } else { + emit resumed(); + } +} + +void LogindManager::handleLockRequested() { + emit lockRequested(); +} + +void LogindManager::handleUnlockRequested() { + emit unlockRequested(); +} + +} // namespace caelestia::internal diff --git a/plugin/src/Caelestia/Internal/logindmanager.hpp b/plugin/src/Caelestia/Internal/logindmanager.hpp new file mode 100644 index 0000000..72a3401 --- /dev/null +++ b/plugin/src/Caelestia/Internal/logindmanager.hpp @@ -0,0 +1,27 @@ +#pragma once + +#include +#include + +namespace caelestia::internal { + +class LogindManager : public QObject { + Q_OBJECT + QML_ELEMENT + +public: + explicit LogindManager(QObject* parent = nullptr); + +signals: + void aboutToSleep(); + void resumed(); + void lockRequested(); + void unlockRequested(); + +private slots: + void handlePrepareForSleep(bool sleep); + void handleLockRequested(); + void handleUnlockRequested(); +}; + +} // namespace caelestia::internal diff --git a/plugin/src/Caelestia/Internal/sleepnotifier.cpp b/plugin/src/Caelestia/Internal/sleepnotifier.cpp deleted file mode 100644 index b730f38..0000000 --- a/plugin/src/Caelestia/Internal/sleepnotifier.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "sleepnotifier.hpp" - -#include -#include - -namespace caelestia::internal { - -SleepNotifier::SleepNotifier(QObject* parent) - : QObject(parent) { - auto bus = QDBusConnection::systemBus(); - if (!bus.isConnected()) { - qWarning() << "SleepNotifier::SleepNotifier: failed to connect to system bus:" << bus.lastError().message(); - return; - } - - const bool ok = bus.connect("org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", - "PrepareForSleep", this, SLOT(handlePrepareForSleep(bool))); - - if (!ok) { - qWarning() << "SleepNotifier::SleepNotifier: failed to connect to dbus:" << bus.lastError().message(); - } -} - -void SleepNotifier::handlePrepareForSleep(bool sleep) { - if (sleep) { - emit aboutToSleep(); - } else { - emit resumed(); - } -} - -} // namespace caelestia::internal diff --git a/plugin/src/Caelestia/Internal/sleepnotifier.hpp b/plugin/src/Caelestia/Internal/sleepnotifier.hpp deleted file mode 100644 index aaa6c68..0000000 --- a/plugin/src/Caelestia/Internal/sleepnotifier.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include -#include - -namespace caelestia::internal { - -class SleepNotifier : public QObject { - Q_OBJECT - QML_ELEMENT - -public: - explicit SleepNotifier(QObject* parent = nullptr); - -signals: - void aboutToSleep(); - void resumed(); - -private slots: - void handlePrepareForSleep(bool sleep); -}; - -} // namespace caelestia::internal -- cgit v1.2.3-freya