summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2020-04-03 14:39:31 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2023-01-18 13:33:54 +1000
commit3a02f56b4336c5220a67b297e5d90e3a709893db (patch)
tree3027d62ac5e980a1237d114a43d13e820a2efa41
parent2f0d39e1f1e1a5c266ed638a68c04ad0ed232fb7 (diff)
downloadxserver-3a02f56b4336c5220a67b297e5d90e3a709893db.tar.gz
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>
-rw-r--r--hw/xwayland/xwayland-input.c62
-rw-r--r--hw/xwayland/xwayland-input.h8
-rw-r--r--include/meson.build1
-rw-r--r--include/xwayland-config.h.meson.in3
-rw-r--r--meson.build5
5 files changed, 57 insertions, 22 deletions
diff --git a/hw/xwayland/xwayland-input.c b/hw/xwayland/xwayland-input.c
index 2dae45e8d..5892dd502 100644
--- a/hw/xwayland/xwayland-input.c
+++ b/hw/xwayland/xwayland-input.c
@@ -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,
diff --git a/hw/xwayland/xwayland-input.h b/hw/xwayland/xwayland-input.h
index 4fd175b13..ee94d73ae 100644
--- a/hw/xwayland/xwayland-input.h
+++ b/hw/xwayland/xwayland-input.h
@@ -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;
diff --git a/include/meson.build b/include/meson.build
index 6c1c1dcd4..855fbba5d 100644
--- a/include/meson.build
+++ b/include/meson.build
@@ -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',
diff --git a/include/xwayland-config.h.meson.in b/include/xwayland-config.h.meson.in
index c254c1fd3..43b9ff29e 100644
--- a/include/xwayland-config.h.meson.in
+++ b/include/xwayland-config.h.meson.in
@@ -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
diff --git a/meson.build b/meson.build
index fd85ad86a..73c2bf9b1 100644
--- a/meson.build
+++ b/meson.build
@@ -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