[waybar] Rework nightlight

This commit is contained in:
Tibo De Peuter 2025-11-08 21:49:03 +01:00
parent c6c570dc1c
commit 8923862edc
Signed by: tdpeuter
GPG key ID: 38297DE43F75FFE2
6 changed files with 105 additions and 23 deletions

View file

@ -1,15 +0,0 @@
#!/usr/bin/env bash
# Script to disable for an hour or immediately continue wlsunset. 'Toggle'
# Check if wlsunset is still running
pid=$(pgrep wlsunset)
if [[ -z ${pid} ]] ; then
# Start wlsunset right away.
wlsunset -l 50.50 -L 4.00 -t 3000 -T 6500 &
else
# Currently stop wlsunset but restart in an hour.
kill ${pid}
notify-send 'Stopping sunset' 'Restarting in an hour'
at now +1 hours -f "${0}"
fi

44
scripts/toggle-nightlight.sh Executable file
View file

@ -0,0 +1,44 @@
#!/usr/bin/env bash
# Script to disable for an hour or immediately continue wlsunset. 'Toggle'
# Get current state
pid=$(pgrep wlsunset)
while getopts ":g" option; do
case "${option}" in
g)
if [[ -z "${pid}" ]]; then
state='active'
tooltip='Turn off nightlight'
class='activated'
else
state='inactive'
tooltip='Turn on nightlight'
class='none'
fi
printf '{"alt": "%s", "tooltip": "%s", "class": "%s" }' \
"${state}" "${tooltip}" "${class}"
exit 0
;;
*)
echo 'Invalid option'
exit 1
;;
esac
done
# Toggle
if [[ -z ${pid} ]] ; then
if [ "$( command -v wlsunset )" ]; then
notify-send 'Starting nightlight' --app-name='twm'
wlsunset -l 50.50 -L 4.00 -t 3000 -T 6500 &
else
notify-send 'Nightlight is not available'
exit 1
fi
else
# Currently stop wlsunset but restart in an hour.
kill ${pid}
notify-send 'Stopping sunset' 'Restarting in an hour'
at now +1 hours -f "${0}"
fi