From 5146bd00fd5613c7e10b3ced4bf5d26b9d78a69e Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 19 Feb 2015 11:00:27 +1000 Subject: [PATCH] tablet: de-couple tool enum values from linux/input.h There's no real reason to keep them in sync but it has drawbacks when we start introducing tools that the kernel doesn't have (and can't easily add due to range constraints). Signed-off-by: Peter Hutterer Reviewed-by: Benjamin Tissoires Reviewed-by: Stephen Chandler Paul --- src/evdev-tablet.c | 27 +++++++++++++++++++++++++-- src/libinput.h | 2 +- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index e994de4d..013038b7 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -244,6 +244,27 @@ tablet_update_button(struct tablet_dispatch *tablet, } } +static inline enum libinput_tool_type +tablet_evcode_to_tool(int code) +{ + enum libinput_tool_type type; + + switch (code) { + case BTN_TOOL_PEN: type = LIBINPUT_TOOL_PEN; break; + case BTN_TOOL_RUBBER: type = LIBINPUT_TOOL_ERASER; break; + case BTN_TOOL_BRUSH: type = LIBINPUT_TOOL_BRUSH; break; + case BTN_TOOL_PENCIL: type = LIBINPUT_TOOL_PENCIL; break; + case BTN_TOOL_AIRBRUSH: type = LIBINPUT_TOOL_AIRBRUSH; break; + case BTN_TOOL_FINGER: type = LIBINPUT_TOOL_FINGER; break; + case BTN_TOOL_MOUSE: type = LIBINPUT_TOOL_MOUSE; break; + case BTN_TOOL_LENS: type = LIBINPUT_TOOL_LENS; break; + default: + abort(); + } + + return type; +} + static void tablet_process_key(struct tablet_dispatch *tablet, struct evdev_device *device, @@ -259,8 +280,10 @@ tablet_process_key(struct tablet_dispatch *tablet, case BTN_TOOL_FINGER: case BTN_TOOL_MOUSE: case BTN_TOOL_LENS: - /* These codes have an equivalent libinput_tool value */ - tablet_update_tool(tablet, device, e->code, e->value); + tablet_update_tool(tablet, + device, + tablet_evcode_to_tool(e->code), + e->value); break; case BTN_TOUCH: if (e->value) diff --git a/src/libinput.h b/src/libinput.h index 3cb02b92..7e1e5fdf 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -159,7 +159,7 @@ struct libinput_tool; * LIBINPUT_DEVICE_CAP_TABLET capability. */ enum libinput_tool_type { - LIBINPUT_TOOL_PEN = 0x140, /* Matches BTN_TOOL_PEN */ + LIBINPUT_TOOL_PEN = 1, LIBINPUT_TOOL_ERASER, LIBINPUT_TOOL_BRUSH, LIBINPUT_TOOL_PENCIL,