From 08dbbd4f06c11607ce971c908bbac1238af98d72 Mon Sep 17 00:00:00 2001 From: Marius Vlad Date: Thu, 2 Apr 2026 16:10:32 +0300 Subject: [PATCH] input: Re-work weston_pointer_motion_event This adapts weston_pointer_motion_event struct to align in with weston_key_event and includes the following changes: - include base struct - remove the const struct timespec from calls and use the base struct - pass by a const pointer motion event in all the callers - add init / reset functions Signed-off-by: Marius Vlad --- desktop-shell/shell.c | 12 +-- include/libweston/libweston.h | 37 ++++++---- ivi-shell/hmi-controller.c | 3 +- kiosk-shell/kiosk-shell-grab.c | 3 +- libweston/backend-rdp/rdp.c | 16 +++- libweston/backend-vnc/vnc.c | 7 +- libweston/backend-wayland/wayland.c | 7 +- libweston/backend-x11/x11.c | 14 ++-- libweston/backend.h | 8 +- libweston/compositor.c | 4 +- libweston/data-device.c | 5 +- libweston/desktop/seat.c | 5 +- libweston/input.c | 109 +++++++++++++++------------- libweston/libinput-device.c | 26 ++++--- tests/harness/weston-test.c | 14 ++-- 15 files changed, 153 insertions(+), 117 deletions(-) diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c index df34b5441..568345bfd 100644 --- a/desktop-shell/shell.c +++ b/desktop-shell/shell.c @@ -911,8 +911,7 @@ constrain_position(struct weston_move_grab *move) static void move_grab_motion(struct weston_pointer_grab *grab, - const struct timespec *time, - struct weston_pointer_motion_event *event) + const struct weston_pointer_motion_event *event) { struct weston_move_grab *move = (struct weston_move_grab *) grab; struct weston_pointer *pointer = grab->pointer; @@ -1141,8 +1140,7 @@ surface_tablet_tool_move(struct shell_surface *shsurf, struct weston_tablet_tool static void resize_grab_motion(struct weston_pointer_grab *grab, - const struct timespec *time, - struct weston_pointer_motion_event *event) + const struct weston_pointer_motion_event *event) { struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; struct weston_pointer *pointer = grab->pointer; @@ -1311,8 +1309,7 @@ busy_cursor_grab_focus(struct weston_pointer_grab *base) static void busy_cursor_grab_motion(struct weston_pointer_grab *grab, - const struct timespec *time, - struct weston_pointer_motion_event *event) + const struct weston_pointer_motion_event *event) { weston_pointer_move(grab->pointer, event); } @@ -3220,8 +3217,7 @@ terminate_binding(struct weston_keyboard *keyboard, const struct timespec *time, static void rotate_grab_motion(struct weston_pointer_grab *grab, - const struct timespec *time, - struct weston_pointer_motion_event *event) + const struct weston_pointer_motion_event *event) { struct rotate_grab *rotate = container_of(grab, struct rotate_grab, base.grab); diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h index cdd9cf285..5f686b430 100644 --- a/include/libweston/libweston.h +++ b/include/libweston/libweston.h @@ -605,12 +605,18 @@ enum weston_pointer_motion_mask { WESTON_POINTER_MOTION_REL_UNACCEL = 1 << 2, }; +/* base/common struct which all weston_xxx_event should "inherit" */ +struct weston_input_event { + struct timespec ts; + struct weston_seat *seat; +}; + struct weston_pointer_motion_event { + struct weston_input_event base; uint32_t mask; - struct timespec time; - struct weston_coord_global abs; - struct weston_coord rel; - struct weston_coord rel_unaccel; + const struct weston_coord_global *abs; + const struct weston_coord *rel; + const struct weston_coord *rel_unaccel; }; struct weston_pointer_axis_event { @@ -620,12 +626,6 @@ struct weston_pointer_axis_event { int32_t discrete; }; -/* base/common struct which all weston_xxx_event should "inherit" */ -struct weston_input_event { - struct timespec ts; - struct weston_seat *seat; -}; - struct weston_key_event { struct weston_input_event base; uint32_t key; @@ -638,8 +638,7 @@ struct weston_pointer_grab; struct weston_pointer_grab_interface { void (*focus)(struct weston_pointer_grab *grab); void (*motion)(struct weston_pointer_grab *grab, - const struct timespec *time, - struct weston_pointer_motion_event *event); + const struct weston_pointer_motion_event *event); void (*button)(struct weston_pointer_grab *grab, const struct timespec *time, uint32_t button, uint32_t state); @@ -967,12 +966,11 @@ struct weston_color_representation_matrix { struct weston_coord_global weston_pointer_motion_to_abs(struct weston_pointer *pointer, - struct weston_pointer_motion_event *event); + const struct weston_pointer_motion_event *event); void weston_pointer_send_motion(struct weston_pointer *pointer, - const struct timespec *time, - struct weston_pointer_motion_event *event); + const struct weston_pointer_motion_event *event); bool weston_pointer_has_focus_resource(struct weston_pointer *pointer); void @@ -1003,7 +1001,7 @@ void weston_pointer_end_grab(struct weston_pointer *pointer); void weston_pointer_move(struct weston_pointer *pointer, - struct weston_pointer_motion_event *event); + const struct weston_pointer_motion_event *event); void weston_keyboard_set_focus(struct weston_keyboard *keyboard, struct weston_surface *surface); @@ -1032,6 +1030,13 @@ weston_key_event_init(struct weston_key_event *event, uint32_t key, enum wl_keyboard_key_state key_state, enum weston_key_state_update key_update_state); +void +weston_pointer_motion_event_init(struct weston_pointer_motion_event *event, + uint32_t mask, + const struct weston_coord_global *abs, + const struct weston_coord *rel, + const struct weston_coord *rel_unaccel); + void weston_keyboard_send_modifiers(struct weston_keyboard *keyboard, uint32_t serial, uint32_t mods_depressed, diff --git a/ivi-shell/hmi-controller.c b/ivi-shell/hmi-controller.c index 0bbfa2c6e..295da77fa 100644 --- a/ivi-shell/hmi-controller.c +++ b/ivi-shell/hmi-controller.c @@ -1713,8 +1713,7 @@ layer_set_pos(struct hmi_controller *hmi_ctrl, struct ivi_layout_layer *layer, static void pointer_move_grab_motion(struct weston_pointer_grab *grab, - const struct timespec *time, - struct weston_pointer_motion_event *event) + const struct weston_pointer_motion_event *event) { struct pointer_move_grab *pnt_move_grab = (struct pointer_move_grab *)grab; diff --git a/kiosk-shell/kiosk-shell-grab.c b/kiosk-shell/kiosk-shell-grab.c index bff706fb3..24b0750c2 100644 --- a/kiosk-shell/kiosk-shell-grab.c +++ b/kiosk-shell/kiosk-shell-grab.c @@ -68,8 +68,7 @@ pointer_move_grab_frame(struct weston_pointer_grab *grab) static void pointer_move_grab_motion(struct weston_pointer_grab *pointer_grab, - const struct timespec *time, - struct weston_pointer_motion_event *event) + const struct weston_pointer_motion_event *event) { struct kiosk_shell_grab *shgrab = container_of(pointer_grab, struct kiosk_shell_grab, pointer_grab); diff --git a/libweston/backend-rdp/rdp.c b/libweston/backend-rdp/rdp.c index 8580a1b88..3e6e97bf4 100644 --- a/libweston/backend-rdp/rdp.c +++ b/libweston/backend-rdp/rdp.c @@ -1282,9 +1282,15 @@ rdp_translate_and_notify_mouse_position(RdpPeerContext *peerContext, UINT16 x, U different scaling. In such case, hit test to that window area on non primary-resident monitor (surface->output) dosn't work. */ if (to_weston_coordinate(peerContext, &sx, &sy)) { + struct weston_pointer_motion_event event; + pos.c = weston_coord(sx, sy); weston_compositor_get_time(&time); - notify_motion_absolute(peerContext->item.seat, &time, pos); + + weston_input_event_init(&event.base, &time, peerContext->item.seat); + weston_pointer_motion_event_init(&event, WESTON_POINTER_MOTION_ABS, + &pos, NULL, NULL); + notify_motion_absolute(peerContext->item.seat, &event); return TRUE; } return FALSE; @@ -1515,9 +1521,15 @@ xf_extendedMouseEvent(rdpInput *input, UINT16 flags, UINT16 x, UINT16 y) output = rdp_get_first_output(peerContext->rdpBackend); if (x < output->base.width && y < output->base.height) { + struct weston_pointer_motion_event event; + weston_compositor_get_time(&time); pos.c = weston_coord(x, y); - notify_motion_absolute(peerContext->item.seat, &time, pos); + + weston_input_event_init(&event.base, &time, peerContext->item.seat); + weston_pointer_motion_event_init(&event, WESTON_POINTER_MOTION_ABS, + &pos, NULL, NULL); + notify_motion_absolute(peerContext->item.seat, &event); need_frame = true; } diff --git a/libweston/backend-vnc/vnc.c b/libweston/backend-vnc/vnc.c index a632260a2..c400c2140 100644 --- a/libweston/backend-vnc/vnc.c +++ b/libweston/backend-vnc/vnc.c @@ -447,9 +447,14 @@ vnc_pointer_event(struct nvnc_client *client, uint16_t x, uint16_t y, if (x < output->base.width && y < output->base.height) { struct weston_coord_global pos; + struct weston_pointer_motion_event event; pos = weston_coord_global_from_output_point(x, y, &output->base); - notify_motion_absolute(peer->seat, &time, pos); + + weston_input_event_init(&event.base, &time, peer->seat); + weston_pointer_motion_event_init(&event, WESTON_POINTER_MOTION_ABS, + &pos, NULL, NULL); + notify_motion_absolute(peer->seat, &event); } changed_button_mask = peer->last_button_mask ^ button_mask; diff --git a/libweston/backend-wayland/wayland.c b/libweston/backend-wayland/wayland.c index e31ecd70b..c28e8c618 100644 --- a/libweston/backend-wayland/wayland.c +++ b/libweston/backend-wayland/wayland.c @@ -1677,6 +1677,7 @@ input_handle_motion(void *data, struct wl_pointer *pointer, bool want_frame = false; double x, y; struct weston_coord_global pos; + struct weston_pointer_motion_event event; struct timespec ts; if (!input->output) @@ -1717,7 +1718,11 @@ input_handle_motion(void *data, struct wl_pointer *pointer, if (location == THEME_LOCATION_CLIENT_AREA) { timespec_from_msec(&ts, time); - notify_motion_absolute(&input->base, &ts, pos); + + weston_input_event_init(&event.base, &ts, &input->base); + weston_pointer_motion_event_init(&event, WESTON_POINTER_MOTION_ABS, + &pos, NULL, NULL); + notify_motion_absolute(&input->base, &event); want_frame = true; } diff --git a/libweston/backend-x11/x11.c b/libweston/backend-x11/x11.c index 7a6ed9557..3795a1c0f 100644 --- a/libweston/backend-x11/x11.c +++ b/libweston/backend-x11/x11.c @@ -1520,7 +1520,8 @@ x11_backend_deliver_motion_event(struct x11_backend *b, { struct x11_output *output; struct weston_coord_global pos; - struct weston_pointer_motion_event motion_event = { 0 }; + struct weston_pointer_motion_event motion_event; + struct weston_coord rel; xcb_motion_notify_event_t *motion_notify = (xcb_motion_notify_event_t *) event; struct timespec time; @@ -1535,12 +1536,13 @@ x11_backend_deliver_motion_event(struct x11_backend *b, motion_notify->event_y, &output->base); - motion_event = (struct weston_pointer_motion_event) { - .mask = WESTON_POINTER_MOTION_REL, - .rel = weston_coord_global_sub(pos, b->prev_pos).c, - }; + rel = weston_coord_global_sub(pos, b->prev_pos).c; weston_compositor_get_time(&time); - notify_motion(&b->core_seat, &time, &motion_event); + + weston_input_event_init(&motion_event.base, &time, &b->core_seat); + weston_pointer_motion_event_init(&motion_event, WESTON_POINTER_MOTION_REL, + NULL, &rel, NULL); + notify_motion(&b->core_seat, &motion_event); notify_pointer_frame(&b->core_seat); b->prev_pos = pos; diff --git a/libweston/backend.h b/libweston/backend.h index ea232af7d..8442e9325 100644 --- a/libweston/backend.h +++ b/libweston/backend.h @@ -251,11 +251,11 @@ void notify_keyboard_focus_out(struct weston_seat *seat); void -notify_motion(struct weston_seat *seat, const struct timespec *time, - struct weston_pointer_motion_event *event); +notify_motion(struct weston_seat *seat, const struct weston_pointer_motion_event *event); + void -notify_motion_absolute(struct weston_seat *seat, const struct timespec *time, - struct weston_coord_global pos); +notify_motion_absolute(struct weston_seat *seat, const struct weston_pointer_motion_event *event); + void notify_modifiers(struct weston_seat *seat, uint32_t serial); diff --git a/libweston/compositor.c b/libweston/compositor.c index 8259f9795..cc0ba27f7 100644 --- a/libweston/compositor.c +++ b/libweston/compositor.c @@ -8012,6 +8012,7 @@ weston_output_set_transform(struct weston_output *output, uint32_t transform) { struct weston_pointer_motion_event ev; + struct weston_coord_global pos; struct wl_resource *resource; struct weston_seat *seat; pixman_region32_t old_region; @@ -8067,7 +8068,8 @@ weston_output_set_transform(struct weston_output *output, mid_y = output->pos.c.y + output->height / 2; ev.mask = WESTON_POINTER_MOTION_ABS; - ev.abs.c = weston_coord(mid_x, mid_y); + pos.c = weston_coord(mid_x, mid_y); + ev.abs = &pos; wl_list_for_each(seat, &output->compositor->seat_list, link) { struct weston_pointer *pointer = weston_seat_get_pointer(seat); diff --git a/libweston/data-device.c b/libweston/data-device.c index cb899b642..a5eec6cb0 100644 --- a/libweston/data-device.c +++ b/libweston/data-device.c @@ -591,8 +591,7 @@ drag_grab_focus(struct weston_pointer_grab *grab) static void drag_grab_motion(struct weston_pointer_grab *grab, - const struct timespec *time, - struct weston_pointer_motion_event *event) + const struct weston_pointer_motion_event *event) { struct weston_pointer_drag *drag = container_of(grab, struct weston_pointer_drag, grab); @@ -610,7 +609,7 @@ drag_grab_motion(struct weston_pointer_grab *grab, if (drag->base.focus_resource) { struct weston_coord_surface surf_pos; - msecs = timespec_to_msec(time); + msecs = timespec_to_msec(&event->base.ts); surf_pos = weston_coord_global_to_surface(drag->base.focus, pointer->pos); diff --git a/libweston/desktop/seat.c b/libweston/desktop/seat.c index 7886d5000..b681e12c2 100644 --- a/libweston/desktop/seat.c +++ b/libweston/desktop/seat.c @@ -117,10 +117,9 @@ weston_desktop_seat_popup_grab_pointer_focus(struct weston_pointer_grab *grab) static void weston_desktop_seat_popup_grab_pointer_motion(struct weston_pointer_grab *grab, - const struct timespec *time, - struct weston_pointer_motion_event *event) + const struct weston_pointer_motion_event *event) { - weston_pointer_send_motion(grab->pointer, time, event); + weston_pointer_send_motion(grab->pointer, event); } static void diff --git a/libweston/input.c b/libweston/input.c index 46bdd231f..c20a4c0ea 100644 --- a/libweston/input.c +++ b/libweston/input.c @@ -41,6 +41,7 @@ #include #include "shared/helpers.h" +#include "shared/weston-assert.h" #include "shared/os-compatibility.h" #include "shared/timespec-util.h" #include @@ -304,14 +305,14 @@ static void unbind_resource(struct wl_resource *resource) WL_EXPORT struct weston_coord_global weston_pointer_motion_to_abs(struct weston_pointer *pointer, - struct weston_pointer_motion_event *event) + const struct weston_pointer_motion_event *event) { struct weston_coord_global pos; if (event->mask & WESTON_POINTER_MOTION_ABS) { - return event->abs; + return *event->abs; } else if (event->mask & WESTON_POINTER_MOTION_REL) { - pos.c = weston_coord_add(pointer->pos.c, event->rel); + pos.c = weston_coord_add(pointer->pos.c, *event->rel); return pos; } @@ -322,22 +323,22 @@ weston_pointer_motion_to_abs(struct weston_pointer *pointer, static bool weston_pointer_motion_to_rel(struct weston_pointer *pointer, - struct weston_pointer_motion_event *event, + const struct weston_pointer_motion_event *event, struct weston_coord *rel, struct weston_coord *rel_unaccel) { if (event->mask & WESTON_POINTER_MOTION_REL && event->mask & WESTON_POINTER_MOTION_REL_UNACCEL) { - *rel = event->rel; - *rel_unaccel = event->rel_unaccel; + *rel = *event->rel; + *rel_unaccel = *event->rel_unaccel; return true; } else if (event->mask & WESTON_POINTER_MOTION_REL) { - *rel = event->rel; - *rel_unaccel = event->rel; + *rel = *event->rel; + *rel_unaccel = *event->rel; return true; } else if (event->mask & WESTON_POINTER_MOTION_REL_UNACCEL) { - *rel = event->rel_unaccel; - *rel_unaccel = event->rel_unaccel; + *rel = *event->rel_unaccel; + *rel_unaccel = *event->rel_unaccel; return true; } else { return false; @@ -546,7 +547,7 @@ weston_pointer_move_to(struct weston_pointer *pointer, WL_EXPORT void weston_pointer_move(struct weston_pointer *pointer, - struct weston_pointer_motion_event *event) + const struct weston_pointer_motion_event *event) { struct weston_coord_global pos; @@ -556,8 +557,7 @@ weston_pointer_move(struct weston_pointer *pointer, static void pointer_send_relative_motion(struct weston_pointer *pointer, - const struct timespec *time, - struct weston_pointer_motion_event *event) + const struct weston_pointer_motion_event *event) { uint64_t time_usec; struct weston_coord rel, rel_unaccel; @@ -573,9 +573,9 @@ pointer_send_relative_motion(struct weston_pointer *pointer, return; resource_list = &pointer->focus_client->relative_pointer_resources; - time_usec = timespec_to_usec(&event->time); + time_usec = timespec_to_usec(&event->base.ts); if (time_usec == 0) - time_usec = timespec_to_usec(time); + time_usec = timespec_to_usec(&event->base.ts); wl_resource_for_each(resource, resource_list) { zwp_relative_pointer_v1_send_relative_motion( @@ -590,9 +590,8 @@ pointer_send_relative_motion(struct weston_pointer *pointer, } static void -pointer_send_motion(struct weston_pointer *pointer, - const struct timespec *time, - wl_fixed_t sx, wl_fixed_t sy) +pointer_send_motion(struct weston_pointer *pointer, wl_fixed_t sx, wl_fixed_t sy, + const struct weston_pointer_motion_event *event) { struct wl_list *resource_list; struct wl_resource *resource; @@ -602,19 +601,18 @@ pointer_send_motion(struct weston_pointer *pointer, return; resource_list = &pointer->focus_client->pointer_resources; - msecs = timespec_to_msec(time); + msecs = timespec_to_msec(&event->base.ts); wl_resource_for_each(resource, resource_list) { send_timestamps_for_input_resource(resource, &pointer->timestamps_list, - time); + &event->base.ts); wl_pointer_send_motion(resource, msecs, sx, sy); } } WL_EXPORT void weston_pointer_send_motion(struct weston_pointer *pointer, - const struct timespec *time, - struct weston_pointer_motion_event *event) + const struct weston_pointer_motion_event *event) { wl_fixed_t old_sx; wl_fixed_t old_sy; @@ -622,7 +620,7 @@ weston_pointer_send_motion(struct weston_pointer *pointer, struct weston_coord_global pos; pos = weston_pointer_motion_to_abs(pointer, event); - pos = weston_pointer_clamp(pointer,pos); + pos = weston_pointer_clamp(pointer, pos); if (pointer->focus) { struct weston_coord_surface surf_pos; @@ -642,19 +640,17 @@ weston_pointer_send_motion(struct weston_pointer *pointer, if (pointer->focus && old_focus == pointer->focus && (old_sx != pointer->sx || old_sy != pointer->sy)) { - pointer_send_motion(pointer, time, - pointer->sx, pointer->sy); + pointer_send_motion(pointer, pointer->sx, pointer->sy, event); } - pointer_send_relative_motion(pointer, time, event); + pointer_send_relative_motion(pointer, event); } static void default_grab_pointer_motion(struct weston_pointer_grab *grab, - const struct timespec *time, - struct weston_pointer_motion_event *event) + const struct weston_pointer_motion_event *event) { - weston_pointer_send_motion(grab->pointer, time, event); + weston_pointer_send_motion(grab->pointer, event); } /** Check if the pointer has focused resources. @@ -2244,14 +2240,13 @@ weston_pointer_handle_output_destroy(struct wl_listener *listener, void *data) WL_EXPORT void notify_motion(struct weston_seat *seat, - const struct timespec *time, - struct weston_pointer_motion_event *event) + const struct weston_pointer_motion_event *event) { struct weston_compositor *ec = seat->compositor; struct weston_pointer *pointer = weston_seat_get_pointer(seat); weston_compositor_wake(ec); - pointer->grab->interface->motion(pointer->grab, time, event); + pointer->grab->interface->motion(pointer->grab, event); } static void @@ -2291,20 +2286,14 @@ run_modifier_bindings(struct weston_seat *seat, uint32_t old, uint32_t new) } WL_EXPORT void -notify_motion_absolute(struct weston_seat *seat, const struct timespec *time, - struct weston_coord_global pos) +notify_motion_absolute(struct weston_seat *seat, + const struct weston_pointer_motion_event *event) { struct weston_compositor *ec = seat->compositor; struct weston_pointer *pointer = weston_seat_get_pointer(seat); - struct weston_pointer_motion_event event = { 0 }; weston_compositor_wake(ec); - - event = (struct weston_pointer_motion_event) { - .mask = WESTON_POINTER_MOTION_ABS, - .abs = pos, - }; - pointer->grab->interface->motion(pointer->grab, time, &event); + pointer->grab->interface->motion(pointer->grab, event); } static unsigned int @@ -4734,10 +4723,9 @@ locked_pointer_grab_pointer_focus(struct weston_pointer_grab *grab) static void locked_pointer_grab_pointer_motion(struct weston_pointer_grab *grab, - const struct timespec *time, - struct weston_pointer_motion_event *event) + const struct weston_pointer_motion_event *event) { - pointer_send_relative_motion(grab->pointer, time, event); + pointer_send_relative_motion(grab->pointer, event); } static void @@ -5538,7 +5526,7 @@ get_motion_directions(struct line *motion) static struct weston_coord_global weston_pointer_clamp_event_to_region(struct weston_pointer *pointer, - struct weston_pointer_motion_event *event, + const struct weston_pointer_motion_event *event, pixman_region32_t *region) { wl_fixed_t old_sx = pointer->sx; @@ -5705,8 +5693,7 @@ maybe_warp_confined_pointer(struct weston_pointer_constraint *constraint) static void confined_pointer_grab_pointer_motion(struct weston_pointer_grab *grab, - const struct timespec *time, - struct weston_pointer_motion_event *event) + const struct weston_pointer_motion_event *event) { struct weston_pointer_constraint *constraint = container_of(grab, struct weston_pointer_constraint, grab); @@ -5737,11 +5724,10 @@ confined_pointer_grab_pointer_motion(struct weston_pointer_grab *grab, pointer->sy = wl_fixed_from_double(surf_pos.c.y); if (old_sx != pointer->sx || old_sy != pointer->sy) { - pointer_send_motion(pointer, time, - pointer->sx, pointer->sy); + pointer_send_motion(pointer, pointer->sx, pointer->sy, event); } - pointer_send_relative_motion(pointer, time, event); + pointer_send_relative_motion(pointer, event); } static void @@ -6045,3 +6031,26 @@ weston_key_event_init(struct weston_key_event *event, uint32_t key, enum wl_keyb event->key_state = key_state; event->key_update_state = key_update_state; } + +WL_EXPORT void +weston_pointer_motion_event_init(struct weston_pointer_motion_event *event, + uint32_t mask, + const struct weston_coord_global *abs, + const struct weston_coord *rel, + const struct weston_coord *rel_unaccel) +{ + + if (mask & WESTON_POINTER_MOTION_ABS) + weston_assert_ptr_not_null(event->base.seat->compositor, abs); + + if (mask & WESTON_POINTER_MOTION_REL) + weston_assert_ptr_not_null(event->base.seat->compositor, rel); + + if (mask & WESTON_POINTER_MOTION_REL_UNACCEL) + weston_assert_ptr_not_null(event->base.seat->compositor, rel_unaccel); + + event->mask = mask; + event->abs = abs; + event->rel = rel; + event->rel_unaccel = rel_unaccel; +} diff --git a/libweston/libinput-device.c b/libweston/libinput-device.c index 948dc8711..945dde060 100644 --- a/libweston/libinput-device.c +++ b/libweston/libinput-device.c @@ -122,9 +122,10 @@ handle_pointer_motion(struct libinput_device *libinput_device, { struct evdev_device *device = libinput_device_get_user_data(libinput_device); - struct weston_pointer_motion_event event = { 0 }; + struct weston_pointer_motion_event event; struct timespec time; double dx_unaccel, dy_unaccel; + struct weston_coord rel, rel_unaccel; ensure_pointer_capability(libinput_device); @@ -133,15 +134,14 @@ handle_pointer_motion(struct libinput_device *libinput_device, dx_unaccel = libinput_event_pointer_get_dx_unaccelerated(pointer_event); dy_unaccel = libinput_event_pointer_get_dy_unaccelerated(pointer_event); - event = (struct weston_pointer_motion_event) { - .mask = WESTON_POINTER_MOTION_REL | - WESTON_POINTER_MOTION_REL_UNACCEL, - .time = time, - }; - event.rel = weston_coord(libinput_event_pointer_get_dx(pointer_event), - libinput_event_pointer_get_dy(pointer_event)); - event.rel_unaccel = weston_coord(dx_unaccel, dy_unaccel); - notify_motion(device->seat, &time, &event); + rel = weston_coord(libinput_event_pointer_get_dx(pointer_event), + libinput_event_pointer_get_dy(pointer_event)); + rel_unaccel = weston_coord(dx_unaccel, dy_unaccel); + + weston_input_event_init(&event.base, &time, device->seat); + weston_pointer_motion_event_init(&event, WESTON_POINTER_MOTION_REL | + WESTON_POINTER_MOTION_REL_UNACCEL, NULL, &rel, &rel_unaccel); + notify_motion(device->seat, &event); return true; } @@ -156,6 +156,7 @@ handle_pointer_motion_absolute( struct weston_output *output = device->output; struct weston_coord_global pos; struct timespec time; + struct weston_pointer_motion_event event; double x, y; uint32_t width, height; @@ -174,7 +175,10 @@ handle_pointer_motion_absolute( y = libinput_event_pointer_get_absolute_y_transformed(pointer_event, height); pos = weston_coord_global_from_output_point(x, y, output); - notify_motion_absolute(device->seat, &time, pos); + weston_input_event_init(&event.base, &time, device->seat); + weston_pointer_motion_event_init(&event, WESTON_POINTER_MOTION_ABS, + &pos, NULL, NULL); + notify_motion_absolute(device->seat, &event); return true; } diff --git a/tests/harness/weston-test.c b/tests/harness/weston-test.c index 6e4a97823..247097510 100644 --- a/tests/harness/weston-test.c +++ b/tests/harness/weston-test.c @@ -412,19 +412,19 @@ move_pointer(struct wl_client *client, struct wl_resource *resource, struct weston_test *test = wl_resource_get_user_data(resource); struct weston_seat *seat = get_seat(test); struct weston_pointer *pointer = weston_seat_get_pointer(seat); - struct weston_pointer_motion_event event = { 0 }; + struct weston_pointer_motion_event event; struct weston_coord_global pos; + struct weston_coord rel; struct timespec time; pos.c = weston_coord(x, y); - event = (struct weston_pointer_motion_event) { - .mask = WESTON_POINTER_MOTION_REL, - .rel = weston_coord_global_sub(pos, pointer->pos).c, - }; - timespec_from_proto(&time, tv_sec_hi, tv_sec_lo, tv_nsec); + rel = weston_coord_global_sub(pos, pointer->pos).c; - notify_motion(seat, &time, &event); + weston_input_event_init(&event.base, &time, seat); + weston_pointer_motion_event_init(&event, WESTON_POINTER_MOTION_REL, + NULL, &rel, NULL); + notify_motion(seat, &event); notify_pointer_position(test, resource); }