Advertisement
Guest User

script for linux tablet setup on multiple monitors

a guest
Dec 7th, 2014
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.28 KB | None | 0 0
  1. #!/bin/bash
  2. # setup active screen for tablet usage in a multi-monitor environment
  3. # author: christopher barry
  4. # license: public domain
  5.  
  6. ##### C O N F I G U R A T I O N #####
  7.  
  8. # Configure left,right,center to match your xrandr display names
  9. # to find them, run 'xrandr --query' to see the names of your ports.
  10. declare -r left="DVI-1"
  11. declare -r center="DisplayPort-0"
  12. declare -r right="DVI-0"
  13.  
  14. # tablet name as expressed in /var/log/Xorg.0.log
  15. # For Huion H610, it is: "HUION PenTablet"
  16. declare -r tablet="HUION PenTablet"
  17.  
  18. ##### E N D  C O N F I G U R A T I O N #####
  19.  
  20. ##### S C R I P T  B E G I N S #####
  21.  
  22. function evar() {
  23.     [[ ${#} -gt 0 ]] || return
  24.     eval "echo -n \${$@}"
  25. }
  26.  
  27. case "${1}" in
  28.  
  29.     left|center|right)
  30.  
  31.         # assign the graphics port from parameter
  32.         screen=$(evar "${1}")
  33.         [[ ${screen} ]] || {
  34.             echo "oops! '${1}' has no graphics port value assigned."
  35.             echo "did you configure the top section of this script ("$0") to match your setup?"
  36.             exit 1
  37.         }
  38.  
  39.         # verify we have tools to operate
  40.         [[ $(which xrandr) ]] || {
  41.             echo "You need xrandr installed for this script to function"
  42.             exit 1
  43.         }
  44.  
  45.         # verify configured port exists
  46.         xrandr | grep -w connected | awk '{print $1}' | grep -qw "${screen}" || {
  47.             echo "oops! cannot find graphics port ${screen} supposedly located @ ${1}"
  48.             echo "did you configure the top section of this script ("$0") to match your setup?"
  49.             exit 1
  50.         }
  51.  
  52.         # get all instances of tablet
  53.         declare -a ids=( $(grep  "${tablet}" /var/log/Xorg.0.log | grep "type:" | tr [[:punct:]] ' ' | awk '{ print $NF }' | sort -u) )
  54.  
  55.         for id in "${ids[@]}"; do
  56.  
  57.             # map each instance to the selected monitor
  58.             xinput map-to-output ${id} "${screen}" &>/dev/null || {
  59.                 echo "an error occurred attempting to map ${tablet} id=${id} to ${1} screen '${screen}'"
  60.                 exit 1
  61.             }
  62.             echo -n "."
  63.  
  64.         done
  65.  
  66.         echo -e "\n${tablet} is now mapped to ${screen} located on ${1} monitor"
  67.         exit 0
  68.         ;;
  69.  
  70.     *)
  71.         echo "Usage: $(basename "$0") <left|center|right>"
  72.         exit 1
  73.         ;;
  74. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement