pointer: transform low-res to high-res axis events

Currently, the "wlr_event_pointer_axis" event stores low-resolution
values in its "delta_discrete" field. Low-resolution values are always
multiples of one, i.e., 1 for one wheel detent, 2 for two wheel
detents, etc.

In order to simplify internal handling of events, always transform in
the backend from the low-resolution value into the high-resolution
value.

The transformation is performed by multiplying by 120. The 120 magic
number is used by the kernel and it is exposed to clients in the
"WLR_POINTER_AXIS_DISCRETE_STEP" constant.
This commit is contained in:
José Expósito 2022-02-25 17:30:31 +01:00
parent c84cc660f0
commit 65c436407f
4 changed files with 5 additions and 2 deletions

View File

@ -116,6 +116,7 @@ void handle_pointer_axis(struct libinput_event *event,
libinput_event_pointer_get_axis_value(pevent, axes[i]); libinput_event_pointer_get_axis_value(pevent, axes[i]);
wlr_event.delta_discrete = wlr_event.delta_discrete =
libinput_event_pointer_get_axis_value_discrete(pevent, axes[i]); libinput_event_pointer_get_axis_value_discrete(pevent, axes[i]);
wlr_event.delta_discrete *= WLR_POINTER_AXIS_DISCRETE_STEP;
wlr_signal_emit_safe(&pointer->events.axis, &wlr_event); wlr_signal_emit_safe(&pointer->events.axis, &wlr_event);
} }
} }

View File

@ -184,7 +184,7 @@ static void pointer_handle_axis_discrete(void *data,
return; return;
} }
pointer->axis_discrete = discrete; pointer->axis_discrete = discrete * WLR_POINTER_AXIS_DISCRETE_STEP;
} }
static const struct wl_pointer_listener pointer_listener = { static const struct wl_pointer_listener pointer_listener = {

View File

@ -78,6 +78,8 @@ enum wlr_axis_orientation {
WLR_AXIS_ORIENTATION_HORIZONTAL, WLR_AXIS_ORIENTATION_HORIZONTAL,
}; };
#define WLR_POINTER_AXIS_DISCRETE_STEP 120
struct wlr_pointer_axis_event { struct wlr_pointer_axis_event {
struct wlr_pointer *pointer; struct wlr_pointer *pointer;
uint32_t time_msec; uint32_t time_msec;

View File

@ -301,7 +301,7 @@ void wlr_seat_pointer_send_axis(struct wlr_seat *wlr_seat, uint32_t time,
if (value_discrete && if (value_discrete &&
version >= WL_POINTER_AXIS_DISCRETE_SINCE_VERSION) { version >= WL_POINTER_AXIS_DISCRETE_SINCE_VERSION) {
wl_pointer_send_axis_discrete(resource, orientation, wl_pointer_send_axis_discrete(resource, orientation,
value_discrete); value_discrete / WLR_POINTER_AXIS_DISCRETE_STEP);
} }
wl_pointer_send_axis(resource, time, orientation, wl_pointer_send_axis(resource, time, orientation,