2026-08-03 14:30:55 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
|
|
# Triggered by <Alt><Shift>n
|
|
|
|
|
# as defined in [org/gnome/settings-daemon/plugins/media-keys]
|
|
|
|
|
# in ~/.config/gnome-settings/key-bindings.ini
|
|
|
|
|
#
|
|
|
|
|
# See ~/.local/bin/night-light-toggle-schedule
|
|
|
|
|
# for the other half of the toggling logic
|
|
|
|
|
# and extensive documentation
|
|
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [ "$(gsettings get $Schema night-light-enabled)" = "true" ]; then
|
|
|
|
|
|
|
|
|
|
active_before=$(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)
|
|
|
|
|
|
|
|
|
|
gsettings set $Schema night-light-enabled false
|
|
|
|
|
|
|
|
|
|
if [ "$active_before" = "(<false>,)" ]; then
|
|
|
|
|
notify "is now disabled, but the screen was not tinted anyways"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
|
|
gsettings set $Schema night-light-enabled true
|
|
|
|
|
|
|
|
|
|
# We could start from our default warmth, as defined
|
|
|
|
|
# in [org/gnome/settings-daemon/plugins/color]
|
|
|
|
|
# in ~/.config/gnome-settings/misc.ini
|
2026-08-14 20:45:34 +02:00
|
|
|
# but choose not to do that because this is meant to be
|
|
|
|
|
# a plain on/off switch with no side effects
|
|
|
|
|
# => Snapping is left to <Alt><Shift>Right, which is about
|
|
|
|
|
# warmth rather than about the feature being on or off
|
|
|
|
|
#
|
|
|
|
|
# _DEFAULT_TEMPERATURE=2200
|
|
|
|
|
# current=$(gsettings get $Schema night-light-temperature | awk '{print $2}')
|
|
|
|
|
#
|
|
|
|
|
# if [ "$current" -gt $_DEFAULT_TEMPERATURE ]; then
|
|
|
|
|
# gsettings set $Schema night-light-temperature "uint32 $_DEFAULT_TEMPERATURE"
|
|
|
|
|
# fi
|
2026-08-03 14:30:55 +02:00
|
|
|
|
|
|
|
|
# Give the settings daemon a moment to recompute "NightLightActive"
|
|
|
|
|
sleep 0.1
|
|
|
|
|
|
|
|
|
|
active_after=$(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)
|
|
|
|
|
|
|
|
|
|
if [ "$active_after" = "(<false>,)" ]; then
|
|
|
|
|
notify "is now enabled, but the schedule keeps it off for now"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
fi
|