Skip to content

Instantly share code, notes, and snippets.

@RomanHargrave
Created January 2, 2021 08:20
Show Gist options
  • Save RomanHargrave/9b0c1f426481fe29b2bb3587a0640499 to your computer and use it in GitHub Desktop.
Save RomanHargrave/9b0c1f426481fe29b2bb3587a0640499 to your computer and use it in GitHub Desktop.
Set up X params for wacom tablets (specifically Cintiq 13HD)
#!/usr/bin/perl
use Getopt::Long;
my $dev_name = 'Wacom Cintiq 13HD';
my @randr_setup = qw(--rotate inverted --right-of DP-3 --mode 1920x1080);
my $randr_output = 'HDMI-1';
my $invert_tab = 1;
my $ddc_mfg = 'WAC';
my %ddc_vcp = qw(
10 64
16 46
);
# Buttons are described assuming that the Cintiq umbilical is on the LEFT
my %buttons = (
2 => 'key ctrl', # Bottom-most button
3 => 'key tab', # Second button from the bottom
8 => 'key ctrl shift z', # Second buttom from the top
9 => 'key ctrl z', # Top button
1 => '3', # D-Pad center
10 => 'key left', # D-Pad left
11 => 'key down', # D-Pad down
12 => 'key right', # D-Pad right
13 => 'key up', # D-Pad up
);
GetOptions(
'd|device-name=s' => \$dev_name,
'randr=s@' => \@randr_setup,
'o|output=s' => \$randr_output
);
sub say_sys {
print join(' ', @_) . "\n";
system(@_);
}
my %devices =
map { /(^.+[^\s])\s*id: (\d+)/; ($1, $2) }
split '\n', `xsetwacom --list devices`;
my @matched_devs =
grep { /^$dev_name/ }
keys %devices;
my @pads =
grep { /^$dev_name Pad pad/ }
keys %devices;
say_sys(qw(xrandr --output), $randr_output, @randr_setup);
for my $dev (@matched_devs) {
my @base = (qw(xsetwacom --set), $devices{$dev});
say_sys(@base, 'MapToOutput', $randr_output);
say_sys(@base, qw(Rotate half)) if $invert_tab;
}
warn "More than one pad present!" if $#pads > 1;
for my $pad (@pads) {
for my $btn_id (keys %buttons) {
say_sys(qw(xsetwacom --set), $devices{$pad}, 'Button', $btn_id, $buttons{$btn_id});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment