aboutsummaryrefslogtreecommitdiff
path: root/yoga/bin
diff options
context:
space:
mode:
authorCamil Staps2023-02-20 16:29:45 +0100
committerCamil Staps2023-02-20 16:29:45 +0100
commitb413ed41605f3bff1d95e8b403c3cc4384ab0576 (patch)
treea65e8e4b27a542ba903aa6675239e37049e0ee4b /yoga/bin
parentAdd i3 shortcuts for enabling/disabling displayport as well as turning its br... (diff)
Add night light shortcuts
Diffstat (limited to 'yoga/bin')
-rwxr-xr-xyoga/bin/night-light46
1 files changed, 46 insertions, 0 deletions
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