plugin: add sleep notifier
Lock before sleep
This commit is contained in:
parent
39f52d73f9
commit
dc986c00aa
7 changed files with 70 additions and 3 deletions
|
|
@ -280,6 +280,7 @@ default, you must create it manually.
|
||||||
"criticalLevel": 3
|
"criticalLevel": 3
|
||||||
},
|
},
|
||||||
"idle": {
|
"idle": {
|
||||||
|
"lockBeforeSleep": true,
|
||||||
"inhibitWhenAudio": true,
|
"inhibitWhenAudio": true,
|
||||||
"timeouts": [
|
"timeouts": [
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ JsonObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
component Idle: JsonObject {
|
component Idle: JsonObject {
|
||||||
|
property bool lockBeforeSleep: true
|
||||||
property bool inhibitWhenAudio: true
|
property bool inhibitWhenAudio: true
|
||||||
property list<var> timeouts: [
|
property list<var> timeouts: [
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ pragma ComponentBehavior: Bound
|
||||||
import "lock"
|
import "lock"
|
||||||
import qs.config
|
import qs.config
|
||||||
import qs.services
|
import qs.services
|
||||||
|
import Caelestia.Internal
|
||||||
import Quickshell
|
import Quickshell
|
||||||
import Quickshell.Wayland
|
import Quickshell.Wayland
|
||||||
|
|
||||||
|
|
@ -17,15 +18,22 @@ Scope {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (action === "lock")
|
if (action === "lock")
|
||||||
root.lock.lock.locked = true;
|
lock.lock.locked = true;
|
||||||
else if (action === "unlock")
|
else if (action === "unlock")
|
||||||
root.lock.lock.locked = false;
|
lock.lock.locked = false;
|
||||||
else if (typeof action === "string")
|
else if (typeof action === "string")
|
||||||
Hypr.dispatch(action);
|
Hypr.dispatch(action);
|
||||||
else
|
else
|
||||||
Quickshell.execDetached(action);
|
Quickshell.execDetached(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SleepNotifier {
|
||||||
|
onAboutToSleep: {
|
||||||
|
if (Config.general.idle.lockBeforeSleep)
|
||||||
|
root.lock.lock.locked = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Variants {
|
Variants {
|
||||||
model: Config.general.idle.timeouts
|
model: Config.general.idle.timeouts
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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)
|
find_package(PkgConfig REQUIRED)
|
||||||
pkg_check_modules(Qalculate IMPORTED_TARGET libqalculate REQUIRED)
|
pkg_check_modules(Qalculate IMPORTED_TARGET libqalculate REQUIRED)
|
||||||
pkg_check_modules(Pipewire IMPORTED_TARGET libpipewire-0.3 REQUIRED)
|
pkg_check_modules(Pipewire IMPORTED_TARGET libpipewire-0.3 REQUIRED)
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,11 @@ qml_module(caelestia-internal
|
||||||
circularindicatormanager.hpp circularindicatormanager.cpp
|
circularindicatormanager.hpp circularindicatormanager.cpp
|
||||||
hyprdevices.hpp hyprdevices.cpp
|
hyprdevices.hpp hyprdevices.cpp
|
||||||
hyprextras.hpp hyprextras.cpp
|
hyprextras.hpp hyprextras.cpp
|
||||||
|
sleepnotifier.hpp sleepnotifier.cpp
|
||||||
LIBRARIES
|
LIBRARIES
|
||||||
Qt::Gui
|
Qt::Gui
|
||||||
Qt::Quick
|
Qt::Quick
|
||||||
Qt::Concurrent
|
Qt::Concurrent
|
||||||
Qt::Network
|
Qt::Network
|
||||||
|
Qt::DBus
|
||||||
)
|
)
|
||||||
|
|
|
||||||
32
plugin/src/Caelestia/Internal/sleepnotifier.cpp
Normal file
32
plugin/src/Caelestia/Internal/sleepnotifier.cpp
Normal file
|
|
@ -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
|
||||||
23
plugin/src/Caelestia/Internal/sleepnotifier.hpp
Normal file
23
plugin/src/Caelestia/Internal/sleepnotifier.hpp
Normal file
|
|
@ -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
|
||||||
Loading…
Add table
Reference in a new issue