summaryrefslogtreecommitdiff
path: root/plugin/src/Caelestia/Internal/sleepnotifier.cpp
diff options
context:
space:
mode:
authorSoramane <61896496+soramanew@users.noreply.github.com>2025-09-26 14:35:54 +1000
committerSoramane <61896496+soramanew@users.noreply.github.com>2025-09-26 14:35:54 +1000
commitdc986c00aa441f555e86449ccd044e24fa56a33a (patch)
tree11d54c955084fd9fc898ce0c27c167f31a672154 /plugin/src/Caelestia/Internal/sleepnotifier.cpp
parentnix: add clazy to devshell (diff)
downloadcaelestia-shell-dc986c00aa441f555e86449ccd044e24fa56a33a.tar.gz
caelestia-shell-dc986c00aa441f555e86449ccd044e24fa56a33a.tar.bz2
caelestia-shell-dc986c00aa441f555e86449ccd044e24fa56a33a.zip
plugin: add sleep notifier
Lock before sleep
Diffstat (limited to 'plugin/src/Caelestia/Internal/sleepnotifier.cpp')
-rw-r--r--plugin/src/Caelestia/Internal/sleepnotifier.cpp32
1 files changed, 32 insertions, 0 deletions
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 <QtDBus/qdbusconnection.h>
+#include <QtDBus/qdbuserror.h>
+
+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