reconf-screen 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/bin/sh
  2. usage()
  3. {
  4. echo "reconf-screen [OPTIONS]"
  5. echo
  6. echo "Options:"
  7. echo " -u|--unified Show one desktop on all screens"
  8. echo " -r|--resolution 1024x768 Force a specific resolution"
  9. echo " --nodvi Disable DVI"
  10. echo " --nohdmi Disable HDMI"
  11. echo " --nodp Disable DP"
  12. echo " --novga Disable VGA"
  13. echo " --nolvds Disable LVDS"
  14. echo " -h|--help Show this help text"
  15. }
  16. unified=0
  17. res=
  18. nodvi=0
  19. nohdmi=0
  20. nodp=0
  21. novga=0
  22. nolvds=0
  23. while [ $# -ne 0 ]; do
  24. case "$1" in
  25. --help|-h)
  26. usage
  27. exit 0
  28. ;;
  29. --unified|-u)
  30. unified=1
  31. ;;
  32. --resolution|-r)
  33. shift
  34. res="$1"
  35. ;;
  36. --nodvi)
  37. nodvi=1
  38. ;;
  39. --nohdmi)
  40. nohdmi=1
  41. ;;
  42. --nodp)
  43. nodp=1
  44. ;;
  45. --novga)
  46. novga=1
  47. ;;
  48. --nolvds)
  49. nolvds=1
  50. ;;
  51. *)
  52. echo "Unknown option: $1"
  53. exit 1
  54. ;;
  55. esac
  56. shift
  57. done
  58. [ -n "$res" ] && res="--mode $res"
  59. getconn()
  60. {
  61. # Assumes there is only one of each connection type
  62. xrandr | grep -Exe '^'$1'[0-9\-]* connected.*$' | head -n1 | cut -d' ' -f1
  63. }
  64. getdisconn()
  65. {
  66. # Assumes there is only one of each connection type
  67. xrandr | grep -Exe '^'$1'[0-9\-]* disconnected.*$' | head -n1 | cut -d' ' -f1
  68. }
  69. DVI="$(getconn DVI)"
  70. DVI_DISCONN="$(getdisconn DVI)"
  71. HDMI="$(getconn HDMI)"
  72. HDMI_DISCONN="$(getdisconn HDMI)"
  73. DP="$(getconn DP)"
  74. DP_DISCONN="$(getdisconn DP)"
  75. VGA="$(getconn VGA)"
  76. VGA_DISCONN="$(getdisconn VGA)"
  77. LVDS="$(getconn LVDS)"
  78. LVDS_DISCONN="$(getdisconn LVDS)"
  79. [ $nodvi -ne 0 ] && { OFF_DVI="$DVI"; ON_DVI=; } || { OFF_DVI=; ON_DVI="$DVI"; }
  80. [ $nohdmi -ne 0 ] && { OFF_HDMI="$HDMI"; ON_HDMI=; } || { OFF_HDMI=; ON_HDMI="$HDMI"; }
  81. [ $nodp -ne 0 ] && { OFF_DP="$DP"; ON_DP=; } || { OFF_DP=; ON_DP="$DP"; }
  82. [ $novga -ne 0 ] && { OFF_VGA="$VGA"; ON_VGA=; } || { OFF_VGA=; ON_VGA="$VGA"; }
  83. [ $nolvds -ne 0 ] && { OFF_LVDS="$LVDS"; ON_LVDS=; } || { OFF_LVDS=; ON_LVDS="$LVDS"; }
  84. ALL="$LVDS $DVI $HDMI $DP $VGA"
  85. ON_ALL="$ON_LVDS $ON_DVI $ON_HDMI $ON_DP $ON_VGA"
  86. OFF_ALL="$OFF_LVDS $OFF_DVI $OFF_HDMI $OFF_DP $OFF_VGA"
  87. ALL_DISCONN="$LVDS_DISCONN $DVI_DISCONN $HDMI_DISCONN $DP_DISCONN $VGA_DISCONN"
  88. for out in $ALL; do
  89. xrandr --output $out --auto
  90. done
  91. for out in $OFF_ALL $ALL_DISCONN; do
  92. xrandr --output $out --off
  93. done
  94. last_out=
  95. for out in $ON_ALL; do
  96. if [ -z "$last_out" -o $unified -ne 0 ]; then
  97. xrandr --output $out --pos 0x0 $res
  98. else
  99. xrandr --output $out --right-of $last_out $res
  100. fi
  101. last_out=$out
  102. done