3 command -v xrandr &>/dev/null ||
4 (echo "please install xrandr" && exit 1)
7 mkdir -p ~/instantos/monitor &>/dev/null
10 POSITIONS="$(xrandr | grep '[^s]connected' | grep -o '[0-9]*x[0-9]*+[0-9]*' | grep -o '[0-9]*$')"
11 AMOUNT=$(wc -l <<<"$POSITIONS")
13 # get monitor with highest resolution
14 RESOLUTIONS=$(xrandr | grep '[^s]connected' | grep -Eo '[0-9]{1,}x[0-9]{1,}\+[0-9]{1,}\+[0-9]{1,}' |
15 grep -o '[0-9]*x[0-9]*' | sed 's/ /\n/g')
17 if OLDRES="$(iconf resolutions)"; then
18 # see if resolution has changed
19 if ! [ "$RESOLUTIONS" = "$OLDRES" ]; then
20 iconf resolutions "$RESOLUTIONS"
22 echo "Resolution change detected"
26 if [ $(echo "$RESOLUTIONS" | sort -u | wc -l) = "1" ]; then
27 echo "resolutions identical"
28 iconf -i max $(head -1 <<<"$RESOLUTIONS")
30 let PIXELS1="$(head -1 <<<$RESOLUTIONS | grep -o '^[0-9]*') * $(head -1 <<<$RESOLUTIONS | grep -o '[0-9]*$')"
31 let PIXELS2="$(tail -1 <<<$RESOLUTIONS | grep -o '^[0-9]*') * $(tail -1 <<<$RESOLUTIONS | grep -o '[0-9]*$')"
32 if [ "$PIXELS1" -gt "$PIXELS2" ]; then
33 iconf -i max "$(head -1 <<<$RESOLUTIONS)"
35 iconf -i max "$(tail -1 <<<$RESOLUTIONS)"
39 # rebuild wallpaper after resolution change
41 if [ -z "$CHANGERES" ]; then
42 echo "no resolution change"
44 if [ -e ~/instantos/wallpapers ] && command -v instantwallpaper; then
45 rm -rf ~/instantos/wallpapers
46 instantwallpaper random
51 if [ "$AMOUNT" = "1" ]; then
52 echo "only one monitor found, further setup not needed"
56 if [ "$AMOUNT" -gt 2 ]; then
57 echo "only 2 monitors are supported"
60 echo "$AMOUNT monitors found"
63 iconf names "$(xrandr | grep '[^s]connected' | grep -o '^[^ ]*')"
65 MONITOR1=$(head -1 <<<"$POSITIONS")
66 MONITOR2=$(tail -1 <<<"$POSITIONS")
68 if [ "$MONITOR1" -gt "$MONITOR2" ]; then
69 echo "Monitor 1 is ${MONITOR1}px on the right"
70 iconf -i right "$MONITOR2"
72 echo "Monitor 2 is ${MONITOR2}px on the right"
73 iconf -i right "$MONITOR2"