This was driving me nuts so I made a script that changed monitors automatically depending on where I'm plugged in. Previously I setup a hot key combination, but that was hit and miss because of response time on waking up. This could be customized for multiple setups. I couldn't find a good way to compare multi-line strings other than by letting bash sort it out with echo.
1 #!/bin/bash 2 3 4 sleep_time=10 5 _num=0 6 7 work_setup=" 8 DFP-0 (0x00010000): LGD 9 DFP-1 (0x00020000): DELL U2211H 10 DFP-2 (0x00040000): DELL U2312HM 11 " 12 13 standalone=" 14 DFP-0 (0x00010000): LGD 15 " 16 17 function check_state { 18 _num=$((${_num} + 1)) 19 _exist=$(echo $1) 20 _current=$(/home/stevenh/bin/nv-control-dpy | grep DFP ) 21 22 test -z "${_exist}" && _exist=${_current} 23 24 case $(echo $_current) in 25 #exists, sleep then repeat 26 $(echo ${_exist})) 27 echo exists ${_exist} 28 sleep ${sleep_time} 29 check_state "${_current}" 30 ;; 31 $(echo ${work_setup})) 32 /home/stevenh/bin/nv-control-dpy --add-metamode "DFP-1: nvidia-auto-select @1920x1080 +1920+0, DFP-2: nvidia-auto-select @1920x1080 +0+0" 33 xrandr -s 3840x1080 34 xrandr --output DP-1 --primary 35 echo swtich to work ${_current} ${_num} 36 sleep ${sleep_time} 37 check_state "${_current}" 38 ;; 39 $(echo ${standalone})) 40 /home/stevenh/bin/nv-control-dpy --add-metamode 1280x800 41 xrandr -s 1280x800 42 echo switch to standalone ${_current} ${_num} 43 sleep ${sleep_time} 44 check_state "${_current}" 45 ;; 46 esac 47 48 check_state "${_current}" 49 } 50 51 check_stateYou can select, copy and paste the code below
No comments:
Post a Comment