Skip to content

Instantly share code, notes, and snippets.

@bigibas123
Created October 11, 2021 23:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bigibas123/6ec6db0b84fb8ed0edaadbc0802388e3 to your computer and use it in GitHub Desktop.
Save bigibas123/6ec6db0b84fb8ed0edaadbc0802388e3 to your computer and use it in GitHub Desktop.
xinput tablet settings script
#!/bin/sh
#USER VARIABLES
tablet_name="Wacom One by Wacom S Pen stylus" #search-term for the tablet, execute `xinput` to see the names
pan_scroll_threshold="200" #when scrolling with the pen how sensitive is it. Ranke:1-2147483647 Default: 1700
pressure_threshold="27" #how much pressure is needed on the pen tip to trigger a button press. Range:0-2048 Default:27
proximity="30" #how close the pen needs to be to start working. Range:0-63 Default:30
#RELATIVE
pointer_pct="30" #percentage by how much the pointer should be sped up in relative mode 100 is slow 1 is wroom
rotation_deg="180" #degrees by how much the tablet is rotated in relative mode
#ABSOLUTE
display_search="1680/459x1050/296" #search-term for the monitor output in absolute mode, execute xrandr --listmonitors and pick an unique part of the output line of your monitor
shrink_pct="90" #percentage by how much te area must be shrunk/ the pointer should be sped up in absolute mode
#DEVICE SPECIFICATION
#Get the xinput id of the tablet
xinput_id=$(xinput | grep "${tablet_name}" | cut -f 2 | cut -d '=' -f 2)
#get the main display output port
display_name=$(xrandr --listmonitors | grep "${display_search}" | cut -d ' ' -f 6)
dp="scale=3;" #precision of the calulations x digits after the decimal point
rads_per_deg=$(echo "scale=10; (4*a(1))/180" | bc -l) #radians per degree for convertion
#shrink factors need to be divided by two for usefull results becouse it is chopping off from both sides at the same time
area_shrink_factor=$(echo "${dp} (${shrink_pct}/100)/2" | bc)
# pointer speed is a float that gets subtracted from the raw input velocity
rel_pointer_speed=$(echo "${dp} ${pointer_pct}/100" | bc)
# if you want to change that aspect ratio of the speedup do it here
area_shrink_factor_x=$(echo "${dp} ${area_shrink_factor}" | bc)
area_shrink_factor_y=$(echo "${dp} ${area_shrink_factor}" | bc)
#XINPUT IDS, uses these names from inputting into xinput
WACOM_PRESSURE_THRESHOLD="Wacom Pressure Threshold"
WACOM_ROTATION="Wacom Rotation"
DEV_ACCEL_ADAPTIVE_DECEL="Device Accel Adaptive Deceleration"
DEV_ACCEL_PROFILE="Device Accel Profile"
DEV_ACCEL_CONST_DECEL="Device Accel Constant Deceleration"
WACOM_TABLET_AREA="Wacom Tablet Area"
if [ -z ${xinput_id} ]
then
echo "tablet not found"
else
xsetwacom --set ${xinput_id} ResetArea #Reset area so this script can be run multiple times
xsetwacom --set ${xinput_id} CursorProximity ${proximity}
xsetwacom --set ${xinput_id} PanScrollThreshold ${pan_scroll_threshold}
xinput set-prop ${xinput_id} "${WACOM_PRESSURE_THRESHOLD}" ${pressure_threshold}
if [ "${1}" = "abs" ] || [ "${1}" = "nos" ]
then
echo "Setting movement to ABSOLUTE"
xinput set-mode ${xinput_id} ABSOLUTE
echo "mapping input:${xinput_id} to display:${display_name}"
xinput map-to-output ${xinput_id} ${display_name}
if [ "${1}" != "nos" ]
then
prop_line=$(xinput list-props ${xinput_id} | grep Area | cut -f 3)
x_min=$(echo "${prop_line}" | cut -d ',' -f 1)
y_min=$(echo "${prop_line}" | cut -d ',' -f 2)
x_max=$(echo "${prop_line}" | cut -d ',' -f 3)
y_max=$(echo "${prop_line}" | cut -d ',' -f 4)
echo "OLD: x_min:${x_min}, x_max:${x_max}, y_min:${y_min}, y_max:${y_max}"
#amount of pixel that are cut of the edges
x_sub=$(echo "${dp} ${x_max}*${area_shrink_factor_x}" | bc)
y_sub=$(echo "${dp} ${y_max}*${area_shrink_factor_y}" | bc)
#new values
x_min=$(echo "${x_min}+${x_sub}" | bc)
x_max=$(echo "${x_max}-${x_sub}" | bc)
y_min=$(echo "${y_min}+${y_sub}" | bc)
y_max=$(echo "${y_max}-${y_sub}" | bc)
echo "NEW: x_min:${x_min}, x_max:${x_max}, y_min:${y_min}, y_max:${y_max}"
echo "shrink_factor: ${area_shrink_factor}, x:${area_shrink_factor_x}, y:${area_shrink_factor_y}"
echo "cut_off: x:${x_sub}, y:${y_sub}"
xinput set-prop ${xinput_id} "${WACOM_TABLET_AREA}" ${x_min}, ${y_min}, ${x_max}, ${y_max}
fi
else
echo "Setting movement to RELATIVE"
xinput set-mode ${xinput_id} RELATIVE
xinput set-prop ${xinput_id} "${DEV_ACCEL_ADAPTIVE_DECEL}" 1 #disable adaptive deceleration
xinput set-prop ${xinput_id} "${DEV_ACCEL_PROFILE}" -1 #Set accel profile to none
rotation_rad=$(echo "${dp} ${rotation_deg}*${rads_per_deg}" | bc)
echo "${rotation_deg}=${rotation_rad}"
xinput set-prop ${xinput_id} "${WACOM_ROTATION}" ${rotation_rad} #set rotation
if [ "${1}" = "rels" ]
then
echo "setting acceleration to 1"
xinput set-prop ${xinput_id} "${DEV_ACCEL_CONST_DECEL}" 1
xsetwacom --set ${xinput_id} Button 2 "pan"
else
echo "setting acceleration to ${rel_pointer_speed}"
xinput set-prop ${xinput_id} "${DEV_ACCEL_CONST_DECEL}" ${rel_pointer_speed}
xsetwacom --set ${xinput_id} Button 2 2
fi
fi
fi
@bigibas123
Copy link
Author

remap-tablet.sh [rels,abs,nos]

  • nos real absolute mode (top left of screen is top left of tablet)
  • abs fast absolute mode (top left of screen is about 1cm from center)
  • rels slow relative mode (functions like a mouse where the entire tablet is equal to one screen)
  • anything else fast relative mode (functions like a mouse with high sensitivity)

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