From 1cd5b0ba1d6104d254a418fce280b7f3b2aa17fa Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Mon, 23 Jun 2025 01:34:10 +0200 Subject: [PATCH] battery: add auto suspend --- .config/quickshell/modules/common/ConfigOptions.qml | 3 ++- .config/quickshell/services/Battery.qml | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.config/quickshell/modules/common/ConfigOptions.qml b/.config/quickshell/modules/common/ConfigOptions.qml index 241fcecf1..bd9c85522 100644 --- a/.config/quickshell/modules/common/ConfigOptions.qml +++ b/.config/quickshell/modules/common/ConfigOptions.qml @@ -77,7 +77,8 @@ Singleton { property QtObject battery: QtObject { property int low: 20 property int critical: 5 - property int suspend: 2 + property bool automaticSuspend: true + property int suspend: 3 } property QtObject dock: QtObject { diff --git a/.config/quickshell/services/Battery.qml b/.config/quickshell/services/Battery.qml index b19910d85..e952dab97 100644 --- a/.config/quickshell/services/Battery.qml +++ b/.config/quickshell/services/Battery.qml @@ -12,6 +12,7 @@ Singleton { property bool isCharging: chargeState == UPowerDeviceState.Charging property bool isPluggedIn: isCharging || chargeState == UPowerDeviceState.PendingCharge property real percentage: UPower.displayDevice.percentage + readonly property bool allowAutomaticSuspend: ConfigOptions.battery.automaticSuspend property bool isLow: percentage <= ConfigOptions.battery.low / 100 property bool isCritical: percentage <= ConfigOptions.battery.critical / 100 @@ -19,6 +20,7 @@ Singleton { property bool isLowAndNotCharging: isLow && !isCharging property bool isCriticalAndNotCharging: isCritical && !isCharging + property bool isSuspendingAndNotCharging: allowAutomaticSuspend && isSuspending && !isCharging onIsLowAndNotChargingChanged: { if (available && isLowAndNotCharging) @@ -29,4 +31,10 @@ Singleton { if (available && isCriticalAndNotCharging) Quickshell.execDetached(["bash", "-c", `notify-send "Critically low battery" "🙏 I beg for pleas charg\nAutomatic suspend triggers at ${ConfigOptions.battery.suspend}%" -u critical -a "Shell"`]); } + + onIsSuspendingAndNotChargingChanged: { + if (available && isSuspendingAndNotCharging) { + Quickshell.execDetached(["bash", "-c", `systemctl suspend || loginctl suspend`]); + } + } }