summaryrefslogtreecommitdiff
path: root/polybar/scripts/display-toggle.sh
diff options
context:
space:
mode:
Diffstat (limited to 'polybar/scripts/display-toggle.sh')
-rwxr-xr-xpolybar/scripts/display-toggle.sh40
1 files changed, 40 insertions, 0 deletions
diff --git a/polybar/scripts/display-toggle.sh b/polybar/scripts/display-toggle.sh
new file mode 100755
index 0000000..df810e8
--- /dev/null
+++ b/polybar/scripts/display-toggle.sh
@@ -0,0 +1,40 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+state_dir="${XDG_RUNTIME_DIR:-/tmp}"
+if [ ! -w "$state_dir" ]; then
+ state_dir="${XDG_CACHE_HOME:-$HOME/.cache}"
+ mkdir -p "$state_dir"
+fi
+if [ ! -w "$state_dir" ]; then
+ state_dir="/tmp"
+fi
+state_file="$state_dir/polybar-display-night.state"
+
+export DISPLAY="${DISPLAY:-:0}"
+if [ -z "${XAUTHORITY:-}" ] && [ -r "$HOME/.Xauthority" ]; then
+ export XAUTHORITY="$HOME/.Xauthority"
+fi
+
+output="$(
+ xrandr --query 2>/dev/null |
+ awk '/ connected primary/ { print $1; exit } / connected/ && !out { out = $1 } END { if (out) print out }'
+)"
+
+[ -n "$output" ] || exit 0
+
+notify() {
+ if command -v dunstify >/dev/null 2>&1; then
+ dunstify -a polybar -u low "Display" "$1"
+ fi
+}
+
+if [ -f "$state_file" ]; then
+ xrandr --output "$output" --gamma 1:1:1
+ rm -f "$state_file"
+ notify "day mode"
+else
+ xrandr --output "$output" --gamma 1:0.88:0.72
+ : >"$state_file"
+ notify "night mode"
+fi