From b413ed41605f3bff1d95e8b403c3cc4384ab0576 Mon Sep 17 00:00:00 2001
From: Camil Staps
Date: Mon, 20 Feb 2023 16:29:45 +0100
Subject: Add night light shortcuts

---
 yoga/bin/night-light | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
 create mode 100755 yoga/bin/night-light

(limited to 'yoga/bin')

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
-- 
cgit v1.2.3