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 <marius.vlad@collabora.com>
This commit is contained in:
Marius Vlad 2026-04-17 17:36:13 +03:00
parent bb4e88ed36
commit 2aa32c214c
16 changed files with 113 additions and 111 deletions

View file

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

View file

@ -626,6 +626,7 @@ struct weston_pointer_button_event {
};
struct weston_pointer_axis_event {
struct weston_input_event base;
uint32_t axis;
double value;
bool has_discrete;
@ -648,8 +649,7 @@ struct weston_pointer_grab_interface {
void (*button)(struct weston_pointer_grab *grab,
const struct weston_pointer_button_event *button_event);
void (*axis)(struct weston_pointer_grab *grab,
const struct timespec *time,
struct weston_pointer_axis_event *event);
const struct weston_pointer_axis_event *event);
void (*axis_source)(struct weston_pointer_grab *grab, uint32_t source);
void (*frame)(struct weston_pointer_grab *grab);
void (*cancel)(struct weston_pointer_grab *grab);
@ -983,8 +983,7 @@ weston_pointer_send_button(struct weston_pointer *pointer,
const struct weston_pointer_button_event *button_event);
void
weston_pointer_send_axis(struct weston_pointer *pointer,
const struct timespec *time,
struct weston_pointer_axis_event *event);
const struct weston_pointer_axis_event *event);
void
weston_pointer_send_axis_source(struct weston_pointer *pointer,
enum wl_pointer_axis_source source);
@ -1044,6 +1043,11 @@ void
weston_pointer_button_event_init(struct weston_pointer_button_event *event,
uint32_t button, enum wl_pointer_button_state button_state);
void
weston_pointer_axis_event_init(struct weston_pointer_axis_event *event,
uint32_t axis, double value, bool has_value,
int32_t discrete);
void
weston_keyboard_send_modifiers(struct weston_keyboard *keyboard,
uint32_t serial, uint32_t mods_depressed,
@ -2328,7 +2332,7 @@ weston_compositor_add_tablet_tool_binding(struct weston_compositor *compositor,
typedef void (*weston_axis_binding_handler_t)(struct weston_pointer *pointer,
const struct timespec *time,
struct weston_pointer_axis_event *event,
const struct weston_pointer_axis_event *event,
void *data);
struct weston_binding *
weston_compositor_add_axis_binding(struct weston_compositor *compositor,

View file

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

View file

@ -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)
{
}

View file

@ -1363,7 +1363,6 @@ rdp_notify_wheel_scroll(RdpPeerContext *peerContext, UINT16 flags, uint32_t axis
struct weston_pointer_axis_event weston_event;
struct rdp_backend *b = peerContext->rdpBackend;
int ivalue;
double value;
struct timespec time;
int *accumWheelRotationPrecise;
int *accumWheelRotationDiscrete;
@ -1407,19 +1406,18 @@ rdp_notify_wheel_scroll(RdpPeerContext *peerContext, UINT16 flags, uint32_t axis
ivalue, *accumWheelRotationPrecise, *accumWheelRotationDiscrete);
if (abs(*accumWheelRotationPrecise) >= 12) {
value = (double)(*accumWheelRotationPrecise / 12);
weston_compositor_get_time(&time);
weston_event.axis = axis;
weston_event.value = value;
weston_event.discrete = *accumWheelRotationDiscrete / 120;
weston_event.has_discrete = true;
weston_input_event_init(&weston_event.base,
&time, peerContext->item.seat);
weston_pointer_axis_event_init(&weston_event, axis,
(double) *accumWheelRotationPrecise / 12,
true, *accumWheelRotationDiscrete / 120);
rdp_debug_verbose(b, "wheel: value:%f discrete:%d\n",
weston_event.value, weston_event.discrete);
weston_compositor_get_time(&time);
notify_axis(peerContext->item.seat, &time, &weston_event);
notify_axis(peerContext->item.seat, &weston_event);
*accumWheelRotationPrecise %= 12;
*accumWheelRotationDiscrete %= 120;

View file

@ -489,17 +489,19 @@ vnc_pointer_event(struct nvnc_client *client, uint16_t x, uint16_t y,
if ((button_mask & NVNC_SCROLL_UP) ||
(button_mask & NVNC_SCROLL_DOWN)) {
struct weston_pointer_axis_event weston_event;
weston_event.axis = WL_POINTER_AXIS_VERTICAL_SCROLL;
double value = 0;
/* DEFAULT_AXIS_STEP_DISTANCE is stolen from compositor-x11.c */
if (button_mask & NVNC_SCROLL_UP)
weston_event.value = -DEFAULT_AXIS_STEP_DISTANCE;
value = -DEFAULT_AXIS_STEP_DISTANCE;
if (button_mask & NVNC_SCROLL_DOWN)
weston_event.value = DEFAULT_AXIS_STEP_DISTANCE;
weston_event.has_discrete = false;
value = DEFAULT_AXIS_STEP_DISTANCE;
notify_axis(peer->seat, &time, &weston_event);
weston_input_event_init(&weston_event.base,
&time, peer->seat);
weston_pointer_axis_event_init(&weston_event, WL_POINTER_AXIS_VERTICAL_SCROLL,
value, false, 0);
notify_axis(peer->seat, &weston_event);
}
peer->last_button_mask = button_mask;

View file

@ -1799,26 +1799,27 @@ input_handle_axis(void *data, struct wl_pointer *pointer,
struct wayland_input *input = data;
struct weston_pointer_axis_event weston_event;
struct timespec ts;
weston_event.axis = axis;
weston_event.value = wl_fixed_to_double(value);
weston_event.has_discrete = false;
bool has_discrete = false;
int32_t discrete = 0;
if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL &&
input->vert.has_discrete) {
weston_event.has_discrete = true;
weston_event.discrete = input->vert.discrete;
has_discrete = true;
discrete = input->vert.discrete;
input->vert.has_discrete = false;
} else if (axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL &&
input->horiz.has_discrete) {
weston_event.has_discrete = true;
weston_event.discrete = input->horiz.discrete;
has_discrete = true;
discrete = input->horiz.discrete;
input->horiz.has_discrete = false;
}
timespec_from_msec(&ts, time);
notify_axis(&input->base, &ts, &weston_event);
weston_input_event_init(&weston_event.base, &ts, &input->base);
weston_pointer_axis_event_init(&weston_event, axis, wl_fixed_to_double(value),
has_discrete, discrete);
notify_axis(&input->base, &weston_event);
if (input->seat_version < WL_POINTER_FRAME_SINCE_VERSION)
notify_pointer_frame(&input->base);
@ -1849,12 +1850,11 @@ input_handle_axis_stop(void *data, struct wl_pointer *pointer,
struct weston_pointer_axis_event weston_event;
struct timespec ts;
weston_event.axis = axis;
weston_event.value = 0;
timespec_from_msec(&ts, time);
notify_axis(&input->base, &ts, &weston_event);
weston_input_event_init(&weston_event.base, &ts, &input->base);
weston_pointer_axis_event_init(&weston_event, axis, 0, false, 0);
notify_axis(&input->base, &weston_event);
}
static void

View file

@ -1456,49 +1456,53 @@ x11_backend_deliver_button_event(struct x11_backend *b,
/* Axis are measured in pixels, but the xcb events are discrete
* steps. Therefore move the axis by some pixels every step. */
if (is_button_pressed) {
weston_event.value = -DEFAULT_AXIS_STEP_DISTANCE;
weston_event.discrete = -1;
weston_event.has_discrete = true;
weston_event.axis =
WL_POINTER_AXIS_VERTICAL_SCROLL;
weston_compositor_get_time(&time);
notify_axis(&b->core_seat, &time, &weston_event);
weston_input_event_init(&weston_event.base,
&time, &b->core_seat);
weston_pointer_axis_event_init(&weston_event,
WL_POINTER_AXIS_VERTICAL_SCROLL,
-DEFAULT_AXIS_STEP_DISTANCE, true, -1);
notify_axis(&b->core_seat, &weston_event);
notify_pointer_frame(&b->core_seat);
}
return;
case 5:
if (is_button_pressed) {
weston_event.value = DEFAULT_AXIS_STEP_DISTANCE;
weston_event.discrete = 1;
weston_event.has_discrete = true;
weston_event.axis =
WL_POINTER_AXIS_VERTICAL_SCROLL;
weston_compositor_get_time(&time);
notify_axis(&b->core_seat, &time, &weston_event);
weston_input_event_init(&weston_event.base,
&time, &b->core_seat);
weston_pointer_axis_event_init(&weston_event,
WL_POINTER_AXIS_VERTICAL_SCROLL,
DEFAULT_AXIS_STEP_DISTANCE, true, 1);
notify_axis(&b->core_seat, &weston_event);
notify_pointer_frame(&b->core_seat);
}
return;
case 6:
if (is_button_pressed) {
weston_event.value = -DEFAULT_AXIS_STEP_DISTANCE;
weston_event.discrete = -1;
weston_event.has_discrete = true;
weston_event.axis =
WL_POINTER_AXIS_HORIZONTAL_SCROLL;
weston_compositor_get_time(&time);
notify_axis(&b->core_seat, &time, &weston_event);
weston_input_event_init(&weston_event.base,
&time, &b->core_seat);
weston_pointer_axis_event_init(&weston_event,
WL_POINTER_AXIS_HORIZONTAL_SCROLL,
-DEFAULT_AXIS_STEP_DISTANCE, true, -1);
notify_axis(&b->core_seat, &weston_event);
notify_pointer_frame(&b->core_seat);
}
return;
case 7:
if (is_button_pressed) {
weston_event.value = DEFAULT_AXIS_STEP_DISTANCE;
weston_event.discrete = 1;
weston_event.has_discrete = true;
weston_event.axis =
WL_POINTER_AXIS_HORIZONTAL_SCROLL;
weston_compositor_get_time(&time);
notify_axis(&b->core_seat, &time, &weston_event);
weston_input_event_init(&weston_event.base,
&time, &b->core_seat);
weston_pointer_axis_event_init(&weston_event,
WL_POINTER_AXIS_HORIZONTAL_SCROLL,
DEFAULT_AXIS_STEP_DISTANCE, true, 1);
notify_axis(&b->core_seat, &weston_event);
notify_pointer_frame(&b->core_seat);
}
return;

View file

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

View file

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

View file

@ -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)
{
}

View file

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

View file

@ -729,7 +729,6 @@ default_grab_pointer_button(struct weston_pointer_grab *grab,
/** Send wl_pointer.axis events to focused resources.
*
* \param pointer The pointer where the axis events originates from.
* \param time The timestamp of the event
* \param event The axis value of the event
*
* For every resource that is currently in focus, send a wl_pointer.axis event
@ -738,8 +737,7 @@ default_grab_pointer_button(struct weston_pointer_grab *grab,
*/
WL_EXPORT void
weston_pointer_send_axis(struct weston_pointer *pointer,
const struct timespec *time,
struct weston_pointer_axis_event *event)
const struct weston_pointer_axis_event *event)
{
struct wl_resource *resource;
struct wl_list *resource_list;
@ -749,7 +747,7 @@ weston_pointer_send_axis(struct weston_pointer *pointer,
return;
resource_list = &pointer->focus_client->pointer_resources;
msecs = timespec_to_msec(time);
msecs = timespec_to_msec(&event->base.ts);
wl_resource_for_each(resource, resource_list) {
if (event->has_discrete &&
wl_resource_get_version(resource) >=
@ -760,7 +758,7 @@ weston_pointer_send_axis(struct weston_pointer *pointer,
if (event->value) {
send_timestamps_for_input_resource(resource,
&pointer->timestamps_list,
time);
&event->base.ts);
wl_pointer_send_axis(resource, msecs,
event->axis,
wl_fixed_from_double(event->value));
@ -768,7 +766,7 @@ weston_pointer_send_axis(struct weston_pointer *pointer,
WL_POINTER_AXIS_STOP_SINCE_VERSION) {
send_timestamps_for_input_resource(resource,
&pointer->timestamps_list,
time);
&event->base.ts);
wl_pointer_send_axis_stop(resource, msecs,
event->axis);
}
@ -836,10 +834,9 @@ weston_pointer_send_frame(struct weston_pointer *pointer)
static void
default_grab_pointer_axis(struct weston_pointer_grab *grab,
const struct timespec *time,
struct weston_pointer_axis_event *event)
const struct weston_pointer_axis_event *event)
{
weston_pointer_send_axis(grab->pointer, time, event);
weston_pointer_send_axis(grab->pointer, event);
}
static void
@ -2354,19 +2351,17 @@ notify_button(struct weston_seat *seat, struct weston_pointer_button_event *even
}
WL_EXPORT void
notify_axis(struct weston_seat *seat, const struct timespec *time,
struct weston_pointer_axis_event *event)
notify_axis(struct weston_seat *seat, const struct weston_pointer_axis_event *event)
{
struct weston_compositor *compositor = seat->compositor;
struct weston_pointer *pointer = weston_seat_get_pointer(seat);
weston_compositor_wake(compositor);
if (weston_compositor_run_axis_binding(compositor, pointer,
time, event))
if (weston_compositor_run_axis_binding(compositor, pointer, &event->base.ts, event))
return;
pointer->grab->interface->axis(pointer->grab, time, event);
pointer->grab->interface->axis(pointer->grab, event);
}
WL_EXPORT void
@ -4725,10 +4720,9 @@ locked_pointer_grab_pointer_button(struct weston_pointer_grab *grab,
static void
locked_pointer_grab_pointer_axis(struct weston_pointer_grab *grab,
const struct timespec *time,
struct weston_pointer_axis_event *event)
const struct weston_pointer_axis_event *event)
{
weston_pointer_send_axis(grab->pointer, time, event);
weston_pointer_send_axis(grab->pointer, event);
}
static void
@ -5725,10 +5719,9 @@ confined_pointer_grab_pointer_button(struct weston_pointer_grab *grab,
static void
confined_pointer_grab_pointer_axis(struct weston_pointer_grab *grab,
const struct timespec *time,
struct weston_pointer_axis_event *event)
const struct weston_pointer_axis_event *event)
{
weston_pointer_send_axis(grab->pointer, time, event);
weston_pointer_send_axis(grab->pointer, event);
}
static void
@ -6046,3 +6039,15 @@ weston_pointer_button_event_init(struct weston_pointer_button_event *event,
event->button = button;
event->button_state = button_state;
}
WL_EXPORT void
weston_pointer_axis_event_init(struct weston_pointer_axis_event *event,
uint32_t axis, double value, bool has_discrete,
int32_t discrete)
{
event->axis = axis;
event->value = value;
event->has_discrete = has_discrete;
event->discrete = discrete;
}

View file

@ -315,12 +315,10 @@ handle_pointer_axis(struct libinput_device *libinput_device,
vert_discrete = get_axis_discrete(pointer_event, axis);
vert = normalize_scroll(pointer_event, axis);
weston_event.axis = WL_POINTER_AXIS_VERTICAL_SCROLL;
weston_event.value = vert;
weston_event.discrete = vert_discrete;
weston_event.has_discrete = (vert_discrete != 0);
notify_axis(device->seat, &time, &weston_event);
weston_input_event_init(&weston_event.base, &time, device->seat);
weston_pointer_axis_event_init(&weston_event, WL_POINTER_AXIS_VERTICAL_SCROLL,
vert, (vert_discrete != 0), vert_discrete);
notify_axis(device->seat, &weston_event);
}
if (has_horiz) {
@ -328,12 +326,10 @@ handle_pointer_axis(struct libinput_device *libinput_device,
horiz_discrete = get_axis_discrete(pointer_event, axis);
horiz = normalize_scroll(pointer_event, axis);
weston_event.axis = WL_POINTER_AXIS_HORIZONTAL_SCROLL;
weston_event.value = horiz;
weston_event.discrete = horiz_discrete;
weston_event.has_discrete = (horiz_discrete != 0);
notify_axis(device->seat, &time, &weston_event);
weston_input_event_init(&weston_event.base, &time, device->seat);
weston_pointer_axis_event_init(&weston_event, WL_POINTER_AXIS_HORIZONTAL_SCROLL,
horiz, (horiz_discrete != 0), horiz_discrete);
notify_axis(device->seat, &weston_event);
}
return true;

View file

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

View file

@ -458,12 +458,11 @@ send_axis(struct wl_client *client, struct wl_resource *resource,
struct weston_pointer_axis_event axis_event;
timespec_from_proto(&time, tv_sec_hi, tv_sec_lo, tv_nsec);
axis_event.axis = axis;
axis_event.value = wl_fixed_to_double(value);
axis_event.has_discrete = false;
axis_event.discrete = 0;
notify_axis(seat, &time, &axis_event);
weston_input_event_init(&axis_event.base, &time, seat);
weston_pointer_axis_event_init(&axis_event, axis,
wl_fixed_to_double(value), false, 0);
notify_axis(seat, &axis_event);
}
static void