waybar: Improve keepawake module

Improved display - can be always-on, with toggling idle management
on-and-off on a click.
This commit is contained in:
Marty Oehme 2025-06-13 12:24:02 +02:00
parent 8e7aaef291
commit 75fcc025f9
Signed by: Marty
GPG key ID: 4E535BC19C61886E
2 changed files with 25 additions and 6 deletions

View file

@ -1,18 +1,18 @@
{
"layer": "top",
"modules-left": ["river/tags", "custom/events", "custom/vidl", "river/window"],
"modules-center": ["clock", "custom/media", "custom/keepawake"],
"modules-right": ["river/mode", "custom/wireguard", "custom/archupdates", "pulseaudio", "backlight", "network", "cpu", "memory", "temperature", "tray", "battery"],
"modules-center": ["clock", "custom/media"],
"modules-right": ["river/mode", "custom/keepawake", "custom/wireguard", "custom/archupdates", "pulseaudio", "backlight", "network", "cpu", "memory", "temperature", "tray", "battery"],
"custom/keepawake": {
"format": "{icon}",
"format-alt": "{} {icon}",
"format-alt-click": "click-right",
"format-icons": {
"idle-disabled": "󰅶 ",
"idle-enabled": ""
"idle-disabled": "󰾫 ",
"idle-enabled": "󰅶 "
},
"exec": "~/.config/waybar/modules/keepawake",
"on-click": "SVDIR=~/.local/state/service sv start swayidle",
"on-click": "~/.config/waybar/modules/keepawake toggle",
"return-type": "json",
"interval": 5
},

View file

@ -1,7 +1,26 @@
#!/usr/bin/env sh
USER_SV_DIR="$HOME/.local/state/service"
cmd="${1}"
if [ "$cmd" != "" ]; then
pid=$(pgrep -x swayidle)
status="idle-disabled"
if [ "$pid" != "" ]; then
status="idle-enabled"
fi
if [ "$cmd" = "start" ] || [ "$cmd" = "toggle" ] && [ "$status" = "idle-disabled" ]; then
SVDIR="$USER_SV_DIR" sv start swayidle
elif [ "$cmd" = "stop" ] || [ "$cmd" = "toggle" ] && [ "$status" = "idle-enabled" ]; then
SVDIR="$USER_SV_DIR" sv stop swayidle
fi
fi
pid=$(pgrep -x swayidle)
status="idle-disabled"
if pgrep -x swayidle >/dev/null; then
if [ "$pid" != "" ]; then
status="idle-enabled"
fi