From e38d54bf0825e4aa061e6d96ab925daec94b20e6 Mon Sep 17 00:00:00 2001 From: "duna.oh" Date: Thu, 19 May 2022 10:03:25 +0900 Subject: [PATCH] libinput: get event time from libinput_event Change-Id: I51c5ef5ca3d3a7b1bd27172617e484303205c46c --- src/libds/backend/libinput/backend.c | 4 ++++ src/libds/backend/libinput/backend.h | 2 ++ src/libds/backend/libinput/keyboard.c | 12 ++++++------ src/libds/backend/libinput/pointer.c | 9 ++++++--- src/libds/backend/libinput/touch.c | 9 ++++++--- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/libds/backend/libinput/backend.c b/src/libds/backend/libinput/backend.c index f3ee044..b6dc4f1 100644 --- a/src/libds/backend/libinput/backend.c +++ b/src/libds/backend/libinput/backend.c @@ -225,3 +225,7 @@ libinput_backend_handle_display_destroy(struct wl_listener *listener, wl_container_of(listener, libinput_backend, display_destroy); libinput_backend_destroy(libinput_backend); } + +uint32_t usec_to_msec(uint64_t usec) { + return (uint32_t)(usec / 1000); +} \ No newline at end of file diff --git a/src/libds/backend/libinput/backend.h b/src/libds/backend/libinput/backend.h index 6fa2122..4d1c0ce 100644 --- a/src/libds/backend/libinput/backend.h +++ b/src/libds/backend/libinput/backend.h @@ -34,6 +34,8 @@ struct ds_libinput_input_device struct wl_list link; //ds_libinput_backend.devices }; +uint32_t usec_to_msec(uint64_t usec); + struct ds_libinput_backend * libinput_backend_from_backend(struct ds_backend *backend); diff --git a/src/libds/backend/libinput/keyboard.c b/src/libds/backend/libinput/keyboard.c index 53db0c9..9376f11 100644 --- a/src/libds/backend/libinput/keyboard.c +++ b/src/libds/backend/libinput/keyboard.c @@ -9,6 +9,7 @@ handle_keyboard_key(struct libinput_event *event, uint32_t key; enum libinput_key_state li_state; enum wl_keyboard_key_state state = WL_KEYBOARD_KEY_STATE_PRESSED; + struct ds_event_keyboard_key ds_event = {0}; kbevent = libinput_event_get_keyboard_event(event); @@ -24,12 +25,11 @@ handle_keyboard_key(struct libinput_event *event, ds_log(DS_DBG, "Keyboard(%p) key event key:%d, state:%s", kbd, key, (state == WL_KEYBOARD_KEY_STATE_PRESSED) ? "PRESSED":"RELEASED"); - struct ds_event_keyboard_key ds_event = { - .keycode = key, - .state = state, - .time_msec = -1, - .update_state = false, - }; + ds_event.keycode = key; + ds_event.state = state; + ds_event.time_msec = usec_to_msec( + libinput_event_keyboard_get_time_usec(kbevent)); + ds_event.update_state = false; ds_keyboard_notify_key(kbd, &ds_event); } diff --git a/src/libds/backend/libinput/pointer.c b/src/libds/backend/libinput/pointer.c index c118d06..efdbaa7 100644 --- a/src/libds/backend/libinput/pointer.c +++ b/src/libds/backend/libinput/pointer.c @@ -17,7 +17,8 @@ handle_pointer_motion(struct libinput_event *event, ds_log(DS_DBG, "pointer motion event delta_x:%f, delta_y:%f", delta_x, delta_y); ds_event.device = NULL; - ds_event.time_msec = -1; + ds_event.time_msec = usec_to_msec( + libinput_event_pointer_get_time_usec(pevent)); ds_event.delta_x = delta_x; ds_event.delta_y = delta_y; @@ -40,7 +41,8 @@ handle_pointer_motion_abs(struct libinput_event *event, ds_log(DS_DBG, "Pointer(%p) motion abs event x:%f, y:%f", pointer, x, y); ds_event.device = NULL; - ds_event.time_msec = -1; + ds_event.time_msec = usec_to_msec( + libinput_event_pointer_get_time_usec(pevent)); ds_event.x = x; ds_event.y = y; @@ -75,7 +77,8 @@ handle_pointer_button(struct libinput_event *event, (state == DS_BUTTON_PRESSED) ? "PRESSED" : "RELEASED"); ds_event.device = NULL; - ds_event.time_msec = -1; + ds_event.time_msec = usec_to_msec( + libinput_event_pointer_get_time_usec(pevent)); ds_event.button = button; ds_event.state = state; diff --git a/src/libds/backend/libinput/touch.c b/src/libds/backend/libinput/touch.c index 08b7b80..fd94c0b 100644 --- a/src/libds/backend/libinput/touch.c +++ b/src/libds/backend/libinput/touch.c @@ -19,7 +19,8 @@ handle_touch_down(struct libinput_event *event, ds_log(DS_DBG, "touch down event id:%d, x:%f, y:%f", touch_id, x, y); ds_event.device = NULL; - ds_event.time_msec = -1; + ds_event.time_msec = usec_to_msec( + libinput_event_touch_get_time_usec(tevent)); ds_event.id = touch_id; ds_event.x = x; ds_event.y = y; @@ -42,7 +43,8 @@ handle_touch_up(struct libinput_event *event, ds_log(DS_DBG, "touch up event id:%d", touch_id); ds_event.device = NULL; - ds_event.time_msec = -1; + ds_event.time_msec = usec_to_msec( + libinput_event_touch_get_time_usec(tevent)); ds_event.id = touch_id; wl_signal_emit(&touch->events.up, &ds_event); @@ -66,7 +68,8 @@ handle_touch_motion(struct libinput_event *event, ds_log(DS_DBG, "touch motion event id:%d, x:%f, y:%f", touch_id, x, y); ds_event.device = NULL; - ds_event.time_msec = -1; + ds_event.time_msec = usec_to_msec( + libinput_event_touch_get_time_usec(tevent)); ds_event.id = touch_id; ds_event.x = x; ds_event.y = y; -- 2.7.4