aboutsummaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorYuchen Pei <id@ypei.org>2024-11-03 17:33:22 +1100
committerYuchen Pei <id@ypei.org>2024-11-03 17:33:22 +1100
commit12d93a75c9662ce7906035fd01742879e735bc75 (patch)
treef5faff6e9a6d93599812ffab988352adc3b30d13 /misc
parentb14f5dbd299ff45a8a569f7c13c41629e384f4f0 (diff)
[xrandr] A script to switch to the biggest connected monitor
Diffstat (limited to 'misc')
-rwxr-xr-xmisc/bin/switch-display.sh35
1 files changed, 35 insertions, 0 deletions
diff --git a/misc/bin/switch-display.sh b/misc/bin/switch-display.sh
new file mode 100755
index 0000000..4c3cba6
--- /dev/null
+++ b/misc/bin/switch-display.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+logger "$1" "$2" "$3"
+# Switch to the biggest display available. for use as an acpid hook
+
+# Make sure the variables from pipe can be assigned
+# https://stackoverflow.com/questions/42963395/bash-assign-variable-from-pipe
+shopt -s lastpipe
+
+# enable all monitors so that they show up in xrandr
+# --listactivemonitors output. somehow this output is identical to
+# that of xrandr --listmonitors
+xrandr --auto
+
+# find the widest monitor
+regex="^.*/([0-9]+)x.*/([0-9]+).* ([^ ]+)$"
+widest=0
+widest_name=""
+xrandr --listactivemonitors | while IFS=$'\n' read -r line; do
+ if [[ $line =~ $regex ]]; then
+ if (( "${BASH_REMATCH[1]}" > "$widest" )); then
+ widest="${BASH_REMATCH[1]}"
+ widest_name="${BASH_REMATCH[3]}"
+ fi
+ fi
+done
+
+# turn off all other monitors
+xrandr --listactivemonitors | while IFS=$'\n' read -r line; do
+ if [[ $line =~ $regex ]]; then
+ if [[ "${BASH_REMATCH[3]}" != "$widest_name" ]]; then
+ xrandr --output "${BASH_REMATCH[3]}" --off
+ fi
+ fi
+done