diff options
author | Camil Staps | 2023-02-20 16:29:45 +0100 |
---|---|---|
committer | Camil Staps | 2023-02-20 16:29:45 +0100 |
commit | b413ed41605f3bff1d95e8b403c3cc4384ab0576 (patch) | |
tree | a65e8e4b27a542ba903aa6675239e37049e0ee4b | |
parent | Add i3 shortcuts for enabling/disabling displayport as well as turning its br... (diff) |
Add night light shortcuts
-rw-r--r-- | i3/.i3/config | 2 | ||||
-rwxr-xr-x | yoga/bin/night-light | 46 |
2 files changed, 48 insertions, 0 deletions
diff --git a/i3/.i3/config b/i3/.i3/config index 74c8d49..2cb64b2 100644 --- a/i3/.i3/config +++ b/i3/.i3/config @@ -38,6 +38,8 @@ bindsym XF86MonBrightnessUp exec bash -c 'echo "$(($(cat /sys/class/backlight/am bindsym XF86MonBrightnessDown exec bash -c 'echo "$(($(cat /sys/class/backlight/amdgpu_bl0/brightness)-10))" > /sys/class/backlight/amdgpu_bl0/brightness' bindsym $mod+XF86MonBrightnessUp exec bash -c 'echo 255 > /sys/class/backlight/amdgpu_bl0/brightness' bindsym $mod+XF86MonBrightnessDown exec bash -c 'echo 1 > /sys/class/backlight/amdgpu_bl0/brightness' +bindsym $mod+Shift+XF86MonBrightnessUp exec night-light increase +bindsym $mod+Shift+XF86MonBrightnessDown exec night-light decrease bindsym $mod+F7 exec toggle-dp bindsym $mod+Shift+F7 exec toggle-dp-brightness diff --git a/yoga/bin/night-light b/yoga/bin/night-light new file mode 100755 index 0000000..6c4224c --- /dev/null +++ b/yoga/bin/night-light @@ -0,0 +1,46 @@ +#!/bin/bash +# Usage: night-light [increase|decrease] +set -e + +TMPFILE=/tmp/.night-light-index + +# https://askubuntu.com/a/1061304 +STEPS=( + "1:0.18172716:0.00000001" + "1:0.42322816:0.00000001" + "1:0.54360078:0.08679949" + "1:0.64373109:0.28819679" + "1:0.71976951:0.42860152" + "1:0.77987699:0.54642268" + "1:0.82854786:0.64816570" + "1:0.86860704:0.73688797" + "1:0.90198230:0.81465502" + "1:0.93853986:0.88130458" + "1:0.97107439:0.94305985" + "1:1:1" +) + +CUR=${#STEPS[@]} +if [ -f $TMPFILE ]; then + CUR=$(cat $TMPFILE) +fi + +case "$1" in + increase) + NEW=$(($CUR >= ${#STEPS[@]} ? $CUR : $CUR+1)) + ;; + decrease) + NEW=$(($CUR <= 0 ? $CUR : $CUR-1)) + ;; + *) + echo "Invalid argument '$1'" + exit 1 + ;; +esac + +echo $NEW > $TMPFILE + +for MONITOR in $(xrandr --listactivemonitors | tail -n +2 | cut -d'+' -f2 | cut -d' ' -f1 | sed 's/^\*//'); do + BRIGHTNESS=$(xrandr --verbose | grep "^$MONITOR" -A5 | grep Brightness | cut -d':' -f2 | sed 's/\s*//') + xrandr --output $MONITOR --gamma ${STEPS[$NEW]} --brightness $BRIGHTNESS || true +done |