Tint the screen at night.

This commit is contained in:
Tom Alexander
2024-07-21 21:48:48 -04:00
parent 3a63d4d307
commit 621625d831
12 changed files with 132 additions and 20 deletions

View File

@@ -63,6 +63,7 @@ tooltip {
#custom-available_memory,
#custom-battery,
#custom-clock,
#custom-night_mode,
#custom-sound,
#custom-temperature,
#idle_inhibitor,

View File

@@ -1,7 +1,7 @@
{
// "height": 10, // Waybar height (to be removed for auto height)
"modules-left": ["sway/workspaces", "sway/mode"],
"modules-right": ["custom/temperature", "custom/sound", "custom/available_memory", "custom/battery", "idle_inhibitor", "custom/clock", "tray"],
"modules-right": ["custom/night_mode", "custom/temperature", "custom/sound", "custom/available_memory", "custom/battery", "idle_inhibitor", "custom/clock", "tray"],
"sway/workspaces": {
"disable-scroll": true
},
@@ -12,7 +12,7 @@
"format": "{icon}",
"format-icons": {
"activated": "☕",//☕
"deactivated": ""//☾☁⛾⛔⏾⌛⏳
"deactivated": "💤"//☾☁⛾⛔⏾⌛⏳💤
}
},
"tray": {
@@ -43,5 +43,11 @@
"exec": "waybar_custom_temperature",
"return-type": "json",
"restart-interval": 30
},
"custom/night_mode": {
"exec": "waybar_night_mode",
"return-type": "json",
"restart-interval": 30,
"on-click": "pkill --signal USR1 -f waybar_night_mode"
}
}

View File

@@ -0,0 +1,93 @@
#!/usr/bin/env bash
#
# Power an icon for tinting the screen at night.
set -euo pipefail
IFS=$'\n\t'
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SLEEP_INTERVAL=${SLEEP_INTERVAL:-30}
# ◓◒●◌◎
# 🟠🟡🟢🟣🟤
# 🟥🟦🟧🟨🟩🟪🟫
# ☀☯⭐🌝🌞⏾
# 🌑🌓🌗🌕
# 👓
############## Setup #########################
function cleanup {
log "Killing child process $wlsunset_pid"
kill "$wlsunset_pid"
true
}
for sig in EXIT INT QUIT HUP TERM; do
trap "set +e; cleanup" "$sig"
done
function die {
local status_code="$1"
shift
(>&2 echo "${@}")
exit "$status_code"
}
function log {
(>&2 echo "${@}")
}
############## Program #########################
function main {
local night_mode_icon night_mode_text night_mode_class
night_mode_mode="auto"
night_mode_class=""
wlsunset -l 40.7 -L -74.0 &
wlsunset_pid=$!
while true; do
if [ "$night_mode_mode" == "auto" ]; then
night_mode_icon="🌗"
night_mode_text="auto"
elif [ "$night_mode_mode" == "on" ]; then
night_mode_icon="🌑"
night_mode_text="night"
elif [ "$night_mode_mode" == "off" ]; then
night_mode_icon="🌕"
night_mode_text="day"
fi
render
sleep "$SLEEP_INTERVAL" &
wait $! || true
done
}
function render {
jq --unbuffered --compact-output <<EOF
{
"text":"${night_mode_icon}",
"tooltip":"${night_mode_text}",
"percentage":100,
"class":"${night_mode_class}"
}
EOF
}
function handle_click {
if [ "$night_mode_mode" == "auto" ]; then
log "Setting night mode to force-day."
night_mode_mode="off"
elif [ "$night_mode_mode" == "on" ]; then
log "Setting night mode to auto."
night_mode_mode="auto"
elif [ "$night_mode_mode" == "off" ]; then
log "Setting night mode to force-night."
night_mode_mode="on"
fi
kill -USR1 "$wlsunset_pid"
}
trap "handle_click" SIGUSR1
main "${@}"