Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # setup active screen for tablet usage in a multi-monitor environment
- # author: christopher barry
- # license: public domain
- ##### C O N F I G U R A T I O N #####
- # Configure left,right,center to match your xrandr display names
- # to find them, run 'xrandr --query' to see the names of your ports.
- declare -r left="DVI-1"
- declare -r center="DisplayPort-0"
- declare -r right="DVI-0"
- # tablet name as expressed in /var/log/Xorg.0.log
- # For Huion H610, it is: "HUION PenTablet"
- declare -r tablet="HUION PenTablet"
- ##### E N D C O N F I G U R A T I O N #####
- ##### S C R I P T B E G I N S #####
- function evar() {
- [[ ${#} -gt 0 ]] || return
- eval "echo -n \${$@}"
- }
- case "${1}" in
- left|center|right)
- # assign the graphics port from parameter
- screen=$(evar "${1}")
- [[ ${screen} ]] || {
- echo "oops! '${1}' has no graphics port value assigned."
- echo "did you configure the top section of this script ("$0") to match your setup?"
- exit 1
- }
- # verify we have tools to operate
- [[ $(which xrandr) ]] || {
- echo "You need xrandr installed for this script to function"
- exit 1
- }
- # verify configured port exists
- xrandr | grep -w connected | awk '{print $1}' | grep -qw "${screen}" || {
- echo "oops! cannot find graphics port ${screen} supposedly located @ ${1}"
- echo "did you configure the top section of this script ("$0") to match your setup?"
- exit 1
- }
- # get all instances of tablet
- declare -a ids=( $(grep "${tablet}" /var/log/Xorg.0.log | grep "type:" | tr [[:punct:]] ' ' | awk '{ print $NF }' | sort -u) )
- for id in "${ids[@]}"; do
- # map each instance to the selected monitor
- xinput map-to-output ${id} "${screen}" &>/dev/null || {
- echo "an error occurred attempting to map ${tablet} id=${id} to ${1} screen '${screen}'"
- exit 1
- }
- echo -n "."
- done
- echo -e "\n${tablet} is now mapped to ${screen} located on ${1} monitor"
- exit 0
- ;;
- *)
- echo "Usage: $(basename "$0") <left|center|right>"
- exit 1
- ;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement