From dc986c00aa441f555e86449ccd044e24fa56a33a Mon Sep 17 00:00:00 2001 From: Soramane <61896496+soramanew@users.noreply.github.com> Date: Fri, 26 Sep 2025 14:35:54 +1000 Subject: plugin: add sleep notifier Lock before sleep --- plugin/src/Caelestia/Internal/sleepnotifier.cpp | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 plugin/src/Caelestia/Internal/sleepnotifier.cpp (limited to 'plugin/src/Caelestia/Internal/sleepnotifier.cpp') diff --git a/plugin/src/Caelestia/Internal/sleepnotifier.cpp b/plugin/src/Caelestia/Internal/sleepnotifier.cpp new file mode 100644 index 0000000..b730f38 --- /dev/null +++ b/plugin/src/Caelestia/Internal/sleepnotifier.cpp @@ -0,0 +1,32 @@ +#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 -- cgit v1.2.3-freya