[systemd-devel] [PATCH] udev: input_id: fix detection of various touchscreens
Andreas Pokorny
andreas.pokorny at canonical.com
Thu May 28 02:59:57 PDT 2015
There are touch screens that do not provide 'BTN_TOUCH' and hence no
'EV_KEY'. Previously those would not get any properties assigned and
libinput would not treat those as input devices. Additionally there
is an 'IS_DIRECT' property exposed by most touch screens, that would
otherwise be detected as touch pads.
---
src/udev/udev-builtin-input_id.c | 134 +++++++++++++++++++++------------------
1 file changed, 74 insertions(+), 60 deletions(-)
diff --git a/src/udev/udev-builtin-input_id.c b/src/udev/udev-builtin-input_id.c
index b14190e..8b08742 100644
--- a/src/udev/udev-builtin-input_id.c
+++ b/src/udev/udev-builtin-input_id.c
@@ -135,77 +135,91 @@ static bool test_pointers(struct udev_device *dev,
bool test) {
int is_mouse = 0;
int is_touchpad = 0;
- bool ret = false;
-
- if (test_bit(INPUT_PROP_ACCELEROMETER, bitmask_props)) {
- udev_builtin_add_property(dev, test, "ID_INPUT_ACCELEROMETER", "1");
- return true;
- }
-
- if (!test_bit(EV_KEY, bitmask_ev)) {
- if (test_bit(EV_ABS, bitmask_ev) &&
- test_bit(ABS_X, bitmask_abs) &&
- test_bit(ABS_Y, bitmask_abs) &&
- test_bit(ABS_Z, bitmask_abs)) {
- udev_builtin_add_property(dev, test, "ID_INPUT_ACCELEROMETER", "1");
- ret = true;
- }
- return ret;
- }
-
- if (test_bit(EV_ABS, bitmask_ev) &&
- test_bit(ABS_X, bitmask_abs) && test_bit(ABS_Y, bitmask_abs)) {
- if (test_bit(BTN_STYLUS, bitmask_key) || test_bit(BTN_TOOL_PEN, bitmask_key)) {
- udev_builtin_add_property(dev, test, "ID_INPUT_TABLET", "1");
- ret = true;
- } else if (test_bit(BTN_TOOL_FINGER, bitmask_key) && !test_bit(BTN_TOOL_PEN, bitmask_key)) {
+ int is_direct = 0;
+ int has_coordinates = 0;
+ int has_mt_coordinates = 0;
+ int has_joystick_axes_or_buttons = 0;
+ int has_touch = 0;
+ int stylus_or_pen = 0;
+ int finger_but_no_pen = 0;
+ int has_mouse = 0;
+ int is_touchscreen = 0;
+ int is_tablet = 0;
+ int is_joystick = 0;
+ int is_accelerometer = 0;
+ int is_pointing_stick= 0;
+ int has_3d_coordinates = 0;
+ int has_keys = 0;
+
+ has_keys = test_bit (EV_KEY, bitmask_ev);
+ has_touch = test_bit (BTN_TOUCH, bitmask_key);
+ has_mouse = test_bit (BTN_MOUSE, bitmask_key);
+ has_coordinates = test_bit (ABS_X, bitmask_abs) && test_bit (ABS_Y, bitmask_abs);
+ has_3d_coordinates = has_coordinates && test_bit (ABS_Z, bitmask_abs);
+ has_mt_coordinates = test_bit (ABS_MT_POSITION_X, bitmask_abs) &&
+ test_bit (ABS_MT_POSITION_Y, bitmask_abs);
+ is_direct = test_bit (INPUT_PROP_DIRECT, bitmask_props);
+ is_accelerometer = test_bit (INPUT_PROP_ACCELEROMETER, bitmask_props);
+ is_pointing_stick = test_bit(INPUT_PROP_POINTING_STICK, bitmask_props);
+ stylus_or_pen = test_bit (BTN_STYLUS, bitmask_key) ||
+ test_bit (BTN_STYLUS2, bitmask_key) ||
+ 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);
+ /* joysticks don't necessarily have to have buttons; e. g.
+ * rudders/pedals are joystick-like, but buttonless; they have
+ * other fancy axes */
+ has_joystick_axes_or_buttons = test_bit (BTN_TRIGGER, bitmask_key) ||
+ test_bit (BTN_A, bitmask_key) ||
+ test_bit (BTN_1, bitmask_key) ||
+ test_bit (ABS_RX, bitmask_abs) ||
+ test_bit (ABS_RY, bitmask_abs) ||
+ test_bit (ABS_RZ, bitmask_abs) ||
+ test_bit (ABS_THROTTLE, bitmask_abs) ||
+ test_bit (ABS_RUDDER, bitmask_abs) ||
+ test_bit (ABS_WHEEL, bitmask_abs) ||
+ test_bit (ABS_GAS, bitmask_abs) ||
+ test_bit (ABS_BRAKE, bitmask_abs);
+
+ if (has_coordinates) {
+ if (stylus_or_pen)
+ is_tablet = 1;
+ else if (!is_direct && finger_but_no_pen)
is_touchpad = 1;
- } else if (test_bit(BTN_MOUSE, bitmask_key)) {
+ else if (has_mouse)
/* This path is taken by VMware's USB mouse, which has
* absolute axes, but no touch/pressure button. */
is_mouse = 1;
- } else if (test_bit(BTN_TOUCH, bitmask_key)) {
- udev_builtin_add_property(dev, test, "ID_INPUT_TOUCHSCREEN", "1");
- ret = true;
- /* joysticks don't necessarily have to have buttons; e. g.
- * rudders/pedals are joystick-like, but buttonless; they have
- * other fancy axes */
- } else if (test_bit(BTN_TRIGGER, bitmask_key) ||
- test_bit(BTN_A, bitmask_key) ||
- test_bit(BTN_1, bitmask_key) ||
- test_bit(ABS_RX, bitmask_abs) ||
- test_bit(ABS_RY, bitmask_abs) ||
- test_bit(ABS_RZ, bitmask_abs) ||
- test_bit(ABS_THROTTLE, bitmask_abs) ||
- test_bit(ABS_RUDDER, bitmask_abs) ||
- test_bit(ABS_WHEEL, bitmask_abs) ||
- test_bit(ABS_GAS, bitmask_abs) ||
- test_bit(ABS_BRAKE, bitmask_abs)) {
- udev_builtin_add_property(dev, test, "ID_INPUT_JOYSTICK", "1");
- ret = true;
- }
+ else if (has_touch)
+ is_touchscreen = 1;
+ else if (has_joystick_axes_or_buttons)
+ is_joystick= 1;
+ else if (has_3d_coordinates && !has_keys)
+ is_accelerometer = 1;
}
+ if (has_mt_coordinates && is_direct)
+ is_touchscreen = 1;
- if (test_bit(INPUT_PROP_POINTING_STICK, bitmask_props)) {
- udev_builtin_add_property(dev, test, "ID_INPUT_POINTINGSTICK", "1");
- ret = true;
- }
-
- if (test_bit(EV_REL, bitmask_ev) &&
- test_bit(REL_X, bitmask_rel) && test_bit(REL_Y, bitmask_rel) &&
- test_bit(BTN_MOUSE, bitmask_key))
+ if (test_bit (EV_REL, bitmask_ev) && test_bit (REL_X, bitmask_rel) &&
+ test_bit (REL_Y, bitmask_rel) && has_mouse)
is_mouse = 1;
- if (is_mouse) {
+ if (is_mouse)
udev_builtin_add_property(dev, test, "ID_INPUT_MOUSE", "1");
- ret = true;
- }
- if (is_touchpad) {
+ if (is_touchpad)
udev_builtin_add_property(dev, test, "ID_INPUT_TOUCHPAD", "1");
- ret = true;
- }
+ if (is_touchscreen)
+ udev_builtin_add_property(dev, test, "ID_INPUT_TOUCHSCREEN", "1");
+ if (is_tablet)
+ udev_builtin_add_property(dev, test, "ID_INPUT_TABLET", "1");
+ if (is_joystick)
+ udev_builtin_add_property(dev, test, "ID_INPUT_JOYSTICK", "1");
+ if (is_accelerometer)
+ udev_builtin_add_property(dev, test, "ID_INPUT_ACCELEROMETER", "1");
+ if (is_pointing_stick)
+ udev_builtin_add_property(dev, test, "ID_INPUT_POINTINGSTICK", "1");
- return ret;
+ return is_mouse | is_touchpad | is_touchscreen | is_tablet | is_joystick | is_accelerometer | is_pointing_stick;
}
/* key like devices */
--
2.1.4
More information about the systemd-devel
mailing list