diff options
Diffstat (limited to 'plugin/src/Caelestia/Internal')
| -rw-r--r-- | plugin/src/Caelestia/Internal/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | plugin/src/Caelestia/Internal/sleepnotifier.cpp | 32 | ||||
| -rw-r--r-- | plugin/src/Caelestia/Internal/sleepnotifier.hpp | 23 |
3 files changed, 57 insertions, 0 deletions
diff --git a/plugin/src/Caelestia/Internal/CMakeLists.txt b/plugin/src/Caelestia/Internal/CMakeLists.txt index 96538b8..3a49d5a 100644 --- a/plugin/src/Caelestia/Internal/CMakeLists.txt +++ b/plugin/src/Caelestia/Internal/CMakeLists.txt @@ -5,9 +5,11 @@ qml_module(caelestia-internal circularindicatormanager.hpp circularindicatormanager.cpp hyprdevices.hpp hyprdevices.cpp hyprextras.hpp hyprextras.cpp + sleepnotifier.hpp sleepnotifier.cpp LIBRARIES Qt::Gui Qt::Quick Qt::Concurrent Qt::Network + Qt::DBus ) 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 diff --git a/plugin/src/Caelestia/Internal/sleepnotifier.hpp b/plugin/src/Caelestia/Internal/sleepnotifier.hpp new file mode 100644 index 0000000..aaa6c68 --- /dev/null +++ b/plugin/src/Caelestia/Internal/sleepnotifier.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include <qobject.h> +#include <qqmlintegration.h> + +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 |