From 215bedc88bf90fb367e086b6fb39f8dbcc7baa81 Mon Sep 17 00:00:00 2001 From: Alexandros Frantzis Date: Thu, 16 Nov 2017 18:20:55 +0200 Subject: [PATCH] libweston: Use struct timespec for button events Change code related to button events to use struct timespec to represent time. This commit is part of a larger effort to transition the Weston codebase to struct timespec. Signed-off-by: Alexandros Frantzis Reviewed-by: Pekka Paalanen --- compositor/screen-share.c | 5 ++++- desktop-shell/exposay.c | 4 ++-- desktop-shell/shell.c | 22 +++++++++++++--------- ivi-shell/hmi-controller.c | 2 +- ivi-shell/ivi-shell.c | 3 ++- libweston-desktop/seat.c | 7 +++++-- libweston/bindings.c | 3 ++- libweston/compositor-rdp.c | 3 ++- libweston/compositor-wayland.c | 4 +++- libweston/compositor-x11.c | 6 ++++-- libweston/compositor.h | 18 +++++++++++------- libweston/data-device.c | 3 ++- libweston/input.c | 18 ++++++++++-------- libweston/libinput-device.c | 7 +++++-- tests/weston-test.c | 6 +++++- 15 files changed, 71 insertions(+), 40 deletions(-) diff --git a/compositor/screen-share.c b/compositor/screen-share.c index c7aad313..368d0cd6 100644 --- a/compositor/screen-share.c +++ b/compositor/screen-share.c @@ -159,8 +159,11 @@ ss_seat_handle_button(void *data, struct wl_pointer *pointer, uint32_t state) { struct ss_seat *seat = data; + struct timespec ts; + + timespec_from_msec(&ts, time); - notify_button(&seat->base, time, button, state); + notify_button(&seat->base, &ts, button, state); notify_pointer_frame(&seat->base); } diff --git a/desktop-shell/exposay.c b/desktop-shell/exposay.c index 15b86863..3571c5d7 100644 --- a/desktop-shell/exposay.c +++ b/desktop-shell/exposay.c @@ -364,8 +364,8 @@ exposay_motion(struct weston_pointer_grab *grab, } static void -exposay_button(struct weston_pointer_grab *grab, uint32_t time, uint32_t button, - uint32_t state_w) +exposay_button(struct weston_pointer_grab *grab, const struct timespec *time, + uint32_t button, uint32_t state_w) { struct desktop_shell *shell = container_of(grab, struct desktop_shell, exposay.grab_ptr); diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c index 62dfa450..2d2a6c8b 100644 --- a/desktop-shell/shell.c +++ b/desktop-shell/shell.c @@ -1507,7 +1507,7 @@ move_grab_motion(struct weston_pointer_grab *grab, static void move_grab_button(struct weston_pointer_grab *grab, - uint32_t time, uint32_t button, uint32_t state_w) + const struct timespec *time, uint32_t button, uint32_t state_w) { struct shell_grab *shell_grab = container_of(grab, struct shell_grab, grab); @@ -1634,7 +1634,8 @@ resize_grab_motion(struct weston_pointer_grab *grab, static void resize_grab_button(struct weston_pointer_grab *grab, - uint32_t time, uint32_t button, uint32_t state_w) + const struct timespec *time, + uint32_t button, uint32_t state_w) { struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; struct weston_pointer *pointer = grab->pointer; @@ -1778,7 +1779,8 @@ busy_cursor_grab_motion(struct weston_pointer_grab *grab, static void busy_cursor_grab_button(struct weston_pointer_grab *base, - uint32_t time, uint32_t button, uint32_t state) + const struct timespec *time, + uint32_t button, uint32_t state) { struct shell_grab *grab = (struct shell_grab *) base; struct shell_surface *shsurf = grab->shsurf; @@ -3203,7 +3205,7 @@ static const struct weston_desktop_shell_interface desktop_shell_implementation }; static void -move_binding(struct weston_pointer *pointer, uint32_t time, +move_binding(struct weston_pointer *pointer, const struct timespec *time, uint32_t button, void *data) { struct weston_surface *focus; @@ -3295,7 +3297,7 @@ touch_move_binding(struct weston_touch *touch, uint32_t time, void *data) } static void -resize_binding(struct weston_pointer *pointer, uint32_t time, +resize_binding(struct weston_pointer *pointer, const struct timespec *time, uint32_t button, void *data) { struct weston_surface *focus; @@ -3515,7 +3517,8 @@ rotate_grab_motion(struct weston_pointer_grab *grab, static void rotate_grab_button(struct weston_pointer_grab *grab, - uint32_t time, uint32_t button, uint32_t state_w) + const struct timespec *time, + uint32_t button, uint32_t state_w) { struct rotate_grab *rotate = container_of(grab, struct rotate_grab, base.grab); @@ -3593,8 +3596,8 @@ surface_rotate(struct shell_surface *shsurf, struct weston_pointer *pointer) } static void -rotate_binding(struct weston_pointer *pointer, uint32_t time, uint32_t button, - void *data) +rotate_binding(struct weston_pointer *pointer, const struct timespec *time, + uint32_t button, void *data) { struct weston_surface *focus; struct weston_surface *base_surface; @@ -3754,7 +3757,8 @@ activate_binding(struct weston_seat *seat, } static void -click_to_activate_binding(struct weston_pointer *pointer, uint32_t time, +click_to_activate_binding(struct weston_pointer *pointer, + const struct timespec *time, uint32_t button, void *data) { if (pointer->grab != &pointer->default_grab) diff --git a/ivi-shell/hmi-controller.c b/ivi-shell/hmi-controller.c index 6713eca3..b91b7f2b 100644 --- a/ivi-shell/hmi-controller.c +++ b/ivi-shell/hmi-controller.c @@ -1571,7 +1571,7 @@ touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, static void pointer_move_workspace_grab_button(struct weston_pointer_grab *grab, - uint32_t time, uint32_t button, + const struct timespec *time, uint32_t button, uint32_t state_w) { if (BTN_LEFT == button && diff --git a/ivi-shell/ivi-shell.c b/ivi-shell/ivi-shell.c index 67619b8f..7eef1cec 100644 --- a/ivi-shell/ivi-shell.c +++ b/ivi-shell/ivi-shell.c @@ -450,7 +450,8 @@ activate_binding(struct weston_seat *seat, } static void -click_to_activate_binding(struct weston_pointer *pointer, uint32_t time, +click_to_activate_binding(struct weston_pointer *pointer, + const struct timespec *time, uint32_t button, void *data) { if (pointer->grab != &pointer->default_grab) diff --git a/libweston-desktop/seat.c b/libweston-desktop/seat.c index 18a329c4..2c62f4fd 100644 --- a/libweston-desktop/seat.c +++ b/libweston-desktop/seat.c @@ -35,6 +35,7 @@ #include "libweston-desktop.h" #include "internal.h" +#include "shared/timespec-util.h" struct weston_desktop_seat { struct wl_listener seat_destroy_listener; @@ -116,7 +117,8 @@ weston_desktop_seat_popup_grab_pointer_motion(struct weston_pointer_grab *grab, static void weston_desktop_seat_popup_grab_pointer_button(struct weston_pointer_grab *grab, - uint32_t time, uint32_t button, + const struct timespec *time, + uint32_t button, enum wl_pointer_button_state state) { struct weston_desktop_seat *seat = @@ -130,7 +132,8 @@ weston_desktop_seat_popup_grab_pointer_button(struct weston_pointer_grab *grab, if (weston_pointer_has_focus_resource(pointer)) weston_pointer_send_button(pointer, time, button, state); else if (state == WL_POINTER_BUTTON_STATE_RELEASED && - (initial_up || (time - grab->pointer->grab_time) > 500)) + (initial_up || + (timespec_sub_to_msec(time, &grab->pointer->grab_time) > 500))) weston_desktop_seat_popup_grab_end(seat); } diff --git a/libweston/bindings.c b/libweston/bindings.c index 21366522..ae616743 100644 --- a/libweston/bindings.c +++ b/libweston/bindings.c @@ -349,7 +349,8 @@ weston_compositor_run_modifier_binding(struct weston_compositor *compositor, void weston_compositor_run_button_binding(struct weston_compositor *compositor, struct weston_pointer *pointer, - uint32_t time, uint32_t button, + const struct timespec *time, + uint32_t button, enum wl_pointer_button_state state) { struct weston_binding *b, *tmp; diff --git a/libweston/compositor-rdp.c b/libweston/compositor-rdp.c index 315d2ade..ad435b14 100644 --- a/libweston/compositor-rdp.c +++ b/libweston/compositor-rdp.c @@ -1050,7 +1050,8 @@ xf_mouseEvent(rdpInput *input, UINT16 flags, UINT16 x, UINT16 y) button = BTN_MIDDLE; if (button) { - notify_button(peerContext->item.seat, weston_compositor_get_time(), button, + timespec_from_msec(&time, weston_compositor_get_time()); + notify_button(peerContext->item.seat, &time, button, (flags & PTR_FLAGS_DOWN) ? WL_POINTER_BUTTON_STATE_PRESSED : WL_POINTER_BUTTON_STATE_RELEASED ); need_frame = true; diff --git a/libweston/compositor-wayland.c b/libweston/compositor-wayland.c index 8f26c545..46f7aba3 100644 --- a/libweston/compositor-wayland.c +++ b/libweston/compositor-wayland.c @@ -1644,6 +1644,7 @@ input_handle_button(void *data, struct wl_pointer *pointer, { struct wayland_input *input = data; enum theme_location location; + struct timespec ts; if (!input->output) return; @@ -1682,7 +1683,8 @@ input_handle_button(void *data, struct wl_pointer *pointer, } if (location == THEME_LOCATION_CLIENT_AREA) { - notify_button(&input->base, time, button, state); + timespec_from_msec(&ts, time); + notify_button(&input->base, &ts, button, state); if (input->seat_version < WL_POINTER_FRAME_SINCE_VERSION) notify_pointer_frame(&input->base); } diff --git a/libweston/compositor-x11.c b/libweston/compositor-x11.c index 7e24afcb..32622c06 100644 --- a/libweston/compositor-x11.c +++ b/libweston/compositor-x11.c @@ -1133,6 +1133,7 @@ x11_backend_deliver_button_event(struct x11_backend *b, struct x11_output *output; struct weston_pointer_axis_event weston_event; bool is_button_pressed = event->response_type == XCB_BUTTON_PRESS; + struct timespec time = { 0 }; assert(event->response_type == XCB_BUTTON_PRESS || event->response_type == XCB_BUTTON_RELEASE); @@ -1227,8 +1228,9 @@ x11_backend_deliver_button_event(struct x11_backend *b, break; } - notify_button(&b->core_seat, - weston_compositor_get_time(), button, + timespec_from_msec(&time, weston_compositor_get_time()); + + notify_button(&b->core_seat, &time, button, is_button_pressed ? WL_POINTER_BUTTON_STATE_PRESSED : WL_POINTER_BUTTON_STATE_RELEASED); notify_pointer_frame(&b->core_seat); diff --git a/libweston/compositor.h b/libweston/compositor.h index 971676cf..cd42006a 100644 --- a/libweston/compositor.h +++ b/libweston/compositor.h @@ -272,7 +272,8 @@ struct weston_pointer_grab_interface { const struct timespec *time, struct weston_pointer_motion_event *event); void (*button)(struct weston_pointer_grab *grab, - uint32_t time, uint32_t button, uint32_t state); + const struct timespec *time, + uint32_t button, uint32_t state); void (*axis)(struct weston_pointer_grab *grab, uint32_t time, struct weston_pointer_axis_event *event); @@ -383,7 +384,7 @@ struct weston_pointer { wl_fixed_t grab_x, grab_y; uint32_t grab_button; uint32_t grab_serial; - uint32_t grab_time; + struct timespec grab_time; wl_fixed_t x, y; wl_fixed_t sx, sy; @@ -431,7 +432,8 @@ bool weston_pointer_has_focus_resource(struct weston_pointer *pointer); void weston_pointer_send_button(struct weston_pointer *pointer, - uint32_t time, uint32_t button, uint32_t state_w); + const struct timespec *time, + uint32_t button, uint32_t state_w); void weston_pointer_send_axis(struct weston_pointer *pointer, uint32_t time, @@ -1371,8 +1373,8 @@ void notify_motion_absolute(struct weston_seat *seat, const struct timespec *time, double x, double y); void -notify_button(struct weston_seat *seat, uint32_t time, int32_t button, - enum wl_pointer_button_state state); +notify_button(struct weston_seat *seat, const struct timespec *time, + int32_t button, enum wl_pointer_button_state state); void notify_axis(struct weston_seat *seat, uint32_t time, struct weston_pointer_axis_event *event); @@ -1492,7 +1494,8 @@ weston_compositor_add_modifier_binding(struct weston_compositor *compositor, void *data); typedef void (*weston_button_binding_handler_t)(struct weston_pointer *pointer, - uint32_t time, uint32_t button, + const struct timespec *time, + uint32_t button, void *data); struct weston_binding * weston_compositor_add_button_binding(struct weston_compositor *compositor, @@ -1549,7 +1552,8 @@ weston_compositor_run_modifier_binding(struct weston_compositor *compositor, enum wl_keyboard_key_state state); void weston_compositor_run_button_binding(struct weston_compositor *compositor, - struct weston_pointer *pointer, uint32_t time, + struct weston_pointer *pointer, + const struct timespec *time, uint32_t button, enum wl_pointer_button_state value); void diff --git a/libweston/data-device.c b/libweston/data-device.c index 58a440ae..20de9b8a 100644 --- a/libweston/data-device.c +++ b/libweston/data-device.c @@ -638,7 +638,8 @@ data_device_end_pointer_drag_grab(struct weston_pointer_drag *drag) static void drag_grab_button(struct weston_pointer_grab *grab, - uint32_t time, uint32_t button, uint32_t state_w) + const struct timespec *time, + uint32_t button, uint32_t state_w) { struct weston_pointer_drag *drag = container_of(grab, struct weston_pointer_drag, grab); diff --git a/libweston/input.c b/libweston/input.c index c167b8ce..7f789333 100644 --- a/libweston/input.c +++ b/libweston/input.c @@ -460,26 +460,28 @@ weston_pointer_has_focus_resource(struct weston_pointer *pointer) */ WL_EXPORT void weston_pointer_send_button(struct weston_pointer *pointer, - uint32_t time, uint32_t button, + const struct timespec *time, uint32_t button, enum wl_pointer_button_state state) { struct wl_display *display = pointer->seat->compositor->wl_display; struct wl_list *resource_list; struct wl_resource *resource; uint32_t serial; + uint32_t msecs; if (!weston_pointer_has_focus_resource(pointer)) return; resource_list = &pointer->focus_client->pointer_resources; serial = wl_display_next_serial(display); + msecs = timespec_to_msec(time); wl_resource_for_each(resource, resource_list) - wl_pointer_send_button(resource, serial, time, button, state); + wl_pointer_send_button(resource, serial, msecs, button, state); } static void default_grab_pointer_button(struct weston_pointer_grab *grab, - uint32_t time, uint32_t button, + const struct timespec *time, uint32_t button, enum wl_pointer_button_state state) { struct weston_pointer *pointer = grab->pointer; @@ -1652,8 +1654,8 @@ weston_view_activate(struct weston_view *view, } WL_EXPORT void -notify_button(struct weston_seat *seat, uint32_t time, int32_t button, - enum wl_pointer_button_state state) +notify_button(struct weston_seat *seat, const struct timespec *time, + int32_t button, enum wl_pointer_button_state state) { struct weston_compositor *compositor = seat->compositor; struct weston_pointer *pointer = weston_seat_get_pointer(seat); @@ -1662,7 +1664,7 @@ notify_button(struct weston_seat *seat, uint32_t time, int32_t button, weston_compositor_idle_inhibit(compositor); if (pointer->button_count == 0) { pointer->grab_button = button; - pointer->grab_time = time; + pointer->grab_time = *time; pointer->grab_x = pointer->x; pointer->grab_y = pointer->y; } @@ -3328,7 +3330,7 @@ locked_pointer_grab_pointer_motion(struct weston_pointer_grab *grab, static void locked_pointer_grab_pointer_button(struct weston_pointer_grab *grab, - uint32_t time, + const struct timespec *time, uint32_t button, uint32_t state_w) { @@ -4336,7 +4338,7 @@ confined_pointer_grab_pointer_motion(struct weston_pointer_grab *grab, static void confined_pointer_grab_pointer_button(struct weston_pointer_grab *grab, - uint32_t time, + const struct timespec *time, uint32_t button, uint32_t state_w) { diff --git a/libweston/libinput-device.c b/libweston/libinput-device.c index 24f79b4c..e2f20468 100644 --- a/libweston/libinput-device.c +++ b/libweston/libinput-device.c @@ -151,6 +151,7 @@ handle_pointer_button(struct libinput_device *libinput_device, libinput_event_pointer_get_button_state(pointer_event); int seat_button_count = libinput_event_pointer_get_seat_button_count(pointer_event); + struct timespec time; /* Ignore button events that are not seat wide state changes. */ if ((button_state == LIBINPUT_BUTTON_STATE_PRESSED && @@ -159,8 +160,10 @@ handle_pointer_button(struct libinput_device *libinput_device, seat_button_count != 0)) return false; - notify_button(device->seat, - libinput_event_pointer_get_time(pointer_event), + timespec_from_usec(&time, + libinput_event_pointer_get_time_usec(pointer_event)); + + notify_button(device->seat, &time, libinput_event_pointer_get_button(pointer_event), button_state); diff --git a/tests/weston-test.c b/tests/weston-test.c index 3f684820..306757a0 100644 --- a/tests/weston-test.c +++ b/tests/weston-test.c @@ -171,10 +171,14 @@ static void send_button(struct wl_client *client, struct wl_resource *resource, int32_t button, uint32_t state) { + struct timespec time; + struct weston_test *test = wl_resource_get_user_data(resource); struct weston_seat *seat = get_seat(test); - notify_button(seat, 100, button, state); + timespec_from_msec(&time, 100); + + notify_button(seat, &time, button, state); } static void