xserver: Branch 'master' - 2 commits

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Jan 19 07:27:41 UTC 2023


 hw/xwayland/xwayland-input.c       |   81 +++++++++++++++++++++++++------------
 hw/xwayland/xwayland-input.h       |    8 +--
 include/meson.build                |    1 
 include/xwayland-config.h.meson.in |    3 +
 meson.build                        |    5 +-
 5 files changed, 68 insertions(+), 30 deletions(-)

New commits:
commit 3a02f56b4336c5220a67b297e5d90e3a709893db
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Apr 3 14:39:31 2020 +1000

    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 at who-t.net>

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
commit 2f0d39e1f1e1a5c266ed638a68c04ad0ed232fb7
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Jul 26 15:47:06 2022 +1000

    xwayland: use a define for the horiz/vert scroll valuators
    
    Slightly more readable and less prone to copy/paste errors.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/xwayland/xwayland-input.c b/hw/xwayland/xwayland-input.c
index 9eda1ef71..2dae45e8d 100644
--- a/hw/xwayland/xwayland-input.c
+++ b/hw/xwayland/xwayland-input.c
@@ -51,6 +51,9 @@
 #include "xwayland-keyboard-grab-unstable-v1-client-protocol.h"
 #include "keyboard-shortcuts-inhibit-unstable-v1-client-protocol.h"
 
+#define SCROLL_AXIS_HORIZ 2
+#define SCROLL_AXIS_VERT 3
+
 struct sync_pending {
     struct xorg_list l;
     DeviceIntPtr pending_dev;
@@ -189,8 +192,8 @@ xwl_pointer_proc(DeviceIntPtr device, int what)
 
         axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_X);
         axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_Y);
-        axes_labels[2] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_HWHEEL);
-        axes_labels[3] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_WHEEL);
+        axes_labels[SCROLL_AXIS_HORIZ] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_HWHEEL);
+        axes_labels[SCROLL_AXIS_VERT] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_WHEEL);
 
         if (!InitValuatorClassDeviceStruct(device, NAXES, axes_labels,
                                            GetMotionHistorySize(), Absolute))
@@ -201,13 +204,13 @@ xwl_pointer_proc(DeviceIntPtr device, int what)
                                0, 0xFFFF, 10000, 0, 10000, Absolute);
         InitValuatorAxisStruct(device, 1, axes_labels[1],
                                0, 0xFFFF, 10000, 0, 10000, Absolute);
-        InitValuatorAxisStruct(device, 2, axes_labels[2],
+        InitValuatorAxisStruct(device, SCROLL_AXIS_HORIZ, axes_labels[2],
                                NO_AXIS_LIMITS, NO_AXIS_LIMITS, 0, 0, 0, Relative);
-        InitValuatorAxisStruct(device, 3, axes_labels[3],
+        InitValuatorAxisStruct(device, SCROLL_AXIS_VERT, axes_labels[3],
                                NO_AXIS_LIMITS, NO_AXIS_LIMITS, 0, 0, 0, Relative);
 
-        SetScrollValuator(device, 2, SCROLL_TYPE_HORIZONTAL, 1.0, SCROLL_FLAG_NONE);
-        SetScrollValuator(device, 3, SCROLL_TYPE_VERTICAL, 1.0, SCROLL_FLAG_PREFERRED);
+        SetScrollValuator(device, SCROLL_AXIS_HORIZ, SCROLL_TYPE_HORIZONTAL, 1.0, SCROLL_FLAG_NONE);
+        SetScrollValuator(device, SCROLL_AXIS_VERT, SCROLL_TYPE_VERTICAL, 1.0, SCROLL_FLAG_PREFERRED);
 
         if (!InitPtrFeedbackClassDeviceStruct(device, xwl_pointer_control))
             return BadValue;
@@ -676,17 +679,17 @@ dispatch_scroll_motion(struct xwl_seat *xwl_seat)
     valuator_mask_zero(&mask);
     if (xwl_seat->pending_pointer_event.has_vertical_scroll)
         valuator_mask_set_double(&mask,
-                                 3,
+                                 SCROLL_AXIS_VERT,
                                  wl_fixed_to_double(dy) / divisor);
     else if (xwl_seat->pending_pointer_event.has_vertical_scroll_discrete)
-        valuator_mask_set(&mask, 3, discrete_dy);
+        valuator_mask_set(&mask, SCROLL_AXIS_VERT, discrete_dy);
 
     if (xwl_seat->pending_pointer_event.has_horizontal_scroll)
         valuator_mask_set_double(&mask,
-                                 2,
+                                 SCROLL_AXIS_HORIZ,
                                  wl_fixed_to_double(dx) / divisor);
     else if (xwl_seat->pending_pointer_event.has_horizontal_scroll_discrete)
-        valuator_mask_set(&mask, 2, discrete_dx);
+        valuator_mask_set(&mask, SCROLL_AXIS_HORIZ, discrete_dx);
 
     QueuePointerEvents(get_pointer_device(xwl_seat),
                        MotionNotify, 0, POINTER_RELATIVE, &mask);


More information about the xorg-commit mailing list