udev: if a tablet has BTN_0, label it as ID_INPUT_TABLET_PAD

Graphics tablet devices comprise multiple event nodes, usually a Pen, Finger
and Pad node (that's how the kernel postfixes them). Pen and Pad are labeled
as ID_INPUT_TABLET but the pad doesn't actually send stylus events - it
doesn't usually have BTN_TOOL_PEN, merely BTN_STYLUS.

For the last several years, libwacom has set ID_INPUT_TABLET_PAD for all pad
devices known to it based on vid/pid and a "* Pad" name match. That does not
cover devices not in libwacom. libinput relies on ID_INPUT_TABLET_PAD to
initialize the pad backend.

We can't drop ID_INPUT_TABLET without breaking userspace, but we can add
ID_INPUT_TABLET_PAD ourselves - where a device has BTN_0 in addition to
BTN_STYLUS, let's add it as a pad.

There are some devices (notably: bamboos) that use BTN_LEFT instead of BTN_0
but they are relatively rare and there's a risk of mislabeling those devices,
so let's just stick with BTN_0 only.
This commit is contained in:
Peter Hutterer 2020-09-17 13:06:19 +10:00 committed by Zbigniew Jędrzejewski-Szmek
parent 3dd8ae5c70
commit 9aa5c97158
1 changed files with 14 additions and 4 deletions

View File

@ -154,17 +154,20 @@ static bool test_pointers(sd_device *dev,
bool has_rel_coordinates = false;
bool has_mt_coordinates = false;
bool has_joystick_axes_or_buttons = false;
bool has_pad_buttons = false;
bool is_direct = false;
bool has_touch = false;
bool has_3d_coordinates = false;
bool has_keys = false;
bool stylus_or_pen = false;
bool has_stylus = false;
bool has_pen = false;
bool finger_but_no_pen = false;
bool has_mouse_button = false;
bool is_mouse = false;
bool is_touchpad = false;
bool is_touchscreen = false;
bool is_tablet = false;
bool is_tablet_pad = false;
bool is_joystick = false;
bool is_accelerometer = false;
bool is_pointing_stick = false;
@ -183,7 +186,8 @@ static bool test_pointers(sd_device *dev,
}
is_pointing_stick = test_bit(INPUT_PROP_POINTING_STICK, bitmask_props);
stylus_or_pen = test_bit(BTN_STYLUS, bitmask_key) || test_bit(BTN_TOOL_PEN, bitmask_key);
has_stylus = test_bit(BTN_STYLUS, bitmask_key);
has_pen = test_bit(BTN_TOOL_PEN, bitmask_key);
finger_but_no_pen = test_bit(BTN_TOOL_FINGER, bitmask_key) && !test_bit(BTN_TOOL_PEN, bitmask_key);
for (button = BTN_MOUSE; button < BTN_JOYSTICK && !has_mouse_button; button++)
has_mouse_button = test_bit(button, bitmask_key);
@ -195,6 +199,7 @@ static bool test_pointers(sd_device *dev,
has_mt_coordinates = false;
is_direct = test_bit(INPUT_PROP_DIRECT, bitmask_props);
has_touch = test_bit(BTN_TOUCH, bitmask_key);
has_pad_buttons = test_bit(BTN_0, bitmask_key) && has_stylus && !has_pen;
/* joysticks don't necessarily have buttons; e. g.
* rudders/pedals are joystick-like, but buttonless; they have
@ -216,7 +221,7 @@ static bool test_pointers(sd_device *dev,
has_joystick_axes_or_buttons = test_bit(axis, bitmask_abs);
if (has_abs_coordinates) {
if (stylus_or_pen)
if (has_stylus || has_pen)
is_tablet = true;
else if (finger_but_no_pen && !is_direct)
is_touchpad = true;
@ -232,7 +237,7 @@ static bool test_pointers(sd_device *dev,
is_joystick = true;
if (has_mt_coordinates) {
if (stylus_or_pen)
if (has_stylus || has_pen)
is_tablet = true;
else if (finger_but_no_pen && !is_direct)
is_touchpad = true;
@ -240,6 +245,9 @@ static bool test_pointers(sd_device *dev,
is_touchscreen = true;
}
if (is_tablet && has_pad_buttons)
is_tablet_pad = true;
if (!is_tablet && !is_touchpad && !is_joystick &&
has_mouse_button &&
(has_rel_coordinates ||
@ -262,6 +270,8 @@ static bool test_pointers(sd_device *dev,
udev_builtin_add_property(dev, test, "ID_INPUT_JOYSTICK", "1");
if (is_tablet)
udev_builtin_add_property(dev, test, "ID_INPUT_TABLET", "1");
if (is_tablet_pad)
udev_builtin_add_property(dev, test, "ID_INPUT_TABLET_PAD", "1");
return is_tablet || is_mouse || is_touchpad || is_touchscreen || is_joystick || is_pointing_stick;
}