From 496e71f1469c45423640ddbd1dfdd823f426cbdb Mon Sep 17 00:00:00 2001 From: Marius Vlad Date: Tue, 31 Mar 2026 10:19:24 +0300 Subject: [PATCH 1/9] 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 | 12 +++++-- 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 | 14 +++++--- libweston/data-device.c | 2 +- libweston/desktop/seat.c | 6 ++-- libweston/input.c | 44 ++++++++++++++++------- libweston/libinput-device.c | 12 ++++--- tests/harness/weston-test.c | 5 ++- 14 files changed, 169 insertions(+), 88 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..7eeb96873 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_event.ts; + uint32_t state_w = key_event->key_state; if (!keyboard->input_method_resource) return; @@ -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_event, &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..81c029929 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_event; + 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..810cea3f6 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_event, + &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..d7191b6b9 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_event, &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_event, &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..4e6147dae 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_event, &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..09e6665c5 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_event, &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_event, &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_event, &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_event, &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..7b0f6877f 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_event.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; @@ -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_event.ts; + uint32_t key = key_event->key; + uint32_t state = key_event->key_state; int i; struct wl_list *resource_list; uint32_t msecs; 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..343819aaf 100644 --- a/libweston/input.c +++ b/libweston/input.c @@ -1089,24 +1089,24 @@ 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 + * For every resource that is currently in focus, send a key event * with the passed parameters. The focused resources are the wl_keyboard * resources of the client which currently has the surface with keyboard focus. */ 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_event.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; @@ -1124,10 +1124,9 @@ weston_keyboard_send_key(struct weston_keyboard *keyboard, 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_event.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; @@ -2702,7 +2703,7 @@ notify_key(struct weston_seat *seat, const struct timespec *time, uint32_t key, grab = keyboard->grab; } - grab->interface->key(grab, time, key, state); + grab->interface->key(grab, key_event); if (keyboard->pending_keymap && keyboard->keys.size == 0) @@ -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..91140e58f 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_event, &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..a04de41ca 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_event, &time, seat); + weston_key_event_init(&key_event, key, state, STATE_UPDATE_AUTOMATIC); + notify_key(seat, &key_event); } static void From d99754ef70a48952e8deaffa410eb3902bc4fec0 Mon Sep 17 00:00:00 2001 From: Marius Vlad Date: Thu, 2 Apr 2026 16:10:32 +0300 Subject: [PATCH 2/9] 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_event class - remove the const struct timespec from calls and use the base_event class - 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 81c029929..809979a7c 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_event; 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_event; 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 810cea3f6..b7884bead 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_event, &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_event, &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 d7191b6b9..68ebc442f 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_event, &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 4e6147dae..52284dcf1 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_event, &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 09e6665c5..8b8e4fb19 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_event, &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 c2822ad44..5e891dd09 100644 --- a/libweston/compositor.c +++ b/libweston/compositor.c @@ -8006,6 +8006,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; @@ -8061,7 +8062,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..9cdf032c6 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_event.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 343819aaf..5658be702 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_event.ts); if (time_usec == 0) - time_usec = timespec_to_usec(time); + time_usec = timespec_to_usec(event->base_event.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_event.ts); wl_resource_for_each(resource, resource_list) { send_timestamps_for_input_resource(resource, &pointer->timestamps_list, - time); + event->base_event.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_event.seat->compositor, abs); + + if (mask & WESTON_POINTER_MOTION_REL) + weston_assert_ptr_not_null(event->base_event.seat->compositor, rel); + + if (mask & WESTON_POINTER_MOTION_REL_UNACCEL) + weston_assert_ptr_not_null(event->base_event.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 91140e58f..09f3b1b8d 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_event, &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_event, &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 a04de41ca..1bff4bf1b 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_event, &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 8bf96e6f2ff21facabb3d6a4481a9e9f0767c7c6 Mon Sep 17 00:00:00 2001 From: Marius Vlad Date: Tue, 21 Apr 2026 11:52:34 +0300 Subject: [PATCH 3/9] 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 b7884bead..bf59958f0 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_event, &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_event, &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 68ebc442f..03ab79006 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_event, &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 52284dcf1..809ecdee7 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_event, &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 5658be702..ba3f5dbc3 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 09f3b1b8d..1e1081d1f 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_event, &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 bf1f7363f40326659b1b423ada8cedaada1e9e25 Mon Sep 17 00:00:00 2001 From: Marius Vlad Date: Thu, 2 Apr 2026 20:49:56 +0300 Subject: [PATCH 4/9] 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 | 8 ++--- libweston/input.c | 51 +++++++++++++++-------------- libweston/libinput-device.c | 9 +++-- tests/harness/weston-test.c | 7 ++-- 14 files changed, 130 insertions(+), 87 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 809979a7c..e8b16cf33 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_event; + 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 bf59958f0..85f8e1184 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_event, &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_event, &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 03ab79006..76b819ec7 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_event, &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 809ecdee7..c72d898c6 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_event, &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 8b8e4fb19..6d8ab502b 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_event, &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 9cdf032c6..d582a452a 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..b4535b122 100644 --- a/libweston/desktop/seat.c +++ b/libweston/desktop/seat.c @@ -124,20 +124,20 @@ 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_event.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))) diff --git a/libweston/input.c b/libweston/input.c index ba3f5dbc3..315b3f2a6 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,14 +681,16 @@ 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_event.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; @@ -708,14 +708,14 @@ weston_pointer_send_button(struct weston_pointer *pointer, 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_event.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_event.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 1e1081d1f..131e79bca 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_event, &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 1bff4bf1b..d9f8908c1 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_event, &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 3b21078309b50a75c189c932cc3ec5ecbac2f00c Mon Sep 17 00:00:00 2001 From: Marius Vlad Date: Fri, 17 Apr 2026 17:36:13 +0300 Subject: [PATCH 5/9] 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 e8b16cf33..9415fb793 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_event; 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 85f8e1184..e79709062 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_event, + &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 76b819ec7..4f5b69b1e 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_event, + &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 c72d898c6..eb680f841 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_event, &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_event, &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 6d8ab502b..dc26cdc95 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_event, + &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_event, + &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_event, + &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_event, + &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 7b0f6877f..dd0e201f8 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 d582a452a..9da912b31 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 b4535b122..3c0ac225e 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 315b3f2a6..1d5d184fc 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_event.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_event.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_event.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_event.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 131e79bca..f89c7eb0d 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_event, &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_event, &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 65f754c25..8bc498ff6 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 d9f8908c1..581b4323f 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_event, &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 7993052a1feec96e664632296445d719a3a18ede Mon Sep 17 00:00:00 2001 From: Marius Vlad Date: Thu, 2 Apr 2026 21:59:57 +0300 Subject: [PATCH 6/9] 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/li | 0 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 ++- 13 files changed, 161 insertions(+), 167 deletions(-) create mode 100644 include/libweston/li 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/li b/include/libweston/li new file mode 100644 index 000000000..e69de29bb diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h index 9415fb793..7309df041 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_event; + 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 eb680f841..78a4a6abd 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_event, &ts, &input->base); + weston_input_event_init(&event.base_event, &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_event, &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_event, &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_event, &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 9da912b31..1a3cc8f8c 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_event.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 3c0ac225e..4bdd016df 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 1d5d184fc..244253101 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_event.ts); wl_resource_for_each(resource, resource_list) { send_timestamps_for_input_resource(resource, &touch->timestamps_list, - time); + event->base_event.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_event.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_event.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_event.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_event.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_event.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_event.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 f89c7eb0d..d42991404 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_event, &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_event, &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..7851a2ebb 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_event.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 581b4323f..3f977d058 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_event, &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); } } From 3f727bf1b539f609cd93f982259975bc1bf4bacf Mon Sep 17 00:00:00 2001 From: Marius Vlad Date: Mon, 6 Apr 2026 14:16:44 +0300 Subject: [PATCH 7/9] timeline: Add support for weston_seat And with it include a dedicated track in Perfetto to display event time on a particular seat. Signed-off-by: Marius Vlad --- include/libweston/libweston.h | 1 + libweston/perfetto/u_perfetto.cc | 26 +++++++++ libweston/perfetto/u_perfetto.h | 8 +++ libweston/timeline-perfetto.c | 40 +++++++++++++- libweston/timeline.c | 92 ++++++++++++++++++++++++++++++++ libweston/timeline.h | 10 +++- libweston/weston-trace.h | 12 +++++ 7 files changed, 187 insertions(+), 2 deletions(-) diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h index 7309df041..55faa5fa0 100644 --- a/include/libweston/libweston.h +++ b/include/libweston/libweston.h @@ -1243,6 +1243,7 @@ struct weston_seat { struct wl_list tablet_tool_list; struct wl_list tablet_seat_resource_list; struct wl_signal tablet_tool_added_signal; + uint64_t track_id; }; enum { diff --git a/libweston/perfetto/u_perfetto.cc b/libweston/perfetto/u_perfetto.cc index 9d0a2eb99..431cf4d25 100644 --- a/libweston/perfetto/u_perfetto.cc +++ b/libweston/perfetto/u_perfetto.cc @@ -145,6 +145,32 @@ util_perfetto_counter_set(const char *name, double value) perfetto::DynamicString(name), value); } +void +util_perfetto_trace_instant_timestamp(const char *name, uint64_t track_id, uint64_t id, clockid_t clock, uint64_t ts) +{ + if (id) { + TRACE_EVENT_INSTANT(UTIL_PERFETTO_CATEGORY_DEFAULT_STR, + nullptr, + perfetto::Track(track_id), + perfetto::TraceTimestamp{clockid_to_perfetto_clock(clock), ts}, + perfetto::Flow::ProcessScoped(id), + [&](perfetto::EventContext ctx) { + ctx.event()->set_name(name); + ctx.AddDebugAnnotation(name, ts); + }); + return; + } + + TRACE_EVENT_INSTANT(UTIL_PERFETTO_CATEGORY_DEFAULT_STR, + nullptr, + perfetto::Track(track_id), + perfetto::TraceTimestamp{clockid_to_perfetto_clock(clock), ts}, + [&](perfetto::EventContext ctx) { + ctx.event()->set_name(name); + ctx.AddDebugAnnotation(name, ts); + }); +} + uint64_t util_perfetto_next_id(void) { diff --git a/libweston/perfetto/u_perfetto.h b/libweston/perfetto/u_perfetto.h index 576348fce..602a0bcc4 100644 --- a/libweston/perfetto/u_perfetto.h +++ b/libweston/perfetto/u_perfetto.h @@ -63,10 +63,13 @@ void util_perfetto_trace_full_begin(const char *name, uint64_t track_id, uint64_ void util_perfetto_trace_full_end(const char *name, uint64_t track_id, clockid_t clock, uint64_t timestamp); +void util_perfetto_trace_instant_timestamp(const char *name, uint64_t track_id, uint64_t id, clockid_t clock, uint64_t ts); + uint64_t util_perfetto_next_id(void); uint64_t util_perfetto_new_track(const char *name); + #else /* HAVE_PERFETTO */ static inline void @@ -104,6 +107,11 @@ util_perfetto_trace_full_end(const char *name, uint64_t track_id, clockid_t cloc { } +static inline void +util_perfetto_trace_instant_timestamp(const char *name, uint64_t track_id, clockid_t clock, uint64_t ts) +{ +} + static inline void util_perfetto_counter_set(const char *name, double value) { } diff --git a/libweston/timeline-perfetto.c b/libweston/timeline-perfetto.c index c8c2e9e71..a6dbd88b0 100644 --- a/libweston/timeline-perfetto.c +++ b/libweston/timeline-perfetto.c @@ -64,6 +64,14 @@ build_track_name(struct weston_surface *surface, char *name, int size) snprintf(name, size, "%s #%d", surface->label, surface->s_id); } +static void +build_seat_track_name(struct weston_seat *seat, char *name, int size) +{ + assert(seat->track_id == 0); + + snprintf(name, size, "seat: %s", seat->seat_name); +} + static void weston_perfetto_ensure_surface_id(struct weston_surface *surface) { @@ -77,6 +85,19 @@ weston_perfetto_ensure_surface_id(struct weston_surface *surface) surface->damage_track_id = util_perfetto_new_track(track_name); } +static void +weston_perfetto_ensure_seat_id(struct weston_seat *seat) +{ + char track_name[600]; + + if (seat->track_id) + return; + + build_seat_track_name(seat, track_name, sizeof(track_name)); + + seat->track_id = util_perfetto_new_track(track_name); +} + /** * Translates a timeline point for perfetto. * @@ -94,9 +115,11 @@ weston_timeline_perfetto(struct weston_log_scope *timeline_scope, { struct weston_output *output = NULL; struct weston_surface *surface = NULL; + struct weston_seat *seat = NULL; + struct weston_input_event *ievent = NULL; struct timespec ts; uint64_t now_ns; - uint64_t vblank_ns = 0, gpu_ns = 0; + uint64_t vblank_ns = 0, gpu_ns = 0, kernel_input_ts = 0; va_list argp; if (!util_perfetto_is_tracing_enabled()) @@ -130,6 +153,18 @@ weston_timeline_perfetto(struct weston_log_scope *timeline_scope, case TLT_GPU: gpu_ns = timespec_to_nsec(obj); break; + case TLT_SEAT: + seat = obj; + weston_perfetto_ensure_seat_id(seat); + break; + case TLT_KERNEL_TS: + kernel_input_ts = timespec_to_nsec(obj); + break; + case TLT_INPUT_EVENT: + ievent = obj; + weston_perfetto_ensure_seat_id(ievent->seat); + kernel_input_ts = timespec_to_nsec(ievent->ts); + break; default: assert(!"not reached"); } @@ -170,6 +205,9 @@ weston_timeline_perfetto(struct weston_log_scope *timeline_scope, case TLP_RENDERER_GPU_END: WESTON_TRACE_TIMESTAMP_END("Active", output->gpu_track_id, CLOCK_MONOTONIC, gpu_ns); break; + case TLP_INPUT_KERNEL_TS: + WESTON_TRACE_INSTANT_TIMESTAMP("event ts", seat->track_id, 0, CLOCK_MONOTONIC, kernel_input_ts); + break; default: assert(!"not reached"); } diff --git a/libweston/timeline.c b/libweston/timeline.c index f919ebc3b..11e47d0bd 100644 --- a/libweston/timeline.c +++ b/libweston/timeline.c @@ -222,6 +222,24 @@ weston_timeline_subscription_surface_ensure(struct weston_timeline_subscription return sub_obj; } +static struct weston_timeline_subscription_object * +weston_timeline_subscription_seat_ensure(struct weston_timeline_subscription *tl_sub, + struct weston_seat *seat) +{ + struct weston_timeline_subscription_object *sub_obj; + + sub_obj = weston_timeline_subscription_search(tl_sub, seat); + if (!sub_obj) { + sub_obj = weston_timeline_subscription_object_create(seat, tl_sub); + + sub_obj->destroy_listener.notify = + weston_timeline_destroy_subscription_object_notify; + wl_signal_add(&seat->destroy_signal, + &sub_obj->destroy_listener); + } + return sub_obj; +} + static void fprint_quoted_string(struct weston_log_subscription *sub, const char *str) { @@ -265,6 +283,47 @@ emit_weston_output(struct timeline_emit_context *ctx, void *obj) return 1; } +static void +emit_weston_seat_print_id(struct weston_log_subscription *sub, + struct weston_timeline_subscription_object *sub_obj, + const char *name) +{ + if (!weston_timeline_check_object_refresh(sub_obj)) + return; + + weston_log_subscription_printf(sub, "{ \"id\":%u, " + "\"type\":\"weston_seat\", \"name\":", sub_obj->id); + fprint_quoted_string(sub, name); + weston_log_subscription_printf(sub, " }\n"); +} + +static int +common_emit_seat(struct timeline_emit_context *ctx, struct weston_seat *seat) +{ + struct weston_log_subscription *sub = ctx->subscription; + struct weston_timeline_subscription_object *sub_obj; + struct weston_timeline_subscription *tl_sub; + + tl_sub = weston_log_subscription_get_data(sub); + sub_obj = weston_timeline_subscription_seat_ensure(tl_sub, seat); + emit_weston_seat_print_id(sub, sub_obj, seat->seat_name); + + assert(sub_obj->id != 0); + fprintf(ctx->cur, "\"seat\":%u", sub_obj->id); + + return 1; +} + +static int +emit_seat(struct timeline_emit_context *ctx, void *obj) +{ + struct weston_seat *seat = obj; + + common_emit_seat(ctx, seat); + + return 1; +} + static struct weston_timeline_subscription_object * check_weston_surface_description(struct weston_log_subscription *sub, @@ -342,6 +401,32 @@ emit_gpu_timestamp(struct timeline_emit_context *ctx, void *obj) return 1; } +static int +emit_kernel_input_timestamp(struct timeline_emit_context *ctx, void *obj) +{ + struct timespec *ts = obj; + + fprintf(ctx->cur, "\"event ts\":[%" PRId64 ", %ld]", + (int64_t)ts->tv_sec, ts->tv_nsec); + + return 1; +} + +static int +emit_input_event(struct timeline_emit_context *ctx, void *obj) +{ + struct weston_input_event *ievent = obj; + struct timespec *ts = ievent->ts; + struct weston_seat *seat = ievent->seat; + + common_emit_seat(ctx, seat); + + fprintf(ctx->cur, ", \"event ts\":[%" PRId64 ", %ld]", + (int64_t)ts->tv_sec, ts->tv_nsec); + + return 1; +} + static struct weston_timeline_subscription_object * weston_timeline_get_subscription_object(struct weston_log_subscription *sub, void *object) @@ -392,6 +477,9 @@ static const type_func type_dispatch[] = { [TLT_SURFACE] = emit_weston_surface, [TLT_VBLANK] = emit_vblank_timestamp, [TLT_GPU] = emit_gpu_timestamp, + [TLT_SEAT] = emit_seat, + [TLT_KERNEL_TS] = emit_kernel_input_timestamp, + [TLT_INPUT_EVENT] = emit_input_event, }; static const char * @@ -420,6 +508,10 @@ tlp_to_string(enum timeline_point_name tlp) return "renderer_gpu_begin"; case TLP_RENDERER_GPU_END: return "renderer_gpu_end"; + case TLP_INPUT_SEAT: + return "seat"; + case TLP_INPUT_KERNEL_TS: + return "kernel_ts"; } assert(!"not reached"); } diff --git a/libweston/timeline.h b/libweston/timeline.h index 95b65b52c..38134ec6a 100644 --- a/libweston/timeline.h +++ b/libweston/timeline.h @@ -43,6 +43,9 @@ enum timeline_type { TLT_SURFACE, TLT_VBLANK, TLT_GPU, + TLT_SEAT, + TLT_KERNEL_TS, + TLT_INPUT_EVENT, }; enum timeline_point_name { @@ -56,7 +59,9 @@ enum timeline_point_name { TLP_CORE_REPAINT_ENTER_LOOP, TLP_CORE_COMMIT_DAMAGE, TLP_RENDERER_GPU_BEGIN, - TLP_RENDERER_GPU_END + TLP_RENDERER_GPU_END, + TLP_INPUT_SEAT, + TLP_INPUT_KERNEL_TS, }; /** Timeline subscription created for each subscription @@ -96,6 +101,9 @@ struct weston_timeline_subscription_object { #define TLP_SURFACE(s) TLT_SURFACE, TYPEVERIFY(struct weston_surface *, (s)) #define TLP_VBLANK(t) TLT_VBLANK, TYPEVERIFY(const struct timespec *, (t)) #define TLP_GPU(t) TLT_GPU, TYPEVERIFY(const struct timespec *, (t)) +#define TLP_SEAT(t) TLT_SEAT, TYPEVERIFY(const struct weston_seat *, (t)) +#define TLP_KERNEL_TS(t) TLT_KERNEL_TS, TYPEVERIFY(const struct timespec *, (t)) +#define TLP_INPUT_EVENT(t) TLT_INPUT_EVENT, TYPEVERIFY(const struct weston_input_event *, (t)) /** This macro is used to add timeline points. * diff --git a/libweston/weston-trace.h b/libweston/weston-trace.h index 154663157..b39b65a93 100644 --- a/libweston/weston-trace.h +++ b/libweston/weston-trace.h @@ -69,6 +69,14 @@ clock, timestamp); \ } while (0) +#define _WESTON_TRACE_INSTANT_TIMESTAMP(name, track_id, id, clock, timestamp) \ + do { \ + if (unlikely(util_perfetto_is_tracing_enabled())) \ + util_perfetto_trace_instant_timestamp(name, track_id, \ + id, clock, \ + timestamp); \ + } while (0) + #if __has_attribute(cleanup) && __has_attribute(unused) #define _WESTON_TRACE_SCOPE_VAR_CONCAT(name, suffix) name##suffix @@ -129,6 +137,7 @@ _weston_trace_scope_end(int *scope) #define _WESTON_TRACE_SET_COUNTER(name, value) #define _WESTON_TRACE_TIMESTAMP_BEGIN(name, track_id, flow_id, clock, timestamp) #define _WESTON_TRACE_TIMESTAMP_END(name, track_id, clock, timestamp) +#define _WESTON_TRACE_INSTANT_TIMESTAMP(name, track_id, id, clock, timestamp) #endif /* HAVE_PERFETTO */ @@ -141,5 +150,8 @@ _weston_trace_scope_end(int *scope) _WESTON_TRACE_TIMESTAMP_BEGIN(name, track_id, flow_id, clock, timestamp) #define WESTON_TRACE_TIMESTAMP_END(name, track_id, clock, timestamp) \ _WESTON_TRACE_TIMESTAMP_END(name, track_id, clock, timestamp) +#define WESTON_TRACE_INSTANT_TIMESTAMP(name, track_id, id, clock, timestamp) \ + _WESTON_TRACE_INSTANT_TIMESTAMP(name, track_id, id, clock, timestamp) + #endif /* WESTON_TRACE_H */ From c0d7bcd39af6dba02d459e78eca786ded01ef679 Mon Sep 17 00:00:00 2001 From: Marius Vlad Date: Thu, 23 Apr 2026 11:38:23 +0300 Subject: [PATCH 8/9] input: Add TL_POINTs for kernel timestamps Signed-off-by: Marius Vlad --- libweston/libinput-device.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/libweston/libinput-device.c b/libweston/libinput-device.c index d42991404..4fb1d0341 100644 --- a/libweston/libinput-device.c +++ b/libweston/libinput-device.c @@ -44,6 +44,7 @@ #include "libinput-device.h" #include "shared/helpers.h" #include "shared/timespec-util.h" +#include "timeline.h" #include "tablet-unstable-v2-server-protocol.h" @@ -111,6 +112,8 @@ handle_keyboard_key(struct libinput_device *libinput_device, timespec_from_usec(&time, libinput_event_keyboard_get_time_usec(keyboard_event)); weston_input_event_init(&key_event.base_event, &time, device->seat); + TL_POINT(device->seat->compositor, TLP_INPUT_KERNEL_TS, + TLP_INPUT_EVENT(&key_event.base_event), TLP_END); weston_key_event_init(&key_event, key, key_state, STATE_UPDATE_AUTOMATIC); notify_key(device->seat, &key_event); @@ -141,6 +144,8 @@ handle_pointer_motion(struct libinput_device *libinput_device, weston_input_event_init(&event.base_event, &time, device->seat); weston_pointer_motion_event_init(&event, WESTON_POINTER_MOTION_REL | WESTON_POINTER_MOTION_REL_UNACCEL, NULL, &rel, &rel_unaccel); + TL_POINT(device->seat->compositor, TLP_INPUT_KERNEL_TS, + TLP_INPUT_EVENT(&event.base_event), TLP_END); notify_motion(device->seat, &event); return true; @@ -176,6 +181,8 @@ handle_pointer_motion_absolute( height); pos = weston_coord_global_from_output_point(x, y, output); weston_input_event_init(&event.base_event, &time, device->seat); + TL_POINT(device->seat->compositor, TLP_INPUT_KERNEL_TS, + TLP_INPUT_EVENT(&event.base_event), TLP_END); weston_pointer_motion_event_init(&event, WESTON_POINTER_MOTION_ABS, &pos, NULL, NULL); notify_motion(device->seat, &event); @@ -209,6 +216,8 @@ handle_pointer_button(struct libinput_device *libinput_device, libinput_event_pointer_get_time_usec(pointer_event)); weston_input_event_init(&button_event.base_event, &time, device->seat); + TL_POINT(device->seat->compositor, TLP_INPUT_KERNEL_TS, + TLP_INPUT_EVENT(&button_event.base_event), TLP_END); weston_pointer_button_event_init(&button_event, libinput_event_pointer_get_button(pointer_event), button_state); @@ -316,6 +325,8 @@ handle_pointer_axis(struct libinput_device *libinput_device, vert = normalize_scroll(pointer_event, axis); weston_input_event_init(&weston_event.base_event, &time, device->seat); + TL_POINT(device->seat->compositor, TLP_INPUT_KERNEL_TS, + TLP_INPUT_EVENT(&weston_event.base_event), TLP_END); weston_pointer_axis_event_init(&weston_event, WL_POINTER_AXIS_VERTICAL_SCROLL, vert, (vert_discrete != 0), vert_discrete); notify_axis(device->seat, &weston_event); @@ -327,6 +338,8 @@ handle_pointer_axis(struct libinput_device *libinput_device, horiz = normalize_scroll(pointer_event, axis); weston_input_event_init(&weston_event.base_event, &time, device->seat); + TL_POINT(device->seat->compositor, TLP_INPUT_KERNEL_TS, + TLP_INPUT_EVENT(&weston_event.base_event), TLP_END); weston_pointer_axis_event_init(&weston_event, WL_POINTER_AXIS_HORIZONTAL_SCROLL, horiz, (horiz_discrete != 0), horiz_discrete); notify_axis(device->seat, &weston_event); @@ -482,6 +495,9 @@ handle_touch_with_coords(struct libinput_device *libinput_device, weston_input_event_init(&event.base_event, &time, seat); weston_touch_event_init(&event, touch_type, touch_id, &pos); + TL_POINT(device->seat->compositor, TLP_INPUT_KERNEL_TS, + TLP_INPUT_EVENT(&event.base_event), TLP_END); + 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); @@ -525,6 +541,8 @@ handle_touch_up(struct libinput_device *libinput_device, weston_input_event_init(&event.base_event, &time, seat); weston_touch_event_init(&event, WL_TOUCH_UP, libinput_event_touch_get_seat_slot(touch_event), NULL); + TL_POINT(device->seat->compositor, TLP_INPUT_KERNEL_TS, + TLP_INPUT_EVENT(&event.base_event), TLP_END); notify_touch(device->touch_device, &event); } From cdbbc6129e7b3d52e95614f0622af664cc7a2958 Mon Sep 17 00:00:00 2001 From: Marius Vlad Date: Mon, 27 Apr 2026 13:43:14 +0300 Subject: [PATCH 9/9] input: Embed TL_POINT at weston_input_event initialization And with it, this starts tracking input events on the ingress side, having always a distinct input event and with a Perfetto flow id. On the egress side, Weston would then use this flow id to associate with the input event. Signed-off-by: Marius Vlad --- libweston/input.c | 3 +++ libweston/libinput-device.c | 18 ------------------ 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/libweston/input.c b/libweston/input.c index 244253101..ec3781ec8 100644 --- a/libweston/input.c +++ b/libweston/input.c @@ -52,6 +52,7 @@ #include "pointer-constraints-unstable-v1-server-protocol.h" #include "input-timestamps-unstable-v1-server-protocol.h" #include "tablet-unstable-v2-server-protocol.h" +#include "timeline.h" enum pointer_constraint_type { POINTER_CONSTRAINT_TYPE_LOCK, @@ -5978,6 +5979,8 @@ weston_input_event_init(struct weston_input_event *ievent, struct timespec *ts, { ievent->ts = ts; ievent->seat = seat; + + TL_POINT(seat->compositor, TLP_INPUT_KERNEL_TS, TLP_INPUT_EVENT(ievent), TLP_END); } WL_EXPORT void diff --git a/libweston/libinput-device.c b/libweston/libinput-device.c index 4fb1d0341..d42991404 100644 --- a/libweston/libinput-device.c +++ b/libweston/libinput-device.c @@ -44,7 +44,6 @@ #include "libinput-device.h" #include "shared/helpers.h" #include "shared/timespec-util.h" -#include "timeline.h" #include "tablet-unstable-v2-server-protocol.h" @@ -112,8 +111,6 @@ handle_keyboard_key(struct libinput_device *libinput_device, timespec_from_usec(&time, libinput_event_keyboard_get_time_usec(keyboard_event)); weston_input_event_init(&key_event.base_event, &time, device->seat); - TL_POINT(device->seat->compositor, TLP_INPUT_KERNEL_TS, - TLP_INPUT_EVENT(&key_event.base_event), TLP_END); weston_key_event_init(&key_event, key, key_state, STATE_UPDATE_AUTOMATIC); notify_key(device->seat, &key_event); @@ -144,8 +141,6 @@ handle_pointer_motion(struct libinput_device *libinput_device, weston_input_event_init(&event.base_event, &time, device->seat); weston_pointer_motion_event_init(&event, WESTON_POINTER_MOTION_REL | WESTON_POINTER_MOTION_REL_UNACCEL, NULL, &rel, &rel_unaccel); - TL_POINT(device->seat->compositor, TLP_INPUT_KERNEL_TS, - TLP_INPUT_EVENT(&event.base_event), TLP_END); notify_motion(device->seat, &event); return true; @@ -181,8 +176,6 @@ handle_pointer_motion_absolute( height); pos = weston_coord_global_from_output_point(x, y, output); weston_input_event_init(&event.base_event, &time, device->seat); - TL_POINT(device->seat->compositor, TLP_INPUT_KERNEL_TS, - TLP_INPUT_EVENT(&event.base_event), TLP_END); weston_pointer_motion_event_init(&event, WESTON_POINTER_MOTION_ABS, &pos, NULL, NULL); notify_motion(device->seat, &event); @@ -216,8 +209,6 @@ handle_pointer_button(struct libinput_device *libinput_device, libinput_event_pointer_get_time_usec(pointer_event)); weston_input_event_init(&button_event.base_event, &time, device->seat); - TL_POINT(device->seat->compositor, TLP_INPUT_KERNEL_TS, - TLP_INPUT_EVENT(&button_event.base_event), TLP_END); weston_pointer_button_event_init(&button_event, libinput_event_pointer_get_button(pointer_event), button_state); @@ -325,8 +316,6 @@ handle_pointer_axis(struct libinput_device *libinput_device, vert = normalize_scroll(pointer_event, axis); weston_input_event_init(&weston_event.base_event, &time, device->seat); - TL_POINT(device->seat->compositor, TLP_INPUT_KERNEL_TS, - TLP_INPUT_EVENT(&weston_event.base_event), TLP_END); weston_pointer_axis_event_init(&weston_event, WL_POINTER_AXIS_VERTICAL_SCROLL, vert, (vert_discrete != 0), vert_discrete); notify_axis(device->seat, &weston_event); @@ -338,8 +327,6 @@ handle_pointer_axis(struct libinput_device *libinput_device, horiz = normalize_scroll(pointer_event, axis); weston_input_event_init(&weston_event.base_event, &time, device->seat); - TL_POINT(device->seat->compositor, TLP_INPUT_KERNEL_TS, - TLP_INPUT_EVENT(&weston_event.base_event), TLP_END); weston_pointer_axis_event_init(&weston_event, WL_POINTER_AXIS_HORIZONTAL_SCROLL, horiz, (horiz_discrete != 0), horiz_discrete); notify_axis(device->seat, &weston_event); @@ -495,9 +482,6 @@ handle_touch_with_coords(struct libinput_device *libinput_device, weston_input_event_init(&event.base_event, &time, seat); weston_touch_event_init(&event, touch_type, touch_id, &pos); - TL_POINT(device->seat->compositor, TLP_INPUT_KERNEL_TS, - TLP_INPUT_EVENT(&event.base_event), TLP_END); - 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); @@ -541,8 +525,6 @@ handle_touch_up(struct libinput_device *libinput_device, weston_input_event_init(&event.base_event, &time, seat); weston_touch_event_init(&event, WL_TOUCH_UP, libinput_event_touch_get_seat_slot(touch_event), NULL); - TL_POINT(device->seat->compositor, TLP_INPUT_KERNEL_TS, - TLP_INPUT_EVENT(&event.base_event), TLP_END); notify_touch(device->touch_device, &event); }