Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Evdev code parsing #594

Merged
merged 1 commit into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [ push, pull_request ]

env:
CFLAGS: "-Werror -Wno-error=missing-field-initializers"
UBUNTU_PACKAGES: libgudev-1.0-dev libxml++2.6-dev valgrind tree python3-pip python3-setuptools libevdev2
UBUNTU_PACKAGES: libgudev-1.0-dev libxml++2.6-dev valgrind tree python3-pip python3-setuptools libevdev-dev
PIP_PACKAGES: meson ninja libevdev pyudev pytest yq

jobs:
Expand Down
2 changes: 1 addition & 1 deletion data/bamboo-0fg-m-p-alt.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ Ring=true

[Buttons]
Top=A;B;C;D
EvdevCodes=0x116;0x115;0x110;0x111
EvdevCodes=BTN_BACK;BTN_FORWARD;BTN_LEFT;BTN_RIGHT
2 changes: 1 addition & 1 deletion data/bamboo-0fg-s-p-alt.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ Ring=true

[Buttons]
Top=A;B;C;D
EvdevCodes=0x116;0x115;0x110;0x111
EvdevCodes=BTN_BACK;BTN_FORWARD;BTN_LEFT;BTN_RIGHT
2 changes: 1 addition & 1 deletion data/bamboo-0fg-s-p.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ Ring=true

[Buttons]
Top=A;B;C;D
EvdevCodes=0x116;0x115;0x110;0x111
EvdevCodes=BTN_BACK;BTN_FORWARD;BTN_LEFT;BTN_RIGHT
2 changes: 1 addition & 1 deletion data/bamboo-16fg-m-pt.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ Buttons=4

[Buttons]
Left=A;B;C;D
EvdevCodes=0x110;0x115;0x116;0x111
EvdevCodes=BTN_LEFT;BTN_FORWARD;BTN_BACK;BTN_RIGHT
2 changes: 1 addition & 1 deletion data/bamboo-16fg-s-p.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ Stylus=true
Reversible=true
Touch=false
Buttons=0
EvdevCodes=0x110;0x115;0x116;0x111
EvdevCodes=BTN_LEFT;BTN_FORWARD;BTN_BACK;BTN_RIGHT
2 changes: 1 addition & 1 deletion data/bamboo-16fg-s-pt.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ Buttons=4

[Buttons]
Left=A;B;C;D
EvdevCodes=0x110;0x115;0x116;0x111
EvdevCodes=BTN_LEFT;BTN_FORWARD;BTN_BACK;BTN_RIGHT
2 changes: 1 addition & 1 deletion data/bamboo-16fg-s-t.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ Buttons=4

[Buttons]
Left=A;B;C;D
EvdevCodes=0x110;0x115;0x116;0x111
EvdevCodes=BTN_LEFT;BTN_FORWARD;BTN_BACK;BTN_RIGHT
2 changes: 1 addition & 1 deletion data/bamboo-2fg-fun-m-pt.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ Buttons=4

[Buttons]
Left=A;B;C;D
EvdevCodes=0x111;0x116;0x115;0x110
EvdevCodes=BTN_RIGHT;BTN_BACK;BTN_FORWARD;BTN_LEFT
2 changes: 1 addition & 1 deletion data/bamboo-2fg-fun-s-pt.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ Buttons=4

[Buttons]
Left=A;B;C;D
EvdevCodes=0x111;0x116;0x115;0x110
EvdevCodes=BTN_RIGHT;BTN_BACK;BTN_FORWARD;BTN_LEFT
2 changes: 1 addition & 1 deletion data/bamboo-2fg-s-pt.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ Buttons=4

[Buttons]
Left=A;B;C;D
EvdevCodes=0x111;0x116;0x115;0x110
EvdevCodes=BTN_RIGHT;BTN_BACK;BTN_FORWARD;BTN_LEFT
2 changes: 1 addition & 1 deletion data/bamboo-2fg-s-t.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ Buttons=4

[Buttons]
Left=A;B;C;D
EvdevCodes=0x111;0x116;0x115;0x110
EvdevCodes=BTN_RIGHT;BTN_BACK;BTN_FORWARD;BTN_LEFT
2 changes: 1 addition & 1 deletion data/bamboo-4fg-fun-m.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ Buttons=4

[Buttons]
Left=A;B;C;D
EvdevCodes=0x111;0x116;0x115;0x110
EvdevCodes=BTN_RIGHT;BTN_BACK;BTN_FORWARD;BTN_LEFT
2 changes: 1 addition & 1 deletion data/bamboo-4fg-fun-s.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ Buttons=4

[Buttons]
Left=A;B;C;D
EvdevCodes=0x111;0x116;0x115;0x110
EvdevCodes=BTN_RIGHT;BTN_BACK;BTN_FORWARD;BTN_LEFT
2 changes: 1 addition & 1 deletion data/bamboo-4fg-s-pt.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ Buttons=4

[Buttons]
Left=A;B;C;D
EvdevCodes=0x111;0x116;0x115;0x110
EvdevCodes=BTN_RIGHT;BTN_BACK;BTN_FORWARD;BTN_LEFT
2 changes: 1 addition & 1 deletion data/bamboo-4fg-s-t.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ Buttons=4

[Buttons]
Left=A;B;C;D
EvdevCodes=0x111;0x116;0x115;0x110
EvdevCodes=BTN_RIGHT;BTN_BACK;BTN_FORWARD;BTN_LEFT
2 changes: 1 addition & 1 deletion data/bamboo-4fg-se-m-pt.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ Buttons=4

[Buttons]
Left=A;B;C;D
EvdevCodes=0x111;0x116;0x115;0x110
EvdevCodes=BTN_RIGHT;BTN_BACK;BTN_FORWARD;BTN_LEFT
2 changes: 1 addition & 1 deletion data/bamboo-4fg-se-s-pt.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ Buttons=4

[Buttons]
Left=A;B;C;D
EvdevCodes=0x111;0x116;0x115;0x110
EvdevCodes=BTN_RIGHT;BTN_BACK;BTN_FORWARD;BTN_LEFT
2 changes: 1 addition & 1 deletion data/bamboo-pad-wireless.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ Buttons=2

[Buttons]
Bottom=A;B
EvdevCodes=0x110;0x111
EvdevCodes=BTN_LEFT;BTN_RIGHT
2 changes: 1 addition & 1 deletion data/bamboo-pad.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ Buttons=2

[Buttons]
Bottom=A;B
EvdevCodes=0x110;0x111
EvdevCodes=BTN_LEFT;BTN_RIGHT
2 changes: 1 addition & 1 deletion data/ek-remote.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ StatusLEDs=Ring

[Buttons]
Left=A;B;C;D;E;F;G;H;I;J;K;L;M;N;O;P;Q;R
EvdevCodes=0x100;0x101;0x102;0x103;0x104;0x105;0x106;0x107;0x108;0x109;0x130;0x131;0x132;0x133;0x134;0x135;0x126;0x127
EvdevCodes=BTN_0;BTN_1;BTN_2;BTN_3;BTN_4;BTN_5;BTN_6;BTN_7;BTN_8;BTN_9;0x130;0x131;0x132;0x133;0x134;0x135;0x126;0x127

#Note that though this device has 3 ring modes
#this mode selection does not function the same
Expand Down
2 changes: 1 addition & 1 deletion data/gaomon-s620.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ Buttons=4

[Buttons]
Left=A;B;C;D
EvdevCodes=0x100;0x101;0x102;0x103
EvdevCodes=BTN_0;BTN_1;BTN_2;BTN_3
2 changes: 1 addition & 1 deletion data/graphire4-6x8.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ Buttons=2

[Buttons]
Top=A;B
EvdevCodes=0x116;0x115
EvdevCodes=BTN_BACK;BTN_FORWARD
2 changes: 1 addition & 1 deletion data/huion-h1060p.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ Buttons=12

[Buttons]
Left=A;B;C;D;E;F;G;H;I;J;K;L
EvdevCodes=0x100;0x101;0x102;0x103;0x104;0x105;0x106;0x107;0x108;0x109;0x130;0x131
EvdevCodes=BTN_0;BTN_1;BTN_2;BTN_3;BTN_4;BTN_5;BTN_6;BTN_7;BTN_8;BTN_9;0x130;0x131
2 changes: 1 addition & 1 deletion data/huion-h420.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ Buttons=3

[Buttons]
Left=A;B;C
EvdevCodes=0x100;0x101;0x102;
EvdevCodes=BTN_0;BTN_1;BTN_2;
2 changes: 1 addition & 1 deletion data/huion-h610-pro.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ Buttons=8

[Buttons]
Left=A;B;C;D;E;F;G;H
EvdevCodes=0x100;0x101;0x102;0x103;0x104;0x105;0x106;0x107
EvdevCodes=BTN_0;BTN_1;BTN_2;BTN_3;BTN_4;BTN_5;BTN_6;BTN_7
2 changes: 1 addition & 1 deletion data/huion-h640p.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ Buttons=6

[Buttons]
Left=A;B;C;D;E;F
EvdevCodes=0x100;0x101;0x102;0x103;0x104;0x105
EvdevCodes=BTN_0;BTN_1;BTN_2;BTN_3;BTN_4;BTN_5
2 changes: 1 addition & 1 deletion data/huion-h950p.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ Buttons=8

[Buttons]
Left=A;B;C;D;E;F;G;H
EvdevCodes=0x100;0x101;0x102;0x103;0x104;0x105;0x106;0x107
EvdevCodes=BTN_0;BTN_1;BTN_2;BTN_3;BTN_4;BTN_5;BTN_6;BTN_7
2 changes: 1 addition & 1 deletion data/huion-hs611.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ Buttons=10

[Buttons]
Left=A;B;C;D;E;F;G;H;I;J
EvdevCodes=0x100;0x101;0x102;0x103;0x104;0x105;0x106;0x107;0x108;0x109
EvdevCodes=BTN_0;BTN_1;BTN_2;BTN_3;BTN_4;BTN_5;BTN_6;BTN_7;BTN_8;BTN_9
2 changes: 1 addition & 1 deletion data/huion-kamvas-13.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ Buttons=8

[Buttons]
Left=A;B;C;D;E;F;G;H
EvdevCodes=0x100;0x101;0x102;0x103;0x104;0x105;0x106;0x107
EvdevCodes=BTN_0;BTN_1;BTN_2;BTN_3;BTN_4;BTN_5;BTN_6;BTN_7
2 changes: 1 addition & 1 deletion data/huion-new-1060-plus.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ Buttons=12

[Buttons]
Left=A;B;C;D;E;F;G;H;I;J;K;L
EvdevCodes=0x100;0x101;0x102;0x103;0x104;0x105;0x106;0x107;0x108;0x109;0x130;0x131
EvdevCodes=BTN_0;BTN_1;BTN_2;BTN_3;BTN_4;BTN_5;BTN_6;BTN_7;BTN_8;BTN_9;0x130;0x131
2 changes: 1 addition & 1 deletion data/intuos-m-p3-wl.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ Buttons=4

[Buttons]
Top=A;B;C;D
EvdevCodes=0x100;0x101;0x102;0x103
EvdevCodes=BTN_0;BTN_1;BTN_2;BTN_3
2 changes: 1 addition & 1 deletion data/intuos-m-p3.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ Buttons=4

[Buttons]
Top=A;B;C;D
EvdevCodes=0x100;0x101;0x102;0x103
EvdevCodes=BTN_0;BTN_1;BTN_2;BTN_3
2 changes: 1 addition & 1 deletion data/intuos-s-p3-android.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ Buttons=4

[Buttons]
Top=A;B;C;D
EvdevCodes=0x100;0x101;0x102;0x103
EvdevCodes=BTN_0;BTN_1;BTN_2;BTN_3
2 changes: 1 addition & 1 deletion data/intuos-s-p3-wl.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ Buttons=4

[Buttons]
Top=A;B;C;D
EvdevCodes=0x100;0x101;0x102;0x103
EvdevCodes=BTN_0;BTN_1;BTN_2;BTN_3
2 changes: 1 addition & 1 deletion data/intuos-s-p3.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ Buttons=4

[Buttons]
Top=A;B;C;D
EvdevCodes=0x100;0x101;0x102;0x103
EvdevCodes=BTN_0;BTN_1;BTN_2;BTN_3
4 changes: 2 additions & 2 deletions data/kamvas-pro-13.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#
# Touch Strip Map:
# NOTE: not enabled because i couldnt get it to work
# evtest reports 0x108 (BTN_8), 0x109 (BTN_9), 0x130 (BTN_SOUTH)
# evtest reports BTN_8, BTN_9, BTN_SOUTH
#
# *-----------------------*
# | |
Expand Down Expand Up @@ -54,4 +54,4 @@ Buttons=5

[Buttons]
Left=A;B;C;D;E
EvdevCodes=0x100;0x101;0x102;0x103;0x104
EvdevCodes=BTN_0;BTN_1;BTN_2;BTN_3;BTN_4
2 changes: 1 addition & 1 deletion data/wacom.example
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ Top=
Bottom=
# The evdev codes for the buttons in order A, B, C, ...
# The code must be defined for all buttons or this line is ignored
EvdevCodes=0x110;0x112;0x111;0x113
EvdevCodes=BTN_LEFT;BTN_MIDDLE;BTN_RIGHT;BTN_SIDE

#####################
# ADVANCED FEATURES #
Expand Down
2 changes: 1 addition & 1 deletion data/xp-pen-artist12.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ Buttons=6

[Buttons]
Left=A;B;C;D;E;F
EvdevCodes=0x100;0x101;0x102;0x103;0x104;0x105
EvdevCodes=BTN_0;BTN_1;BTN_2;BTN_3;BTN_4;BTN_5
2 changes: 1 addition & 1 deletion data/xp-pen-deco-l.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ Buttons=8

[Buttons]
Left=A;B;C;D;E;F;G;H
EvdevCodes=0x100;0x101;0x102;0x103;0x104;0x105;0x106;0x107
EvdevCodes=BTN_0;BTN_1;BTN_2;BTN_3;BTN_4;BTN_5;BTN_6;BTN_7
2 changes: 1 addition & 1 deletion data/xp-pen-deco-mini7.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ Buttons=8

[Buttons]
Left=A;B;C;D;E;F;G;H
EvdevCodes=0x100;0x101;0x102;0x103;0x104;0x105;0x106;0x107
EvdevCodes=BTN_0;BTN_1;BTN_2;BTN_3;BTN_4;BTN_5;BTN_6;BTN_7
2 changes: 1 addition & 1 deletion data/xp-pen-deco-mw.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ Buttons=8

[Buttons]
Left=A;B;C;D;E;F;G;H
EvdevCodes=0x100;0x101;0x102;0x103;0x104;0x105;0x106;0x107
EvdevCodes=BTN_0;BTN_1;BTN_2;BTN_3;BTN_4;BTN_5;BTN_6;BTN_7

2 changes: 1 addition & 1 deletion data/xp-pen-deco-pro-mw.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ Buttons=8

[Buttons]
Left=A;B;C;D;E;F;G;H
EvdevCodes=0x100;0x101;0x102;0x103;0x104;0x105;0x106;0x107
EvdevCodes=BTN_0;BTN_1;BTN_2;BTN_3;BTN_4;BTN_5;BTN_6;BTN_7
2 changes: 1 addition & 1 deletion data/xp-pen-deco-pro-sw.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ Buttons=8

[Buttons]
Left=A;B;C;D;E;F;G;H
EvdevCodes=0x100;0x101;0x102;0x103;0x104;0x105;0x106;0x107
EvdevCodes=BTN_0;BTN_1;BTN_2;BTN_3;BTN_4;BTN_5;BTN_6;BTN_7
2 changes: 1 addition & 1 deletion data/xp-pen-deco01-v2.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ Buttons=8

[Buttons]
Left=A;B;C;D;E;F;G;H
EvdevCodes=0x100;0x101;0x102;0x103;0x104;0x105;0x106;0x107
EvdevCodes=BTN_0;BTN_1;BTN_2;BTN_3;BTN_4;BTN_5;BTN_6;BTN_7
2 changes: 1 addition & 1 deletion data/xp-pen-star03.tablet
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ Buttons=8

[Buttons]
Left=A;B;C;D;E;F;G;H
EvdevCodes=0x100;0x101;0x102;0x103;0x104;0x105;0x106;0x107
EvdevCodes=BTN_0;BTN_1;BTN_2;BTN_3;BTN_4;BTN_5;BTN_6;BTN_7
15 changes: 11 additions & 4 deletions libwacom/libwacom-database.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "libwacomint.h"
#include "util-strings.h"
#include <linux/input-event-codes.h>
#include <libevdev/libevdev.h>

#include <assert.h>
#include <glib.h>
Expand Down Expand Up @@ -455,26 +456,32 @@ set_button_codes_from_string(WacomDevice *device, char **strvals)

for (guint i = 0; i < g_hash_table_size(device->buttons); i++) {
char key = 'A' + i;
int code;
int code = -1;
WacomButton *button = g_hash_table_lookup(device->buttons, GINT_TO_POINTER(key));
const char *str = strvals[i];

if (!button) {
g_error("%s: Button %c is not defined, ignoring all codes\n",
device->name, key);
goto out;
}

if (!strvals[i]) {
if (!str) {
g_error ("%s: Missing EvdevCode for button %d, ignoring all codes\n",
device->name, i);
goto out;
} else if (g_str_has_prefix(str, "BTN")) {
code = libevdev_event_code_from_code_name(str);
} else if (!safe_atoi_base(str, &code, 16)) {
code = -1;
}

if (!safe_atoi_base (strvals[i], &code, 16) || code < BTN_MISC || code >= BTN_DIGI) {
if (code < BTN_MISC || code >= BTN_DIGI) {
g_warning ("%s: Invalid EvdevCode %s for button %c, ignoring all codes\n",
device->name, strvals[i], key);
device->name, str, key);
goto out;
}

button->code = code;
}
success = true;
Expand Down
12 changes: 8 additions & 4 deletions libwacom/libwacom.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
#include <stdio.h>
#include <string.h>
#include <gudev/gudev.h>

#include <linux/input-event-codes.h>
#include <libevdev/libevdev.h>

#if !HAVE_G_MEMDUP2
#define g_memdup2 g_memdup
Expand Down Expand Up @@ -754,9 +753,14 @@ static void print_button_evdev_codes(int fd, const WacomDevice *device)
unsigned idx = 0;

for (b = 'A'; b < 'A' + nbuttons; b++) {
unsigned int code = libwacom_get_button_evdev_code(device, b);
const char *str = libevdev_event_code_get_name(EV_KEY, code);

assert(idx < sizeof(buf) - 30);
idx += snprintf(buf + idx, 30, "0x%x;",
libwacom_get_button_evdev_code(device, b));
if (str)
idx += snprintf(buf + idx, 30, "%s;", str);
else
idx += snprintf(buf + idx, 30, "0x%x;", code);
}
dprintf(fd, "EvdevCodes=%s\n", buf);
}
Expand Down
10 changes: 6 additions & 4 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ cflags = cc.get_supported_arguments(
add_project_arguments(cflags, language: 'c')

# Dependencies
pkgconfig = import('pkgconfig')
dep_gudev = dependency('gudev-1.0')
dep_glib = dependency('glib-2.0')
pkgconfig = import('pkgconfig')
dep_gudev = dependency('gudev-1.0')
dep_glib = dependency('glib-2.0')
dep_libevdev = dependency('libevdev')

includes_include = include_directories('include')
includes_src = include_directories('libwacom')
Expand All @@ -75,7 +76,8 @@ src_libwacom = [

deps_libwacom = [
dep_gudev,
dep_glib
dep_glib,
dep_libevdev,
]

inc_libwacom = [
Expand Down