Skip to content

Instantly share code, notes, and snippets.

@clo-yunhee
Last active November 25, 2018 19:38
Show Gist options
  • Save clo-yunhee/281ffbaf748c614a7c20f55536dc3a22 to your computer and use it in GitHub Desktop.
Save clo-yunhee/281ffbaf748c614a7c20f55536dc3a22 to your computer and use it in GitHub Desktop.
Small(kinda?) configurable shell script to calculate active tablet area units for Xorg drivers (You'll have to adapt the output depending on which driver you're using)
#!/bin/sh
#Monitor display ratio
disprat=$(echo "16 / 9" | bc -l)
#Full area size in real units (for the G640, in mm)
tabw=152.4
tabh=101.6
#Full area size in driver units
driw=32768
drih=32768
#Execution:
echo -n "Enter Top X (0): "
read x0
echo -n "Enter Top Y (0): "
read y0
echo -n "Enter Width (/$tabw): "
read w
[ -z $x0 ] && x0=0
[ -z $y0 ] && y0=0
[ -z $w ] && w=$tabw
h=$(echo "$w / $disprat" | bc -l)
# Turn them into ratios
w=$(echo "$w / $tabw" | bc -l)
h=$(echo "$h / $tabh" | bc -l)
# Add the offset and scale for the drivers
x1=$(echo "(($x0 + $w) * $driw) / 1" | bc)
y1=$(echo "(($y0 + $h) * $drih) / 1" | bc)
msg=$(cat <<'EOT'
Edit your Xorg tablet configuration file with these options:
Option "TopX" "%d"
Option "TopY" "%d"
Option "BottomX" "%d"
Option "BottomY" "%d"
EOT
)
printf "$msg\n" $x0 $y0 $x1 $y1
# Example configuration file for an XP-PEN STAR G640 tablet, full area mapped to a 16:9 monitor.
Section "InputClass"
Identifier "Wizardpen Tablet"
MatchIsTablet "on"
MatchProduct "XP-PEN STAR G640" # Change this to your tablet model.
Driver "wizardpen"
# Edit these lines to your wanted area.
Option "TopX" "0"
Option "TopY" "0"
Option "BottomX" "32359"
Option "BottomY" "27303"
# Apply custom Options below.
EndSection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment