The only difference here is the axis number.

Signed-off-by: Peter Hutterer <[email protected]>
---
 src/xf86libinput.c | 52 +++++++++++++++++++++++++++++++++-------------------
 1 file changed, 33 insertions(+), 19 deletions(-)

diff --git a/src/xf86libinput.c b/src/xf86libinput.c
index 324bfc8..7f61e9b 100644
--- a/src/xf86libinput.c
+++ b/src/xf86libinput.c
@@ -1320,6 +1320,31 @@ xf86libinput_handle_key(InputInfoPtr pInfo, struct 
libinput_event_keyboard *even
        xf86PostKeyboardEvent(dev, key, is_press);
 }
 
+static inline bool
+calculate_axis_value(struct xf86libinput *driver_data,
+                    enum libinput_pointer_axis axis,
+                    struct libinput_event_pointer *event,
+                    double *value_out)
+{
+       enum libinput_pointer_axis_source source;
+       double value;
+
+       if (!libinput_event_pointer_has_axis(event, axis))
+               return false;
+
+       source = libinput_event_pointer_get_axis_source(event);
+       if (source == LIBINPUT_POINTER_AXIS_SOURCE_WHEEL) {
+               value = libinput_event_pointer_get_axis_value_discrete(event, 
axis);
+               value *= driver_data->scroll.vdist;
+       } else {
+               value = libinput_event_pointer_get_axis_value(event, axis);
+       }
+
+       *value_out = value;
+
+       return true;
+}
+
 static void
 xf86libinput_handle_axis(InputInfoPtr pInfo, struct libinput_event_pointer 
*event)
 {
@@ -1327,7 +1352,6 @@ xf86libinput_handle_axis(InputInfoPtr pInfo, struct 
libinput_event_pointer *even
        struct xf86libinput *driver_data = pInfo->private;
        ValuatorMask *mask = driver_data->valuators;
        double value;
-       enum libinput_pointer_axis axis;
        enum libinput_pointer_axis_source source;
 
        if ((driver_data->capabilities & CAP_POINTER) == 0)
@@ -1345,30 +1369,20 @@ xf86libinput_handle_axis(InputInfoPtr pInfo, struct 
libinput_event_pointer *even
                        return;
        }
 
-       axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
-       if (libinput_event_pointer_has_axis(event, axis)) {
-               if (source == LIBINPUT_POINTER_AXIS_SOURCE_WHEEL) {
-                       value = 
libinput_event_pointer_get_axis_value_discrete(event, axis);
-                       value *= driver_data->scroll.vdist;
-               } else {
-                       value = libinput_event_pointer_get_axis_value(event, 
axis);
-               }
+       if (calculate_axis_value(driver_data,
+                                LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
+                                event,
+                                &value))
                valuator_mask_set_double(mask, 3, value);
-       }
 
        if (!driver_data->options.horiz_scrolling_enabled)
                goto out;
 
-       axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
-       if (libinput_event_pointer_has_axis(event, axis)) {
-               if (source == LIBINPUT_POINTER_AXIS_SOURCE_WHEEL) {
-                       value = 
libinput_event_pointer_get_axis_value_discrete(event, axis);
-                       value *= driver_data->scroll.hdist;
-               } else {
-                       value = libinput_event_pointer_get_axis_value(event, 
axis);
-               }
+       if (calculate_axis_value(driver_data,
+                                LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
+                                event,
+                                &value))
                valuator_mask_set_double(mask, 2, value);
-       }
 
 out:
        xf86PostMotionEventM(dev, Relative, mask);
-- 
2.9.3

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

Reply via email to