blob: 4c3cba6f3fb7336561d75cc1ef01399803a2971a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
|