3 #####################################################
4 # This script detects and saves screen resolutions ##
5 # It resizes the wallpaper if things change ##
6 #####################################################
8 command -v xrandr &>/dev/null ||
9 (echo "please install xrandr" && exit 1)
13 mkdir -p ~/instantos/monitor &>/dev/null
14 cd ~/instantos/monitor
16 POSITIONS="$(xrandr | grep '[^s]connected' | grep -o '[0-9]*x[0-9]*+[0-9]*' | grep -o '[0-9]*$')"
17 AMOUNT=$(wc -l <<<"$POSITIONS")
19 RESOLUTIONS=$(xrandr | grep '[^s]connected' | grep -Eo '[0-9]{1,}x[0-9]{1,}\+[0-9]{1,}\+[0-9]{1,}' |
20 grep -o '[0-9]*x[0-9]*' | sed 's/ /\n/g')
22 # check if resolutions are already configured
24 if iconf resolutions; then
25 OLDRES="$(iconf resolutions)"
26 # see if resolution has changed
27 if ! [ "$RESOLUTIONS" = "$OLDRES" ]; then
28 iconf resolutions "$RESOLUTIONS"
29 echo "Resolution change detected"
31 echo "no resolution change"
32 [ "$1" = "-f" ] || exit
35 iconf resolutions "$RESOLUTIONS"
38 if [ $(echo "$RESOLUTIONS" | sort -u | wc -l) = "1" ]; then
39 echo "resolutions identical"
40 iconf max $(head -1 <<<"$RESOLUTIONS")
42 # get monitor with highest resolution
43 let PIXELS1="$(head -1 <<<$RESOLUTIONS | grep -o '^[0-9]*') * $(head -1 <<<$RESOLUTIONS | grep -o '[0-9]*$')"
44 let PIXELS2="$(tail -1 <<<$RESOLUTIONS | grep -o '^[0-9]*') * $(tail -1 <<<$RESOLUTIONS | grep -o '[0-9]*$')"
45 if [ "$PIXELS1" -gt "$PIXELS2" ]; then
46 iconf max "$(head -1 <<<$RESOLUTIONS)"
48 iconf max "$(tail -1 <<<$RESOLUTIONS)"
52 # rebuild wallpaper after resolution change
55 rm ~/instantos/wallpapers/overlay.*
56 rm -rf ~/instantos/wallpapers/default
58 if iconf -i setwallpaper; then
59 instantwallpaper resolution
63 if [ "$AMOUNT" = "1" ]; then
64 echo "only one monitor found, further setup not needed"
68 if [ "$AMOUNT" -gt 2 ]; then
69 echo "only 2 monitors are testes"
72 echo "$AMOUNT monitors found"
75 iconf names "$(xrandr | grep '[^s]connected' | grep -o '^[^ ]*')"
77 MONITOR1=$(head -1 <<<"$POSITIONS")
78 MONITOR2=$(tail -1 <<<"$POSITIONS")
81 # in case some program ever needs it
82 if [ "$MONITOR1" -gt "$MONITOR2" ]; then
83 echo "Monitor 1 is ${MONITOR1}px on the right"
84 iconf right "$MONITOR2"
86 echo "Monitor 2 is ${MONITOR2}px on the right"
87 iconf right "$MONITOR2"