Skip to content

Instantly share code, notes, and snippets.

@borkweb
Created August 20, 2020 03:09
Show Gist options
  • Save borkweb/0465a0b8ae1daae56f5fe65264c4b995 to your computer and use it in GitHub Desktop.
Save borkweb/0465a0b8ae1daae56f5fe65264c4b995 to your computer and use it in GitHub Desktop.
Script for setting up my wacom on linux using xsetwacom
#!/usr/bin/env php
<?php
$command = 'xsetwacom --set "%s" MapToOutput 3840x2160+1920+0';
$output = shell_exec( 'xsetwacom --list devices' );
$output = explode( "\n", $output );
// Parts will include:
// STYLUS
// ERASER
// CURSOR
// PAD
// TOUCH
$devices = [];
$device_names = [
'STYLUS' => 'Wacom Intuos5 touch L Pen stylus',
'ERASER' => 'Wacom Intuos5 touch L Pen eraser',
'CURSOR' => 'Wacom Intuos5 touch L Pen cursor',
'PAD' => 'Wacom Intuos5 touch L Pad pad',
'TOUCH' => 'Wacom Intuos5 touch L Finger touch',
];
// Paramters:
$parameters = [];
// Area - Valid tablet area in device coordinates.
// Button - X11 event to which the given button should be mapped.
// ToolDebugLevel - Level of debugging trace for individual tools (default is 0 [off]).
// TabletDebugLevel - Level of debugging statements applied to shared code paths between all tools associated with the same tablet (default is 0 [off]).
// Suppress - Number of points trimmed (default is 2).
// RawSample - Number of raw data used to filter the points (default is 4).
// PressureCurve - Bezier curve for pressure (default is 0 0 100 100 [linear]).
// Mode - Switches cursor movement mode (default is absolute).
// TabletPCButton - Turns on/off Tablet PC buttons (default is off for regular tablets, on for Tablet PC).
// Touch - Turns on/off Touch events (default is on).
// HWTouchSwitchState - Touch events turned on/off by hardware switch.
// Gesture - Turns on/off multi-touch gesture events (default is on).
// ZoomDistance - Minimum distance for a zoom gesture (default is 50).
// ScrollDistance - Minimum motion before sending a scroll gesture (default is 20).
// TapTime - Minimum time between taps for a right click (default is 250).
// CursorProximity - Sets cursor distance for proximity-out in distance from the tablet (default is 10 for Intuos series, 42 for Graphire series).
// Rotate - Sets the rotation of the tablet. Values = none, cw, ccw, half (default is none).
// RelWheelUp - X11 event to which relative wheel up should be mapped.
// RelWheelDown - X11 event to which relative wheel down should be mapped.
// AbsWheelUp - X11 event to which absolute wheel up should be mapped.
// AbsWheelDown - X11 event to which absolute wheel down should be mapped.
// AbsWheel2Up - X11 event to which absolute wheel up should be mapped.
// AbsWheel2Down - X11 event to which absolute wheel down should be mapped.
// StripLeftUp - X11 event to which left strip up should be mapped.
// StripLeftDown - X11 event to which left strip down should be mapped.
// StripRightUp - X11 event to which right strip up should be mapped.
// StripRightDown - X11 event to which right strip down should be mapped.
// Threshold - Sets tip/eraser pressure threshold (default is 27).
// ResetArea - Resets the bounding coordinates to default in tablet units.
// ToolType - Returns the tool type of the associated device.
// ToolSerial - Returns the serial number of the current device in proximity.
// ToolID - Returns the tool ID of the current tool in proximity.
// ToolSerialPrevious - Returns the serial number of the previous device in proximity.
// BindToSerial - Binds this device to the serial number.
// TabletID - Returns the tablet ID of the associated device.
// PressureRecalibration - Turns on/off Tablet pressure recalibration
// PanScrollThreshold - Adjusts distance required for pan actions to generate a scroll event
// MapToOutput - Map the device to the given output.
// all - Get value for all parameters.
/**
* BUTTON MAPPING
*
* [ 2 ]
* [ 3 ]
* [ 8 ]
* [ 9 ]
*
* ( 1 )
*
* [ 10 ]
* [ 11 ]
* [ 12 ]
* [ 13 ]
*/
$parameters['PAD'] = [];
$parameters['PAD']['Touch'] = 'off';
$parameters['PAD']['Gesture'] = 'off';
$parameters['PAD']['Button 9'] = 'key t';
$parameters['PAD']['Button 10'] = 'key l';
$parameters['PAD']['Button 11'] = 'key b';
$parameters['PAD']['Button 12'] = 'key p';
$parameters['PAD']['Button 13'] = 'key +space';
$parameters['STYLUS']['Button 2'] = 'button +3';
$parameters['STYLUS']['Button 3'] = 'key +ctrl z -ctrl';
/*************************************
*
* Set up the devices
*
*************************************/
foreach ( $output as $line ) {
if ( empty( $line ) ) {
continue;
}
preg_match( '/.*id:\s+(\d+)\s+.*type:\s+([A-Z]+)/', $line, $matches );
passthru( sprintf( $command, $matches[1] ) );
$devices[ $matches[2] ] = $matches[1];
}
/*************************************
*
* Set up the parameters
*
*************************************/
foreach ( $parameters as $device => $device_parameters ) {
foreach ( $device_parameters as $parameter => $value ) {
if ( null === $value ) {
continue;
}
$command = "xsetwacom --set {$devices[ $device ]} {$parameter} \"{$value}\"";
echo $command . "\n";
passthru( $command );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment