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 helper

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
This commit is contained in:
Marius Vlad 2026-04-02 16:10:32 +03:00
parent 754d00e400
commit f9c1a4bf5d
14 changed files with 146 additions and 101 deletions

View file

@ -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);

View file

@ -605,7 +605,14 @@ 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 weston_coord_global abs;
struct weston_coord rel;
@ -619,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;
@ -637,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);
@ -966,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
@ -1002,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_pointer_move_to(struct weston_pointer *pointer,
struct weston_coord_global pos);
@ -1032,6 +1031,14 @@ weston_key_event_init(struct weston_key_event *event, struct timespec *ts,
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,
struct timespec *ts, struct weston_seat *seat,
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,

View file

@ -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;

View file

@ -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);

View file

@ -1282,9 +1282,16 @@ 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_pointer_motion_event_init(&event, &time,
peerContext->item.seat,
WESTON_POINTER_MOTION_ABS,
&pos, NULL, NULL);
notify_motion_absolute(&event);
return TRUE;
}
return FALSE;
@ -1515,9 +1522,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_pointer_motion_event_init(&event, &time, peerContext->item.seat,
WESTON_POINTER_MOTION_ABS,
&pos, NULL, NULL);
notify_motion_absolute(&event);
need_frame = true;
}

View file

@ -448,9 +448,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_pointer_motion_event_init(&event, &time, peer->seat,
WESTON_POINTER_MOTION_ABS,
&pos, NULL, NULL);
notify_motion_absolute(&event);
}
changed_button_mask = peer->last_button_mask ^ button_mask;

View file

@ -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_pointer_motion_event_init(&event, &ts, &input->base,
WESTON_POINTER_MOTION_ABS,
&pos, NULL, NULL);
notify_motion_absolute(&event);
want_frame = true;
}

View file

@ -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_pointer_motion_event_init(&motion_event, &time, &b->core_seat,
WESTON_POINTER_MOTION_REL,
NULL, &rel, NULL);
notify_motion(&motion_event);
notify_pointer_frame(&b->core_seat);
b->prev_pos = pos;

View file

@ -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(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(const struct weston_pointer_motion_event *event);
void
notify_modifiers(struct weston_seat *seat, uint32_t serial);

View file

@ -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);

View file

@ -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

View file

@ -41,6 +41,7 @@
#include <linux/input.h>
#include "shared/helpers.h"
#include "shared/weston-assert.h"
#include "shared/os-compatibility.h"
#include "shared/timespec-util.h"
#include <libweston/libweston.h>
@ -304,7 +305,7 @@ 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;
@ -322,7 +323,7 @@ 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)
{
@ -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,7 +573,7 @@ pointer_send_relative_motion(struct weston_pointer *pointer,
return;
resource_list = &pointer->focus_client->relative_pointer_resources;
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(
@ -589,7 +589,7 @@ pointer_send_relative_motion(struct weston_pointer *pointer,
static void
pointer_send_motion(struct weston_pointer *pointer,
const struct timespec *time,
const struct timespec *ts,
wl_fixed_t sx, wl_fixed_t sy)
{
struct wl_list *resource_list;
@ -600,19 +600,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(ts);
wl_resource_for_each(resource, resource_list) {
send_timestamps_for_input_resource(resource,
&pointer->timestamps_list,
time);
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;
@ -620,7 +619,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;
@ -640,19 +639,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, &event->base.ts, pointer->sx, pointer->sy);
}
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.
@ -2241,15 +2238,14 @@ 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)
notify_motion(const struct weston_pointer_motion_event *event)
{
struct weston_seat *seat = event->base.seat;
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
@ -2289,20 +2285,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(const struct weston_pointer_motion_event *event)
{
struct weston_seat *seat = event->base.seat;
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
@ -4733,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
@ -5537,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;
@ -5704,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);
@ -5736,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, &event->base.ts, pointer->sx, pointer->sy);
}
pointer_send_relative_motion(pointer, time, event);
pointer_send_relative_motion(pointer, event);
}
static void
@ -6048,3 +6035,32 @@ weston_key_event_init(struct weston_key_event *event, struct timespec *ts,
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,
struct timespec *ts, struct weston_seat *seat,
uint32_t mask,
const struct weston_coord_global *abs,
const struct weston_coord *rel,
const struct weston_coord *rel_unaccel)
{
weston_input_event_init(&event->base, ts, seat);
if (mask & WESTON_POINTER_MOTION_ABS) {
weston_assert_ptr_not_null(event->base.seat->compositor, abs);
event->abs = *abs;
}
if (mask & WESTON_POINTER_MOTION_REL) {
weston_assert_ptr_not_null(event->base.seat->compositor, rel);
event->rel = *rel;
}
if (mask & WESTON_POINTER_MOTION_REL_UNACCEL) {
weston_assert_ptr_not_null(event->base.seat->compositor, rel_unaccel);
event->rel_unaccel = *rel_unaccel;
}
event->mask = mask;
}

View file

@ -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,14 +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,
};
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_pointer_motion_event_init(&event, &time, device->seat,
WESTON_POINTER_MOTION_REL | WESTON_POINTER_MOTION_REL_UNACCEL,
NULL, &rel, &rel_unaccel);
notify_motion(&event);
return true;
}
@ -155,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;
@ -173,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_pointer_motion_event_init(&event, &time, device->seat,
WESTON_POINTER_MOTION_ABS,
&pos, NULL, NULL);
notify_motion_absolute(&event);
return true;
}

View file

@ -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_pointer_motion_event_init(&event, &time, seat,
WESTON_POINTER_MOTION_REL,
NULL, &rel, NULL);
notify_motion(&event);
notify_pointer_position(test, resource);
}