Files
omarchycn/bin/omarchy-toggle-nightlight
T
David Heinemeier HanssonandClaude Fable 5 ba91bad3a4 Move Night Light onto a first-party nightlight service
Same treatment as Stay Awake: the indicator polled the toggle CLI over
a Process with a timer to paper over the race after clicking, and the
CLI ended by asking the shell to refresh every indicator over IPC. A new
omarchy.nightlight service owns hyprsunset instead - it probes the
temperature on startup, applies changes itself for in-shell toggles, and
answers on the nightlight IPC target. The indicator becomes a plain
binding. The CLI still drives hyprctl directly so keybindings, the menu,
and ssh work without the shell, but now just nudges the service to
re-probe since hyprsunset has no state file to watch.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-21 15:26:20 -07:00

53 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
# omarchy:summary=Toggle nightlight screen temperature
# omarchy:args=[--status]
# omarchy:examples=omarchy toggle nightlight
ON_TEMP=4000
OFF_TEMP=6500
IDENTITY_TEMP=6000
current_temp() {
local output
output=$(hyprctl hyprsunset temperature 2>/dev/null) || return
grep -oE '[0-9]+' <<<"$output" | head -n1
}
status_json() {
local temp enabled
temp=$(current_temp)
if [[ -n $temp ]] && (( temp < IDENTITY_TEMP )); then
enabled=true
else
enabled=false
fi
jq -cn --argjson enabled "$enabled" --arg temp "$temp" \
'{enabled:$enabled, temperature:(($temp | tonumber?) // null)}'
}
if [[ ${1:-} == "--status" ]]; then
status_json
exit 0
fi
# Ensure hyprsunset is running
if ! pgrep -x hyprsunset >/dev/null; then
setsid uwsm-app -- hyprsunset &
sleep 1 # Give it time to register
fi
# Query the current temperature
CURRENT_TEMP=$(current_temp)
if [[ -z $CURRENT_TEMP || $CURRENT_TEMP == $OFF_TEMP ]]; then
hyprctl hyprsunset temperature $ON_TEMP
else
hyprctl hyprsunset temperature $OFF_TEMP
fi
omarchy-shell -q nightlight refresh