Add configuration for GNOME
This commit is contained in:
parent
46b9bacd18
commit
7804080953
47 changed files with 6899 additions and 0 deletions
102
.local/bin/night-light-make-warmer
Executable file
102
.local/bin/night-light-make-warmer
Executable file
|
|
@ -0,0 +1,102 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Triggered by <Super><Alt>bracketright
|
||||
# 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
|
||||
# or makes the screen a bit warmer than it currently is
|
||||
#
|
||||
# The default warmth is restored at login by ~/.local/bin/gnome-restore
|
||||
|
||||
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
|
||||
|
||||
_DEFAULT_TEMPERATURE=2200
|
||||
|
||||
|
||||
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)
|
||||
|
||||
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/')
|
||||
|
||||
automatic=$(gsettings get $Schema night-light-schedule-automatic)
|
||||
current=$(gsettings get $Schema night-light-temperature | awk '{print $2}')
|
||||
|
||||
|
||||
if [ "$active" = "(<true>,)" ] \
|
||||
&& { [ "$automatic" = "false" ] || [ $((applied - current)) -le 300 ]; }; then
|
||||
at_target=true
|
||||
else
|
||||
at_target=false
|
||||
fi
|
||||
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
# Always force "Night Light" on, saving a <Super><Alt>backslash call,
|
||||
# with the same settings as in ~/.local/bin/night-light-toggle-schedule
|
||||
if [ "$active" = "(<false>,)" ] || [ "$automatic" = "true" ]; then
|
||||
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
|
||||
|
||||
|
||||
# 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)"
|
||||
fi
|
||||
Loading…
Reference in a new issue