caffeine persist

This commit is contained in:
Benjamin Palko 2025-08-25 22:11:04 -04:00
parent 705465e7b1
commit 97c40a7302
2 changed files with 34 additions and 13 deletions

View file

@ -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"]
}
}

31
services/Caffeine.qml Normal file
View file

@ -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"]
}
}