2026-08-03 14:30:55 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
|
|
# Triggered by <Alt><Shift>Right
|
|
|
|
|
# as defined in [org/gnome/settings-daemon/plugins/media-keys]
|
|
|
|
|
# in ~/.config/gnome-settings/key-bindings.ini
|
|
|
|
|
#
|
|
|
|
|
# This script ensures "Night Light" is forced on
|
2026-08-14 20:45:34 +02:00
|
|
|
# or makes the screen a bit warmer than it currently is
|
2026-08-03 14:30:55 +02:00
|
|
|
#
|
|
|
|
|
# The default warmth is restored at login by ~/.local/bin/restore-gnome
|
|
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# GNOME's GUI lets one choose between 1700 and 4700 only,
|
|
|
|
|
# and 6500 is the point where no color correction is applied at all
|
|
|
|
|
# while 1000 is the absolute minimum supported by the OS
|
|
|
|
|
_MIN_TEMPERATURE=1200
|
|
|
|
|
_MAX_TEMPERATURE=4700
|
|
|
|
|
|
2026-08-14 20:45:34 +02:00
|
|
|
_DEFAULT_TEMPERATURE=2200
|
|
|
|
|
|
2026-08-03 14:30:55 +02:00
|
|
|
|
|
|
|
|
notify() {
|
|
|
|
|
ID_FILE="${XDG_RUNTIME_DIR}/night-light-notification-id"
|
|
|
|
|
_id=$(cat "$ID_FILE" 2>/dev/null || true)
|
|
|
|
|
|
|
|
|
|
if [ -n "$_id" ]; then
|
|
|
|
|
notify-send -p -t 5000 --replace-id="$_id" "Night Light" "$1" > "$ID_FILE" || rm -f "$ID_FILE"
|
|
|
|
|
else
|
|
|
|
|
notify-send -p -t 5000 "Night Light" "$1" > "$ID_FILE" || rm -f "$ID_FILE"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Schema=org.gnome.settings-daemon.plugins.color
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
active=$(gdbus call --session \
|
|
|
|
|
--dest org.gnome.SettingsDaemon.Color \
|
|
|
|
|
--object-path /org/gnome/SettingsDaemon/Color \
|
|
|
|
|
--method org.freedesktop.DBus.Properties.Get \
|
|
|
|
|
org.gnome.SettingsDaemon.Color NightLightActive)
|
|
|
|
|
|
2026-08-14 20:45:34 +02:00
|
|
|
applied=$(gdbus call --session \
|
|
|
|
|
--dest org.gnome.SettingsDaemon.Color \
|
|
|
|
|
--object-path /org/gnome/SettingsDaemon/Color \
|
|
|
|
|
--method org.freedesktop.DBus.Properties.Get \
|
|
|
|
|
org.gnome.SettingsDaemon.Color Temperature \
|
|
|
|
|
| sed -E 's/.*uint32 ([0-9]+).*/\1/')
|
2026-08-03 14:30:55 +02:00
|
|
|
|
2026-08-14 20:45:34 +02:00
|
|
|
automatic=$(gsettings get $Schema night-light-schedule-automatic)
|
|
|
|
|
current=$(gsettings get $Schema night-light-temperature | awk '{print $2}')
|
2026-08-03 14:30:55 +02:00
|
|
|
|
|
|
|
|
|
2026-08-14 20:45:34 +02:00
|
|
|
if [ "$active" = "(<true>,)" ] \
|
|
|
|
|
&& { [ "$automatic" = "false" ] || [ $((applied - current)) -le 300 ]; }; then
|
|
|
|
|
at_target=true
|
|
|
|
|
else
|
|
|
|
|
at_target=false
|
2026-08-03 14:30:55 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
2026-08-14 20:45:34 +02:00
|
|
|
# Step only if the screen already shows the target tint
|
|
|
|
|
# while off or ramping in, forcing on below provides the warming already
|
|
|
|
|
if [ "$at_target" = "true" ]; then
|
|
|
|
|
|
|
|
|
|
# 500 = (4700 - 1700 + 500) / 7
|
|
|
|
|
# => Seven steps spanning more than the range in the GUI,
|
|
|
|
|
# mainly because we want to allow a bit more warmth (i.e., +500)
|
|
|
|
|
new=$((current - 500))
|
|
|
|
|
|
|
|
|
|
if [ "$new" -lt $_MIN_TEMPERATURE ]; then
|
|
|
|
|
new=$_MIN_TEMPERATURE
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
gsettings set $Schema night-light-temperature "uint32 $new"
|
|
|
|
|
|
|
|
|
|
# Untinted and parked at a cool target
|
|
|
|
|
# => Forcing on would barely show otherwise
|
|
|
|
|
elif [ "$active" = "(<false>,)" ] && [ "$current" -gt $_DEFAULT_TEMPERATURE ]; then
|
|
|
|
|
|
|
|
|
|
gsettings set $Schema night-light-temperature "uint32 $_DEFAULT_TEMPERATURE"
|
|
|
|
|
|
|
|
|
|
fi
|
2026-08-03 14:30:55 +02:00
|
|
|
|
|
|
|
|
|
2026-08-14 20:45:34 +02:00
|
|
|
# Always force "Night Light" on, saving a <Control><Alt>n call,
|
2026-08-03 14:30:55 +02:00
|
|
|
# with the same settings as in ~/.local/bin/night-light-toggle-schedule
|
2026-08-14 20:45:34 +02:00
|
|
|
if [ "$active" = "(<false>,)" ] || [ "$automatic" = "true" ]; then
|
2026-08-03 14:30:55 +02:00
|
|
|
gsettings set $Schema night-light-enabled true
|
|
|
|
|
gsettings set $Schema night-light-schedule-automatic false
|
|
|
|
|
gsettings set $Schema night-light-schedule-from 0.0
|
|
|
|
|
gsettings set $Schema night-light-schedule-to 24.0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
2026-08-14 20:45:34 +02:00
|
|
|
# Notify only if the press produced no visible change
|
|
|
|
|
# (i.e., already at the minimum and not just snapped to full warmth by the force)
|
|
|
|
|
if [ "$at_target" = "true" ] && [ "$current" -le $_MIN_TEMPERATURE ]; then
|
|
|
|
|
notify "is already as warm as it gets (${_MIN_TEMPERATURE}K)"
|
2026-08-03 14:30:55 +02:00
|
|
|
fi
|