From cc44e747c7bd182c908e3c00b2dd0f32649d5761 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 3 Sep 2014 15:50:28 +1000 Subject: [PATCH] evdev: add internal tagging system For conditional touchpad disabling we need two pieces of knowledge: is the device an internal touchpad and is another device an external mouse-like device. For that use-case it's enough to tag any device that's on USB and Bluetooth with pointer capabilities as external mouse. A more complex can be done when needed. The tag function is part of the dispatch interface (to save on udev code) and called before the caller is notified about the new device, i.e. the device is fully configured by the time it needs to be tagged, and other devices can rely on the tags being assigned by the time they get notified about the new device. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-mt-touchpad.c | 1 + src/evdev.c | 44 +++++++++++++++++++++++++++++++++++++++++ src/evdev.h | 10 ++++++++++ 3 files changed, 55 insertions(+) diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c index 62becbaa..c6bfd1d9 100644 --- a/src/evdev-mt-touchpad.c +++ b/src/evdev-mt-touchpad.c @@ -681,6 +681,7 @@ static struct evdev_dispatch_interface tp_interface = { tp_destroy, NULL, /* device_added */ NULL, /* device_removed */ + NULL, /* tag_device */ }; static void diff --git a/src/evdev.c b/src/evdev.c index 638493fb..f7fd2b4f 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -24,6 +24,7 @@ #include "config.h" #include +#include #include #include #include "linux/input.h" @@ -545,6 +546,19 @@ evdev_need_touch_frame(struct evdev_device *device) return 0; } +static void +evdev_tag_external_mouse(struct evdev_device *device, + struct udev_device *udev_device) +{ + int bustype; + + bustype = libevdev_get_id_bustype(device->evdev); + if (bustype == BUS_USB || bustype == BUS_BLUETOOTH) { + if (device->seat_caps & EVDEV_DEVICE_POINTER) + device->tags |= EVDEV_TAG_EXTERNAL_MOUSE; + } +} + static void fallback_process(struct evdev_dispatch *dispatch, struct evdev_device *device, @@ -578,6 +592,13 @@ fallback_destroy(struct evdev_dispatch *dispatch) free(dispatch); } +static void +fallback_tag_device(struct evdev_device *device, + struct udev_device *udev_device) +{ + evdev_tag_external_mouse(device, udev_device); +} + static int evdev_calibration_has_matrix(struct libinput_device *libinput_device) { @@ -624,6 +645,7 @@ struct evdev_dispatch_interface fallback_interface = { fallback_destroy, NULL, /* device_added */ NULL, /* device_removed */ + fallback_tag_device, }; static uint32_t @@ -792,6 +814,7 @@ configure_pointer_acceleration(struct evdev_device *device) return 0; } + static inline int evdev_need_mtdev(struct evdev_device *device) { @@ -802,6 +825,25 @@ evdev_need_mtdev(struct evdev_device *device) !libevdev_has_event_code(evdev, EV_ABS, ABS_MT_SLOT)); } +static void +evdev_tag_device(struct evdev_device *device) +{ + struct udev *udev; + struct udev_device *udev_device = NULL; + + udev = udev_new(); + if (!udev) + return; + + udev_device = udev_device_new_from_syspath(udev, device->syspath); + if (udev_device) { + if (device->dispatch->interface->tag_device) + device->dispatch->interface->tag_device(device, udev_device); + udev_device_unref(udev_device); + } + udev_unref(udev); +} + static int evdev_configure_device(struct evdev_device *device) { @@ -1064,6 +1106,8 @@ evdev_device_create(struct libinput_seat *seat, goto err; list_insert(seat->devices_list.prev, &device->base.link); + + evdev_tag_device(device); evdev_notify_added_device(device); return device; diff --git a/src/evdev.h b/src/evdev.h index 74053c5d..f5345fa3 100644 --- a/src/evdev.h +++ b/src/evdev.h @@ -48,6 +48,11 @@ enum evdev_device_seat_capability { EVDEV_DEVICE_TOUCH = (1 << 2) }; +enum evdev_device_tags { + EVDEV_TAG_EXTERNAL_MOUSE = (1 << 0), + EVDEV_TAG_INTERNAL_TOUCHPAD = (1 << 1), +}; + struct mt_slot { int32_t seat_slot; int32_t x, y; @@ -92,6 +97,7 @@ struct evdev_device { enum evdev_event_type pending_event; enum evdev_device_seat_capability seat_caps; + enum evdev_device_tags tags; int is_mt; @@ -128,6 +134,10 @@ struct evdev_dispatch_interface { /* A device was removed */ void (*device_removed)(struct evdev_device *device, struct evdev_device *removed_device); + + /* Tag device with one of EVDEV_TAG */ + void (*tag_device)(struct evdev_device *device, + struct udev_device *udev_device); }; struct evdev_dispatch { -- 2.34.1