xwayland: hook up wl_pointer.axis_v120 events

For details on the protocol itself see the Wayland merge request:
https://gitlab.freedesktop.org/wayland/wayland/-/merge_requests/72

The v120 event has a value base of 120, so one wheel detent is 120, half a
wheel is 60, etc. This is the API Windows has been using since Vista but it
requires HW support from the device. Logitech mice and many Microsoft mice of
the last decade or so have support and it's enabled in the kernel since v5.0.

The new events replace wl_pointer.axis_discrete events, once you bind to
wl_pointer >= 8 you only get the v120 events. So backwards compatibility
is simple, we just multiply the discrete events if we get them and
treat everything as 120 event internally.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2020-04-03 14:39:31 +10:00
parent 2f0d39e1f1
commit 3a02f56b43
5 changed files with 57 additions and 22 deletions

View File

@ -673,23 +673,23 @@ dispatch_scroll_motion(struct xwl_seat *xwl_seat)
const int divisor = 10;
wl_fixed_t dy = xwl_seat->pending_pointer_event.scroll_dy;
wl_fixed_t dx = xwl_seat->pending_pointer_event.scroll_dx;
int32_t discrete_dy = xwl_seat->pending_pointer_event.scroll_discrete_dy;
int32_t discrete_dx = xwl_seat->pending_pointer_event.scroll_discrete_dx;
int32_t dy_v120 = xwl_seat->pending_pointer_event.scroll_dy_v120;
int32_t dx_v120 = xwl_seat->pending_pointer_event.scroll_dx_v120;
valuator_mask_zero(&mask);
if (xwl_seat->pending_pointer_event.has_vertical_scroll)
if (xwl_seat->pending_pointer_event.has_vertical_scroll_v120)
valuator_mask_set_double(&mask, SCROLL_AXIS_VERT, dy_v120 / 120.0);
else if (xwl_seat->pending_pointer_event.has_vertical_scroll)
valuator_mask_set_double(&mask,
SCROLL_AXIS_VERT,
wl_fixed_to_double(dy) / divisor);
else if (xwl_seat->pending_pointer_event.has_vertical_scroll_discrete)
valuator_mask_set(&mask, SCROLL_AXIS_VERT, discrete_dy);
if (xwl_seat->pending_pointer_event.has_horizontal_scroll)
if (xwl_seat->pending_pointer_event.has_horizontal_scroll_v120)
valuator_mask_set_double(&mask, SCROLL_AXIS_HORIZ, dx_v120 / 120.0);
else if (xwl_seat->pending_pointer_event.has_horizontal_scroll)
valuator_mask_set_double(&mask,
SCROLL_AXIS_HORIZ,
wl_fixed_to_double(dx) / divisor);
else if (xwl_seat->pending_pointer_event.has_horizontal_scroll_discrete)
valuator_mask_set(&mask, SCROLL_AXIS_HORIZ, discrete_dx);
QueuePointerEvents(get_pointer_device(xwl_seat),
MotionNotify, 0, POINTER_RELATIVE, &mask);
@ -714,16 +714,16 @@ dispatch_pointer_motion_event(struct xwl_seat *xwl_seat)
if (xwl_seat->pending_pointer_event.has_vertical_scroll ||
xwl_seat->pending_pointer_event.has_horizontal_scroll ||
xwl_seat->pending_pointer_event.has_vertical_scroll_discrete ||
xwl_seat->pending_pointer_event.has_horizontal_scroll_discrete)
xwl_seat->pending_pointer_event.has_vertical_scroll_v120 ||
xwl_seat->pending_pointer_event.has_horizontal_scroll_v120)
dispatch_scroll_motion(xwl_seat);
xwl_seat->pending_pointer_event.has_absolute = FALSE;
xwl_seat->pending_pointer_event.has_relative = FALSE;
xwl_seat->pending_pointer_event.has_vertical_scroll = FALSE;
xwl_seat->pending_pointer_event.has_horizontal_scroll = FALSE;
xwl_seat->pending_pointer_event.has_vertical_scroll_discrete = FALSE;
xwl_seat->pending_pointer_event.has_horizontal_scroll_discrete = FALSE;
xwl_seat->pending_pointer_event.has_vertical_scroll_v120 = FALSE;
xwl_seat->pending_pointer_event.has_horizontal_scroll_v120 = FALSE;
}
static void
@ -835,16 +835,36 @@ pointer_handle_axis_discrete(void *data, struct wl_pointer *wl_pointer,
switch (axis) {
case WL_POINTER_AXIS_VERTICAL_SCROLL:
xwl_seat->pending_pointer_event.has_vertical_scroll_discrete = TRUE;
xwl_seat->pending_pointer_event.scroll_discrete_dy = discrete;
xwl_seat->pending_pointer_event.has_vertical_scroll_v120 = TRUE;
xwl_seat->pending_pointer_event.scroll_dy_v120 = 120 * discrete;
break;
case WL_POINTER_AXIS_HORIZONTAL_SCROLL:
xwl_seat->pending_pointer_event.has_horizontal_scroll_discrete = TRUE;
xwl_seat->pending_pointer_event.scroll_discrete_dx = discrete;
xwl_seat->pending_pointer_event.has_horizontal_scroll_v120 = TRUE;
xwl_seat->pending_pointer_event.scroll_dx_v120 = 120 * discrete;
break;
}
}
#ifdef XWL_HAS_WL_POINTER_AXIS_V120
static void
pointer_handle_axis_v120(void *data, struct wl_pointer *pointer,
uint32_t axis, int32_t v120)
{
struct xwl_seat *xwl_seat = data;
switch (axis) {
case WL_POINTER_AXIS_VERTICAL_SCROLL:
xwl_seat->pending_pointer_event.has_vertical_scroll_v120 = TRUE;
xwl_seat->pending_pointer_event.scroll_dy_v120 = v120;
break;
case WL_POINTER_AXIS_HORIZONTAL_SCROLL:
xwl_seat->pending_pointer_event.has_horizontal_scroll_v120 = TRUE;
xwl_seat->pending_pointer_event.scroll_dx_v120 = v120;
break;
}
}
#endif
static const struct wl_pointer_listener pointer_listener = {
pointer_handle_enter,
pointer_handle_leave,
@ -855,6 +875,9 @@ static const struct wl_pointer_listener pointer_listener = {
pointer_handle_axis_source,
pointer_handle_axis_stop,
pointer_handle_axis_discrete,
#ifdef XWL_HAS_WL_POINTER_AXIS_V120
pointer_handle_axis_v120,
#endif
};
static void
@ -1831,6 +1854,11 @@ static void
create_input_device(struct xwl_screen *xwl_screen, uint32_t id, uint32_t version)
{
struct xwl_seat *xwl_seat;
int seat_version = 5;
#ifdef XWL_HAS_WL_POINTER_AXIS_V120
seat_version = 8;
#endif
xwl_seat = calloc(1, sizeof *xwl_seat);
if (xwl_seat == NULL) {
@ -1843,7 +1871,7 @@ create_input_device(struct xwl_screen *xwl_screen, uint32_t id, uint32_t version
xwl_seat->seat =
wl_registry_bind(xwl_screen->registry, id,
&wl_seat_interface, min(version, 5));
&wl_seat_interface, min(version, seat_version));
xwl_seat->id = id;
xwl_cursor_init(&xwl_seat->cursor, xwl_seat->xwl_screen,

View File

@ -113,12 +113,12 @@ struct xwl_seat {
wl_fixed_t scroll_dy;
wl_fixed_t scroll_dx;
int32_t scroll_discrete_dy;
int32_t scroll_discrete_dx;
int32_t scroll_dy_v120;
int32_t scroll_dx_v120;
Bool has_vertical_scroll;
Bool has_horizontal_scroll;
Bool has_vertical_scroll_discrete;
Bool has_horizontal_scroll_discrete;
Bool has_vertical_scroll_v120;
Bool has_horizontal_scroll_v120;
} pending_pointer_event;
struct xorg_list tablets;

View File

@ -418,6 +418,7 @@ xwayland_data.set('XWL_HAS_GLAMOR', build_glamor and (gbm_dep.found() or build_e
xwayland_data.set('XWL_HAS_EGLSTREAM', build_eglstream ? '1' : false)
xwayland_data.set('XWL_HAS_LIBDECOR', have_libdecor ? '1' : false)
xwayland_data.set('XWL_HAS_XWAYLAND_EXTENSION', xwaylandproto_dep.found() ? '1' : false)
xwayland_data.set('XWL_HAS_WL_POINTER_AXIS_V120', wayland_client_dep.found() and wayland_client_dep.version().version_compare('>= 1.21.0'))
configure_file(output : 'xwayland-config.h',
input : 'xwayland-config.h.meson.in',

View File

@ -15,3 +15,6 @@
/* Build Xwayland with XWAYLAND extension */
#mesondefine XWL_HAS_XWAYLAND_EXTENSION
/* libwayland has support for wl_pointer.axis_v120 events */
#mesondefine XWL_HAS_WL_POINTER_AXIS_V120

View File

@ -215,8 +215,9 @@ if (host_machine.system() != 'darwin' and
xwayland_path = join_paths(get_option('prefix'), get_option('bindir'))
endif
wayland_client_dep = dependency('wayland-client', version: wayland_req, required: xwayland_required)
xwayland_dep = [
dependency('wayland-client', version: wayland_req, required: xwayland_required),
wayland_client_dep,
dependency('wayland-protocols', version: wayland_protocols_req, required: xwayland_required),
dependency('libxcvt', fallback: ['libxcvt', 'libxcvt_dep'], required: xwayland_required),
]
@ -234,6 +235,8 @@ if (host_machine.system() != 'darwin' and
endif
endforeach
endif
else
wayland_client_dep = dependency('', required: false)
endif
build_xnest = false