Skip to content

Instantly share code, notes, and snippets.

@jigpu
Created June 1, 2020 20:54
Show Gist options
  • Select an option

  • Save jigpu/1fad061de7e84c2a1ee3208e1a971342 to your computer and use it in GitHub Desktop.

Select an option

Save jigpu/1fad061de7e84c2a1ee3208e1a971342 to your computer and use it in GitHub Desktop.
Wacom Autoconfig on Hotplug
#!/bin/bash
# Usage:
# xorg-hotplug.sh [device]
#
# device - Name of an Xorg device to configure.
#
# xorg-hotplug should be added to your window manager's list of startup programs. If
# run with no arguments, it will sit in the background monitoring for hotplug events
# by monitoring the Xorg log file. When a new device is connected, it will automatically
# launch a new instance of itself with the name of the deivce to handle configuration.
#
# The bottom half of this script should be customized to change the list of devices that
# it recognizes and the commands that get run in response.
# If run without arguments, monitor for xorg hotplug events
if [[ $# -eq 0 ]]; then
CMD=$(readlink -e "$0")
DPY=${DISPLAY#:}
[[ -f "$LOG" ]] || LOG=~/.local/share/xorg/Xorg.${DPY}.log
[[ -f "$LOG" ]] || LOG=/var/log/Xorg.${DPY}.log
[[ -f "$LOG" ]] || exit 1
AWKPROG=$(cat <<'EOF'
/XINPUT: Adding extended input device/ {
DEVICE=$2
if (length(DEVICE) > 0) {
print "Hotplugging " DEVICE;
system("\""CMD"\" \""DEVICE"\"");
}
}
EOF
)
echo "Monitoring for hotplug events from ${LOG}"
tail -f -n +1 "${LOG}" | awk -vFS=\" -vCMD="${CMD}" "${AWKPROG}"
exit 0
fi
# If run with arguments, set up the specified device
DEVICE=$1
echo "Configuring ${DEVICE}"
case "${DEVICE}" in
"Wacom Cintiq 24HD touch Pen stylus")
xsetwacom set "${DEVICE}" maptooutput DVI-I-2
# Other
# Commands
# Go
# Here
;;
"Wacom Cintiq 24HD touch Pen eraser")
xsetwacom set "${DEVICE}" maptooutput DVI-I-2
# Other
# Commands
# Go
# Here
;;
"Wacom Cintiq 24HD touch Finger touch")
xsetwacom set "${DEVICE}" maptooutput DVI-I-2
# Other
# Commands
# Go
# Here
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment