Advertisement
constantin-net

switch_display.sh

Feb 17th, 2020
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.23 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. LVDS=eDP1
  4. VGA=VGA1
  5.  
  6. if [ -z $SWITCH_DISPLAY_CURRENT ]; then
  7.   export SWITCH_DISPLAY_CURRENT=0
  8. fi
  9.  
  10. xrandr | grep -q "$VGA connected " && VGA_IS_ON=1 || VGA_IS_ON=0
  11.  
  12. # Switch displays
  13. switch_display()
  14. {
  15. if [[ $VGA_IS_ON -eq 0 ]]; then
  16.     xrandr --output $LVDS --auto --scale 1x1
  17.     export SWITCH_DISPLAY_CURRENT=0
  18. return 0
  19. fi
  20. if [[ $VGA_IS_ON -eq 1 && $SWITCH_DISPLAY_CURRENT -eq 0 ]]; then
  21.     xrandr --output $LVDS --auto --output $VGA --off
  22.     export SWITCH_DISPLAY_CURRENT=1
  23. return 0
  24. fi
  25. if [[ $VGA_IS_ON -eq 1 && $SWITCH_DISPLAY_CURRENT -eq 1 ]]; then
  26.     xrandr --output eDP1 --scale 1.405x1.405 --output VGA1 --auto --scale 1x1 --same-as eDP1
  27.     export SWITCH_DISPLAY_CURRENT=2
  28. return 0
  29. fi
  30. if [[ $VGA_IS_ON -eq 1 && $SWITCH_DISPLAY_CURRENT -eq 2 ]]; then
  31.     xrandr --output $VGA --auto --left-of $LVDS --output $LVDS --auto --scale 1x1
  32.     export SWITCH_DISPLAY_CURRENT=3
  33. return 0
  34. fi
  35. if [[ $VGA_IS_ON -eq 1 && $SWITCH_DISPLAY_CURRENT -eq 3 ]]; then
  36.     xrandr --output $VGA --auto --right-of $LVDS
  37.     export SWITCH_DISPLAY_CURRENT=4
  38. return 0
  39. fi
  40. if [[ $VGA_IS_ON -eq 1 && $SWITCH_DISPLAY_CURRENT -eq 4 ]]; then
  41.     xrandr --output $VGA --auto --output $LVDS --off
  42.     export SWITCH_DISPLAY_CURRENT=0
  43. return 0
  44. fi
  45. }
  46. switch_display
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement