From 6f5693c6fd60cdac92261caa26d62bcea45aab98 Mon Sep 17 00:00:00 2001 From: Marius Vlad Date: Tue, 31 Mar 2026 10:19:24 +0300 Subject: [PATCH 1/6] input: Introduce weston_key_event struct Rather than passing a time stamp, key, key state and key event state use a weston_key_event struct to pass by all that using it. This would allow in further patches to attach additional information like a flow id used by Perfetto debug annotations for input events. This patch has no functional change as it is now. All the callees will just will extract the required information out of struct weston_key_event. Signed-off-by: Marius Vlad --- desktop-shell/shell.c | 6 ++-- frontend/text-backend.c | 14 +++++--- include/libweston/libweston.h | 39 ++++++++++++++++----- libweston/backend-rdp/rdp.c | 17 +++++---- libweston/backend-vnc/vnc.c | 31 +++++++++++------ libweston/backend-wayland/wayland.c | 10 +++--- libweston/backend-x11/x11.c | 54 ++++++++++++++++++----------- libweston/backend.h | 5 ++- libweston/bindings.c | 20 ++++++----- libweston/data-device.c | 2 +- libweston/desktop/seat.c | 6 ++-- libweston/input.c | 50 +++++++++++++++++--------- libweston/libinput-device.c | 12 ++++--- tests/harness/weston-test.c | 5 ++- 14 files changed, 176 insertions(+), 95 deletions(-) diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c index fffb3d68a..df34b5441 100644 --- a/desktop-shell/shell.c +++ b/desktop-shell/shell.c @@ -4189,11 +4189,11 @@ switcher_destroy(struct switcher *switcher) } static void -switcher_key(struct weston_keyboard_grab *grab, - const struct timespec *time, uint32_t key, uint32_t state_w) +switcher_key(struct weston_keyboard_grab *grab, const struct weston_key_event *key_event) { struct switcher *switcher = container_of(grab, struct switcher, grab); - enum wl_keyboard_key_state state = state_w; + enum wl_keyboard_key_state state = key_event->key_state; + uint32_t key = key_event->key; if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) switcher_next(switcher); diff --git a/frontend/text-backend.c b/frontend/text-backend.c index 73a1eda30..05e34cdfd 100644 --- a/frontend/text-backend.c +++ b/frontend/text-backend.c @@ -621,13 +621,15 @@ unbind_keyboard(struct wl_resource *resource) static void input_method_context_grab_key(struct weston_keyboard_grab *grab, - const struct timespec *time, uint32_t key, - uint32_t state_w) + const struct weston_key_event *key_event) { struct weston_keyboard *keyboard = grab->keyboard; struct wl_display *display; uint32_t serial; uint32_t msecs; + uint32_t key = key_event->key; + struct timespec time = key_event->base.ts; + uint32_t state_w = key_event->key_state; if (!keyboard->input_method_resource) return; @@ -635,7 +637,7 @@ input_method_context_grab_key(struct weston_keyboard_grab *grab, display = wl_client_get_display( wl_resource_get_client(keyboard->input_method_resource)); serial = wl_display_next_serial(display); - msecs = timespec_to_msec(time); + msecs = timespec_to_msec(&time); wl_keyboard_send_key(keyboard->input_method_resource, serial, msecs, key, state_w); } @@ -712,10 +714,14 @@ input_method_context_key(struct wl_client *client, struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); struct weston_keyboard_grab *default_grab = &keyboard->default_grab; struct timespec ts; + struct weston_key_event key_event; timespec_from_msec(&ts, time); - default_grab->interface->key(default_grab, &ts, key, state_w); + weston_input_event_init(&key_event.base, &ts, seat); + weston_key_event_init(&key_event, key, state_w, STATE_UPDATE_NONE); + + default_grab->interface->key(default_grab, &key_event); } static void diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h index aa787386c..cdd9cf285 100644 --- a/include/libweston/libweston.h +++ b/include/libweston/libweston.h @@ -188,6 +188,11 @@ struct weston_spring { uint32_t clip; }; +enum weston_key_state_update { + STATE_UPDATE_AUTOMATIC, + STATE_UPDATE_NONE, +}; + /* bit compatible with drm definitions. */ enum dpms_enum { WESTON_DPMS_ON, @@ -615,6 +620,20 @@ struct weston_pointer_axis_event { int32_t discrete; }; +/* base/common struct which all weston_xxx_event should "inherit" */ +struct weston_input_event { + struct timespec ts; + struct weston_seat *seat; +}; + +struct weston_key_event { + struct weston_input_event base; + uint32_t key; + enum wl_keyboard_key_state key_state; + enum weston_key_state_update key_update_state; +}; + + struct weston_pointer_grab; struct weston_pointer_grab_interface { void (*focus)(struct weston_pointer_grab *grab); @@ -640,7 +659,7 @@ struct weston_pointer_grab { struct weston_keyboard_grab; struct weston_keyboard_grab_interface { void (*key)(struct weston_keyboard_grab *grab, - const struct timespec *time, uint32_t key, uint32_t state); + const struct weston_key_event *key_event); void (*modifiers)(struct weston_keyboard_grab *grab, uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group); @@ -1003,8 +1022,16 @@ weston_keyboard_set_locks(struct weston_keyboard *keyboard, void weston_keyboard_send_key(struct weston_keyboard *keyboard, - const struct timespec *time, uint32_t key, - enum wl_keyboard_key_state state); + const struct weston_key_event *key_event); + +void +weston_input_event_init(struct weston_input_event *ievent, struct timespec *ts, struct weston_seat *seat); + +void +weston_key_event_init(struct weston_key_event *event, uint32_t key, + enum wl_keyboard_key_state key_state, + enum weston_key_state_update key_update_state); + void weston_keyboard_send_modifiers(struct weston_keyboard *keyboard, uint32_t serial, uint32_t mods_depressed, @@ -2125,12 +2152,6 @@ struct content_protection { struct wl_event_source *surface_protection_update; }; - -enum weston_key_state_update { - STATE_UPDATE_AUTOMATIC, - STATE_UPDATE_NONE, -}; - enum weston_activate_flag { WESTON_ACTIVATE_FLAG_NONE = 0, WESTON_ACTIVATE_FLAG_CONFIGURE = 1 << 0, diff --git a/libweston/backend-rdp/rdp.c b/libweston/backend-rdp/rdp.c index d4d0af858..8580a1b88 100644 --- a/libweston/backend-rdp/rdp.c +++ b/libweston/backend-rdp/rdp.c @@ -1573,6 +1573,7 @@ xf_input_keyboard_event(rdpInput *input, UINT16 flags, XF_KEV_CODE_TYPE code) bool send_release_key = false; int notify = 0; struct timespec time; + struct weston_key_event key_event; rdp_debug_verbose(peerContext->rdpBackend, "RDP backend: %s flags:0x%x, code:0x%x\n", __func__, flags, code); @@ -1638,14 +1639,18 @@ xf_input_keyboard_event(rdpInput *input, UINT16 flags, XF_KEV_CODE_TYPE code) /*weston_log("code=%x ext=%d vk_code=%x scan_code=%x\n", code, (flags & KBD_FLAGS_EXTENDED) ? 1 : 0, vk_code, scan_code);*/ weston_compositor_get_time(&time); - notify_key(peerContext->item.seat, &time, - scan_code - 8, keyState, STATE_UPDATE_AUTOMATIC); + + weston_input_event_init(&key_event.base, + &time, peerContext->item.seat); + weston_key_event_init(&key_event, scan_code - 8, + keyState, STATE_UPDATE_AUTOMATIC); + notify_key(peerContext->item.seat, &key_event); if (send_release_key) { - notify_key(peerContext->item.seat, &time, - scan_code - 8, - WL_KEYBOARD_KEY_STATE_RELEASED, - STATE_UPDATE_AUTOMATIC); + weston_key_event_init(&key_event, scan_code - 8, + WL_KEYBOARD_KEY_STATE_RELEASED, + STATE_UPDATE_AUTOMATIC); + notify_key(peerContext->item.seat, &key_event); } } diff --git a/libweston/backend-vnc/vnc.c b/libweston/backend-vnc/vnc.c index ae689d855..a632260a2 100644 --- a/libweston/backend-vnc/vnc.c +++ b/libweston/backend-vnc/vnc.c @@ -301,6 +301,7 @@ vnc_handle_key_event(struct nvnc_client *client, uint32_t keysym, bool needs_shift = false; enum weston_key_state_update state_update; enum wl_keyboard_key_state state; + struct weston_key_event key_event; struct timespec time; int i; @@ -336,20 +337,27 @@ vnc_handle_key_event(struct nvnc_client *client, uint32_t keysym, return; } + weston_input_event_init(&key_event.base, &time, peer->seat); + /* emulate lshift press */ - if (needs_shift) - notify_key(peer->seat, &time, KEY_LEFTSHIFT, - WL_KEYBOARD_KEY_STATE_PRESSED, - STATE_UPDATE_AUTOMATIC); + if (needs_shift) { + weston_key_event_init(&key_event, KEY_LEFTSHIFT, + WL_KEYBOARD_KEY_STATE_PRESSED, + STATE_UPDATE_AUTOMATIC); + notify_key(peer->seat, &key_event); + } /* send detected key code */ - notify_key(peer->seat, &time, key, state, state_update); + weston_key_event_init(&key_event, key, state, state_update); + notify_key(peer->seat, &key_event); /* emulate lshift release */ - if (needs_shift) - notify_key(peer->seat, &time, KEY_LEFTSHIFT, - WL_KEYBOARD_KEY_STATE_RELEASED, - STATE_UPDATE_AUTOMATIC); + if (needs_shift) { + weston_key_event_init(&key_event, KEY_LEFTSHIFT, + WL_KEYBOARD_KEY_STATE_RELEASED, + STATE_UPDATE_AUTOMATIC); + notify_key(peer->seat, &key_event); + } } static void @@ -359,6 +367,7 @@ vnc_handle_key_code_event(struct nvnc_client *client, uint32_t key, struct vnc_peer *peer = nvnc_get_userdata(client); enum wl_keyboard_key_state state; struct timespec time; + struct weston_key_event key_event; weston_compositor_get_time(&time); @@ -367,7 +376,9 @@ vnc_handle_key_code_event(struct nvnc_client *client, uint32_t key, else state = WL_KEYBOARD_KEY_STATE_RELEASED; - notify_key(peer->seat, &time, key, state, STATE_UPDATE_AUTOMATIC); + weston_input_event_init(&key_event.base, &time, peer->seat); + weston_key_event_init(&key_event, key, state, STATE_UPDATE_AUTOMATIC); + notify_key(peer->seat, &key_event); } static void diff --git a/libweston/backend-wayland/wayland.c b/libweston/backend-wayland/wayland.c index 6ad1d7b49..e31ecd70b 100644 --- a/libweston/backend-wayland/wayland.c +++ b/libweston/backend-wayland/wayland.c @@ -2004,6 +2004,7 @@ input_handle_key(void *data, struct wl_keyboard *keyboard, { struct wayland_input *input = data; struct timespec ts; + struct weston_key_event key_event; if (!input->keyboard_focus) return; @@ -2011,10 +2012,11 @@ input_handle_key(void *data, struct wl_keyboard *keyboard, timespec_from_msec(&ts, time); input->key_serial = serial; - notify_key(&input->base, &ts, key, - state ? WL_KEYBOARD_KEY_STATE_PRESSED : - WL_KEYBOARD_KEY_STATE_RELEASED, - input->keyboard_state_update); + + weston_input_event_init(&key_event.base, &ts, &input->base); + weston_key_event_init(&key_event, key, state ? WL_KEYBOARD_KEY_STATE_PRESSED : + WL_KEYBOARD_KEY_STATE_RELEASED, input->keyboard_state_update); + notify_key(&input->base, &key_event); } static void diff --git a/libweston/backend-x11/x11.c b/libweston/backend-x11/x11.c index 182baf6aa..7a6ed9557 100644 --- a/libweston/backend-x11/x11.c +++ b/libweston/backend-x11/x11.c @@ -1630,11 +1630,15 @@ x11_backend_handle_event(int fd, uint32_t mask, void *data) * event below. */ update_xkb_state_from_core(b, key_release->state); weston_compositor_get_time(&time); - notify_key(&b->core_seat, - &time, - key_release->detail - 8, - WL_KEYBOARD_KEY_STATE_RELEASED, - STATE_UPDATE_AUTOMATIC); + + struct weston_key_event key_event; + + weston_input_event_init(&key_event.base, &time, &b->core_seat); + weston_key_event_init(&key_event, key_release->detail - 8, + WL_KEYBOARD_KEY_STATE_RELEASED, + STATE_UPDATE_AUTOMATIC); + + notify_key(&b->core_seat, &key_event); free(b->prev_event); b->prev_event = NULL; break; @@ -1675,12 +1679,15 @@ x11_backend_handle_event(int fd, uint32_t mask, void *data) if (!b->has_xkb) update_xkb_state_from_core(b, key_press->state); weston_compositor_get_time(&time); - notify_key(&b->core_seat, - &time, - key_press->detail - 8, - WL_KEYBOARD_KEY_STATE_PRESSED, - b->has_xkb ? STATE_UPDATE_NONE : - STATE_UPDATE_AUTOMATIC); + + struct weston_key_event key_event; + + weston_input_event_init(&key_event.base, &time, &b->core_seat); + weston_key_event_init(&key_event, key_release->detail - 8, + WL_KEYBOARD_KEY_STATE_PRESSED, + b->has_xkb ? STATE_UPDATE_NONE : STATE_UPDATE_AUTOMATIC); + notify_key(&b->core_seat, &key_event); + break; case XCB_KEY_RELEASE: /* If we don't have XKB, we need to use the lame @@ -1691,11 +1698,13 @@ x11_backend_handle_event(int fd, uint32_t mask, void *data) } key_release = (xcb_key_press_event_t *) event; weston_compositor_get_time(&time); - notify_key(&b->core_seat, - &time, - key_release->detail - 8, - WL_KEYBOARD_KEY_STATE_RELEASED, - STATE_UPDATE_NONE); + + struct weston_key_event w_key_event; + + weston_input_event_init(&w_key_event.base, &time, &b->core_seat); + weston_key_event_init(&w_key_event, key_release->detail - 8, + WL_KEYBOARD_KEY_STATE_RELEASED, STATE_UPDATE_NONE); + notify_key(&b->core_seat, &w_key_event); break; case XCB_BUTTON_PRESS: case XCB_BUTTON_RELEASE: @@ -1824,11 +1833,14 @@ x11_backend_handle_event(int fd, uint32_t mask, void *data) key_release = (xcb_key_press_event_t *) b->prev_event; update_xkb_state_from_core(b, key_release->state); weston_compositor_get_time(&time); - notify_key(&b->core_seat, - &time, - key_release->detail - 8, - WL_KEYBOARD_KEY_STATE_RELEASED, - STATE_UPDATE_AUTOMATIC); + + struct weston_key_event lshift_key_event; + + weston_input_event_init(&lshift_key_event.base, &time, &b->core_seat); + weston_key_event_init(&lshift_key_event, key_release->detail - 8, + WL_KEYBOARD_KEY_STATE_RELEASED, STATE_UPDATE_AUTOMATIC); + notify_key(&b->core_seat, &lshift_key_event); + free(b->prev_event); b->prev_event = NULL; break; diff --git a/libweston/backend.h b/libweston/backend.h index cb4d575d8..ea232af7d 100644 --- a/libweston/backend.h +++ b/libweston/backend.h @@ -242,9 +242,8 @@ notify_button(struct weston_seat *seat, const struct timespec *time, int32_t button, enum wl_pointer_button_state state); void -notify_key(struct weston_seat *seat, const struct timespec *time, uint32_t key, - enum wl_keyboard_key_state state, - enum weston_key_state_update update_state); +notify_key(struct weston_seat *seat, const struct weston_key_event *key_event); + void notify_keyboard_focus_in(struct weston_seat *seat, struct wl_array *keys, enum weston_key_state_update update_state); diff --git a/libweston/bindings.c b/libweston/bindings.c index 4d2ad94f6..7b8df7527 100644 --- a/libweston/bindings.c +++ b/libweston/bindings.c @@ -216,13 +216,14 @@ struct binding_keyboard_grab { }; static void -binding_key(struct weston_keyboard_grab *grab, - const struct timespec *time, uint32_t key, uint32_t state_w) +binding_key(struct weston_keyboard_grab *grab, const struct weston_key_event *key_event) { struct binding_keyboard_grab *b = container_of(grab, struct binding_keyboard_grab, grab); struct wl_resource *resource; - enum wl_keyboard_key_state state = state_w; + enum wl_keyboard_key_state state = key_event->key_state; + struct timespec time = key_event->base.ts; + uint32_t key = key_event->key; uint32_t serial; struct weston_keyboard *keyboard = grab->keyboard; struct wl_display *display = keyboard->seat->compositor->wl_display; @@ -241,7 +242,7 @@ binding_key(struct weston_keyboard_grab *grab, } if (!wl_list_empty(&keyboard->focus_resource_list)) { serial = wl_display_next_serial(display); - msecs = timespec_to_msec(time); + msecs = timespec_to_msec(&time); wl_resource_for_each(resource, &keyboard->focus_resource_list) { wl_keyboard_send_key(resource, serial, @@ -491,8 +492,8 @@ struct debug_binding_grab { }; static void -debug_binding_key(struct weston_keyboard_grab *grab, const struct timespec *time, - uint32_t key, uint32_t state) +debug_binding_key(struct weston_keyboard_grab *grab, + const struct weston_key_event *key_event) { struct debug_binding_grab *db = (struct debug_binding_grab *) grab; struct weston_compositor *ec = db->seat->compositor; @@ -501,6 +502,9 @@ debug_binding_key(struct weston_keyboard_grab *grab, const struct timespec *time uint32_t serial; int send = 0, terminate = 0; int check_binding = 1; + struct timespec time = key_event->base.ts; + uint32_t key = key_event->key; + uint32_t state = key_event->key_state; int i; struct wl_list *resource_list; uint32_t msecs; @@ -535,7 +539,7 @@ debug_binding_key(struct weston_keyboard_grab *grab, const struct timespec *time if (check_binding) { if (weston_compositor_run_debug_binding(ec, grab->keyboard, - time, key, state)) { + &time, key, state)) { /* We ran a binding so swallow the press and keep the * grab to swallow the released too. */ send = 0; @@ -552,7 +556,7 @@ debug_binding_key(struct weston_keyboard_grab *grab, const struct timespec *time if (send) { serial = wl_display_next_serial(display); resource_list = &grab->keyboard->focus_resource_list; - msecs = timespec_to_msec(time); + msecs = timespec_to_msec(&time); wl_resource_for_each(resource, resource_list) { wl_keyboard_send_key(resource, serial, msecs, key, state); } diff --git a/libweston/data-device.c b/libweston/data-device.c index 905d002c1..cb899b642 100644 --- a/libweston/data-device.c +++ b/libweston/data-device.c @@ -838,7 +838,7 @@ static const struct weston_touch_grab_interface touch_drag_grab_interface = { static void drag_grab_keyboard_key(struct weston_keyboard_grab *grab, - const struct timespec *time, uint32_t key, uint32_t state) + const struct weston_key_event *key_event) { } diff --git a/libweston/desktop/seat.c b/libweston/desktop/seat.c index d45719de0..7886d5000 100644 --- a/libweston/desktop/seat.c +++ b/libweston/desktop/seat.c @@ -57,11 +57,9 @@ static void weston_desktop_seat_popup_grab_end(struct weston_desktop_seat *seat) static void weston_desktop_seat_popup_grab_keyboard_key(struct weston_keyboard_grab *grab, - const struct timespec *time, - uint32_t key, - enum wl_keyboard_key_state state) + const struct weston_key_event *key_event) { - weston_keyboard_send_key(grab->keyboard, time, key, state); + weston_keyboard_send_key(grab->keyboard, key_event); } static void diff --git a/libweston/input.c b/libweston/input.c index e51faf78a..46bdd231f 100644 --- a/libweston/input.c +++ b/libweston/input.c @@ -1089,9 +1089,7 @@ weston_keyboard_has_focus_resource(struct weston_keyboard *keyboard) /** Send wl_keyboard.key events to focused resources. * * \param keyboard The keyboard where the key events originates from. - * \param time The timestamp of the event - * \param key The key value of the event - * \param state The state enum value of the event + * \param key_event The weston_key_event as a pointer * * For every resource that is currently in focus, send a wl_keyboard.key event * with the passed parameters. The focused resources are the wl_keyboard @@ -1099,35 +1097,36 @@ weston_keyboard_has_focus_resource(struct weston_keyboard *keyboard) */ WL_EXPORT void weston_keyboard_send_key(struct weston_keyboard *keyboard, - const struct timespec *time, uint32_t key, - enum wl_keyboard_key_state state) + const struct weston_key_event *key_event) { struct wl_resource *resource; struct wl_display *display = keyboard->seat->compositor->wl_display; uint32_t serial; struct wl_list *resource_list; uint32_t msecs; + struct timespec time = key_event->base.ts; + uint32_t key = key_event->key; + enum wl_keyboard_key_state state = key_event->key_state; if (!weston_keyboard_has_focus_resource(keyboard)) return; resource_list = &keyboard->focus_resource_list; serial = wl_display_next_serial(display); - msecs = timespec_to_msec(time); + msecs = timespec_to_msec(&time); wl_resource_for_each(resource, resource_list) { send_timestamps_for_input_resource(resource, &keyboard->timestamps_list, - time); + &time); wl_keyboard_send_key(resource, serial, msecs, key, state); } }; static void default_grab_keyboard_key(struct weston_keyboard_grab *grab, - const struct timespec *time, uint32_t key, - uint32_t state) + const struct weston_key_event *key_event) { - weston_keyboard_send_key(grab->keyboard, time, key, state); + weston_keyboard_send_key(grab->keyboard, key_event); } static void @@ -2664,13 +2663,15 @@ update_keymap(struct weston_seat *seat) } WL_EXPORT void -notify_key(struct weston_seat *seat, const struct timespec *time, uint32_t key, - enum wl_keyboard_key_state state, - enum weston_key_state_update update_state) +notify_key(struct weston_seat *seat, const struct weston_key_event *key_event) { + struct timespec time = key_event->base.ts; struct weston_compositor *compositor = seat->compositor; struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat); struct weston_keyboard_grab *grab = keyboard->grab; + enum wl_keyboard_key_state state = key_event->key_state; + uint32_t key = key_event->key; + enum weston_key_state_update update_state = key_event->key_update_state; uint32_t *k, *end; end = keyboard->keys.data + keyboard->keys.size; @@ -2697,12 +2698,12 @@ notify_key(struct weston_seat *seat, const struct timespec *time, uint32_t key, if (grab == &keyboard->default_grab || grab == &keyboard->input_method_grab) { - weston_compositor_run_key_binding(compositor, keyboard, time, + weston_compositor_run_key_binding(compositor, keyboard, &time, key, state); grab = keyboard->grab; } - grab->interface->key(grab, time, key, state); + grab->interface->key(grab, key_event); if (keyboard->pending_keymap && keyboard->keys.size == 0) @@ -2717,7 +2718,7 @@ notify_key(struct weston_seat *seat, const struct timespec *time, uint32_t key, keyboard->grab_serial = wl_display_get_serial(compositor->wl_display); if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { - keyboard->grab_time = *time; + keyboard->grab_time = time; keyboard->grab_key = key; } } @@ -6027,3 +6028,20 @@ weston_input_init(struct weston_compositor *compositor) return 0; } + +WL_EXPORT void +weston_input_event_init(struct weston_input_event *ievent, struct timespec *ts, + struct weston_seat *seat) +{ + ievent->ts = *ts; + ievent->seat = seat; +} + +WL_EXPORT void +weston_key_event_init(struct weston_key_event *event, uint32_t key, enum wl_keyboard_key_state key_state, + enum weston_key_state_update key_update_state) +{ + event->key = key; + event->key_state = key_state; + event->key_update_state = key_update_state; +} diff --git a/libweston/libinput-device.c b/libweston/libinput-device.c index c79d03db6..948dc8711 100644 --- a/libweston/libinput-device.c +++ b/libweston/libinput-device.c @@ -98,6 +98,8 @@ handle_keyboard_key(struct libinput_device *libinput_device, int seat_key_count = libinput_event_keyboard_get_seat_key_count(keyboard_event); struct timespec time; + uint32_t key = libinput_event_keyboard_get_key(keyboard_event); + struct weston_key_event key_event; /* Ignore key events that are not seat wide state changes. */ if ((key_state == LIBINPUT_KEY_STATE_PRESSED && @@ -106,12 +108,12 @@ handle_keyboard_key(struct libinput_device *libinput_device, seat_key_count != 0)) return; - timespec_from_usec(&time, - libinput_event_keyboard_get_time_usec(keyboard_event)); + timespec_from_usec(&time, libinput_event_keyboard_get_time_usec(keyboard_event)); - notify_key(device->seat, &time, - libinput_event_keyboard_get_key(keyboard_event), - key_state, STATE_UPDATE_AUTOMATIC); + weston_input_event_init(&key_event.base, &time, device->seat); + weston_key_event_init(&key_event, key, key_state, STATE_UPDATE_AUTOMATIC); + + notify_key(device->seat, &key_event); } static bool diff --git a/tests/harness/weston-test.c b/tests/harness/weston-test.c index 59f54644c..6e4a97823 100644 --- a/tests/harness/weston-test.c +++ b/tests/harness/weston-test.c @@ -494,10 +494,13 @@ send_key(struct wl_client *client, struct wl_resource *resource, struct weston_test *test = wl_resource_get_user_data(resource); struct weston_seat *seat = get_seat(test); struct timespec time; + struct weston_key_event key_event; timespec_from_proto(&time, tv_sec_hi, tv_sec_lo, tv_nsec); - notify_key(seat, &time, key, state, STATE_UPDATE_AUTOMATIC); + weston_input_event_init(&key_event.base, &time, seat); + weston_key_event_init(&key_event, key, state, STATE_UPDATE_AUTOMATIC); + notify_key(seat, &key_event); } static void From 08dbbd4f06c11607ce971c908bbac1238af98d72 Mon Sep 17 00:00:00 2001 From: Marius Vlad Date: Thu, 2 Apr 2026 16:10:32 +0300 Subject: [PATCH 2/6] input: Re-work weston_pointer_motion_event This adapts weston_pointer_motion_event struct to align in with weston_key_event and includes the following changes: - include base struct - remove the const struct timespec from calls and use the base struct - pass by a const pointer motion event in all the callers - add init / reset functions Signed-off-by: Marius Vlad --- desktop-shell/shell.c | 12 +-- include/libweston/libweston.h | 37 ++++++---- ivi-shell/hmi-controller.c | 3 +- kiosk-shell/kiosk-shell-grab.c | 3 +- libweston/backend-rdp/rdp.c | 16 +++- libweston/backend-vnc/vnc.c | 7 +- libweston/backend-wayland/wayland.c | 7 +- libweston/backend-x11/x11.c | 14 ++-- libweston/backend.h | 8 +- libweston/compositor.c | 4 +- libweston/data-device.c | 5 +- libweston/desktop/seat.c | 5 +- libweston/input.c | 109 +++++++++++++++------------- libweston/libinput-device.c | 26 ++++--- tests/harness/weston-test.c | 14 ++-- 15 files changed, 153 insertions(+), 117 deletions(-) diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c index df34b5441..568345bfd 100644 --- a/desktop-shell/shell.c +++ b/desktop-shell/shell.c @@ -911,8 +911,7 @@ constrain_position(struct weston_move_grab *move) static void move_grab_motion(struct weston_pointer_grab *grab, - const struct timespec *time, - struct weston_pointer_motion_event *event) + const struct weston_pointer_motion_event *event) { struct weston_move_grab *move = (struct weston_move_grab *) grab; struct weston_pointer *pointer = grab->pointer; @@ -1141,8 +1140,7 @@ surface_tablet_tool_move(struct shell_surface *shsurf, struct weston_tablet_tool static void resize_grab_motion(struct weston_pointer_grab *grab, - const struct timespec *time, - struct weston_pointer_motion_event *event) + const struct weston_pointer_motion_event *event) { struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; struct weston_pointer *pointer = grab->pointer; @@ -1311,8 +1309,7 @@ busy_cursor_grab_focus(struct weston_pointer_grab *base) static void busy_cursor_grab_motion(struct weston_pointer_grab *grab, - const struct timespec *time, - struct weston_pointer_motion_event *event) + const struct weston_pointer_motion_event *event) { weston_pointer_move(grab->pointer, event); } @@ -3220,8 +3217,7 @@ terminate_binding(struct weston_keyboard *keyboard, const struct timespec *time, static void rotate_grab_motion(struct weston_pointer_grab *grab, - const struct timespec *time, - struct weston_pointer_motion_event *event) + const struct weston_pointer_motion_event *event) { struct rotate_grab *rotate = container_of(grab, struct rotate_grab, base.grab); diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h index cdd9cf285..5f686b430 100644 --- a/include/libweston/libweston.h +++ b/include/libweston/libweston.h @@ -605,12 +605,18 @@ enum weston_pointer_motion_mask { WESTON_POINTER_MOTION_REL_UNACCEL = 1 << 2, }; +/* base/common struct which all weston_xxx_event should "inherit" */ +struct weston_input_event { + struct timespec ts; + struct weston_seat *seat; +}; + struct weston_pointer_motion_event { + struct weston_input_event base; uint32_t mask; - struct timespec time; - struct weston_coord_global abs; - struct weston_coord rel; - struct weston_coord rel_unaccel; + const struct weston_coord_global *abs; + const struct weston_coord *rel; + const struct weston_coord *rel_unaccel; }; struct weston_pointer_axis_event { @@ -620,12 +626,6 @@ struct weston_pointer_axis_event { int32_t discrete; }; -/* base/common struct which all weston_xxx_event should "inherit" */ -struct weston_input_event { - struct timespec ts; - struct weston_seat *seat; -}; - struct weston_key_event { struct weston_input_event base; uint32_t key; @@ -638,8 +638,7 @@ struct weston_pointer_grab; struct weston_pointer_grab_interface { void (*focus)(struct weston_pointer_grab *grab); void (*motion)(struct weston_pointer_grab *grab, - const struct timespec *time, - struct weston_pointer_motion_event *event); + const struct weston_pointer_motion_event *event); void (*button)(struct weston_pointer_grab *grab, const struct timespec *time, uint32_t button, uint32_t state); @@ -967,12 +966,11 @@ struct weston_color_representation_matrix { struct weston_coord_global weston_pointer_motion_to_abs(struct weston_pointer *pointer, - struct weston_pointer_motion_event *event); + const struct weston_pointer_motion_event *event); void weston_pointer_send_motion(struct weston_pointer *pointer, - const struct timespec *time, - struct weston_pointer_motion_event *event); + const struct weston_pointer_motion_event *event); bool weston_pointer_has_focus_resource(struct weston_pointer *pointer); void @@ -1003,7 +1001,7 @@ void weston_pointer_end_grab(struct weston_pointer *pointer); void weston_pointer_move(struct weston_pointer *pointer, - struct weston_pointer_motion_event *event); + const struct weston_pointer_motion_event *event); void weston_keyboard_set_focus(struct weston_keyboard *keyboard, struct weston_surface *surface); @@ -1032,6 +1030,13 @@ weston_key_event_init(struct weston_key_event *event, uint32_t key, enum wl_keyboard_key_state key_state, enum weston_key_state_update key_update_state); +void +weston_pointer_motion_event_init(struct weston_pointer_motion_event *event, + uint32_t mask, + const struct weston_coord_global *abs, + const struct weston_coord *rel, + const struct weston_coord *rel_unaccel); + void weston_keyboard_send_modifiers(struct weston_keyboard *keyboard, uint32_t serial, uint32_t mods_depressed, diff --git a/ivi-shell/hmi-controller.c b/ivi-shell/hmi-controller.c index 0bbfa2c6e..295da77fa 100644 --- a/ivi-shell/hmi-controller.c +++ b/ivi-shell/hmi-controller.c @@ -1713,8 +1713,7 @@ layer_set_pos(struct hmi_controller *hmi_ctrl, struct ivi_layout_layer *layer, static void pointer_move_grab_motion(struct weston_pointer_grab *grab, - const struct timespec *time, - struct weston_pointer_motion_event *event) + const struct weston_pointer_motion_event *event) { struct pointer_move_grab *pnt_move_grab = (struct pointer_move_grab *)grab; diff --git a/kiosk-shell/kiosk-shell-grab.c b/kiosk-shell/kiosk-shell-grab.c index bff706fb3..24b0750c2 100644 --- a/kiosk-shell/kiosk-shell-grab.c +++ b/kiosk-shell/kiosk-shell-grab.c @@ -68,8 +68,7 @@ pointer_move_grab_frame(struct weston_pointer_grab *grab) static void pointer_move_grab_motion(struct weston_pointer_grab *pointer_grab, - const struct timespec *time, - struct weston_pointer_motion_event *event) + const struct weston_pointer_motion_event *event) { struct kiosk_shell_grab *shgrab = container_of(pointer_grab, struct kiosk_shell_grab, pointer_grab); diff --git a/libweston/backend-rdp/rdp.c b/libweston/backend-rdp/rdp.c index 8580a1b88..3e6e97bf4 100644 --- a/libweston/backend-rdp/rdp.c +++ b/libweston/backend-rdp/rdp.c @@ -1282,9 +1282,15 @@ rdp_translate_and_notify_mouse_position(RdpPeerContext *peerContext, UINT16 x, U different scaling. In such case, hit test to that window area on non primary-resident monitor (surface->output) dosn't work. */ if (to_weston_coordinate(peerContext, &sx, &sy)) { + struct weston_pointer_motion_event event; + pos.c = weston_coord(sx, sy); weston_compositor_get_time(&time); - notify_motion_absolute(peerContext->item.seat, &time, pos); + + weston_input_event_init(&event.base, &time, peerContext->item.seat); + weston_pointer_motion_event_init(&event, WESTON_POINTER_MOTION_ABS, + &pos, NULL, NULL); + notify_motion_absolute(peerContext->item.seat, &event); return TRUE; } return FALSE; @@ -1515,9 +1521,15 @@ xf_extendedMouseEvent(rdpInput *input, UINT16 flags, UINT16 x, UINT16 y) output = rdp_get_first_output(peerContext->rdpBackend); if (x < output->base.width && y < output->base.height) { + struct weston_pointer_motion_event event; + weston_compositor_get_time(&time); pos.c = weston_coord(x, y); - notify_motion_absolute(peerContext->item.seat, &time, pos); + + weston_input_event_init(&event.base, &time, peerContext->item.seat); + weston_pointer_motion_event_init(&event, WESTON_POINTER_MOTION_ABS, + &pos, NULL, NULL); + notify_motion_absolute(peerContext->item.seat, &event); need_frame = true; } diff --git a/libweston/backend-vnc/vnc.c b/libweston/backend-vnc/vnc.c index a632260a2..c400c2140 100644 --- a/libweston/backend-vnc/vnc.c +++ b/libweston/backend-vnc/vnc.c @@ -447,9 +447,14 @@ vnc_pointer_event(struct nvnc_client *client, uint16_t x, uint16_t y, if (x < output->base.width && y < output->base.height) { struct weston_coord_global pos; + struct weston_pointer_motion_event event; pos = weston_coord_global_from_output_point(x, y, &output->base); - notify_motion_absolute(peer->seat, &time, pos); + + weston_input_event_init(&event.base, &time, peer->seat); + weston_pointer_motion_event_init(&event, WESTON_POINTER_MOTION_ABS, + &pos, NULL, NULL); + notify_motion_absolute(peer->seat, &event); } changed_button_mask = peer->last_button_mask ^ button_mask; diff --git a/libweston/backend-wayland/wayland.c b/libweston/backend-wayland/wayland.c index e31ecd70b..c28e8c618 100644 --- a/libweston/backend-wayland/wayland.c +++ b/libweston/backend-wayland/wayland.c @@ -1677,6 +1677,7 @@ input_handle_motion(void *data, struct wl_pointer *pointer, bool want_frame = false; double x, y; struct weston_coord_global pos; + struct weston_pointer_motion_event event; struct timespec ts; if (!input->output) @@ -1717,7 +1718,11 @@ input_handle_motion(void *data, struct wl_pointer *pointer, if (location == THEME_LOCATION_CLIENT_AREA) { timespec_from_msec(&ts, time); - notify_motion_absolute(&input->base, &ts, pos); + + weston_input_event_init(&event.base, &ts, &input->base); + weston_pointer_motion_event_init(&event, WESTON_POINTER_MOTION_ABS, + &pos, NULL, NULL); + notify_motion_absolute(&input->base, &event); want_frame = true; } diff --git a/libweston/backend-x11/x11.c b/libweston/backend-x11/x11.c index 7a6ed9557..3795a1c0f 100644 --- a/libweston/backend-x11/x11.c +++ b/libweston/backend-x11/x11.c @@ -1520,7 +1520,8 @@ x11_backend_deliver_motion_event(struct x11_backend *b, { struct x11_output *output; struct weston_coord_global pos; - struct weston_pointer_motion_event motion_event = { 0 }; + struct weston_pointer_motion_event motion_event; + struct weston_coord rel; xcb_motion_notify_event_t *motion_notify = (xcb_motion_notify_event_t *) event; struct timespec time; @@ -1535,12 +1536,13 @@ x11_backend_deliver_motion_event(struct x11_backend *b, motion_notify->event_y, &output->base); - motion_event = (struct weston_pointer_motion_event) { - .mask = WESTON_POINTER_MOTION_REL, - .rel = weston_coord_global_sub(pos, b->prev_pos).c, - }; + rel = weston_coord_global_sub(pos, b->prev_pos).c; weston_compositor_get_time(&time); - notify_motion(&b->core_seat, &time, &motion_event); + + weston_input_event_init(&motion_event.base, &time, &b->core_seat); + weston_pointer_motion_event_init(&motion_event, WESTON_POINTER_MOTION_REL, + NULL, &rel, NULL); + notify_motion(&b->core_seat, &motion_event); notify_pointer_frame(&b->core_seat); b->prev_pos = pos; diff --git a/libweston/backend.h b/libweston/backend.h index ea232af7d..8442e9325 100644 --- a/libweston/backend.h +++ b/libweston/backend.h @@ -251,11 +251,11 @@ void notify_keyboard_focus_out(struct weston_seat *seat); void -notify_motion(struct weston_seat *seat, const struct timespec *time, - struct weston_pointer_motion_event *event); +notify_motion(struct weston_seat *seat, const struct weston_pointer_motion_event *event); + void -notify_motion_absolute(struct weston_seat *seat, const struct timespec *time, - struct weston_coord_global pos); +notify_motion_absolute(struct weston_seat *seat, const struct weston_pointer_motion_event *event); + void notify_modifiers(struct weston_seat *seat, uint32_t serial); diff --git a/libweston/compositor.c b/libweston/compositor.c index 8259f9795..cc0ba27f7 100644 --- a/libweston/compositor.c +++ b/libweston/compositor.c @@ -8012,6 +8012,7 @@ weston_output_set_transform(struct weston_output *output, uint32_t transform) { struct weston_pointer_motion_event ev; + struct weston_coord_global pos; struct wl_resource *resource; struct weston_seat *seat; pixman_region32_t old_region; @@ -8067,7 +8068,8 @@ weston_output_set_transform(struct weston_output *output, mid_y = output->pos.c.y + output->height / 2; ev.mask = WESTON_POINTER_MOTION_ABS; - ev.abs.c = weston_coord(mid_x, mid_y); + pos.c = weston_coord(mid_x, mid_y); + ev.abs = &pos; wl_list_for_each(seat, &output->compositor->seat_list, link) { struct weston_pointer *pointer = weston_seat_get_pointer(seat); diff --git a/libweston/data-device.c b/libweston/data-device.c index cb899b642..a5eec6cb0 100644 --- a/libweston/data-device.c +++ b/libweston/data-device.c @@ -591,8 +591,7 @@ drag_grab_focus(struct weston_pointer_grab *grab) static void drag_grab_motion(struct weston_pointer_grab *grab, - const struct timespec *time, - struct weston_pointer_motion_event *event) + const struct weston_pointer_motion_event *event) { struct weston_pointer_drag *drag = container_of(grab, struct weston_pointer_drag, grab); @@ -610,7 +609,7 @@ drag_grab_motion(struct weston_pointer_grab *grab, if (drag->base.focus_resource) { struct weston_coord_surface surf_pos; - msecs = timespec_to_msec(time); + msecs = timespec_to_msec(&event->base.ts); surf_pos = weston_coord_global_to_surface(drag->base.focus, pointer->pos); diff --git a/libweston/desktop/seat.c b/libweston/desktop/seat.c index 7886d5000..b681e12c2 100644 --- a/libweston/desktop/seat.c +++ b/libweston/desktop/seat.c @@ -117,10 +117,9 @@ weston_desktop_seat_popup_grab_pointer_focus(struct weston_pointer_grab *grab) static void weston_desktop_seat_popup_grab_pointer_motion(struct weston_pointer_grab *grab, - const struct timespec *time, - struct weston_pointer_motion_event *event) + const struct weston_pointer_motion_event *event) { - weston_pointer_send_motion(grab->pointer, time, event); + weston_pointer_send_motion(grab->pointer, event); } static void diff --git a/libweston/input.c b/libweston/input.c index 46bdd231f..c20a4c0ea 100644 --- a/libweston/input.c +++ b/libweston/input.c @@ -41,6 +41,7 @@ #include #include "shared/helpers.h" +#include "shared/weston-assert.h" #include "shared/os-compatibility.h" #include "shared/timespec-util.h" #include @@ -304,14 +305,14 @@ static void unbind_resource(struct wl_resource *resource) WL_EXPORT struct weston_coord_global weston_pointer_motion_to_abs(struct weston_pointer *pointer, - struct weston_pointer_motion_event *event) + const struct weston_pointer_motion_event *event) { struct weston_coord_global pos; if (event->mask & WESTON_POINTER_MOTION_ABS) { - return event->abs; + return *event->abs; } else if (event->mask & WESTON_POINTER_MOTION_REL) { - pos.c = weston_coord_add(pointer->pos.c, event->rel); + pos.c = weston_coord_add(pointer->pos.c, *event->rel); return pos; } @@ -322,22 +323,22 @@ weston_pointer_motion_to_abs(struct weston_pointer *pointer, static bool weston_pointer_motion_to_rel(struct weston_pointer *pointer, - struct weston_pointer_motion_event *event, + const struct weston_pointer_motion_event *event, struct weston_coord *rel, struct weston_coord *rel_unaccel) { if (event->mask & WESTON_POINTER_MOTION_REL && event->mask & WESTON_POINTER_MOTION_REL_UNACCEL) { - *rel = event->rel; - *rel_unaccel = event->rel_unaccel; + *rel = *event->rel; + *rel_unaccel = *event->rel_unaccel; return true; } else if (event->mask & WESTON_POINTER_MOTION_REL) { - *rel = event->rel; - *rel_unaccel = event->rel; + *rel = *event->rel; + *rel_unaccel = *event->rel; return true; } else if (event->mask & WESTON_POINTER_MOTION_REL_UNACCEL) { - *rel = event->rel_unaccel; - *rel_unaccel = event->rel_unaccel; + *rel = *event->rel_unaccel; + *rel_unaccel = *event->rel_unaccel; return true; } else { return false; @@ -546,7 +547,7 @@ weston_pointer_move_to(struct weston_pointer *pointer, WL_EXPORT void weston_pointer_move(struct weston_pointer *pointer, - struct weston_pointer_motion_event *event) + const struct weston_pointer_motion_event *event) { struct weston_coord_global pos; @@ -556,8 +557,7 @@ weston_pointer_move(struct weston_pointer *pointer, static void pointer_send_relative_motion(struct weston_pointer *pointer, - const struct timespec *time, - struct weston_pointer_motion_event *event) + const struct weston_pointer_motion_event *event) { uint64_t time_usec; struct weston_coord rel, rel_unaccel; @@ -573,9 +573,9 @@ pointer_send_relative_motion(struct weston_pointer *pointer, return; resource_list = &pointer->focus_client->relative_pointer_resources; - time_usec = timespec_to_usec(&event->time); + time_usec = timespec_to_usec(&event->base.ts); if (time_usec == 0) - time_usec = timespec_to_usec(time); + time_usec = timespec_to_usec(&event->base.ts); wl_resource_for_each(resource, resource_list) { zwp_relative_pointer_v1_send_relative_motion( @@ -590,9 +590,8 @@ pointer_send_relative_motion(struct weston_pointer *pointer, } static void -pointer_send_motion(struct weston_pointer *pointer, - const struct timespec *time, - wl_fixed_t sx, wl_fixed_t sy) +pointer_send_motion(struct weston_pointer *pointer, wl_fixed_t sx, wl_fixed_t sy, + const struct weston_pointer_motion_event *event) { struct wl_list *resource_list; struct wl_resource *resource; @@ -602,19 +601,18 @@ pointer_send_motion(struct weston_pointer *pointer, return; resource_list = &pointer->focus_client->pointer_resources; - msecs = timespec_to_msec(time); + msecs = timespec_to_msec(&event->base.ts); wl_resource_for_each(resource, resource_list) { send_timestamps_for_input_resource(resource, &pointer->timestamps_list, - time); + &event->base.ts); wl_pointer_send_motion(resource, msecs, sx, sy); } } WL_EXPORT void weston_pointer_send_motion(struct weston_pointer *pointer, - const struct timespec *time, - struct weston_pointer_motion_event *event) + const struct weston_pointer_motion_event *event) { wl_fixed_t old_sx; wl_fixed_t old_sy; @@ -622,7 +620,7 @@ weston_pointer_send_motion(struct weston_pointer *pointer, struct weston_coord_global pos; pos = weston_pointer_motion_to_abs(pointer, event); - pos = weston_pointer_clamp(pointer,pos); + pos = weston_pointer_clamp(pointer, pos); if (pointer->focus) { struct weston_coord_surface surf_pos; @@ -642,19 +640,17 @@ weston_pointer_send_motion(struct weston_pointer *pointer, if (pointer->focus && old_focus == pointer->focus && (old_sx != pointer->sx || old_sy != pointer->sy)) { - pointer_send_motion(pointer, time, - pointer->sx, pointer->sy); + pointer_send_motion(pointer, pointer->sx, pointer->sy, event); } - pointer_send_relative_motion(pointer, time, event); + pointer_send_relative_motion(pointer, event); } static void default_grab_pointer_motion(struct weston_pointer_grab *grab, - const struct timespec *time, - struct weston_pointer_motion_event *event) + const struct weston_pointer_motion_event *event) { - weston_pointer_send_motion(grab->pointer, time, event); + weston_pointer_send_motion(grab->pointer, event); } /** Check if the pointer has focused resources. @@ -2244,14 +2240,13 @@ weston_pointer_handle_output_destroy(struct wl_listener *listener, void *data) WL_EXPORT void notify_motion(struct weston_seat *seat, - const struct timespec *time, - struct weston_pointer_motion_event *event) + const struct weston_pointer_motion_event *event) { struct weston_compositor *ec = seat->compositor; struct weston_pointer *pointer = weston_seat_get_pointer(seat); weston_compositor_wake(ec); - pointer->grab->interface->motion(pointer->grab, time, event); + pointer->grab->interface->motion(pointer->grab, event); } static void @@ -2291,20 +2286,14 @@ run_modifier_bindings(struct weston_seat *seat, uint32_t old, uint32_t new) } WL_EXPORT void -notify_motion_absolute(struct weston_seat *seat, const struct timespec *time, - struct weston_coord_global pos) +notify_motion_absolute(struct weston_seat *seat, + const struct weston_pointer_motion_event *event) { struct weston_compositor *ec = seat->compositor; struct weston_pointer *pointer = weston_seat_get_pointer(seat); - struct weston_pointer_motion_event event = { 0 }; weston_compositor_wake(ec); - - event = (struct weston_pointer_motion_event) { - .mask = WESTON_POINTER_MOTION_ABS, - .abs = pos, - }; - pointer->grab->interface->motion(pointer->grab, time, &event); + pointer->grab->interface->motion(pointer->grab, event); } static unsigned int @@ -4734,10 +4723,9 @@ locked_pointer_grab_pointer_focus(struct weston_pointer_grab *grab) static void locked_pointer_grab_pointer_motion(struct weston_pointer_grab *grab, - const struct timespec *time, - struct weston_pointer_motion_event *event) + const struct weston_pointer_motion_event *event) { - pointer_send_relative_motion(grab->pointer, time, event); + pointer_send_relative_motion(grab->pointer, event); } static void @@ -5538,7 +5526,7 @@ get_motion_directions(struct line *motion) static struct weston_coord_global weston_pointer_clamp_event_to_region(struct weston_pointer *pointer, - struct weston_pointer_motion_event *event, + const struct weston_pointer_motion_event *event, pixman_region32_t *region) { wl_fixed_t old_sx = pointer->sx; @@ -5705,8 +5693,7 @@ maybe_warp_confined_pointer(struct weston_pointer_constraint *constraint) static void confined_pointer_grab_pointer_motion(struct weston_pointer_grab *grab, - const struct timespec *time, - struct weston_pointer_motion_event *event) + const struct weston_pointer_motion_event *event) { struct weston_pointer_constraint *constraint = container_of(grab, struct weston_pointer_constraint, grab); @@ -5737,11 +5724,10 @@ confined_pointer_grab_pointer_motion(struct weston_pointer_grab *grab, pointer->sy = wl_fixed_from_double(surf_pos.c.y); if (old_sx != pointer->sx || old_sy != pointer->sy) { - pointer_send_motion(pointer, time, - pointer->sx, pointer->sy); + pointer_send_motion(pointer, pointer->sx, pointer->sy, event); } - pointer_send_relative_motion(pointer, time, event); + pointer_send_relative_motion(pointer, event); } static void @@ -6045,3 +6031,26 @@ weston_key_event_init(struct weston_key_event *event, uint32_t key, enum wl_keyb event->key_state = key_state; event->key_update_state = key_update_state; } + +WL_EXPORT void +weston_pointer_motion_event_init(struct weston_pointer_motion_event *event, + uint32_t mask, + const struct weston_coord_global *abs, + const struct weston_coord *rel, + const struct weston_coord *rel_unaccel) +{ + + if (mask & WESTON_POINTER_MOTION_ABS) + weston_assert_ptr_not_null(event->base.seat->compositor, abs); + + if (mask & WESTON_POINTER_MOTION_REL) + weston_assert_ptr_not_null(event->base.seat->compositor, rel); + + if (mask & WESTON_POINTER_MOTION_REL_UNACCEL) + weston_assert_ptr_not_null(event->base.seat->compositor, rel_unaccel); + + event->mask = mask; + event->abs = abs; + event->rel = rel; + event->rel_unaccel = rel_unaccel; +} diff --git a/libweston/libinput-device.c b/libweston/libinput-device.c index 948dc8711..945dde060 100644 --- a/libweston/libinput-device.c +++ b/libweston/libinput-device.c @@ -122,9 +122,10 @@ handle_pointer_motion(struct libinput_device *libinput_device, { struct evdev_device *device = libinput_device_get_user_data(libinput_device); - struct weston_pointer_motion_event event = { 0 }; + struct weston_pointer_motion_event event; struct timespec time; double dx_unaccel, dy_unaccel; + struct weston_coord rel, rel_unaccel; ensure_pointer_capability(libinput_device); @@ -133,15 +134,14 @@ handle_pointer_motion(struct libinput_device *libinput_device, dx_unaccel = libinput_event_pointer_get_dx_unaccelerated(pointer_event); dy_unaccel = libinput_event_pointer_get_dy_unaccelerated(pointer_event); - event = (struct weston_pointer_motion_event) { - .mask = WESTON_POINTER_MOTION_REL | - WESTON_POINTER_MOTION_REL_UNACCEL, - .time = time, - }; - event.rel = weston_coord(libinput_event_pointer_get_dx(pointer_event), - libinput_event_pointer_get_dy(pointer_event)); - event.rel_unaccel = weston_coord(dx_unaccel, dy_unaccel); - notify_motion(device->seat, &time, &event); + rel = weston_coord(libinput_event_pointer_get_dx(pointer_event), + libinput_event_pointer_get_dy(pointer_event)); + rel_unaccel = weston_coord(dx_unaccel, dy_unaccel); + + weston_input_event_init(&event.base, &time, device->seat); + weston_pointer_motion_event_init(&event, WESTON_POINTER_MOTION_REL | + WESTON_POINTER_MOTION_REL_UNACCEL, NULL, &rel, &rel_unaccel); + notify_motion(device->seat, &event); return true; } @@ -156,6 +156,7 @@ handle_pointer_motion_absolute( struct weston_output *output = device->output; struct weston_coord_global pos; struct timespec time; + struct weston_pointer_motion_event event; double x, y; uint32_t width, height; @@ -174,7 +175,10 @@ handle_pointer_motion_absolute( y = libinput_event_pointer_get_absolute_y_transformed(pointer_event, height); pos = weston_coord_global_from_output_point(x, y, output); - notify_motion_absolute(device->seat, &time, pos); + weston_input_event_init(&event.base, &time, device->seat); + weston_pointer_motion_event_init(&event, WESTON_POINTER_MOTION_ABS, + &pos, NULL, NULL); + notify_motion_absolute(device->seat, &event); return true; } diff --git a/tests/harness/weston-test.c b/tests/harness/weston-test.c index 6e4a97823..247097510 100644 --- a/tests/harness/weston-test.c +++ b/tests/harness/weston-test.c @@ -412,19 +412,19 @@ move_pointer(struct wl_client *client, struct wl_resource *resource, struct weston_test *test = wl_resource_get_user_data(resource); struct weston_seat *seat = get_seat(test); struct weston_pointer *pointer = weston_seat_get_pointer(seat); - struct weston_pointer_motion_event event = { 0 }; + struct weston_pointer_motion_event event; struct weston_coord_global pos; + struct weston_coord rel; struct timespec time; pos.c = weston_coord(x, y); - event = (struct weston_pointer_motion_event) { - .mask = WESTON_POINTER_MOTION_REL, - .rel = weston_coord_global_sub(pos, pointer->pos).c, - }; - timespec_from_proto(&time, tv_sec_hi, tv_sec_lo, tv_nsec); + rel = weston_coord_global_sub(pos, pointer->pos).c; - notify_motion(seat, &time, &event); + weston_input_event_init(&event.base, &time, seat); + weston_pointer_motion_event_init(&event, WESTON_POINTER_MOTION_REL, + NULL, &rel, NULL); + notify_motion(seat, &event); notify_pointer_position(test, resource); } From e9bdb3701d227bd8bc501d69e7f254e2e523c44b Mon Sep 17 00:00:00 2001 From: Marius Vlad Date: Tue, 21 Apr 2026 11:52:34 +0300 Subject: [PATCH 3/6] input: Remove notify_motion_absolute We're now able to use the mask to pass the proper type so need for a specialized version. Signed-off-by: Marius Vlad --- libweston/backend-rdp/rdp.c | 4 ++-- libweston/backend-vnc/vnc.c | 2 +- libweston/backend-wayland/wayland.c | 2 +- libweston/backend.h | 3 --- libweston/input.c | 11 ----------- libweston/libinput-device.c | 2 +- 6 files changed, 5 insertions(+), 19 deletions(-) diff --git a/libweston/backend-rdp/rdp.c b/libweston/backend-rdp/rdp.c index 3e6e97bf4..af85465c0 100644 --- a/libweston/backend-rdp/rdp.c +++ b/libweston/backend-rdp/rdp.c @@ -1290,7 +1290,7 @@ rdp_translate_and_notify_mouse_position(RdpPeerContext *peerContext, UINT16 x, U weston_input_event_init(&event.base, &time, peerContext->item.seat); weston_pointer_motion_event_init(&event, WESTON_POINTER_MOTION_ABS, &pos, NULL, NULL); - notify_motion_absolute(peerContext->item.seat, &event); + notify_motion(peerContext->item.seat, &event); return TRUE; } return FALSE; @@ -1529,7 +1529,7 @@ xf_extendedMouseEvent(rdpInput *input, UINT16 flags, UINT16 x, UINT16 y) weston_input_event_init(&event.base, &time, peerContext->item.seat); weston_pointer_motion_event_init(&event, WESTON_POINTER_MOTION_ABS, &pos, NULL, NULL); - notify_motion_absolute(peerContext->item.seat, &event); + notify_motion(peerContext->item.seat, &event); need_frame = true; } diff --git a/libweston/backend-vnc/vnc.c b/libweston/backend-vnc/vnc.c index c400c2140..bbb0a6f7f 100644 --- a/libweston/backend-vnc/vnc.c +++ b/libweston/backend-vnc/vnc.c @@ -454,7 +454,7 @@ vnc_pointer_event(struct nvnc_client *client, uint16_t x, uint16_t y, weston_input_event_init(&event.base, &time, peer->seat); weston_pointer_motion_event_init(&event, WESTON_POINTER_MOTION_ABS, &pos, NULL, NULL); - notify_motion_absolute(peer->seat, &event); + notify_motion(peer->seat, &event); } changed_button_mask = peer->last_button_mask ^ button_mask; diff --git a/libweston/backend-wayland/wayland.c b/libweston/backend-wayland/wayland.c index c28e8c618..22b438913 100644 --- a/libweston/backend-wayland/wayland.c +++ b/libweston/backend-wayland/wayland.c @@ -1722,7 +1722,7 @@ input_handle_motion(void *data, struct wl_pointer *pointer, weston_input_event_init(&event.base, &ts, &input->base); weston_pointer_motion_event_init(&event, WESTON_POINTER_MOTION_ABS, &pos, NULL, NULL); - notify_motion_absolute(&input->base, &event); + notify_motion(&input->base, &event); want_frame = true; } diff --git a/libweston/backend.h b/libweston/backend.h index 8442e9325..a441f183b 100644 --- a/libweston/backend.h +++ b/libweston/backend.h @@ -253,9 +253,6 @@ notify_keyboard_focus_out(struct weston_seat *seat); void notify_motion(struct weston_seat *seat, const struct weston_pointer_motion_event *event); -void -notify_motion_absolute(struct weston_seat *seat, const struct weston_pointer_motion_event *event); - void notify_modifiers(struct weston_seat *seat, uint32_t serial); diff --git a/libweston/input.c b/libweston/input.c index c20a4c0ea..0371df001 100644 --- a/libweston/input.c +++ b/libweston/input.c @@ -2285,17 +2285,6 @@ run_modifier_bindings(struct weston_seat *seat, uint32_t old, uint32_t new) } } -WL_EXPORT void -notify_motion_absolute(struct weston_seat *seat, - const struct weston_pointer_motion_event *event) -{ - struct weston_compositor *ec = seat->compositor; - struct weston_pointer *pointer = weston_seat_get_pointer(seat); - - weston_compositor_wake(ec); - pointer->grab->interface->motion(pointer->grab, event); -} - static unsigned int peek_next_activate_serial(struct weston_compositor *c) { diff --git a/libweston/libinput-device.c b/libweston/libinput-device.c index 945dde060..f0666ef2e 100644 --- a/libweston/libinput-device.c +++ b/libweston/libinput-device.c @@ -178,7 +178,7 @@ handle_pointer_motion_absolute( weston_input_event_init(&event.base, &time, device->seat); weston_pointer_motion_event_init(&event, WESTON_POINTER_MOTION_ABS, &pos, NULL, NULL); - notify_motion_absolute(device->seat, &event); + notify_motion(device->seat, &event); return true; } From bb4e88ed3624e75dc175b5c758c59c161df8e4dc Mon Sep 17 00:00:00 2001 From: Marius Vlad Date: Thu, 2 Apr 2026 20:49:56 +0300 Subject: [PATCH 4/6] input: Introduce weston_pointer_button_event Similar to 29001fbc96, "input: Introduce weston_key_event struct", this adds a way to store all required information with a common struct event to be able to pass it down and to allow also pass additonal information like Perfetto's flow IDs. Signed-off-by: Marius Vlad --- desktop-shell/shell.c | 23 ++++++------ include/libweston/libweston.h | 17 ++++++--- ivi-shell/hmi-controller.c | 7 ++-- kiosk-shell/kiosk-shell-grab.c | 5 ++- libweston/backend-rdp/rdp.c | 24 ++++++++++--- libweston/backend-vnc/vnc.c | 39 ++++++++++++-------- libweston/backend-wayland/wayland.c | 7 +++- libweston/backend-x11/x11.c | 10 ++++-- libweston/backend.h | 3 +- libweston/data-device.c | 7 ++-- libweston/desktop/seat.c | 10 +++--- libweston/input.c | 55 +++++++++++++++-------------- libweston/libinput-device.c | 9 +++-- tests/harness/weston-test.c | 7 ++-- 14 files changed, 133 insertions(+), 90 deletions(-) diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c index 568345bfd..bb6011fab 100644 --- a/desktop-shell/shell.c +++ b/desktop-shell/shell.c @@ -928,12 +928,12 @@ move_grab_motion(struct weston_pointer_grab *grab, static void move_grab_button(struct weston_pointer_grab *grab, - const struct timespec *time, uint32_t button, uint32_t state_w) + const struct weston_pointer_button_event *button_event) { struct shell_grab *shell_grab = container_of(grab, struct shell_grab, grab); struct weston_pointer *pointer = grab->pointer; - enum wl_pointer_button_state state = state_w; + enum wl_pointer_button_state state = button_event->button_state; if (pointer->button_count == 0 && state == WL_POINTER_BUTTON_STATE_RELEASED) { @@ -1198,12 +1198,11 @@ resize_grab_motion(struct weston_pointer_grab *grab, static void resize_grab_button(struct weston_pointer_grab *grab, - const struct timespec *time, - uint32_t button, uint32_t state_w) + const struct weston_pointer_button_event *button_event) { struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; struct weston_pointer *pointer = grab->pointer; - enum wl_pointer_button_state state = state_w; + enum wl_pointer_button_state state = button_event->button_state; if (pointer->button_count == 0 && state == WL_POINTER_BUTTON_STATE_RELEASED) { @@ -1316,19 +1315,20 @@ busy_cursor_grab_motion(struct weston_pointer_grab *grab, static void busy_cursor_grab_button(struct weston_pointer_grab *base, - const struct timespec *time, - uint32_t button, uint32_t state) + const struct weston_pointer_button_event *button_event) { struct shell_grab *grab = (struct shell_grab *) base; struct shell_surface *shsurf = grab->shsurf; struct weston_pointer *pointer = grab->grab.pointer; struct weston_seat *seat = pointer->seat; - if (shsurf && button == BTN_LEFT && state) { + if (shsurf && button_event->button == BTN_LEFT && + button_event->button_state) { activate(shsurf->shell, shsurf->view, seat, WESTON_ACTIVATE_FLAG_CONFIGURE); surface_move(shsurf, pointer, false); - } else if (shsurf && button == BTN_RIGHT && state) { + } else if (shsurf && button_event->button == BTN_RIGHT && + button_event->button_state) { activate(shsurf->shell, shsurf->view, seat, WESTON_ACTIVATE_FLAG_CONFIGURE); surface_rotate(shsurf, pointer); @@ -3283,14 +3283,13 @@ rotate_grab_motion(struct weston_pointer_grab *grab, static void rotate_grab_button(struct weston_pointer_grab *grab, - const struct timespec *time, - uint32_t button, uint32_t state_w) + const struct weston_pointer_button_event *button_event) { struct rotate_grab *rotate = container_of(grab, struct rotate_grab, base.grab); struct weston_pointer *pointer = grab->pointer; struct shell_surface *shsurf = rotate->base.shsurf; - enum wl_pointer_button_state state = state_w; + enum wl_pointer_button_state state = button_event->button_state; if (pointer->button_count == 0 && state == WL_POINTER_BUTTON_STATE_RELEASED) { diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h index 5f686b430..160cd7a94 100644 --- a/include/libweston/libweston.h +++ b/include/libweston/libweston.h @@ -619,6 +619,12 @@ struct weston_pointer_motion_event { const struct weston_coord *rel_unaccel; }; +struct weston_pointer_button_event { + struct weston_input_event base; + uint32_t button; + enum wl_pointer_button_state button_state; +}; + struct weston_pointer_axis_event { uint32_t axis; double value; @@ -640,8 +646,7 @@ struct weston_pointer_grab_interface { void (*motion)(struct weston_pointer_grab *grab, const struct weston_pointer_motion_event *event); void (*button)(struct weston_pointer_grab *grab, - const struct timespec *time, - uint32_t button, uint32_t state); + const struct weston_pointer_button_event *button_event); void (*axis)(struct weston_pointer_grab *grab, const struct timespec *time, struct weston_pointer_axis_event *event); @@ -975,9 +980,7 @@ bool weston_pointer_has_focus_resource(struct weston_pointer *pointer); void weston_pointer_send_button(struct weston_pointer *pointer, - const struct timespec *time, - uint32_t button, - enum wl_pointer_button_state state); + const struct weston_pointer_button_event *button_event); void weston_pointer_send_axis(struct weston_pointer *pointer, const struct timespec *time, @@ -1037,6 +1040,10 @@ weston_pointer_motion_event_init(struct weston_pointer_motion_event *event, const struct weston_coord *rel, const struct weston_coord *rel_unaccel); +void +weston_pointer_button_event_init(struct weston_pointer_button_event *event, + uint32_t button, enum wl_pointer_button_state button_state); + void weston_keyboard_send_modifiers(struct weston_keyboard *keyboard, uint32_t serial, uint32_t mods_depressed, diff --git a/ivi-shell/hmi-controller.c b/ivi-shell/hmi-controller.c index 295da77fa..9d585812d 100644 --- a/ivi-shell/hmi-controller.c +++ b/ivi-shell/hmi-controller.c @@ -1755,11 +1755,10 @@ touch_move_grab_motion(struct weston_touch_grab *grab, static void pointer_move_workspace_grab_button(struct weston_pointer_grab *grab, - const struct timespec *time, uint32_t button, - uint32_t state_w) + const struct weston_pointer_button_event *button_event) { - if (BTN_LEFT == button && - WL_POINTER_BUTTON_STATE_RELEASED == state_w) { + if (BTN_LEFT == button_event->button && + WL_POINTER_BUTTON_STATE_RELEASED == button_event->button_state) { struct pointer_grab *pg = (struct pointer_grab *)grab; pointer_move_workspace_grab_end(pg); diff --git a/kiosk-shell/kiosk-shell-grab.c b/kiosk-shell/kiosk-shell-grab.c index 24b0750c2..df3aebb29 100644 --- a/kiosk-shell/kiosk-shell-grab.c +++ b/kiosk-shell/kiosk-shell-grab.c @@ -93,13 +93,12 @@ pointer_move_grab_motion(struct weston_pointer_grab *pointer_grab, static void pointer_move_grab_button(struct weston_pointer_grab *pointer_grab, - const struct timespec *time, - uint32_t button, uint32_t state_w) + const struct weston_pointer_button_event *button_event) { struct kiosk_shell_grab *shgrab = container_of(pointer_grab, struct kiosk_shell_grab, pointer_grab); struct weston_pointer *pointer = pointer_grab->pointer; - enum wl_pointer_button_state state = state_w; + enum wl_pointer_button_state state = button_event->button_state; if (pointer->button_count == 0 && state == WL_POINTER_BUTTON_STATE_RELEASED) diff --git a/libweston/backend-rdp/rdp.c b/libweston/backend-rdp/rdp.c index af85465c0..9a034db6d 100644 --- a/libweston/backend-rdp/rdp.c +++ b/libweston/backend-rdp/rdp.c @@ -1465,10 +1465,17 @@ xf_mouseEvent(rdpInput *input, UINT16 flags, UINT16 x, UINT16 y) } if (button) { + struct weston_pointer_button_event button_event; + weston_compositor_get_time(&time); - notify_button(peerContext->item.seat, &time, button, - (flags & PTR_FLAGS_DOWN) ? WL_POINTER_BUTTON_STATE_PRESSED : WL_POINTER_BUTTON_STATE_RELEASED - ); + + weston_input_event_init(&button_event.base, &time, + peerContext->item.seat); + weston_pointer_button_event_init(&button_event, button, + (flags & PTR_FLAGS_DOWN) ? + WL_POINTER_BUTTON_STATE_PRESSED : + WL_POINTER_BUTTON_STATE_RELEASED); + notify_button(peerContext->item.seat, &button_event); need_frame = true; } @@ -1513,9 +1520,16 @@ xf_extendedMouseEvent(rdpInput *input, UINT16 flags, UINT16 x, UINT16 y) } if (button) { + struct weston_pointer_button_event button_event; weston_compositor_get_time(&time); - notify_button(peerContext->item.seat, &time, button, - (flags & PTR_XFLAGS_DOWN) ? WL_POINTER_BUTTON_STATE_PRESSED : WL_POINTER_BUTTON_STATE_RELEASED); + + weston_input_event_init(&button_event.base, &time, + peerContext->item.seat); + weston_pointer_button_event_init(&button_event, button, + (flags & PTR_XFLAGS_DOWN) ? + WL_POINTER_BUTTON_STATE_PRESSED : + WL_POINTER_BUTTON_STATE_RELEASED); + notify_button(peerContext->item.seat, &button_event); need_frame = true; } diff --git a/libweston/backend-vnc/vnc.c b/libweston/backend-vnc/vnc.c index bbb0a6f7f..0e822bc05 100644 --- a/libweston/backend-vnc/vnc.c +++ b/libweston/backend-vnc/vnc.c @@ -442,6 +442,7 @@ vnc_pointer_event(struct nvnc_client *client, uint16_t x, uint16_t y, struct vnc_output *output = peer->backend->output; struct timespec time; enum nvnc_button_mask changed_button_mask; + struct weston_pointer_button_event button_event; weston_compositor_get_time(&time); @@ -459,23 +460,31 @@ vnc_pointer_event(struct nvnc_client *client, uint16_t x, uint16_t y, changed_button_mask = peer->last_button_mask ^ button_mask; - if (changed_button_mask & NVNC_BUTTON_LEFT) - notify_button(peer->seat, &time, BTN_LEFT, - (button_mask & NVNC_BUTTON_LEFT) ? - WL_POINTER_BUTTON_STATE_PRESSED : - WL_POINTER_BUTTON_STATE_RELEASED); + weston_input_event_init(&button_event.base, &time, peer->seat); + if (changed_button_mask & NVNC_BUTTON_LEFT) { + weston_pointer_button_event_init(&button_event, BTN_LEFT, + (button_mask & NVNC_BUTTON_LEFT) ? + WL_POINTER_BUTTON_STATE_PRESSED : + WL_POINTER_BUTTON_STATE_RELEASED); + notify_button(peer->seat, &button_event); + } - if (changed_button_mask & NVNC_BUTTON_MIDDLE) - notify_button(peer->seat, &time, BTN_MIDDLE, - (button_mask & NVNC_BUTTON_MIDDLE) ? - WL_POINTER_BUTTON_STATE_PRESSED : - WL_POINTER_BUTTON_STATE_RELEASED); + if (changed_button_mask & NVNC_BUTTON_MIDDLE) { + weston_pointer_button_event_init(&button_event, BTN_MIDDLE, + (button_mask & NVNC_BUTTON_MIDDLE) ? + WL_POINTER_BUTTON_STATE_PRESSED : + WL_POINTER_BUTTON_STATE_RELEASED); + notify_button(peer->seat, &button_event); + } + + if (changed_button_mask & NVNC_BUTTON_RIGHT) { + weston_pointer_button_event_init(&button_event, BTN_RIGHT, + (button_mask & NVNC_BUTTON_RIGHT) ? + WL_POINTER_BUTTON_STATE_PRESSED : + WL_POINTER_BUTTON_STATE_RELEASED); + notify_button(peer->seat, &button_event); + } - if (changed_button_mask & NVNC_BUTTON_RIGHT) - notify_button(peer->seat, &time, BTN_RIGHT, - (button_mask & NVNC_BUTTON_RIGHT) ? - WL_POINTER_BUTTON_STATE_PRESSED : - WL_POINTER_BUTTON_STATE_RELEASED); if ((button_mask & NVNC_SCROLL_UP) || (button_mask & NVNC_SCROLL_DOWN)) { diff --git a/libweston/backend-wayland/wayland.c b/libweston/backend-wayland/wayland.c index 22b438913..643114f1c 100644 --- a/libweston/backend-wayland/wayland.c +++ b/libweston/backend-wayland/wayland.c @@ -1738,6 +1738,7 @@ input_handle_button(void *data, struct wl_pointer *pointer, struct wayland_input *input = data; enum theme_location location; struct timespec ts; + struct weston_pointer_button_event button_event; if (!input->output) return; @@ -1781,7 +1782,11 @@ input_handle_button(void *data, struct wl_pointer *pointer, if (location == THEME_LOCATION_CLIENT_AREA) { timespec_from_msec(&ts, time); - notify_button(&input->base, &ts, button, state); + + weston_input_event_init(&button_event.base, &ts, &input->base); + weston_pointer_button_event_init(&button_event, button, state); + notify_button(&input->base, &button_event); + if (input->seat_version < WL_POINTER_FRAME_SINCE_VERSION) notify_pointer_frame(&input->base); } diff --git a/libweston/backend-x11/x11.c b/libweston/backend-x11/x11.c index 3795a1c0f..3833077a9 100644 --- a/libweston/backend-x11/x11.c +++ b/libweston/backend-x11/x11.c @@ -1414,6 +1414,7 @@ x11_backend_deliver_button_event(struct x11_backend *b, uint32_t button; struct x11_output *output; struct weston_pointer_axis_event weston_event; + struct weston_pointer_button_event b_event; bool is_button_pressed = event->response_type == XCB_BUTTON_PRESS; struct timespec time = { 0 }; @@ -1507,10 +1508,13 @@ x11_backend_deliver_button_event(struct x11_backend *b, } weston_compositor_get_time(&time); + weston_input_event_init(&b_event.base, &time, &b->core_seat); + weston_pointer_button_event_init(&b_event, button, + is_button_pressed ? + WL_POINTER_BUTTON_STATE_PRESSED : + WL_POINTER_BUTTON_STATE_RELEASED); - notify_button(&b->core_seat, &time, button, - is_button_pressed ? WL_POINTER_BUTTON_STATE_PRESSED : - WL_POINTER_BUTTON_STATE_RELEASED); + notify_button(&b->core_seat, &b_event); notify_pointer_frame(&b->core_seat); } diff --git a/libweston/backend.h b/libweston/backend.h index a441f183b..f8ac5ff93 100644 --- a/libweston/backend.h +++ b/libweston/backend.h @@ -238,8 +238,7 @@ void notify_axis_source(struct weston_seat *seat, uint32_t source); void -notify_button(struct weston_seat *seat, const struct timespec *time, - int32_t button, enum wl_pointer_button_state state); +notify_button(struct weston_seat *seat, struct weston_pointer_button_event *b_event); void notify_key(struct weston_seat *seat, const struct weston_key_event *key_event); diff --git a/libweston/data-device.c b/libweston/data-device.c index a5eec6cb0..a9730cd77 100644 --- a/libweston/data-device.c +++ b/libweston/data-device.c @@ -652,17 +652,16 @@ data_device_end_pointer_drag_grab(struct weston_pointer_drag *drag) static void drag_grab_button(struct weston_pointer_grab *grab, - const struct timespec *time, - uint32_t button, uint32_t state_w) + const struct weston_pointer_button_event *button_event) { struct weston_pointer_drag *drag = container_of(grab, struct weston_pointer_drag, grab); struct weston_pointer *pointer = drag->grab.pointer; - enum wl_pointer_button_state state = state_w; + enum wl_pointer_button_state state = button_event->button_state; struct weston_data_source *data_source = drag->base.data_source; if (data_source && - pointer->grab_button == button && + pointer->grab_button == button_event->button && state == WL_POINTER_BUTTON_STATE_RELEASED) { if (drag->base.focus_resource && data_source->accepted && diff --git a/libweston/desktop/seat.c b/libweston/desktop/seat.c index b681e12c2..0cdc27e99 100644 --- a/libweston/desktop/seat.c +++ b/libweston/desktop/seat.c @@ -124,23 +124,23 @@ 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, - const struct timespec *time, - uint32_t button, - enum wl_pointer_button_state state) + const struct weston_pointer_button_event *button_event) { struct weston_desktop_seat *seat = wl_container_of(grab, seat, popup_grab.pointer); struct weston_pointer *pointer = grab->pointer; bool initial_up = seat->popup_grab.initial_up; + enum wl_pointer_button_state state = button_event->button_state; + struct timespec time = button_event->base.ts; if (state == WL_POINTER_BUTTON_STATE_RELEASED) seat->popup_grab.initial_up = true; if (weston_pointer_has_focus_resource(pointer)) - weston_pointer_send_button(pointer, time, button, state); + weston_pointer_send_button(pointer, button_event); else if (state == WL_POINTER_BUTTON_STATE_RELEASED && (initial_up || - (timespec_sub_to_msec(time, &grab->pointer->grab_time) > 500))) + (timespec_sub_to_msec(&time, &grab->pointer->grab_time) > 500))) weston_desktop_seat_popup_grab_end(seat); } diff --git a/libweston/input.c b/libweston/input.c index 0371df001..24737c824 100644 --- a/libweston/input.c +++ b/libweston/input.c @@ -673,9 +673,7 @@ weston_pointer_has_focus_resource(struct weston_pointer *pointer) /** Send wl_pointer.button events to focused resources. * * \param pointer The pointer where the button events originates from. - * \param time The timestamp of the event - * \param button The button value of the event - * \param state The state enum value of the event + * \param button_event A pointer to weston_pointer_button_event * * For every resource that is currently in focus, send a wl_pointer.button event * with the passed parameters. The focused resources are the wl_pointer @@ -683,39 +681,41 @@ weston_pointer_has_focus_resource(struct weston_pointer *pointer) */ WL_EXPORT void weston_pointer_send_button(struct weston_pointer *pointer, - const struct timespec *time, uint32_t button, - enum wl_pointer_button_state state) + const struct weston_pointer_button_event *button_event) { struct wl_display *display = pointer->seat->compositor->wl_display; struct wl_list *resource_list; struct wl_resource *resource; uint32_t serial; uint32_t msecs; + struct timespec time = button_event->base.ts; + uint32_t button = button_event->button; + enum wl_pointer_button_state state = button_event->button_state; 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); + msecs = timespec_to_msec(&time); wl_resource_for_each(resource, resource_list) { send_timestamps_for_input_resource(resource, &pointer->timestamps_list, - time); + &time); wl_pointer_send_button(resource, serial, msecs, button, state); } } static void default_grab_pointer_button(struct weston_pointer_grab *grab, - const struct timespec *time, uint32_t button, - enum wl_pointer_button_state state) + const struct weston_pointer_button_event *button_event) { struct weston_pointer *pointer = grab->pointer; struct weston_compositor *compositor = pointer->seat->compositor; struct weston_view *view; + enum wl_pointer_button_state state = button_event->button_state; - weston_pointer_send_button(pointer, time, button, state); + weston_pointer_send_button(pointer, button_event); if (pointer->button_count == 0 && state == WL_POINTER_BUTTON_STATE_RELEASED) { @@ -2325,17 +2325,16 @@ weston_view_activate_input(struct weston_view *view, } WL_EXPORT void -notify_button(struct weston_seat *seat, const struct timespec *time, - int32_t button, enum wl_pointer_button_state state) +notify_button(struct weston_seat *seat, struct weston_pointer_button_event *event) { struct weston_compositor *compositor = seat->compositor; struct weston_pointer *pointer = weston_seat_get_pointer(seat); - if (state == WL_POINTER_BUTTON_STATE_PRESSED) { + if (event->button_state == WL_POINTER_BUTTON_STATE_PRESSED) { weston_compositor_idle_inhibit(compositor); if (pointer->button_count == 0) { - pointer->grab_button = button; - pointer->grab_time = *time; + pointer->grab_button = event->button; + pointer->grab_time = event->base.ts; pointer->grab_pos = pointer->pos; } pointer->button_count++; @@ -2344,10 +2343,10 @@ notify_button(struct weston_seat *seat, const struct timespec *time, pointer->button_count--; } - weston_compositor_run_button_binding(compositor, pointer, time, button, - state); + weston_compositor_run_button_binding(compositor, pointer, &event->base.ts, + event->button, event->button_state); - pointer->grab->interface->button(pointer->grab, time, button, state); + pointer->grab->interface->button(pointer->grab, event); if (pointer->button_count == 1) pointer->grab_serial = @@ -4719,11 +4718,9 @@ locked_pointer_grab_pointer_motion(struct weston_pointer_grab *grab, static void locked_pointer_grab_pointer_button(struct weston_pointer_grab *grab, - const struct timespec *time, - uint32_t button, - uint32_t state_w) + const struct weston_pointer_button_event *button_event) { - weston_pointer_send_button(grab->pointer, time, button, state_w); + weston_pointer_send_button(grab->pointer, button_event); } static void @@ -5721,11 +5718,9 @@ confined_pointer_grab_pointer_motion(struct weston_pointer_grab *grab, static void confined_pointer_grab_pointer_button(struct weston_pointer_grab *grab, - const struct timespec *time, - uint32_t button, - uint32_t state_w) + const struct weston_pointer_button_event *button_event) { - weston_pointer_send_button(grab->pointer, time, button, state_w); + weston_pointer_send_button(grab->pointer, button_event); } static void @@ -6043,3 +6038,11 @@ weston_pointer_motion_event_init(struct weston_pointer_motion_event *event, event->rel = rel; event->rel_unaccel = rel_unaccel; } + +WL_EXPORT void +weston_pointer_button_event_init(struct weston_pointer_button_event *event, + uint32_t button, enum wl_pointer_button_state button_state) +{ + event->button = button; + event->button_state = button_state; +} diff --git a/libweston/libinput-device.c b/libweston/libinput-device.c index f0666ef2e..561dbe0cc 100644 --- a/libweston/libinput-device.c +++ b/libweston/libinput-device.c @@ -194,6 +194,7 @@ handle_pointer_button(struct libinput_device *libinput_device, int seat_button_count = libinput_event_pointer_get_seat_button_count(pointer_event); struct timespec time; + struct weston_pointer_button_event button_event; ensure_pointer_capability(libinput_device); @@ -207,9 +208,11 @@ handle_pointer_button(struct libinput_device *libinput_device, 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); + weston_input_event_init(&button_event.base, &time, device->seat); + weston_pointer_button_event_init(&button_event, + libinput_event_pointer_get_button(pointer_event), + button_state); + notify_button(device->seat, &button_event); return true; } diff --git a/tests/harness/weston-test.c b/tests/harness/weston-test.c index 247097510..44fa73646 100644 --- a/tests/harness/weston-test.c +++ b/tests/harness/weston-test.c @@ -434,14 +434,17 @@ send_button(struct wl_client *client, struct wl_resource *resource, uint32_t tv_sec_hi, uint32_t tv_sec_lo, uint32_t tv_nsec, int32_t button, uint32_t state) { - struct timespec time; + struct weston_pointer_button_event button_event; struct weston_test *test = wl_resource_get_user_data(resource); struct weston_seat *seat = get_seat(test); + struct timespec time; timespec_from_proto(&time, tv_sec_hi, tv_sec_lo, tv_nsec); + weston_input_event_init(&button_event.base, &time, seat); + weston_pointer_button_event_init(&button_event, button, state); - notify_button(seat, &time, button, state); + notify_button(seat, &button_event); } static void From 2aa32c214c8e1c68d9ba8b83bb9ef6a627e886d0 Mon Sep 17 00:00:00 2001 From: Marius Vlad Date: Fri, 17 Apr 2026 17:36:13 +0300 Subject: [PATCH 5/6] input: Re-work weston_pointer_axis_event Move to a const struct weston_pointer_axis_event, add the base_event struct that contains the timespec and use the initialization functions. Signed-off-by: Marius Vlad --- desktop-shell/shell.c | 5 ++- include/libweston/libweston.h | 14 +++++--- ivi-shell/hmi-controller.c | 5 ++- kiosk-shell/kiosk-shell-grab.c | 3 +- libweston/backend-rdp/rdp.c | 16 ++++----- libweston/backend-vnc/vnc.c | 14 ++++---- libweston/backend-wayland/wayland.c | 26 +++++++-------- libweston/backend-x11/x11.c | 52 ++++++++++++++++------------- libweston/backend.h | 3 +- libweston/bindings.c | 2 +- libweston/data-device.c | 3 +- libweston/desktop/seat.c | 5 ++- libweston/input.c | 45 ++++++++++++++----------- libweston/libinput-device.c | 20 +++++------ libweston/libweston-internal.h | 2 +- tests/harness/weston-test.c | 9 +++-- 16 files changed, 113 insertions(+), 111 deletions(-) diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c index bb6011fab..8b6499656 100644 --- a/desktop-shell/shell.c +++ b/desktop-shell/shell.c @@ -854,8 +854,7 @@ noop_grab_focus(struct weston_pointer_grab *grab) static void noop_grab_axis(struct weston_pointer_grab *grab, - const struct timespec *time, - struct weston_pointer_axis_event *event) + const struct weston_pointer_axis_event *event) { } @@ -3182,7 +3181,7 @@ resize_binding(struct weston_pointer *pointer, const struct timespec *time, static void surface_opacity_binding(struct weston_pointer *pointer, const struct timespec *time, - struct weston_pointer_axis_event *event, + const struct weston_pointer_axis_event *event, void *data) { float step = 0.005; diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h index 160cd7a94..037d159f8 100644 --- a/include/libweston/libweston.h +++ b/include/libweston/libweston.h @@ -626,6 +626,7 @@ struct weston_pointer_button_event { }; struct weston_pointer_axis_event { + struct weston_input_event base; uint32_t axis; double value; bool has_discrete; @@ -648,8 +649,7 @@ struct weston_pointer_grab_interface { void (*button)(struct weston_pointer_grab *grab, const struct weston_pointer_button_event *button_event); void (*axis)(struct weston_pointer_grab *grab, - const struct timespec *time, - struct weston_pointer_axis_event *event); + const struct weston_pointer_axis_event *event); void (*axis_source)(struct weston_pointer_grab *grab, uint32_t source); void (*frame)(struct weston_pointer_grab *grab); void (*cancel)(struct weston_pointer_grab *grab); @@ -983,8 +983,7 @@ weston_pointer_send_button(struct weston_pointer *pointer, const struct weston_pointer_button_event *button_event); void weston_pointer_send_axis(struct weston_pointer *pointer, - const struct timespec *time, - struct weston_pointer_axis_event *event); + const struct weston_pointer_axis_event *event); void weston_pointer_send_axis_source(struct weston_pointer *pointer, enum wl_pointer_axis_source source); @@ -1044,6 +1043,11 @@ void weston_pointer_button_event_init(struct weston_pointer_button_event *event, uint32_t button, enum wl_pointer_button_state button_state); +void +weston_pointer_axis_event_init(struct weston_pointer_axis_event *event, + uint32_t axis, double value, bool has_value, + int32_t discrete); + void weston_keyboard_send_modifiers(struct weston_keyboard *keyboard, uint32_t serial, uint32_t mods_depressed, @@ -2328,7 +2332,7 @@ weston_compositor_add_tablet_tool_binding(struct weston_compositor *compositor, typedef void (*weston_axis_binding_handler_t)(struct weston_pointer *pointer, const struct timespec *time, - struct weston_pointer_axis_event *event, + const struct weston_pointer_axis_event *event, void *data); struct weston_binding * weston_compositor_add_axis_binding(struct weston_compositor *compositor, diff --git a/ivi-shell/hmi-controller.c b/ivi-shell/hmi-controller.c index 9d585812d..7939c603b 100644 --- a/ivi-shell/hmi-controller.c +++ b/ivi-shell/hmi-controller.c @@ -1639,10 +1639,9 @@ pointer_noop_grab_focus(struct weston_pointer_grab *grab) static void pointer_default_grab_axis(struct weston_pointer_grab *grab, - const struct timespec *time, - struct weston_pointer_axis_event *event) + const struct weston_pointer_axis_event *event) { - weston_pointer_send_axis(grab->pointer, time, event); + weston_pointer_send_axis(grab->pointer, event); } static void diff --git a/kiosk-shell/kiosk-shell-grab.c b/kiosk-shell/kiosk-shell-grab.c index df3aebb29..2508f8ee8 100644 --- a/kiosk-shell/kiosk-shell-grab.c +++ b/kiosk-shell/kiosk-shell-grab.c @@ -50,8 +50,7 @@ pointer_move_grab_focus(struct weston_pointer_grab *grab) static void pointer_move_grab_axis(struct weston_pointer_grab *grab, - const struct timespec *time, - struct weston_pointer_axis_event *event) + const struct weston_pointer_axis_event *event) { } diff --git a/libweston/backend-rdp/rdp.c b/libweston/backend-rdp/rdp.c index 9a034db6d..8ea9b7bf0 100644 --- a/libweston/backend-rdp/rdp.c +++ b/libweston/backend-rdp/rdp.c @@ -1363,7 +1363,6 @@ rdp_notify_wheel_scroll(RdpPeerContext *peerContext, UINT16 flags, uint32_t axis struct weston_pointer_axis_event weston_event; struct rdp_backend *b = peerContext->rdpBackend; int ivalue; - double value; struct timespec time; int *accumWheelRotationPrecise; int *accumWheelRotationDiscrete; @@ -1407,19 +1406,18 @@ rdp_notify_wheel_scroll(RdpPeerContext *peerContext, UINT16 flags, uint32_t axis ivalue, *accumWheelRotationPrecise, *accumWheelRotationDiscrete); if (abs(*accumWheelRotationPrecise) >= 12) { - value = (double)(*accumWheelRotationPrecise / 12); + weston_compositor_get_time(&time); - weston_event.axis = axis; - weston_event.value = value; - weston_event.discrete = *accumWheelRotationDiscrete / 120; - weston_event.has_discrete = true; + weston_input_event_init(&weston_event.base, + &time, peerContext->item.seat); + weston_pointer_axis_event_init(&weston_event, axis, + (double) *accumWheelRotationPrecise / 12, + true, *accumWheelRotationDiscrete / 120); rdp_debug_verbose(b, "wheel: value:%f discrete:%d\n", weston_event.value, weston_event.discrete); - weston_compositor_get_time(&time); - - notify_axis(peerContext->item.seat, &time, &weston_event); + notify_axis(peerContext->item.seat, &weston_event); *accumWheelRotationPrecise %= 12; *accumWheelRotationDiscrete %= 120; diff --git a/libweston/backend-vnc/vnc.c b/libweston/backend-vnc/vnc.c index 0e822bc05..a3c72a28f 100644 --- a/libweston/backend-vnc/vnc.c +++ b/libweston/backend-vnc/vnc.c @@ -489,17 +489,19 @@ vnc_pointer_event(struct nvnc_client *client, uint16_t x, uint16_t y, if ((button_mask & NVNC_SCROLL_UP) || (button_mask & NVNC_SCROLL_DOWN)) { struct weston_pointer_axis_event weston_event; - - weston_event.axis = WL_POINTER_AXIS_VERTICAL_SCROLL; + double value = 0; /* DEFAULT_AXIS_STEP_DISTANCE is stolen from compositor-x11.c */ if (button_mask & NVNC_SCROLL_UP) - weston_event.value = -DEFAULT_AXIS_STEP_DISTANCE; + value = -DEFAULT_AXIS_STEP_DISTANCE; if (button_mask & NVNC_SCROLL_DOWN) - weston_event.value = DEFAULT_AXIS_STEP_DISTANCE; - weston_event.has_discrete = false; + value = DEFAULT_AXIS_STEP_DISTANCE; - notify_axis(peer->seat, &time, &weston_event); + weston_input_event_init(&weston_event.base, + &time, peer->seat); + weston_pointer_axis_event_init(&weston_event, WL_POINTER_AXIS_VERTICAL_SCROLL, + value, false, 0); + notify_axis(peer->seat, &weston_event); } peer->last_button_mask = button_mask; diff --git a/libweston/backend-wayland/wayland.c b/libweston/backend-wayland/wayland.c index 643114f1c..4824bf887 100644 --- a/libweston/backend-wayland/wayland.c +++ b/libweston/backend-wayland/wayland.c @@ -1799,26 +1799,27 @@ input_handle_axis(void *data, struct wl_pointer *pointer, struct wayland_input *input = data; struct weston_pointer_axis_event weston_event; struct timespec ts; - - weston_event.axis = axis; - weston_event.value = wl_fixed_to_double(value); - weston_event.has_discrete = false; + bool has_discrete = false; + int32_t discrete = 0; if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL && input->vert.has_discrete) { - weston_event.has_discrete = true; - weston_event.discrete = input->vert.discrete; + has_discrete = true; + discrete = input->vert.discrete; input->vert.has_discrete = false; } else if (axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL && input->horiz.has_discrete) { - weston_event.has_discrete = true; - weston_event.discrete = input->horiz.discrete; + has_discrete = true; + discrete = input->horiz.discrete; input->horiz.has_discrete = false; } timespec_from_msec(&ts, time); - notify_axis(&input->base, &ts, &weston_event); + weston_input_event_init(&weston_event.base, &ts, &input->base); + weston_pointer_axis_event_init(&weston_event, axis, wl_fixed_to_double(value), + has_discrete, discrete); + notify_axis(&input->base, &weston_event); if (input->seat_version < WL_POINTER_FRAME_SINCE_VERSION) notify_pointer_frame(&input->base); @@ -1849,12 +1850,11 @@ input_handle_axis_stop(void *data, struct wl_pointer *pointer, struct weston_pointer_axis_event weston_event; struct timespec ts; - weston_event.axis = axis; - weston_event.value = 0; - timespec_from_msec(&ts, time); - notify_axis(&input->base, &ts, &weston_event); + weston_input_event_init(&weston_event.base, &ts, &input->base); + weston_pointer_axis_event_init(&weston_event, axis, 0, false, 0); + notify_axis(&input->base, &weston_event); } static void diff --git a/libweston/backend-x11/x11.c b/libweston/backend-x11/x11.c index 3833077a9..28594773e 100644 --- a/libweston/backend-x11/x11.c +++ b/libweston/backend-x11/x11.c @@ -1456,49 +1456,53 @@ x11_backend_deliver_button_event(struct x11_backend *b, /* Axis are measured in pixels, but the xcb events are discrete * steps. Therefore move the axis by some pixels every step. */ if (is_button_pressed) { - weston_event.value = -DEFAULT_AXIS_STEP_DISTANCE; - weston_event.discrete = -1; - weston_event.has_discrete = true; - weston_event.axis = - WL_POINTER_AXIS_VERTICAL_SCROLL; weston_compositor_get_time(&time); - notify_axis(&b->core_seat, &time, &weston_event); + + weston_input_event_init(&weston_event.base, + &time, &b->core_seat); + weston_pointer_axis_event_init(&weston_event, + WL_POINTER_AXIS_VERTICAL_SCROLL, + -DEFAULT_AXIS_STEP_DISTANCE, true, -1); + notify_axis(&b->core_seat, &weston_event); notify_pointer_frame(&b->core_seat); } return; case 5: if (is_button_pressed) { - weston_event.value = DEFAULT_AXIS_STEP_DISTANCE; - weston_event.discrete = 1; - weston_event.has_discrete = true; - weston_event.axis = - WL_POINTER_AXIS_VERTICAL_SCROLL; weston_compositor_get_time(&time); - notify_axis(&b->core_seat, &time, &weston_event); + + weston_input_event_init(&weston_event.base, + &time, &b->core_seat); + weston_pointer_axis_event_init(&weston_event, + WL_POINTER_AXIS_VERTICAL_SCROLL, + DEFAULT_AXIS_STEP_DISTANCE, true, 1); + notify_axis(&b->core_seat, &weston_event); notify_pointer_frame(&b->core_seat); } return; case 6: if (is_button_pressed) { - weston_event.value = -DEFAULT_AXIS_STEP_DISTANCE; - weston_event.discrete = -1; - weston_event.has_discrete = true; - weston_event.axis = - WL_POINTER_AXIS_HORIZONTAL_SCROLL; weston_compositor_get_time(&time); - notify_axis(&b->core_seat, &time, &weston_event); + + weston_input_event_init(&weston_event.base, + &time, &b->core_seat); + weston_pointer_axis_event_init(&weston_event, + WL_POINTER_AXIS_HORIZONTAL_SCROLL, + -DEFAULT_AXIS_STEP_DISTANCE, true, -1); + notify_axis(&b->core_seat, &weston_event); notify_pointer_frame(&b->core_seat); } return; case 7: if (is_button_pressed) { - weston_event.value = DEFAULT_AXIS_STEP_DISTANCE; - weston_event.discrete = 1; - weston_event.has_discrete = true; - weston_event.axis = - WL_POINTER_AXIS_HORIZONTAL_SCROLL; weston_compositor_get_time(&time); - notify_axis(&b->core_seat, &time, &weston_event); + + weston_input_event_init(&weston_event.base, + &time, &b->core_seat); + weston_pointer_axis_event_init(&weston_event, + WL_POINTER_AXIS_HORIZONTAL_SCROLL, + DEFAULT_AXIS_STEP_DISTANCE, true, 1); + notify_axis(&b->core_seat, &weston_event); notify_pointer_frame(&b->core_seat); } return; diff --git a/libweston/backend.h b/libweston/backend.h index f8ac5ff93..2b87e4375 100644 --- a/libweston/backend.h +++ b/libweston/backend.h @@ -232,8 +232,7 @@ weston_output_finish_frame_from_timer(struct weston_output *output); /* weston_seat */ void -notify_axis(struct weston_seat *seat, const struct timespec *time, - struct weston_pointer_axis_event *event); +notify_axis(struct weston_seat *seat, const struct weston_pointer_axis_event *event); void notify_axis_source(struct weston_seat *seat, uint32_t source); diff --git a/libweston/bindings.c b/libweston/bindings.c index 7b8df7527..c5c51be55 100644 --- a/libweston/bindings.c +++ b/libweston/bindings.c @@ -442,7 +442,7 @@ int weston_compositor_run_axis_binding(struct weston_compositor *compositor, struct weston_pointer *pointer, const struct timespec *time, - struct weston_pointer_axis_event *event) + const struct weston_pointer_axis_event *event) { struct weston_binding *b, *tmp; diff --git a/libweston/data-device.c b/libweston/data-device.c index a9730cd77..2051fb254 100644 --- a/libweston/data-device.c +++ b/libweston/data-device.c @@ -693,8 +693,7 @@ drag_grab_button(struct weston_pointer_grab *grab, static void drag_grab_axis(struct weston_pointer_grab *grab, - const struct timespec *time, - struct weston_pointer_axis_event *event) + const struct weston_pointer_axis_event *event) { } diff --git a/libweston/desktop/seat.c b/libweston/desktop/seat.c index 0cdc27e99..2fe9e3b34 100644 --- a/libweston/desktop/seat.c +++ b/libweston/desktop/seat.c @@ -146,10 +146,9 @@ weston_desktop_seat_popup_grab_pointer_button(struct weston_pointer_grab *grab, static void weston_desktop_seat_popup_grab_pointer_axis(struct weston_pointer_grab *grab, - const struct timespec *time, - struct weston_pointer_axis_event *event) + const struct weston_pointer_axis_event *event) { - weston_pointer_send_axis(grab->pointer, time, event); + weston_pointer_send_axis(grab->pointer, event); } static void diff --git a/libweston/input.c b/libweston/input.c index 24737c824..b45964f59 100644 --- a/libweston/input.c +++ b/libweston/input.c @@ -729,7 +729,6 @@ default_grab_pointer_button(struct weston_pointer_grab *grab, /** Send wl_pointer.axis events to focused resources. * * \param pointer The pointer where the axis events originates from. - * \param time The timestamp of the event * \param event The axis value of the event * * For every resource that is currently in focus, send a wl_pointer.axis event @@ -738,8 +737,7 @@ default_grab_pointer_button(struct weston_pointer_grab *grab, */ WL_EXPORT void weston_pointer_send_axis(struct weston_pointer *pointer, - const struct timespec *time, - struct weston_pointer_axis_event *event) + const struct weston_pointer_axis_event *event) { struct wl_resource *resource; struct wl_list *resource_list; @@ -749,7 +747,7 @@ weston_pointer_send_axis(struct weston_pointer *pointer, return; resource_list = &pointer->focus_client->pointer_resources; - msecs = timespec_to_msec(time); + msecs = timespec_to_msec(&event->base.ts); wl_resource_for_each(resource, resource_list) { if (event->has_discrete && wl_resource_get_version(resource) >= @@ -760,7 +758,7 @@ weston_pointer_send_axis(struct weston_pointer *pointer, if (event->value) { send_timestamps_for_input_resource(resource, &pointer->timestamps_list, - time); + &event->base.ts); wl_pointer_send_axis(resource, msecs, event->axis, wl_fixed_from_double(event->value)); @@ -768,7 +766,7 @@ weston_pointer_send_axis(struct weston_pointer *pointer, WL_POINTER_AXIS_STOP_SINCE_VERSION) { send_timestamps_for_input_resource(resource, &pointer->timestamps_list, - time); + &event->base.ts); wl_pointer_send_axis_stop(resource, msecs, event->axis); } @@ -836,10 +834,9 @@ weston_pointer_send_frame(struct weston_pointer *pointer) static void default_grab_pointer_axis(struct weston_pointer_grab *grab, - const struct timespec *time, - struct weston_pointer_axis_event *event) + const struct weston_pointer_axis_event *event) { - weston_pointer_send_axis(grab->pointer, time, event); + weston_pointer_send_axis(grab->pointer, event); } static void @@ -2354,19 +2351,17 @@ notify_button(struct weston_seat *seat, struct weston_pointer_button_event *even } WL_EXPORT void -notify_axis(struct weston_seat *seat, const struct timespec *time, - struct weston_pointer_axis_event *event) +notify_axis(struct weston_seat *seat, const struct weston_pointer_axis_event *event) { struct weston_compositor *compositor = seat->compositor; struct weston_pointer *pointer = weston_seat_get_pointer(seat); weston_compositor_wake(compositor); - if (weston_compositor_run_axis_binding(compositor, pointer, - time, event)) + if (weston_compositor_run_axis_binding(compositor, pointer, &event->base.ts, event)) return; - pointer->grab->interface->axis(pointer->grab, time, event); + pointer->grab->interface->axis(pointer->grab, event); } WL_EXPORT void @@ -4725,10 +4720,9 @@ locked_pointer_grab_pointer_button(struct weston_pointer_grab *grab, static void locked_pointer_grab_pointer_axis(struct weston_pointer_grab *grab, - const struct timespec *time, - struct weston_pointer_axis_event *event) + const struct weston_pointer_axis_event *event) { - weston_pointer_send_axis(grab->pointer, time, event); + weston_pointer_send_axis(grab->pointer, event); } static void @@ -5725,10 +5719,9 @@ confined_pointer_grab_pointer_button(struct weston_pointer_grab *grab, static void confined_pointer_grab_pointer_axis(struct weston_pointer_grab *grab, - const struct timespec *time, - struct weston_pointer_axis_event *event) + const struct weston_pointer_axis_event *event) { - weston_pointer_send_axis(grab->pointer, time, event); + weston_pointer_send_axis(grab->pointer, event); } static void @@ -6046,3 +6039,15 @@ weston_pointer_button_event_init(struct weston_pointer_button_event *event, event->button = button; event->button_state = button_state; } + +WL_EXPORT void +weston_pointer_axis_event_init(struct weston_pointer_axis_event *event, + uint32_t axis, double value, bool has_discrete, + int32_t discrete) +{ + + event->axis = axis; + event->value = value; + event->has_discrete = has_discrete; + event->discrete = discrete; +} diff --git a/libweston/libinput-device.c b/libweston/libinput-device.c index 561dbe0cc..e5b0923a9 100644 --- a/libweston/libinput-device.c +++ b/libweston/libinput-device.c @@ -315,12 +315,10 @@ handle_pointer_axis(struct libinput_device *libinput_device, vert_discrete = get_axis_discrete(pointer_event, axis); vert = normalize_scroll(pointer_event, axis); - weston_event.axis = WL_POINTER_AXIS_VERTICAL_SCROLL; - weston_event.value = vert; - weston_event.discrete = vert_discrete; - weston_event.has_discrete = (vert_discrete != 0); - - notify_axis(device->seat, &time, &weston_event); + weston_input_event_init(&weston_event.base, &time, device->seat); + weston_pointer_axis_event_init(&weston_event, WL_POINTER_AXIS_VERTICAL_SCROLL, + vert, (vert_discrete != 0), vert_discrete); + notify_axis(device->seat, &weston_event); } if (has_horiz) { @@ -328,12 +326,10 @@ handle_pointer_axis(struct libinput_device *libinput_device, horiz_discrete = get_axis_discrete(pointer_event, axis); horiz = normalize_scroll(pointer_event, axis); - weston_event.axis = WL_POINTER_AXIS_HORIZONTAL_SCROLL; - weston_event.value = horiz; - weston_event.discrete = horiz_discrete; - weston_event.has_discrete = (horiz_discrete != 0); - - notify_axis(device->seat, &time, &weston_event); + weston_input_event_init(&weston_event.base, &time, device->seat); + weston_pointer_axis_event_init(&weston_event, WL_POINTER_AXIS_HORIZONTAL_SCROLL, + horiz, (horiz_discrete != 0), horiz_discrete); + notify_axis(device->seat, &weston_event); } return true; diff --git a/libweston/libweston-internal.h b/libweston/libweston-internal.h index 79212d0ce..ea15ee536 100644 --- a/libweston/libweston-internal.h +++ b/libweston/libweston-internal.h @@ -341,7 +341,7 @@ int weston_compositor_run_axis_binding(struct weston_compositor *compositor, struct weston_pointer *pointer, const struct timespec *time, - struct weston_pointer_axis_event *event); + const struct weston_pointer_axis_event *event); void weston_compositor_run_button_binding(struct weston_compositor *compositor, struct weston_pointer *pointer, diff --git a/tests/harness/weston-test.c b/tests/harness/weston-test.c index 44fa73646..7499f80d3 100644 --- a/tests/harness/weston-test.c +++ b/tests/harness/weston-test.c @@ -458,12 +458,11 @@ send_axis(struct wl_client *client, struct wl_resource *resource, struct weston_pointer_axis_event axis_event; timespec_from_proto(&time, tv_sec_hi, tv_sec_lo, tv_nsec); - axis_event.axis = axis; - axis_event.value = wl_fixed_to_double(value); - axis_event.has_discrete = false; - axis_event.discrete = 0; - notify_axis(seat, &time, &axis_event); + weston_input_event_init(&axis_event.base, &time, seat); + weston_pointer_axis_event_init(&axis_event, axis, + wl_fixed_to_double(value), false, 0); + notify_axis(seat, &axis_event); } static void From 192ba4cc961a7fa0446c858eae361cb722d58cd0 Mon Sep 17 00:00:00 2001 From: Marius Vlad Date: Thu, 2 Apr 2026 21:59:57 +0300 Subject: [PATCH 6/6] input: Introduce weston_touch_event Similar to "input: Introduce weston_key_event struct" this struct is for touch events. With this we add the initialization helpers, pass the weston_touch_event as a const and remove the timespec argument. Signed-off-by: Marius Vlad --- desktop-shell/shell.c | 12 +-- include/libweston/libweston.h | 32 ++++---- ivi-shell/hmi-controller.c | 14 +--- kiosk-shell/kiosk-shell-grab.c | 10 +-- libweston/backend-wayland/wayland.c | 27 ++++-- libweston/backend.h | 18 ++-- libweston/data-device.c | 16 ++-- libweston/desktop/seat.c | 17 ++-- libweston/input.c | 123 +++++++++++++--------------- libweston/libinput-device.c | 25 ++++-- libweston/touch-calibration.c | 23 +++--- tests/harness/weston-test.c | 11 ++- 12 files changed, 161 insertions(+), 167 deletions(-) diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c index 8b6499656..8d93b18aa 100644 --- a/desktop-shell/shell.c +++ b/desktop-shell/shell.c @@ -758,20 +758,18 @@ surface_keyboard_focus_lost(struct weston_surface *surface) static void touch_move_grab_down(struct weston_touch_grab *grab, - const struct timespec *time, - int touch_id, struct weston_coord_global c) + const struct weston_touch_event *event) { } static void -touch_move_grab_up(struct weston_touch_grab *grab, const struct timespec *time, - int touch_id) +touch_move_grab_up(struct weston_touch_grab *grab, const struct weston_touch_event *event) { struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) container_of( grab, struct shell_touch_grab, grab); - if (touch_id == 0) + if (event->touch_id == 0) move->active = 0; if (grab->touch->num_tp == 0) { @@ -781,9 +779,7 @@ touch_move_grab_up(struct weston_touch_grab *grab, const struct timespec *time, } static void -touch_move_grab_motion(struct weston_touch_grab *grab, - const struct timespec *time, int touch_id, - struct weston_coord_global unused) +touch_move_grab_motion(struct weston_touch_grab *grab, const struct weston_touch_event *event) { struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; struct shell_surface *shsurf = move->base.shsurf; diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h index 037d159f8..e48c0c4ea 100644 --- a/include/libweston/libweston.h +++ b/include/libweston/libweston.h @@ -640,6 +640,13 @@ struct weston_key_event { enum weston_key_state_update key_update_state; }; +struct weston_touch_event { + struct weston_input_event base; + int32_t touch_type; + int32_t touch_id; + const struct weston_coord_global *pos; +}; + struct weston_pointer_grab; struct weston_pointer_grab_interface { @@ -678,16 +685,11 @@ struct weston_keyboard_grab { struct weston_touch_grab; struct weston_touch_grab_interface { void (*down)(struct weston_touch_grab *grab, - const struct timespec *time, - int touch_id, - struct weston_coord_global c); + const struct weston_touch_event *event); void (*up)(struct weston_touch_grab *grab, - const struct timespec *time, - int touch_id); + const struct weston_touch_event *event); void (*motion)(struct weston_touch_grab *grab, - const struct timespec *time, - int touch_id, - struct weston_coord_global c); + const struct weston_touch_event *event); void (*frame)(struct weston_touch_grab *grab); void (*cancel)(struct weston_touch_grab *grab); }; @@ -1048,6 +1050,10 @@ weston_pointer_axis_event_init(struct weston_pointer_axis_event *event, uint32_t axis, double value, bool has_value, int32_t discrete); +void +weston_touch_event_init(struct weston_touch_event *event, int32_t touch_type, + int32_t touch_id, const struct weston_coord_global *pos); + void weston_keyboard_send_modifiers(struct weston_keyboard *keyboard, uint32_t serial, uint32_t mods_depressed, @@ -1064,15 +1070,11 @@ void weston_touch_end_grab(struct weston_touch *touch); void -weston_touch_send_down(struct weston_touch *touch, const struct timespec *time, - int touch_id, struct weston_coord_global pos); +weston_touch_send_down(struct weston_touch *touch, const struct weston_touch_event *event); void -weston_touch_send_up(struct weston_touch *touch, const struct timespec *time, - int touch_id); +weston_touch_send_up(struct weston_touch *touch, const struct weston_touch_event *event); void -weston_touch_send_motion(struct weston_touch *touch, - const struct timespec *time, int touch_id, - struct weston_coord_global pos); +weston_touch_send_motion(struct weston_touch *touch, const struct weston_touch_event *event); void weston_touch_send_frame(struct weston_touch *touch); diff --git a/ivi-shell/hmi-controller.c b/ivi-shell/hmi-controller.c index 7939c603b..7b4affbe5 100644 --- a/ivi-shell/hmi-controller.c +++ b/ivi-shell/hmi-controller.c @@ -1731,9 +1731,7 @@ pointer_move_grab_motion(struct weston_pointer_grab *grab, } static void -touch_move_grab_motion(struct weston_touch_grab *grab, - const struct timespec *time, int touch_id, - struct weston_coord_global c) +touch_move_grab_motion(struct weston_touch_grab *grab, const struct weston_touch_event *event) { struct touch_move_grab *tch_move_grab = (struct touch_move_grab *)grab; struct hmi_controller *hmi_ctrl = @@ -1766,20 +1764,16 @@ pointer_move_workspace_grab_button(struct weston_pointer_grab *grab, } static void -touch_nope_grab_down(struct weston_touch_grab *grab, - const struct timespec *time, - int touch_id, struct weston_coord_global c) +touch_nope_grab_down(struct weston_touch_grab *grab, const struct weston_touch_event *event) { } static void -touch_move_workspace_grab_up(struct weston_touch_grab *grab, - const struct timespec *time, - int touch_id) +touch_move_workspace_grab_up(struct weston_touch_grab *grab, const struct weston_touch_event *event) { struct touch_move_grab *tch_move_grab = (struct touch_move_grab *)grab; - if (0 == touch_id) + if (0 == event->touch_id) tch_move_grab->is_active = 0; if (0 == grab->touch->num_tp) { diff --git a/kiosk-shell/kiosk-shell-grab.c b/kiosk-shell/kiosk-shell-grab.c index 2508f8ee8..c609dd8bf 100644 --- a/kiosk-shell/kiosk-shell-grab.c +++ b/kiosk-shell/kiosk-shell-grab.c @@ -129,19 +129,18 @@ static const struct weston_pointer_grab_interface pointer_move_grab_interface = static void touch_move_grab_down(struct weston_touch_grab *grab, - const struct timespec *time, - int touch_id, struct weston_coord_global c) + const struct weston_touch_event *event) { } static void touch_move_grab_up(struct weston_touch_grab *touch_grab, - const struct timespec *time, int touch_id) + const struct weston_touch_event *event) { struct kiosk_shell_grab *shgrab = container_of(touch_grab, struct kiosk_shell_grab, touch_grab); - if (touch_id == 0) + if (event->touch_id == 0) shgrab->active = false; if (touch_grab->touch->num_tp == 0) @@ -150,8 +149,7 @@ touch_move_grab_up(struct weston_touch_grab *touch_grab, static void touch_move_grab_motion(struct weston_touch_grab *touch_grab, - const struct timespec *time, int touch_id, - struct weston_coord_global unused) + const struct weston_touch_event *event) { struct kiosk_shell_grab *shgrab = container_of(touch_grab, struct kiosk_shell_grab, touch_grab); diff --git a/libweston/backend-wayland/wayland.c b/libweston/backend-wayland/wayland.c index 4824bf887..2693b0ff6 100644 --- a/libweston/backend-wayland/wayland.c +++ b/libweston/backend-wayland/wayland.c @@ -1679,6 +1679,7 @@ input_handle_motion(void *data, struct wl_pointer *pointer, struct weston_coord_global pos; struct weston_pointer_motion_event event; struct timespec ts; + struct weston_seat *seat; if (!input->output) return; @@ -1716,10 +1717,11 @@ input_handle_motion(void *data, struct wl_pointer *pointer, want_frame = true; } + seat = input->touch_device->aggregate->seat; if (location == THEME_LOCATION_CLIENT_AREA) { timespec_from_msec(&ts, time); - weston_input_event_init(&event.base, &ts, &input->base); + weston_input_event_init(&event.base, &ts, seat); weston_pointer_motion_event_init(&event, WESTON_POINTER_MOTION_ABS, &pos, NULL, NULL); notify_motion(&input->base, &event); @@ -2089,6 +2091,8 @@ input_handle_touch_down(void *data, struct wl_touch *wl_touch, struct weston_coord_global pos; double x, y; struct timespec ts; + struct weston_touch_event event; + struct weston_seat *seat; x = wl_fixed_to_double(fixed_x); y = wl_fixed_to_double(fixed_y); @@ -2103,6 +2107,7 @@ input_handle_touch_down(void *data, struct wl_touch *wl_touch, if (!first_touch && !input->touch_active) return; + seat = input->touch_device->aggregate->seat; if (output->frame) { location = frame_touch_down(output->frame, input, id, x, y); @@ -2129,7 +2134,9 @@ input_handle_touch_down(void *data, struct wl_touch *wl_touch, pos = weston_coord_global_from_output_point(x,y, &output->base); - notify_touch(input->touch_device, &ts, id, &pos, WL_TOUCH_DOWN); + weston_input_event_init(&event.base, &ts, seat); + weston_touch_event_init(&event, WL_TOUCH_DOWN, id, &pos); + notify_touch(input->touch_device, &event); input->touch_active = true; } @@ -2141,6 +2148,8 @@ input_handle_touch_up(void *data, struct wl_touch *wl_touch, struct wayland_output *output = input->touch_focus; bool active = input->touch_active; struct timespec ts; + struct weston_touch_event event; + struct weston_seat *seat; timespec_from_msec(&ts, time); @@ -2149,6 +2158,7 @@ input_handle_touch_up(void *data, struct wl_touch *wl_touch, if (!output) return; + seat = input->touch_device->aggregate->seat; if (output->frame) { frame_touch_up(output->frame, input, id); @@ -2165,8 +2175,11 @@ input_handle_touch_up(void *data, struct wl_touch *wl_touch, weston_output_schedule_repaint(&output->base); } + weston_input_event_init(&event.base, &ts, seat); + weston_touch_event_init(&event, WL_TOUCH_UP, id, NULL); + if (active) - notify_touch(input->touch_device, &ts, id, NULL, WL_TOUCH_UP); + notify_touch(input->touch_device, &event); } static void @@ -2180,6 +2193,8 @@ input_handle_touch_motion(void *data, struct wl_touch *wl_touch, double x, y; struct weston_coord_global pos; struct timespec ts; + struct weston_touch_event event; + struct weston_seat *seat; x = wl_fixed_to_double(fixed_x); y = wl_fixed_to_double(fixed_y); @@ -2188,6 +2203,7 @@ input_handle_touch_motion(void *data, struct wl_touch *wl_touch, if (!output || !input->touch_active) return; + seat = input->touch_device->aggregate->seat; if (output->frame) { frame_interior(output->frame, &fx, &fy, NULL, NULL); x -= fx; @@ -2195,8 +2211,9 @@ input_handle_touch_motion(void *data, struct wl_touch *wl_touch, } pos = weston_coord_global_from_output_point(x, y, &output->base); - - notify_touch(input->touch_device, &ts, id, &pos, WL_TOUCH_MOTION); + weston_input_event_init(&event.base, &ts, seat); + weston_touch_event_init(&event, WL_TOUCH_MOTION, id, &pos); + notify_touch(input->touch_device, &event); } static void diff --git a/libweston/backend.h b/libweston/backend.h index 2b87e4375..4fdd3d868 100644 --- a/libweston/backend.h +++ b/libweston/backend.h @@ -268,21 +268,17 @@ clear_pointer_focus(struct weston_seat *seat); void notify_touch_normalized(struct weston_touch_device *device, - const struct timespec *time, - int touch_id, - const struct weston_coord_global *pos, - const struct weston_point2d_device_normalized *norm, - int touch_type); + const struct weston_touch_event *event, + const struct weston_point2d_device_normalized *norm); /** Feed in touch down, motion, and up events, non-calibratable device. * * @sa notify_touch_cal */ static inline void -notify_touch(struct weston_touch_device *device, const struct timespec *time, - int touch_id, const struct weston_coord_global *pos, int touch_type) +notify_touch(struct weston_touch_device *device, const struct weston_touch_event *event) { - notify_touch_normalized(device, time, touch_id, pos, NULL, touch_type); + notify_touch_normalized(device, event, NULL); } void @@ -292,10 +288,8 @@ void notify_touch_cancel(struct weston_touch_device *device); void -notify_touch_calibrator(struct weston_touch_device *device, - const struct timespec *time, int32_t slot, - const struct weston_point2d_device_normalized *norm, - int touch_type); +notify_touch_calibrator(struct weston_touch_device *device, const struct weston_touch_event *event, + const struct weston_point2d_device_normalized *norm); void notify_touch_calibrator_cancel(struct weston_touch_device *device); void diff --git a/libweston/data-device.c b/libweston/data-device.c index 2051fb254..3c6df2160 100644 --- a/libweston/data-device.c +++ b/libweston/data-device.c @@ -730,9 +730,7 @@ static const struct weston_pointer_grab_interface pointer_drag_grab_interface = }; static void -drag_grab_touch_down(struct weston_touch_grab *grab, - const struct timespec *time, int touch_id, - struct weston_coord_global c) +drag_grab_touch_down(struct weston_touch_grab *grab, const struct weston_touch_event *event) { } @@ -750,14 +748,13 @@ data_device_end_touch_drag_grab(struct weston_touch_drag *drag) } static void -drag_grab_touch_up(struct weston_touch_grab *grab, - const struct timespec *time, int touch_id) +drag_grab_touch_up(struct weston_touch_grab *grab, const struct weston_touch_event *event) { struct weston_touch_drag *touch_drag = container_of(grab, struct weston_touch_drag, grab); struct weston_touch *touch = grab->touch; - if (touch_id != touch->grab_touch_id) + if (event->touch_id != touch->grab_touch_id) return; if (touch_drag->base.focus_resource) @@ -779,15 +776,14 @@ drag_grab_touch_focus(struct weston_touch_drag *drag) static void drag_grab_touch_motion(struct weston_touch_grab *grab, - const struct timespec *time, - int touch_id, struct weston_coord_global unused) + const struct weston_touch_event *event) { struct weston_touch_drag *touch_drag = container_of(grab, struct weston_touch_drag, grab); struct weston_touch *touch = grab->touch; uint32_t msecs; - if (touch_id != touch->grab_touch_id) + if (event->touch_id != touch->grab_touch_id) return; drag_grab_touch_focus(touch_drag); @@ -799,7 +795,7 @@ drag_grab_touch_motion(struct weston_touch_grab *grab, if (touch_drag->base.focus_resource) { struct weston_coord_surface surf_pos; - msecs = timespec_to_msec(time); + msecs = timespec_to_msec(&event->base.ts); surf_pos = weston_coord_global_to_surface(touch_drag->base.focus, touch->grab_pos); wl_data_device_send_motion(touch_drag->base.focus_resource, diff --git a/libweston/desktop/seat.c b/libweston/desktop/seat.c index 2fe9e3b34..b7b2ba421 100644 --- a/libweston/desktop/seat.c +++ b/libweston/desktop/seat.c @@ -185,28 +185,23 @@ static const struct weston_pointer_grab_interface weston_desktop_seat_pointer_po static void weston_desktop_seat_popup_grab_touch_down(struct weston_touch_grab *grab, - const struct timespec *time, - int touch_id, - struct weston_coord_global pos) + const struct weston_touch_event *event) { - weston_touch_send_down(grab->touch, time, touch_id, pos); + weston_touch_send_down(grab->touch, event); } static void weston_desktop_seat_popup_grab_touch_up(struct weston_touch_grab *grab, - const struct timespec *time, - int touch_id) + const struct weston_touch_event *event) { - weston_touch_send_up(grab->touch, time, touch_id); + weston_touch_send_up(grab->touch, event); } static void weston_desktop_seat_popup_grab_touch_motion(struct weston_touch_grab *grab, - const struct timespec *time, - int touch_id, - struct weston_coord_global pos) + const struct weston_touch_event *event) { - weston_touch_send_motion(grab->touch, time, touch_id, pos); + weston_touch_send_motion(grab->touch, event); } static void diff --git a/libweston/input.c b/libweston/input.c index b45964f59..450805e11 100644 --- a/libweston/input.c +++ b/libweston/input.c @@ -888,17 +888,15 @@ weston_touch_has_focus_resource(struct weston_touch *touch) /** Send wl_touch.down events to focused resources. * * \param touch The touch where the down events originates from. - * \param time The timestamp of the event - * \param touch_id The touch_id value of the event - * \param pos The global coordinate of the event + * \param event The weston_touch_event * * For every resource that is currently in focus, send a wl_touch.down event * with the passed parameters. The focused resources are the wl_touch * resources of the client which currently has the surface with touch focus. */ WL_EXPORT void -weston_touch_send_down(struct weston_touch *touch, const struct timespec *time, - int touch_id, struct weston_coord_global pos) +weston_touch_send_down(struct weston_touch *touch, + const struct weston_touch_event *event) { struct wl_display *display = touch->seat->compositor->wl_display; uint32_t serial; @@ -910,18 +908,19 @@ weston_touch_send_down(struct weston_touch *touch, const struct timespec *time, if (!weston_touch_has_focus_resource(touch)) return; - surf_pos = weston_coord_global_to_surface(touch->focus, pos); + surf_pos = weston_coord_global_to_surface(touch->focus, *event->pos); + weston_view_update_transform(touch->focus); resource_list = &touch->focus_resource_list; serial = wl_display_next_serial(display); - msecs = timespec_to_msec(time); + msecs = timespec_to_msec(&event->base.ts); wl_resource_for_each(resource, resource_list) { send_timestamps_for_input_resource(resource, &touch->timestamps_list, - time); + &event->base.ts); wl_touch_send_down(resource, serial, msecs, touch->focus->surface->resource, - touch_id, + event->touch_id, wl_fixed_from_double(surf_pos.c.x), wl_fixed_from_double(surf_pos.c.y)); } @@ -929,25 +928,23 @@ weston_touch_send_down(struct weston_touch *touch, const struct timespec *time, static void default_grab_touch_down(struct weston_touch_grab *grab, - const struct timespec *time, int touch_id, - struct weston_coord_global pos) + const struct weston_touch_event *event) { - weston_touch_send_down(grab->touch, time, touch_id, pos); + weston_touch_send_down(grab->touch, event); } /** Send wl_touch.up events to focused resources. * * \param touch The touch where the up events originates from. - * \param time The timestamp of the event - * \param touch_id The touch_id value of the event + * \param event The weston_touch_event * * For every resource that is currently in focus, send a wl_touch.up event * with the passed parameters. The focused resources are the wl_touch * resources of the client which currently has the surface with touch focus. */ WL_EXPORT void -weston_touch_send_up(struct weston_touch *touch, const struct timespec *time, - int touch_id) +weston_touch_send_up(struct weston_touch *touch, + const struct weston_touch_event *event) { struct wl_display *display = touch->seat->compositor->wl_display; uint32_t serial; @@ -960,28 +957,26 @@ weston_touch_send_up(struct weston_touch *touch, const struct timespec *time, resource_list = &touch->focus_resource_list; serial = wl_display_next_serial(display); - msecs = timespec_to_msec(time); + msecs = timespec_to_msec(&event->base.ts); wl_resource_for_each(resource, resource_list) { send_timestamps_for_input_resource(resource, &touch->timestamps_list, - time); - wl_touch_send_up(resource, serial, msecs, touch_id); + &event->base.ts); + wl_touch_send_up(resource, serial, msecs, event->touch_id); } } static void default_grab_touch_up(struct weston_touch_grab *grab, - const struct timespec *time, int touch_id) + const struct weston_touch_event *event) { - weston_touch_send_up(grab->touch, time, touch_id); + weston_touch_send_up(grab->touch, event); } /** Send wl_touch.motion events to focused resources. * * \param touch The touch where the motion events originates from. - * \param time The timestamp of the event - * \param touch_id The touch_id value of the event - * \param pos The global coordinate of the event + * \param event The weston_touch_event * * For every resource that is currently in focus, send a wl_touch.motion event * with the passed parameters. The focused resources are the wl_touch @@ -989,8 +984,7 @@ default_grab_touch_up(struct weston_touch_grab *grab, */ WL_EXPORT void weston_touch_send_motion(struct weston_touch *touch, - const struct timespec *time, int touch_id, - struct weston_coord_global pos) + const struct weston_touch_event *event) { struct wl_resource *resource; struct wl_list *resource_list; @@ -1000,15 +994,16 @@ weston_touch_send_motion(struct weston_touch *touch, if (!weston_touch_has_focus_resource(touch)) return; - surf_pos = weston_coord_global_to_surface(touch->focus, pos); + surf_pos = weston_coord_global_to_surface(touch->focus, *event->pos); + weston_view_update_transform(touch->focus); resource_list = &touch->focus_resource_list; - msecs = timespec_to_msec(time); + msecs = timespec_to_msec(&event->base.ts); wl_resource_for_each(resource, resource_list) { send_timestamps_for_input_resource(resource, &touch->timestamps_list, - time); - wl_touch_send_motion(resource, msecs, touch_id, + &event->base.ts); + wl_touch_send_motion(resource, msecs, event->touch_id, wl_fixed_from_double(surf_pos.c.x), wl_fixed_from_double(surf_pos.c.y)); } @@ -1016,10 +1011,9 @@ weston_touch_send_motion(struct weston_touch *touch, static void default_grab_touch_motion(struct weston_touch_grab *grab, - const struct timespec *time, int touch_id, - struct weston_coord_global pos) + const struct weston_touch_event *event) { - weston_touch_send_motion(grab->touch, time, touch_id, pos); + weston_touch_send_motion(grab->touch, event); } @@ -2834,28 +2828,24 @@ weston_touch_set_focus(struct weston_touch *touch, struct weston_view *view) static void process_touch_normal(struct weston_touch_device *device, - const struct timespec *time, int touch_id, - const struct weston_coord_global *pos, int touch_type) + const struct weston_touch_event *event) { struct weston_touch *touch = device->aggregate; struct weston_touch_grab *grab = device->aggregate->grab; struct weston_compositor *ec = device->aggregate->seat->compositor; struct weston_view *ev; - if (touch_type != WL_TOUCH_UP) - assert(pos); - /* Update grab's global coordinates. */ - if (touch_id == touch->grab_touch_id && touch_type != WL_TOUCH_UP) - touch->grab_pos = *pos; + if (event->touch_id == touch->grab_touch_id && event->touch_type != WL_TOUCH_UP) + touch->grab_pos = *event->pos; - switch (touch_type) { + switch (event->touch_type) { case WL_TOUCH_DOWN: /* the first finger down picks the view, and all further go * to that view for the remainder of the touch session i.e. * until all touch points are up again. */ if (touch->num_tp == 1) { - ev = weston_compositor_pick_view(ec, *pos); + ev = weston_compositor_pick_view(ec, *event->pos); weston_touch_set_focus(touch, ev); } else if (!touch->focus) { /* Unexpected condition: We have non-initial touch but @@ -2867,15 +2857,16 @@ process_touch_normal(struct weston_touch_device *device, } weston_compositor_run_touch_binding(ec, touch, - time, touch_type); + &event->base.ts, + event->touch_type); - grab->interface->down(grab, time, touch_id, *pos); + grab->interface->down(grab, event); if (touch->num_tp == 1) { touch->grab_serial = wl_display_get_serial(ec->wl_display); - touch->grab_touch_id = touch_id; - touch->grab_time = *time; - touch->grab_pos = *pos; + touch->grab_touch_id = event->touch_id; + touch->grab_time = event->base.ts; + touch->grab_pos = *event->pos; } break; @@ -2884,10 +2875,10 @@ process_touch_normal(struct weston_touch_device *device, if (!ev) break; - grab->interface->motion(grab, time, touch_id, *pos); + grab->interface->motion(grab, event); break; case WL_TOUCH_UP: - grab->interface->up(grab, time, touch_id); + grab->interface->up(grab, event); touch->pending_focus_reset = true; break; } @@ -2999,11 +2990,8 @@ weston_compositor_set_touch_mode_calib(struct weston_compositor *compositor) * for sending along such order. * * \param device The physical device that generated the event. - * \param time The event timestamp. - * \param touch_id ID for the touch point of this event (multi-touch). - * \param pos X,Y coordinate in compositor global space, or NULL for WL_TOUCH_UP. + * \param event The weston_touch_event event * \param norm Normalized device X, Y coordinates in calibration space, or NULL. - * \param touch_type Either WL_TOUCH_DOWN, WL_TOUCH_UP, or WL_TOUCH_MOTION. * * Coordinates double_x and double_y are used for normal operation. * @@ -3017,28 +3005,21 @@ weston_compositor_set_touch_mode_calib(struct weston_compositor *compositor) */ WL_EXPORT void notify_touch_normalized(struct weston_touch_device *device, - const struct timespec *time, - int touch_id, - const struct weston_coord_global *pos, - const struct weston_point2d_device_normalized *norm, - int touch_type) + const struct weston_touch_event *event, + const struct weston_point2d_device_normalized *norm) { struct weston_seat *seat = device->aggregate->seat; struct weston_touch *touch = device->aggregate; - if (touch_type != WL_TOUCH_UP) { - assert(pos); - + if (event->touch_type != WL_TOUCH_UP) { if (weston_touch_device_can_calibrate(device)) assert(norm != NULL); else assert(norm == NULL); - } else { - assert(!pos); } /* Update touchpoints count regardless of the current mode. */ - switch (touch_type) { + switch (event->touch_type) { case WL_TOUCH_DOWN: weston_compositor_idle_inhibit(seat->compositor); @@ -3066,12 +3047,11 @@ notify_touch_normalized(struct weston_touch_device *device, switch (weston_touch_device_get_mode(device)) { case WESTON_TOUCH_MODE_NORMAL: case WESTON_TOUCH_MODE_PREP_CALIB: - process_touch_normal(device, time, touch_id, pos, touch_type); + process_touch_normal(device, event); break; case WESTON_TOUCH_MODE_CALIB: case WESTON_TOUCH_MODE_PREP_NORMAL: - notify_touch_calibrator(device, time, touch_id, - norm, touch_type); + notify_touch_calibrator(device, event, norm); break; } } @@ -6051,3 +6031,12 @@ weston_pointer_axis_event_init(struct weston_pointer_axis_event *event, event->has_discrete = has_discrete; event->discrete = discrete; } + +WL_EXPORT void +weston_touch_event_init(struct weston_touch_event *event, int32_t touch_type, + int32_t touch_id, const struct weston_coord_global *pos) +{ + event->touch_type = touch_type; + event->touch_id = touch_id; + event->pos = pos; +} diff --git a/libweston/libinput-device.c b/libweston/libinput-device.c index e5b0923a9..dbe682357 100644 --- a/libweston/libinput-device.c +++ b/libweston/libinput-device.c @@ -459,15 +459,18 @@ handle_touch_with_coords(struct libinput_device *libinput_device, struct weston_point2d_device_normalized norm; uint32_t width, height; struct timespec time; - int32_t slot; + int32_t touch_id; struct weston_coord_global pos; + struct weston_touch_event event; + struct weston_seat *seat; if (!device->output) return; + seat = device->touch_device->aggregate->seat; timespec_from_usec(&time, libinput_event_touch_get_time_usec(touch_event)); - slot = libinput_event_touch_get_seat_slot(touch_event); + touch_id = libinput_event_touch_get_seat_slot(touch_event); width = device->output->current_mode->width; height = device->output->current_mode->height; @@ -476,14 +479,15 @@ handle_touch_with_coords(struct libinput_device *libinput_device, pos = weston_coord_global_from_output_point(x, y, device->output); + weston_input_event_init(&event.base, &time, seat); + weston_touch_event_init(&event, touch_type, touch_id, &pos); + if (weston_touch_device_can_calibrate(device->touch_device)) { norm.x = libinput_event_touch_get_x_transformed(touch_event, 1); norm.y = libinput_event_touch_get_y_transformed(touch_event, 1); - notify_touch_normalized(device->touch_device, &time, slot, - &pos, &norm, touch_type); + notify_touch_normalized(device->touch_device, &event, &norm); } else { - notify_touch(device->touch_device, &time, slot, - &pos, touch_type); + notify_touch(device->touch_device, &event); } } @@ -508,15 +512,20 @@ handle_touch_up(struct libinput_device *libinput_device, struct evdev_device *device = libinput_device_get_user_data(libinput_device); struct timespec time; - int32_t slot = libinput_event_touch_get_seat_slot(touch_event); + struct weston_touch_event event; + struct weston_seat *seat; if (!device->output) return; + seat = device->touch_device->aggregate->seat; timespec_from_usec(&time, libinput_event_touch_get_time_usec(touch_event)); - notify_touch(device->touch_device, &time, slot, NULL, WL_TOUCH_UP); + weston_input_event_init(&event.base, &time, seat); + weston_touch_event_init(&event, WL_TOUCH_UP, + libinput_event_touch_get_seat_slot(touch_event), NULL); + notify_touch(device->touch_device, &event); } static void diff --git a/libweston/touch-calibration.c b/libweston/touch-calibration.c index f4c9366a0..b261a0ff5 100644 --- a/libweston/touch-calibration.c +++ b/libweston/touch-calibration.c @@ -87,9 +87,8 @@ normalized_is_valid(const struct weston_point2d_device_normalized *p) WL_EXPORT void notify_touch_calibrator(struct weston_touch_device *device, - const struct timespec *time, int32_t slot, - const struct weston_point2d_device_normalized *norm, - int touch_type) + const struct weston_touch_event *event, + const struct weston_point2d_device_normalized *norm) { struct weston_touch_calibrator *calibrator; struct wl_resource *res; @@ -105,7 +104,7 @@ notify_touch_calibrator(struct weston_touch_device *device, /* Ignore any touch events coming from another device */ if (device != calibrator->device) { - if (touch_type == WL_TOUCH_DOWN) + if (event->touch_type == WL_TOUCH_DOWN) weston_touch_calibrator_send_invalid_touch(res); return; } @@ -115,20 +114,20 @@ notify_touch_calibrator(struct weston_touch_device *device, */ if (calibrator->touch_cancelled) { if (calibrator->device->aggregate->num_tp == 0) { - assert(touch_type == WL_TOUCH_UP); + assert(event->touch_type == WL_TOUCH_UP); calibrator->touch_cancelled = false; } return; } - msecs = timespec_to_msec(time); - if (touch_type != WL_TOUCH_UP) { + msecs = timespec_to_msec(&event->base.ts); + if (event->touch_type != WL_TOUCH_UP) { if (normalized_is_valid(norm)) { x = wire_uint_from_double(norm->x); y = wire_uint_from_double(norm->y); } else { /* Coordinates are out of bounds */ - if (touch_type == WL_TOUCH_MOTION) { + if (event->touch_type == WL_TOUCH_MOTION) { weston_touch_calibrator_send_cancel(res); calibrator->touch_cancelled = true; } @@ -137,15 +136,15 @@ notify_touch_calibrator(struct weston_touch_device *device, } } - switch (touch_type) { + switch (event->touch_type) { case WL_TOUCH_UP: - weston_touch_calibrator_send_up(res, msecs, slot); + weston_touch_calibrator_send_up(res, msecs, event->touch_id); break; case WL_TOUCH_DOWN: - weston_touch_calibrator_send_down(res, msecs, slot, x, y); + weston_touch_calibrator_send_down(res, msecs, event->touch_id, x, y); break; case WL_TOUCH_MOTION: - weston_touch_calibrator_send_motion(res, msecs, slot, x, y); + weston_touch_calibrator_send_motion(res, msecs, event->touch_id, x, y); break; default: return; diff --git a/tests/harness/weston-test.c b/tests/harness/weston-test.c index 7499f80d3..bccdcb968 100644 --- a/tests/harness/weston-test.c +++ b/tests/harness/weston-test.c @@ -556,10 +556,14 @@ send_touch(struct wl_client *client, struct wl_resource *resource, struct weston_touch_device *device = test->touch_device[0]; struct timespec time; struct weston_coord_global pos; + struct weston_touch_event event; + struct weston_seat *seat; assert(device); + seat = device->aggregate->seat; timespec_from_proto(&time, tv_sec_hi, tv_sec_lo, tv_nsec); + weston_input_event_init(&event.base, &time, seat); if (touch_type == WL_TOUCH_UP) { if (x != 0 || y != 0) { @@ -570,11 +574,12 @@ send_touch(struct wl_client *client, struct wl_resource *resource, return; } - - notify_touch(device, &time, touch_id, NULL, touch_type); + weston_touch_event_init(&event, touch_type, touch_id, NULL); + notify_touch(device, &event); } else { pos.c = weston_coord_from_fixed(x, y); - notify_touch(device, &time, touch_id, &pos, touch_type); + weston_touch_event_init(&event, touch_type, touch_id, &pos); + notify_touch(device, &event); } }