This looks at active displays and connected tablets and gives you a simple menu to select from. Defaults to whatever display you have designated as "primary".
#!/bin/bash# Get list of active displaysDIS_LIST=($(xrandr | grep 'connected' | grep -v 'disconnected' | awk '{print $1}'))unset DIS_PRI#=======[SELECT DISPLAY]================# Unset validation checkunset gDISv# Loop until validation check is passeduntil [[ $gDISv == "yes" ]]; doecho ""echo "The following ${#DIS_LIST[@]} displays were detected"printf "%2s | %10s | %10s | %7s\n" "#" "Resolution" "Physical Size" "Priority"echo "-----------------------------------"for (( i=0; i<${#DIS_LIST[@]}; i++ )); do# Offset index to offer nicer options - this way the display numbering will# not start at zero, AND theoretically it will match the XORG display# numbering shown in GNOMElet j=$i+1# read the xrandr line into a variableDLINE=$(xrandr | grep "${DIS_LIST[$i]} c")# Pull screen resolution and physical size to make it easier to identify which display is whichTHIS_RES=$(echo $DLINE | sed 's/primary//' | awk '{print $3}' | awk -F'+' '{print $1}')THIS_SIZ=$(echo $DLINE | sed 's/primary//' | awk '{print $(NF-2), $(NF-1), $NF}')# Mark which display is primary (using the offset index) so we can default# to this choiceif [[ -n $(echo $DLINE | grep -o 'primary') ]]; thenDIS_PRI=$jfiprintf "%2s | %10s | %10s | %7s\n" "$j" "$THIS_RES" "$THIS_SIZ" "$(echo $DLINE | grep -o 'primary')"doneecho ""read -p "Select a display (1-${#DIS_LIST[@]})? [$DIS_PRI]:" gDIS# If no input was provided, set value to defaultif [[ -z $gDIS ]]; then let gDIS=$DIS_PRI; fi# Validate inputif [[ $gDIS -gt 0 ]] && [[ $gDIS -lt ${#DIS_LIST[@]} ]]; thengDISv="yes"DIS_TGT=${DIS_LIST[${gDIS}-1]}elseecho "[$gDIS] is not a valid selection."unset gDISecho ""gDISv="no"fidone#=========[Find XINPUT IDs]============ID_STYLUS=$(xinput | grep pointer | grep HUION | grep -i pen | awk '{print $(NF-3)}'| awk -F'=' '{print $2}')#echo "XINPUT device ids: Stylus ($ID_STYLUS), Pad ($ID_PAD)"#=========[Assign Tablet To Screen]=========echo "Assigning the HUION stylus to display $gDIS: $DIS_TGT"xinput map-to-output ${ID_STYLUS} ${DIS_TGT}
No comments:
Post a Comment