tmp night light
This commit is contained in:
parent
cbb1861b25
commit
809bbe08d8
10 changed files with 191 additions and 82 deletions
|
|
@ -5,12 +5,10 @@
|
|||
# in ~/.config/gnome-settings/key-bindings.ini
|
||||
#
|
||||
# This script ensures "Night Light" is forced on
|
||||
# if it was not yet on by schedule
|
||||
# and makes the screen a bit warmer than it currently is
|
||||
# or makes the screen a bit warmer than it currently is
|
||||
#
|
||||
# The default warmth is restored at login by ~/.local/bin/restore-gnome
|
||||
|
||||
|
||||
set -eu
|
||||
|
||||
|
||||
|
|
@ -20,6 +18,8 @@ set -eu
|
|||
_MIN_TEMPERATURE=1200
|
||||
_MAX_TEMPERATURE=4700
|
||||
|
||||
_DEFAULT_TEMPERATURE=2200
|
||||
|
||||
|
||||
notify() {
|
||||
ID_FILE="${XDG_RUNTIME_DIR}/night-light-notification-id"
|
||||
|
|
@ -42,25 +42,52 @@ active=$(gdbus call --session \
|
|||
--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}')
|
||||
|
||||
|
||||
# 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
|
||||
if [ "$active" = "(<true>,)" ] \
|
||||
&& { [ "$automatic" = "false" ] || [ $((applied - current)) -le 300 ]; }; then
|
||||
at_target=true
|
||||
else
|
||||
at_target=false
|
||||
fi
|
||||
|
||||
|
||||
gsettings set $Schema night-light-temperature "uint32 $new"
|
||||
# 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
|
||||
|
||||
|
||||
# Force "Night Light" on, saving a <Control><Alt>n call,
|
||||
# Always force "Night Light" on, saving a <Control><Alt>n call,
|
||||
# with the same settings as in ~/.local/bin/night-light-toggle-schedule
|
||||
if [ "$active" = "(<false>,)" ]; then
|
||||
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
|
||||
|
|
@ -68,18 +95,8 @@ if [ "$active" = "(<false>,)" ]; then
|
|||
fi
|
||||
|
||||
|
||||
if [ "$current" -le $_MIN_TEMPERATURE ]; then
|
||||
|
||||
if [ "$active" = "(<false>,)" ]; then
|
||||
notify "is now forced on and already as warm as it gets (${_MIN_TEMPERATURE}K)"
|
||||
else
|
||||
notify "is already as warm as it gets (${_MIN_TEMPERATURE}K)"
|
||||
fi
|
||||
|
||||
else
|
||||
|
||||
if [ "$active" = "(<false>,)" ]; then
|
||||
notify "is now forced on at ${new}K"
|
||||
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