From e80cff7b0e18da0ac57662afb99e5ec396ab3786 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jonas=20=C3=85dahl?= Date: Thu, 30 Jan 2014 22:44:49 +0100 Subject: [PATCH] Add seat wide slot to touch events MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Since a Wayland compositor have to represent all touch devices of a seat as one virtual device, lets make that easier by also providing seat wide slots with touch events. Seat wide slots may be accessed using libinput_event_touch_get_seat_slot(). Signed-off-by: Jonas Ådahl --- src/evdev.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/evdev.h | 3 +++ src/libinput-private.h | 2 ++ src/libinput.c | 9 +++++++++ src/libinput.h | 16 ++++++++++++++++ tools/event-debug.c | 3 ++- 6 files changed, 80 insertions(+), 1 deletion(-) diff --git a/src/evdev.c b/src/evdev.c index 7168bc0..a00d357 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -110,7 +110,9 @@ evdev_flush_pending_event(struct evdev_device *device, uint32_t time) { int32_t cx, cy; int slot; + int seat_slot; struct libinput_device *base = &device->base; + struct libinput_seat *seat = base->seat; slot = device->mt.slot; @@ -129,9 +131,18 @@ evdev_flush_pending_event(struct evdev_device *device, uint32_t time) if (!(device->seat_caps & EVDEV_DEVICE_TOUCH)) break; + seat_slot = ffs(~seat->slot_map) - 1; + device->mt.slots[slot].seat_slot = seat_slot; + + if (seat_slot == -1) + break; + + seat->slot_map |= 1 << seat_slot; + touch_notify_touch(base, time, slot, + seat_slot, li_fixed_from_int(device->mt.slots[slot].x), li_fixed_from_int(device->mt.slots[slot].y), LIBINPUT_TOUCH_TYPE_DOWN); @@ -140,9 +151,15 @@ evdev_flush_pending_event(struct evdev_device *device, uint32_t time) if (!(device->seat_caps & EVDEV_DEVICE_TOUCH)) break; + seat_slot = device->mt.slots[slot].seat_slot; + + if (seat_slot == -1) + break; + touch_notify_touch(base, time, slot, + seat_slot, li_fixed_from_int(device->mt.slots[slot].x), li_fixed_from_int(device->mt.slots[slot].y), LIBINPUT_TOUCH_TYPE_MOTION); @@ -151,9 +168,17 @@ evdev_flush_pending_event(struct evdev_device *device, uint32_t time) if (!(device->seat_caps & EVDEV_DEVICE_TOUCH)) break; + seat_slot = device->mt.slots[slot].seat_slot; + + if (seat_slot == -1) + break; + + seat->slot_map &= ~(1 << seat_slot); + touch_notify_touch(base, time, slot, + seat_slot, 0, 0, LIBINPUT_TOUCH_TYPE_UP); break; @@ -161,10 +186,19 @@ evdev_flush_pending_event(struct evdev_device *device, uint32_t time) if (!(device->seat_caps & EVDEV_DEVICE_TOUCH)) break; + seat_slot = ffs(~seat->slot_map) - 1; + device->abs.seat_slot = seat_slot; + + if (seat_slot == -1) + break; + + seat->slot_map |= 1 << seat_slot; + transform_absolute(device, &cx, &cy); touch_notify_touch(base, time, -1, + seat_slot, li_fixed_from_int(cx), li_fixed_from_int(cy), LIBINPUT_TOUCH_TYPE_DOWN); @@ -172,9 +206,15 @@ evdev_flush_pending_event(struct evdev_device *device, uint32_t time) case EVDEV_ABSOLUTE_MOTION: transform_absolute(device, &cx, &cy); if (device->seat_caps & EVDEV_DEVICE_TOUCH) { + seat_slot = device->abs.seat_slot; + + if (seat_slot == -1) + break; + touch_notify_touch(base, time, -1, + seat_slot, li_fixed_from_int(cx), li_fixed_from_int(cy), LIBINPUT_TOUCH_TYPE_DOWN); @@ -189,9 +229,17 @@ evdev_flush_pending_event(struct evdev_device *device, uint32_t time) if (!(device->seat_caps & EVDEV_DEVICE_TOUCH)) break; + seat_slot = device->abs.seat_slot; + + if (seat_slot == -1) + break; + + seat->slot_map &= ~(1 << seat_slot); + touch_notify_touch(base, time, -1, + seat_slot, 0, 0, LIBINPUT_TOUCH_TYPE_UP); break; diff --git a/src/evdev.h b/src/evdev.h index a9e27bf..b83a2f9 100644 --- a/src/evdev.h +++ b/src/evdev.h @@ -66,6 +66,8 @@ struct evdev_device { int min_x, max_x, min_y, max_y; int32_t x, y; + int32_t seat_slot; + int apply_calibration; float calibration[6]; } abs; @@ -73,6 +75,7 @@ struct evdev_device { struct { int slot; struct { + int32_t seat_slot; int32_t x, y; } slots[MAX_SLOTS]; } mt; diff --git a/src/libinput-private.h b/src/libinput-private.h index 1fff7de..9cda209 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -57,6 +57,7 @@ struct libinput_seat { struct list devices_list; void *user_data; int refcount; + uint32_t slot_map; char *physical_name; char *logical_name; libinput_seat_destroy_func destroy; @@ -155,6 +156,7 @@ void touch_notify_touch(struct libinput_device *device, uint32_t time, int32_t slot, + int32_t seat_slot, li_fixed_t x, li_fixed_t y, enum libinput_touch_type touch_type); diff --git a/src/libinput.c b/src/libinput.c index d954603..beb199d 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -72,6 +72,7 @@ struct libinput_event_touch { struct libinput_event base; uint32_t time; int32_t slot; + int32_t seat_slot; li_fixed_t x; li_fixed_t y; enum libinput_touch_type touch_type; @@ -357,6 +358,12 @@ libinput_event_touch_get_slot(struct libinput_event_touch *event) return event->slot; } +LIBINPUT_EXPORT int32_t +libinput_event_touch_get_seat_slot(struct libinput_event_touch *event) +{ + return event->seat_slot; +} + LIBINPUT_EXPORT li_fixed_t libinput_event_touch_get_x(struct libinput_event_touch *event) { @@ -836,6 +843,7 @@ void touch_notify_touch(struct libinput_device *device, uint32_t time, int32_t slot, + int32_t seat_slot, li_fixed_t x, li_fixed_t y, enum libinput_touch_type touch_type) @@ -849,6 +857,7 @@ touch_notify_touch(struct libinput_device *device, *touch_event = (struct libinput_event_touch) { .time = time, .slot = slot, + .seat_slot = seat_slot, .x = x, .y = y, .touch_type = touch_type, diff --git a/src/libinput.h b/src/libinput.h index 1d166b2..993472c 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -580,6 +580,22 @@ libinput_event_touch_get_slot(struct libinput_event_touch *event); /** * @ingroup event_touch * + * Get the seat slot of the touch event. A seat slot is a non-negative seat + * wide unique identifier of an active touch point. + * + * Events from single touch devices will be represented as one individual + * touch point per device. + * + * @note this function should not be called for LIBINPUT_EVENT_TOUCH_FRAME. + * + * @return The seat slot of the touch event + */ +int32_t +libinput_event_touch_get_seat_slot(struct libinput_event_touch *event); + +/** + * @ingroup event_touch + * * Return the current absolute x coordinate of the touch event. * * The coordinate is in a device specific coordinate space; to get the diff --git a/tools/event-debug.c b/tools/event-debug.c index d60cb2e..4eb5dd3 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -336,9 +336,10 @@ print_touch_event(struct libinput_event *ev) print_event_time(libinput_event_touch_get_time(t)); - printf("%6s %d %5.2f/%5.2f\n", + printf("%6s %d (%d) %5.2f/%5.2f\n", type, libinput_event_touch_get_slot(t), + libinput_event_touch_get_seat_slot(t), li_fixed_to_double(x), li_fixed_to_double(y)); } -- 2.7.4