From 97c40a7302c9c2a0aa27d38b3c9c84501de496e9 Mon Sep 17 00:00:00 2001 From: Benjamin Palko Date: Mon, 25 Aug 2025 22:11:04 -0400 Subject: [PATCH] caffeine persist --- modules/bar/components/Caffeine.qml | 16 +++------------ services/Caffeine.qml | 31 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 13 deletions(-) create mode 100644 services/Caffeine.qml diff --git a/modules/bar/components/Caffeine.qml b/modules/bar/components/Caffeine.qml index d97ebd1..dd5588c 100644 --- a/modules/bar/components/Caffeine.qml +++ b/modules/bar/components/Caffeine.qml @@ -1,21 +1,16 @@ import qs.config import qs.constants +import qs.services import qs.widgets -import Quickshell.Io StyledButton { id: root - border.color: process.running ? Theme.palette.secondary : 'transparent' + border.color: Caffeine.enabled ? Theme.palette.secondary : 'transparent' border.width: 2 onClicked: { - if (process.running) { - process.signal(888); - process.running = false; - } else { - process.running = true; - } + Caffeine.toggle(); } content: StyledText { @@ -28,9 +23,4 @@ StyledButton { color: root.containsMouse ? Theme.palette.base300 : Theme.palette.basecontent } - - Process { - id: process - command: ["sh", "-c", "systemd-inhibit --what=idle --who=Caffeine --why='Caffeine module is active' --mode=block sleep inf"] - } } diff --git a/services/Caffeine.qml b/services/Caffeine.qml new file mode 100644 index 0000000..04680b0 --- /dev/null +++ b/services/Caffeine.qml @@ -0,0 +1,31 @@ +pragma Singleton + +import Quickshell +import Quickshell.Io + +Singleton { + + property alias enabled: properties.enabled + + PersistentProperties { + id: properties + reloadableId: "Caffeine" + + property bool enabled: false + } + + function toggle() { + if (properties.enabled) { + process.signal(888); + properties.enabled = false; + } else { + properties.enabled = true; + } + } + + Process { + id: process + running: properties.enabled + command: ["sh", "-c", "systemd-inhibit --what=idle --who=Caffeine --why='Caffeine module is active' --mode=block sleep inf"] + } +}