Update waybar config

This commit is contained in:
2026-02-18 00:14:12 -08:00
parent 833e4b51b0
commit 44145ecfde
6 changed files with 291 additions and 33 deletions

View File

@ -8,25 +8,19 @@ function is-desktop-p {
! is-laptop-p
}
systemctl --user --quiet is-active swayidle.service \
&& swayidle_state="Enabled" || swayidle_state="Disabled"
# Format: label action condition
local entries=('Select system sound output' 'select-sound-output.sh' 'true'
"Enable or disable system sleep (Current: ${swayidle_state})" 'system-sleep-menu.sh' 'true'
"Enable or disable system sleep" 'system-sleep-menu.sh' 'true'
'Enable or disable TV' 'tv-power-menu.sh' 'is-desktop-p'
'Configure USB device access' 'usbguard-menu.py' 'pgrep usbguard-daemon'
'Power settings (restart and shutdown)' 'system-power-menu.sh' 'true'
'Login to captive portal protected WiFi' 'login-to-wifi.sh' 'is-laptop-p'
# I'm not using eww right now
# 'Restart top bar' 'river-restart-eww.sh' '[[ "${XDG_CURRENT_DESKTOP}" == river ]]'
)
'Login to captive portal protected WiFi' 'login-to-wifi.sh' 'is-laptop-p')
local entry_array=()
local enabled_entries=()
for ((i = 1; i <= ${#entries}; i+=3)); do
if eval "${entries[${i} + 2]}" >/dev/null 2>&1; then
entry_array[$((${i} / 3 + 1))]="${entries[${i}]}"
entry_array[$((i / 3 + 1))]="${entries[i]}"
enabled_entries+=(${entries[@]:${i} - 1:3})
fi
done

View File

@ -1,31 +1,60 @@
#!/usr/bin/env zsh
let is_active=0
systemctl --user --quiet is-active swayidle.service && is_active=1
zmodload zsh/datetime
zmodload zsh/mathfunc
setopt typeset_silent
local swayidle_state
(( is_active )) && swayidle_state='Enabled' || swayidle_state='Disabled'
local TIMES=(1m 5m 10m 15m 30m 1h 2h 4h 1d forever)
choice="$(fuzzel --index -d -p "Cur: ${swayidle_state} > " <<'EOF'
Enable
Disable
EOF
)"
local -a running_locks
(( ${?} != 0 )) && exit
() {
local IFS=$'\n '
running_locks=(${="$("${HOME}/scripts/cl/bin/list-manual-sleep-locks")"})
}
case "${choice}" in
0)
systemctl --user start swayidle.service
;;
1)
systemctl --user stop swayidle.service
;;
esac
let base_time=${EPOCHSECONDS}
for ((i = 2; i <= ${#running_locks}; i+=2)); do
local nsecs="${running_locks[i]}"
if [[ "${nsecs}" == infinity ]]; then
running_locks[i]="next reboot"
else
running_locks[i]=$(strftime -n '%H:%M:%S %b %-e' \
$(( base_time + nsecs )))
fi
done
if [[ "${XDG_CURRENT_DESKTOP}" == 'river' ]]; then
eww -c "${HOME}/.config/river/config/" update swayidle="$(( ! ${choice} ))"
pkill -RTMIN+3 waybar
elif [[ "${XDG_CURRENT_DESKTOP}" == 'Hyprland' ]]; then
pkill -SIGRTMIN+1 waybar
function is_valid_sleep_time() {
[[ "${1}" = forever ]] \
|| [[ "${1}" =~ ' *([0-9]+[smhd]? *)+' ]]
}
if (( ${#running_locks} )); then
# We have existing locks
local prompt plural_s
if (( ${#running_locks} > 2 )); then
let count_locks=$(( int(${#running_locks} / 2) ))
prompt="Locked by ${count_locks} locks until ${running_locks[2]}> "
plural_s='s'
else
prompt="Locked until ${running_locks[2]}> "
fi
local choice
choice="$(printf "Cancel lock${plural_s}\n" \
| fuzzel --dmenu --only-match --index -p "${prompt}")"
if (( ${?} == 0 )) && (( ${choice} == 0 )); then
systemctl --user stop 'manual-inhibit-sleep@*.service'
fi
else
# No locks
local choice
choice="$(printf '%s\n' ${TIMES} | fuzzel -d -p "Inhibit sleep for> ")"
if (( ${?} )); then
exit
elif is_valid_sleep_time "${choice}"; then
[[ "${choice}" == forever ]] && choice=infinity
systemctl --user start "manual-inhibit-sleep@${choice}.service"
else
printf 'Invalid sleep time: %s\n' "${choice}" 1>&2
fi
fi