Skip to content

Instantly share code, notes, and snippets.

@odysseywestra
Last active June 28, 2021 03:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odysseywestra/8b2455acea34d7fe7776 to your computer and use it in GitHub Desktop.
Save odysseywestra/8b2455acea34d7fe7776 to your computer and use it in GitHub Desktop.
Xsetwacom Config File for the Wacom Pen and Touch Medium CTH-680
#! /bin/sh
# Wacom Intous PT M CTH-680 xsetwacom Config
#:
#: Usage: ./wacom-cth-680.sh [Options]
#:
#: Options:
#: --help Show this message and exit
#: --initiate First time run
#: --reset Reset tablet to defult modes and buttons
#: --set-buttons Set buttons acording to configuration
#: --switch-display Cycle between displays
#: --area-mode Switch between fullscreen, and percision modes.
#: --touch-mode Enable or Diable Touch on the Tablet
#:
#: Percision modes of this script is based off the script by David Revoy:
#: * https://gist.github.com/Deevad/51820854ffd5ea5cd883
#: License: CC-0/Public-Domain/WTFPL (http://www.wtfpl.net/) license
#:
## Measurements
# Enter here the active area of your tablet in cm:
XtabletactiveareaCM=21.7
YtabletactiveareaCM=13.6
## Correction Scalling:
# This setting can enlarge a bit the precision zone. I saw during test a
# precision zone slightly larger has no impact on control quality, and might
# feels better.
#
# default=1 for real precision zone, enlarge=1.5 or reduce=0.8
#
# Tip: If you want the most accurate scale. Use a physical template like a
# circle template to draw on the tablet then compair to the one on your
# screen. If the shape on the monitor matches the shape on the template,
# then bingo you got it!
correctionscalefactor=1.05
# Alternative Size:
#correctionscalefactor=1.5
## Notify-send icon
# Custom Icon if you want to personalize your notifcations.
tablet_icon="/usr/share/icons/Adwaita/scalable/devices/input-tablet-symbolic.svg"
# Buton Mapping:
# -----------------------------
# | 1 3 |
# ------ ------
# | 2 4 |
# -----------------------------
## Button Shortcuts
button1="key +Control_L +z -z" # Undo
button2="key +Control_L +Shift_L +z -z" # Redo
button3="key +Control_L +Alt_L +y -y" # Toggle Percision Mode
button4="key +Control_L +Alt_L +t -t" # Toggle Display
## Duel Monitor
# This is specific to a dual monitor setup. To find out what your display names
# are use xrandr. For me my primary display is my external, and my secondary
# display is my laptop.
#Primary Display - For me its my External Monitor
display1="HDMI1"
#Secondary Display - For me it's my Laptop Montor
display2="eDP1"
# You shouldn't need to edit anything below this line for this device.
# ------------------------------------------------------------------------------
# Determine if Tablet is using the Wireless kit or Not. For me this is a
# better method.
if [ $(xsetwacom --list |grep -c "WL") = 4 ]; then
device="Wacom Intuos PT M (WL)"
else
device="Wacom Intuos PT M"
fi
echo ""
echo "Setup script for your $device PTH-451"
echo "-----------------------------------------"
tabletstylus="$device Pen stylus"
tableteraser="$device Pen eraser"
tabletpad="$device Pad pad"
tablettouch="$device Finger touch"
echo ""
echo "Tablet Information:"
echo "STYLUS: $tabletstylus"
echo "ERASER: $tableteraser"
echo "PAD: $tabletpad"
echo "TOUCH: $tablettouch"
echo ""
echo "-----------------------------------------"
## Set default Buttons
set_buttons(){
echo ""
echo "Setting Default Buttons for $tabletpad."
# This is the ture order of the buttons on the Tablet.
xsetwacom set "$tabletpad" Button 3 "$button1"
xsetwacom set "$tabletpad" Button 1 "$button2"
xsetwacom set "$tabletpad" Button 8 "$button3"
xsetwacom set "$tabletpad" Button 9 "$button4"
echo ""
echo "Buton Mapping:"
echo "-----------------------------"
echo "| 3 8 |"
echo "------ ------"
echo "| 1 9 |"
echo "-----------------------------"
echo ""
echo "Button 3: '$button1'"
echo "Button 1: '$button2'"
echo "Button 8: '$button3'"
echo "Button 9: '$button4'"
echo ""
echo "-----------------------------------------"
}
## Tablet Display Mode
tablet_display_mode(){
## Dual-Monitor Setup
# This is set up for my dual-monitor setup. This allows it to detect
# when my HDMI port is connected and sets the default monitor to map to.
#NOTE: This will be overwritten by tablet_area_mode() if you Reset or Initiate!!
p=$(xrandr | grep -c "$display1 connected primary")
if [ $p = 1 ]; then
primary="$display1"
secondary="$display2"
else
primary="$display1"
secondary="$display2"
fi
echo ""
echo "Display Defaults"
echo "Primary Display:" "$primary"
echo "Secondary Display:" "$secondary"
echo ""
echo "-----------------------------------------"
if [ -f /tmp/wacomscript-680-display-tokken ]; then
# This will map the tablet to the Secondary Display.
echo ""
echo "Mapping to $secondary"
echo ""
echo "-----------------------------------------"
xsetwacom set "$tabletstylus" MapToOutput "$secondary"
xsetwacom set "$tableteraser" MapToOutput "$secondary"
xsetwacom set "$tabletcursor" MapToOutput "$secondary"
xsetwacom set "$tablettouch" MapToOutput "$secondary"
notify-send -i "$tablet_icon" "Tablet Settings" "Mapped to $secondary"
rm /tmp/wacomscript-680-display-tokken
else
# This will map the tablet to the Primary Display.
echo ""
echo "Mapping to $primary"
echo ""
echo "-----------------------------------------"
xsetwacom set "$tabletstylus" MapToOutput "$primary"
xsetwacom set "$tableteraser" MapToOutput "$primary"
xsetwacom set "$tabletcursor" MapToOutput "$primary"
xsetwacom set "$tablettouch" MapToOutput "$primary"
notify-send -i "$tablet_icon" "Tablet Settings" "Mapped to $primary"
touch /tmp/wacomscript-680-display-tokken
fi
}
## Tablet Area Mode
# This mode will only work on the Primary Display.
tablet_area_mode(){
# Tablet
xsetwacom --set "$tabletstylus" ResetArea
xsetwacom --set "$tableteraser" ResetArea
fulltabletarea=`xsetwacom get "$tabletstylus" Area | grep "[0-9]\+ [0-9]\+$" -o`
Xtabletmaxarea=`echo $fulltabletarea | grep "^[0-9]\+" -o`
Ytabletmaxarea=`echo $fulltabletarea | grep "[0-9]\+$" -o`
# Screen
Xscreenpix=$(xrandr --listactivemonitors | grep '0:' | uniq | awk '{print $3}'| cut -d 'x' -f 1 | cut -d '/' -f 1)
Yscreenpix=$(xrandr --listactivemonitors | grep '0:' | uniq | awk '{print $3}'| cut -d 'x' -f 2 | cut -d '/' -f 1)
screenPPI=$(xdpyinfo | grep dots | awk '{print $2}' | awk -Fx '{print $1}')
XscreenPPI=$(bc <<< "scale = 2; $Xscreenpix / $screenPPI")
YscreenPPI=$(bc <<< "scale = 2; $Yscreenpix / $screenPPI")
XscreenCM=$(bc <<< "scale = 0; $Xscreenpix * 0.0254")
YscreenCM=$(bc <<< "scale = 0; $Yscreenpix * 0.0254")
# Precise Mode + Ratio
Ytabletmaxarearatiosized=$(bc <<< "scale = 0; $Yscreenpix * $Xtabletmaxarea / $Xscreenpix")
XtabletactiveareaPIX=$(bc <<< "scale = 0; $XtabletactiveareaCM * $screenPPI / 2.54 * $correctionscalefactor")
YtabletactiveareaPIX=$(bc <<< "scale = 0; $YtabletactiveareaCM * $screenPPI / 2.54 * $correctionscalefactor")
XtabletactiveareaPIX=$(bc <<< "scale = 0; ($XtabletactiveareaPIX + 0.5) / 1")
YtabletactiveareaPIX=$(bc <<< "scale = 0; ($YtabletactiveareaPIX + 0.5) / 1")
XOffsettabletactiveareaPIX=$(bc <<< "scale = 0; ($Xscreenpix - $XtabletactiveareaPIX) / 2")
YOffsettabletactiveareaPIX=$(bc <<< "scale = 0; ($Yscreenpix - $YtabletactiveareaPIX) / 2")
echo ""
echo "Percision Mode Information:"
echo "Tablet size (cm) :" "$XtabletactiveareaCM" x "$YtabletactiveareaCM"
echo "Screen size (px) :" "$Xscreenpix" x "$Yscreenpix"
echo "Screen size (cm) :" "$XscreenCM" x "$YscreenCM"
echo "Screen ppi :" "$screenPPI"
echo "Correction factor :" "$correctionscalefactor"
echo "Maximum tablet-Area (Wacom unit):" "$Xtabletmaxarea" x "$Ytabletmaxarea"
echo "Precision-mode area (px):" "$XtabletactiveareaPIX" x "$YtabletactiveareaPIX"
echo "Precision-mode offset (px):" "$XOffsettabletactiveareaPIX" x "$YOffsettabletactiveareaPIX"
echo ""
echo "-----------------------------------------"
if [ -f /tmp/wacomscript-680-memory-tokken ]; then
# Here Precision mode; full tablet area in cm are 1:1 on a portion of the screen.
echo ""
echo "Precision mode on $primary"
echo ""
echo "-----------------------------------------"
xsetwacom set "$tabletstylus" Area 0 0 "$Xtabletmaxarea" "$Ytabletmaxarea"
xsetwacom set "$tableteraser" Area 0 0 "$Xtabletmaxarea" "$Ytabletmaxarea"
xsetwacom set "$tabletstylus" MapToOutput "$XtabletactiveareaPIX"x"$YtabletactiveareaPIX"+"$XOffsettabletactiveareaPIX"+"$YOffsettabletactiveareaPIX"
notify-send -i "$tablet_icon" "Precision mode" "$XtabletactiveareaPIX x $YtabletactiveareaPIX part-of-screen on $primary"
rm /tmp/wacomscript-680-memory-tokken
else
# Here normal mode; tablet map to Fullscreen with ratio correction
echo ""
echo "Full-screen mode with ratio correction on $primary"
echo ""
echo "-----------------------------------------"
xsetwacom set "$tabletstylus" Area 0 0 "$Xtabletmaxarea" "$Ytabletmaxarearatiosized"
xsetwacom set "$tableteraser" Area 0 0 "$Xtabletmaxarea" "$Ytabletmaxarearatiosized"
xsetwacom set "$tabletstylus" MapToOutput "$Xscreenpix"x"$Yscreenpix"+0+0
notify-send -i "$tablet_icon" "Normal mode" "full-screen on $primary"
touch /tmp/wacomscript-680-memory-tokken
fi
}
## Enable or Disable Touch
tablet_touch_mode(){
if [ -f /tmp/wacomscript-680-touch-tokken ]; then
echo ""
echo "Enabling Touch on $tablettouch"
echo ""
echo "-----------------------------------------"
xsetwacom set "$tablettouch" Touch "on"
notify-send -i "$tablet_icon" "Tablet Settings" "Touch Enabled"
rm /tmp/wacomscript-680-touch-tokken
else
echo ""
echo "Disabling Touch on $tablettouch"
echo ""
echo "-----------------------------------------"
xsetwacom set "$tablettouch" Touch "off"
notify-send -i "$tablet_icon" "Tablet Settings" "Touch Disabled"
touch /tmp/wacomscript-680-touch-tokken
fi
}
# Error Messages
error_msg(){
echo >&2 "No commands given. (try running with --help)"
}
## Commandline Processing
case "$1" in
--help)
grep '^#:' $0 | cut -d ':' -f 2-50
exit 0
;;
--initiate)
set_buttons
tablet_area_mode
tablet_touch_mode
;;
--reset)
set_buttons
rm -fi /tmp/wacomscript-680*
tablet_area_mode
tablet_touch_mode
;;
--set-buttons)
set_buttons
;;
--switch-display)
tablet_display_mode
;;
--area-mode)
tablet_area_mode
;;
--touch-mode)
tablet_touch_mode
;;
*)
error_msg
exit 2
;;
esac
@Franciscoilustrador
Copy link

I tried to use your script with my Intuos CTH-680, in Linux Mint 18.2, and I can not get it to work.

I'm new to Linux, and I do not know if the problem is that I'm only using one monitor, instead of two. The only thing I tried is to change display1 = "HDMI1" to "DP1", since I have a monitor connected via DisplayPort, and also "eDP1" for "HDMI2", the other video output my PC has.

I even changed the order, and connected my monitor with HDMI. I have not achieved any effect (except some pen locks).

I've also tried using David Revoy's script to switch from normal to precision, and in this case, when running the script alternatively, the mode change messages appeared, but no real effect on the projection (does not change to mode precise).

I have run David's script in the terminal and this is what is read, after a first launch:

Full-screen mode with ratio correction
Can not find device 'Wacom Intuos PT M Pen'
Can not find device 'Wacom Intuos PT M Pen'
Can not find device 'Wacom Intuos PT M Pen'

I would appreciate it if you could tell me what I can do to make your script work with my tablet, or if you can give me some clue as I understand that you use it and it works.

Remember that I am absolutely novice and very little Linux.

By the way, when I try to configure the pen buttons through xsetwacom, neither the central click nor the right one works ... Yes I can configure them through the Linux Mint control panel.

Thank you!

@odysseywestra
Copy link
Author

You know what, I really just noticed this( two year later), and I'm so sorry. I Hope you figured it out. ^^'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment