diff options
| author | Soramane <61896496+soramanew@users.noreply.github.com> | 2025-09-26 14:35:54 +1000 |
|---|---|---|
| committer | Soramane <61896496+soramanew@users.noreply.github.com> | 2025-09-26 14:35:54 +1000 |
| commit | dc986c00aa441f555e86449ccd044e24fa56a33a (patch) | |
| tree | 11d54c955084fd9fc898ce0c27c167f31a672154 | |
| parent | nix: add clazy to devshell (diff) | |
| download | caelestia-shell-dc986c00aa441f555e86449ccd044e24fa56a33a.tar.gz caelestia-shell-dc986c00aa441f555e86449ccd044e24fa56a33a.tar.bz2 caelestia-shell-dc986c00aa441f555e86449ccd044e24fa56a33a.zip | |
plugin: add sleep notifier
Lock before sleep
| -rw-r--r-- | README.md | 1 | ||||
| -rw-r--r-- | config/GeneralConfig.qml | 1 | ||||
| -rw-r--r-- | modules/IdleMonitors.qml | 12 | ||||
| -rw-r--r-- | plugin/src/Caelestia/CMakeLists.txt | 2 | ||||
| -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 |
7 files changed, 70 insertions, 3 deletions
@@ -280,6 +280,7 @@ default, you must create it manually. "criticalLevel": 3 }, "idle": { + "lockBeforeSleep": true, "inhibitWhenAudio": true, "timeouts": [ { diff --git a/config/GeneralConfig.qml b/config/GeneralConfig.qml index d53364b..eecca01 100644 --- a/config/GeneralConfig.qml +++ b/config/GeneralConfig.qml @@ -13,6 +13,7 @@ JsonObject { } component Idle: JsonObject { + property bool lockBeforeSleep: true property bool inhibitWhenAudio: true property list<var> timeouts: [ { diff --git a/modules/IdleMonitors.qml b/modules/IdleMonitors.qml index 3e98bc5..a3179e3 100644 --- a/modules/IdleMonitors.qml +++ b/modules/IdleMonitors.qml @@ -3,6 +3,7 @@ pragma ComponentBehavior: Bound import "lock" import qs.config import qs.services +import Caelestia.Internal import Quickshell import Quickshell.Wayland @@ -17,15 +18,22 @@ Scope { return; if (action === "lock") - root.lock.lock.locked = true; + lock.lock.locked = true; else if (action === "unlock") - root.lock.lock.locked = false; + lock.lock.locked = false; else if (typeof action === "string") Hypr.dispatch(action); else Quickshell.execDetached(action); } + SleepNotifier { + onAboutToSleep: { + if (Config.general.idle.lockBeforeSleep) + root.lock.lock.locked = true; + } + } + Variants { model: Config.general.idle.timeouts diff --git a/plugin/src/Caelestia/CMakeLists.txt b/plugin/src/Caelestia/CMakeLists.txt index d344ef7..18c7315 100644 --- a/plugin/src/Caelestia/CMakeLists.txt +++ b/plugin/src/Caelestia/CMakeLists.txt @@ -1,4 +1,4 @@ -find_package(Qt6 REQUIRED COMPONENTS Core Qml Gui Quick Concurrent Sql Network) +find_package(Qt6 REQUIRED COMPONENTS Core Qml Gui Quick Concurrent Sql Network DBus) find_package(PkgConfig REQUIRED) pkg_check_modules(Qalculate IMPORTED_TARGET libqalculate REQUIRED) pkg_check_modules(Pipewire IMPORTED_TARGET libpipewire-0.3 REQUIRED) 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 |