Skip to content

Instantly share code, notes, and snippets.

@achadwick
Created December 14, 2017 11:31
Show Gist options
  • Save achadwick/c7e73078915528fb6517290d019a03d2 to your computer and use it in GitHub Desktop.
Save achadwick/c7e73078915528fb6517290d019a03d2 to your computer and use it in GitHub Desktop.
Xfce4 "tablet inserted" script with support for a Wacom Cintiq 13HD
#!/bin/sh
# Configure Wacom tablets for XFCE4's "Removable Media" scripting.
DEV_13HD="Wacom Cintiq 13HD"
LOCKFILE="/tmp/.xfce4-tablet-inserted-$USER.lock"
set -e
# set -x
# Xfce likes to call this script several times when a tablet is
# inserted, so use a lockfile and give up gracefully if another process
# is handling the configuration.
lockfile -1 -r 0 -l 2 -s 5 "$LOCKFILE" || exit 0
# The unused keys need to be mapped out here. For the unusable ones,
# "xsetwacom --set" reports "Unsupported offset into 'Wacom Button
# Actions' property".
sleep 1
case "`xsetwacom --list devices`" in
*"$DEV_13HD"*)
# Cintiq 13HD. This presents as three devices
DEV_13HD_STYLUS="$DEV_13HD Pen stylus"
DEV_13HD_ERASER="$DEV_13HD Pen eraser"
DEV_13HD_PAD="$DEV_13HD Pad pad"
# The pad has 9 usable buttons. Unused: 4-7,10-11,14-.
# Top pair (dot, square)
xsetwacom --set "$DEV_13HD_PAD" Button 2 Key z
xsetwacom --set "$DEV_13HD_PAD" Button 3 Key y
# Arrow buttons in a d-pad ring middle
xsetwacom --set "$DEV_13HD_PAD" Button 10 Key f # right
xsetwacom --set "$DEV_13HD_PAD" Button 11 Key s # top
xsetwacom --set "$DEV_13HD_PAD" Button 1 Key tab # centre
xsetwacom --set "$DEV_13HD_PAD" Button 12 Key d # left
xsetwacom --set "$DEV_13HD_PAD" Button 13 Key a # bottom
# Bottom pair (square, dot)
xsetwacom --set "$DEV_13HD_PAD" Button 8 Key shift
xsetwacom --set "$DEV_13HD_PAD" Button 9 Key ctrl
# Set the display layout
# xrandr --output HDMI1 --left-of eDP1
# Map all input screen areas to the HDMI output...
for dev in "$DEV_13HD_STYLUS" "$DEV_13HD_ERASER"; do
xsetwacom --set "$dev" MapToOutput HDMI1
done
# Finally, send the user a pretty message.
notify-send --icon=dialog-information \
"$DEV_13HD" \
"Tablet configuration complete."
;;
*)
# Send the user a pretty message.
notify-send --icon=dialog-warning \
"No known graphics tablets" \
"Try updating `basename $0` to cope."
;;
esac
# Keep the lock a a bit longer if we were successful.
sleep 5
rm -f "$LOCKFILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment