From 52e38d1ab7c0e13aee8bdd7695741faf2dbb12ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Wed, 2 Dec 2015 16:13:36 +0800 Subject: evdev: Expose microsecond timestamps via the clutter evdev API This is needed by Wayland compositors for certain types of events. https://bugzilla.gnome.org/show_bug.cgi?id=752752 --- clutter/evdev/clutter-device-manager-evdev.c | 7 +++++++ clutter/evdev/clutter-evdev.h | 3 +++ clutter/evdev/clutter-event-evdev.c | 31 ++++++++++++++++++++++++++++ clutter/evdev/clutter-input-device-evdev.h | 3 +++ 4 files changed, 44 insertions(+) diff --git a/clutter/evdev/clutter-device-manager-evdev.c b/clutter/evdev/clutter-device-manager-evdev.c index 1427dbbcc..53aa8480d 100644 --- a/clutter/evdev/clutter-device-manager-evdev.c +++ b/clutter/evdev/clutter-device-manager-evdev.c @@ -461,6 +461,7 @@ new_absolute_motion_event (ClutterInputDevice *input_device, y = CLAMP (y, 0.f, stage_height - 1); } + _clutter_evdev_event_set_time_usec (event, time_us); event->motion.time = us2ms (time_us); event->motion.stage = stage; event->motion.device = seat->core_pointer; @@ -572,6 +573,7 @@ notify_discrete_scroll (ClutterInputDevice *input_device, event = clutter_event_new (CLUTTER_SCROLL); + _clutter_evdev_event_set_time_usec (event, time_us); event->scroll.time = us2ms (time_us); event->scroll.stage = CLUTTER_STAGE (stage); event->scroll.device = seat->core_pointer; @@ -616,6 +618,7 @@ notify_scroll (ClutterInputDevice *input_device, event = clutter_event_new (CLUTTER_SCROLL); + _clutter_evdev_event_set_time_usec (event, time_us); event->scroll.time = us2ms (time_us); event->scroll.stage = CLUTTER_STAGE (stage); event->scroll.device = seat->core_pointer; @@ -708,6 +711,7 @@ notify_button (ClutterInputDevice *input_device, else seat->button_state &= ~maskmap[button - BTN_LEFT]; + _clutter_evdev_event_set_time_usec (event, time_us); event->button.time = us2ms (time_us); event->button.stage = CLUTTER_STAGE (stage); event->button.device = seat->core_pointer; @@ -749,6 +753,7 @@ notify_touch_event (ClutterInputDevice *input_device, event = clutter_event_new (evtype); + _clutter_evdev_event_set_time_usec (event, time_us); event->touch.time = us2ms (time_us); event->touch.stage = CLUTTER_STAGE (stage); event->touch.device = seat->core_pointer; @@ -796,6 +801,7 @@ notify_pinch_gesture_event (ClutterInputDevice *input_device, clutter_input_device_get_coords (seat->core_pointer, NULL, &pos); + _clutter_evdev_event_set_time_usec (event, time_us); event->touchpad_pinch.phase = phase; event->touchpad_pinch.time = us2ms (time_us); event->touchpad_pinch.stage = CLUTTER_STAGE (stage); @@ -839,6 +845,7 @@ notify_swipe_gesture_event (ClutterInputDevice *input_device, event = clutter_event_new (CLUTTER_TOUCHPAD_SWIPE); + _clutter_evdev_event_set_time_usec (event, time_us); event->touchpad_swipe.phase = phase; event->touchpad_swipe.time = us2ms (time_us); event->touchpad_swipe.stage = CLUTTER_STAGE (stage); diff --git a/clutter/evdev/clutter-evdev.h b/clutter/evdev/clutter-evdev.h index 8278df82b..dca093d5a 100644 --- a/clutter/evdev/clutter-evdev.h +++ b/clutter/evdev/clutter-evdev.h @@ -134,6 +134,9 @@ void clutter_evdev_warp_pointer (ClutterInputDevice *pointer_device, CLUTTER_AVAILABLE_IN_1_26 guint32 clutter_evdev_event_get_event_code (const ClutterEvent *event); +CLUTTER_AVAILABLE_IN_1_26 +guint64 clutter_evdev_event_get_time_usec (const ClutterEvent *event); + CLUTTER_AVAILABLE_IN_1_26 gboolean clutter_evdev_event_get_relative_motion (const ClutterEvent *event, double *dx, diff --git a/clutter/evdev/clutter-event-evdev.c b/clutter/evdev/clutter-event-evdev.c index a0d66c928..c80a642f3 100644 --- a/clutter/evdev/clutter-event-evdev.c +++ b/clutter/evdev/clutter-event-evdev.c @@ -33,6 +33,8 @@ struct _ClutterEventEvdev { guint32 evcode; + guint64 time_usec; + gboolean has_relative_motion; double dx; double dy; @@ -86,6 +88,16 @@ _clutter_evdev_event_set_event_code (ClutterEvent *event, event_evdev->evcode = evcode; } +void +_clutter_evdev_event_set_time_usec (ClutterEvent *event, + guint64 time_usec) +{ + ClutterEventEvdev *event_evdev; + + event_evdev = clutter_evdev_event_ensure_platform_data (event); + event_evdev->time_usec = time_usec; +} + void _clutter_evdev_event_set_relative_motion (ClutterEvent *event, double dx, @@ -123,6 +135,25 @@ clutter_evdev_event_get_event_code (const ClutterEvent *event) return 0; } +/** + * clutter_evdev_event_get_time_usec: + * @event: a #ClutterEvent + * + * Returns the time in microsecond granularity, or 0 if unavailable. + * + * Returns: The time in microsecond granularity, or 0 if unavailable. + */ +guint64 +clutter_evdev_event_get_time_usec (const ClutterEvent *event) +{ + ClutterEventEvdev *event_evdev = _clutter_event_get_platform_data (event); + + if (event_evdev) + return event_evdev->time_usec; + + return 0; +} + /** * clutter_evdev_event_get_pointer_motion * @event: a #ClutterEvent diff --git a/clutter/evdev/clutter-input-device-evdev.h b/clutter/evdev/clutter-input-device-evdev.h index dec373915..c5c3eff5f 100644 --- a/clutter/evdev/clutter-input-device-evdev.h +++ b/clutter/evdev/clutter-input-device-evdev.h @@ -91,6 +91,9 @@ void _clutter_event_evdev_free (ClutterEv void _clutter_evdev_event_set_event_code (ClutterEvent *event, guint32 evcode); +void _clutter_evdev_event_set_time_usec (ClutterEvent *event, + guint64 time_usec); + void _clutter_evdev_event_set_relative_motion (ClutterEvent *event, double dx, double dy, -- cgit v1.2.1