Advertisement
Guest User

OneXPlayer Xrandr

a guest
Jan 15th, 2022
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.28 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # This script attempts to set a known-good mode on a good output
  4.  
  5. function contains() {
  6. local n=$#
  7. local value=${!n}
  8. for ((i=1;i < $#;i++)) {
  9. if [ "${!i}" == "${value}" ]; then
  10. echo "y"
  11. return 0
  12. fi
  13. }
  14. echo "n"
  15. return 1
  16. }
  17.  
  18. # Some devices with incorrect EDID readings may need to have modes added before the compositor loads for it to work correctly.
  19.  
  20. if [ "$(cat /sys/devices/virtual/dmi/id/product_name)" == "ONE XPLAYER" ]; then
  21.  
  22. #Adding 400x640 resolution
  23. DISPLAY=:0 xrandr --newmode "400x640" 20.25 400 424 456 512 640 643 653 665 -hsync +vsync
  24. DISPLAY=:0 xrandr --addmode eDP1 400x640
  25.  
  26. #Adding 600x900 resolution
  27. DISPLAY=:0 xrandr --newmode "600x960" 47.25 600 640 696 792 960 963 973 996 -hsync +vsync
  28. DISPLAY=:0 xrandr --addmode eDP1 600x960
  29.  
  30. #Adding 800x1280 resolution
  31. DISPLAY=:0 xrandr --newmode "800x1280" 85.25 800 856 936 1072 1280 1283 1293 1327 -hsync +vsync
  32. DISPLAY=:0 xrandr --addmode eDP1 800x1280
  33.  
  34. #Adding 900x1440 resolution
  35. DISPLAY=:0 xrandr --newmode "900x1440" 109.50 904 968 1064 1224 1440 1443 1453 1493 -hsync +vsync
  36. DISPLAY=:0 xrandr --addmode eDP1 900x1440
  37.  
  38. #Adding 1050x1680 resolution
  39. DISPLAY=:0 xrandr --newmode "1050x1680" 150.25 1056 1136 1248 1440 1680 1683 1693 1741 -hsync +vsync
  40. DISPLAY=:0 xrandr --addmode eDP1 1050x1680
  41.  
  42. #Adding 1200x1920 resolution
  43. DISPLAY=:0 xrandr --newmode "1200x1920" 196.50 1200 1296 1424 1648 1920 1923 1933 1989 -hsync +vsync
  44. DISPLAY=:0 xrandr --addmode eDP1 1200x1920
  45.  
  46. #Adding 1200x1920 resolution
  47. DISPLAY=:0 xrandr --newmode "1600x2560" 353.50 1600 1736 1912 2224 2560 2563 2573 2651 -hsync +vsync
  48. DISPLAY=:0 xrandr --addmode eDP1 1600x2560
  49. fi
  50.  
  51. # This function echoes the first element from first argument array, matching a
  52. # prefix in the order given by second argument array.
  53. function first_by_prefix_order() {
  54. local values=${!1}
  55. local prefix_order=${!2}
  56. for prefix in ${prefix_order[@]} ; do
  57. for val in ${values[@]} ; do
  58. if [[ $val =~ ^$prefix ]] ; then echo $val ; return ; fi
  59. done
  60. done
  61. }
  62.  
  63. GOODMODES=("3840x2160" "2560x1600" "2560x1440" "1920x1200" "1920x1080" "1280x800" "1280x720")
  64. GOODRATES=("60.0" "59.9") # CEA modes guarantee or one the other, but not both?
  65. ROTATION=
  66.  
  67. CONFIG_PATH=${XDG_CONFIG_HOME:-$HOME/.config}
  68. CONFIG_FILE="$CONFIG_PATH/steamos-compositor-plus"
  69.  
  70. # Override the defaults from the user config
  71. if [ -f "$CONFIG_FILE" ]; then
  72. source "$CONFIG_FILE"
  73. else
  74. echo '#GOODMODES=("3840x2160" "2560x1600" "2560x1440" "1920x1200" "1920x1080" "1280x800" "1280x720")' > "$CONFIG_FILE"
  75. echo '#GOODRATES=("60.0" "59.9")' >> "$CONFIG_FILE"
  76. echo '#ROTATION=' >> "$CONFIG_FILE"
  77. fi
  78.  
  79. # First, some logging
  80. date
  81. xrandr --verbose
  82.  
  83. # List connected outputs
  84. ALL_OUTPUT_NAMES=$(xrandr | grep ' connected' | cut -f1 -d' ')
  85. # Default to first connected output
  86. OUTPUT_NAME=$(echo $ALL_OUTPUT_NAMES | cut -f1 -d' ')
  87.  
  88. # If any is connected, give priority to HDMI then DP
  89. OUTPUT_PRIORITY="HDMI DP"
  90. PREFERRED_OUTPUT=$(first_by_prefix_order ALL_OUTPUT_NAMES[@] OUTPUT_PRIORITY[@])
  91. if [[ -n "$PREFERRED_OUTPUT" ]] ; then
  92. OUTPUT_NAME=$PREFERRED_OUTPUT
  93. fi
  94.  
  95. # Disable everything but the selected output
  96. for i in $ALL_OUTPUT_NAMES; do
  97. if [ "$i" != "$OUTPUT_NAME" ]; then
  98. xrandr --output "$i" --off
  99. fi
  100. done
  101.  
  102.  
  103. CURRENT_MODELINE=`xrandr | grep \* | tr -s ' ' | head -n1`
  104.  
  105. CURRENT_MODE=`echo "$CURRENT_MODELINE" | cut -d' ' -f2`
  106. CURRENT_RATE=`echo "$CURRENT_MODELINE" | tr ' ' '\n' | grep \* | tr -d \* | tr -d +`
  107.  
  108. # If the current mode is already deemed good, we're good, exit
  109. if [ $(contains "${GOODMODES[@]}" "$CURRENT_MODE") == "y" ]; then
  110. if [ $(contains "${GOODRATES[@]}" "$CURRENT_RATE") == "y" ]; then
  111. exit 0
  112. fi
  113. fi
  114.  
  115. w=`echo $CURRENT_MODE | cut -dx -f1`
  116. h=`echo $CURRENT_MODE | cut -dx -f2`
  117. if [ "$h" -gt "$w" ]; then
  118. TRANSPOSED=true
  119. fi
  120.  
  121. if [ -z "$ROTATION" ] && [ "$TRANSPOSED" = true ]; then
  122. ROTATION=right
  123.  
  124. if [ "$(cat /sys/devices/virtual/dmi/id/product_name)" == "ONE XPLAYER" ]; then
  125. ROTATION=left
  126. fi
  127. fi
  128.  
  129. if [ -z "$ROTATION" ]; then
  130. ROTATION=normal
  131. fi
  132.  
  133. # detect and rotate touch screen
  134. TOUCHSCREEN=$(udevadm info --export-db | sed 's/^$/;;/' | tr '\n' '%%' | tr ';;' '\n' | grep ID_INPUT_TOUCHSCREEN=1 | tr '%%' '\n' | grep "E: NAME=" | head -1 | cut -d\" -f 2)
  135. if [ -n "$TOUCHSCREEN" ]; then
  136. MATRIX="1 0 0 0 1 0 0 0 1"
  137.  
  138. if [ "$ROTATION" = "right" ]; then
  139. MATRIX="0 1 0 -1 0 1 0 0 1"
  140. elif [ "$ROTATION" = "left" ]; then
  141. MATRIX="0 -1 1 1 0 0 0 0 1"
  142. elif [ "$ROTATION" = "normal" ]; then
  143. MATRIX="1 0 0 0 1 0 0 0 1"
  144. elif [ "$ROTATION" = "inverted" ]; then
  145. MATRIX="-1 0 1 0 -1 1 0 0 1"
  146. fi
  147.  
  148. xinput set-prop "pointer:$TOUCHSCREEN" --type=float "Coordinate Transformation Matrix" $MATRIX
  149. fi
  150.  
  151. # Otherwise try to set combinations of good modes/rates until it works
  152. for goodmode in "${GOODMODES[@]}"; do
  153. if [ "$TRANSPOSED" = true ]; then
  154. w=`echo $goodmode | cut -dx -f1`
  155. h=`echo $goodmode | cut -dx -f2`
  156. goodmode=${h}x${w}
  157. fi
  158.  
  159. for goodrate in "${GOODRATES[@]}"; do
  160. xrandr --output "$OUTPUT_NAME" --mode "$goodmode" --refresh "$goodrate" --rotate "$ROTATION"
  161. # If good return, we're done
  162. if [[ $? -eq 0 ]]; then
  163. exit 0
  164. fi
  165. done
  166. done
  167.  
  168. exit 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement