Commit ea02578a authored by Peter Hutterer's avatar Peter Hutterer

Move axis value calculation into a helper function

The only difference here is the axis number.
Signed-off-by: Peter Hutterer's avatarPeter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: default avatarHans de Goede <hdegoede@redhat.com>
parent 2ceb2e1b
...@@ -1323,6 +1323,31 @@ xf86libinput_handle_key(InputInfoPtr pInfo, struct libinput_event_keyboard *even ...@@ -1323,6 +1323,31 @@ xf86libinput_handle_key(InputInfoPtr pInfo, struct libinput_event_keyboard *even
xf86PostKeyboardEvent(dev, key, is_press); 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 static void
xf86libinput_handle_axis(InputInfoPtr pInfo, struct libinput_event_pointer *event) xf86libinput_handle_axis(InputInfoPtr pInfo, struct libinput_event_pointer *event)
{ {
...@@ -1330,7 +1355,6 @@ xf86libinput_handle_axis(InputInfoPtr pInfo, struct libinput_event_pointer *even ...@@ -1330,7 +1355,6 @@ xf86libinput_handle_axis(InputInfoPtr pInfo, struct libinput_event_pointer *even
struct xf86libinput *driver_data = pInfo->private; struct xf86libinput *driver_data = pInfo->private;
ValuatorMask *mask = driver_data->valuators; ValuatorMask *mask = driver_data->valuators;
double value; double value;
enum libinput_pointer_axis axis;
enum libinput_pointer_axis_source source; enum libinput_pointer_axis_source source;
if ((driver_data->capabilities & CAP_POINTER) == 0) if ((driver_data->capabilities & CAP_POINTER) == 0)
...@@ -1348,30 +1372,20 @@ xf86libinput_handle_axis(InputInfoPtr pInfo, struct libinput_event_pointer *even ...@@ -1348,30 +1372,20 @@ xf86libinput_handle_axis(InputInfoPtr pInfo, struct libinput_event_pointer *even
return; return;
} }
axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL; if (calculate_axis_value(driver_data,
if (libinput_event_pointer_has_axis(event, axis)) { LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
if (source == LIBINPUT_POINTER_AXIS_SOURCE_WHEEL) { event,
value = libinput_event_pointer_get_axis_value_discrete(event, axis); &value))
value *= driver_data->scroll.vdist;
} else {
value = libinput_event_pointer_get_axis_value(event, axis);
}
valuator_mask_set_double(mask, 3, value); valuator_mask_set_double(mask, 3, value);
}
if (!driver_data->options.horiz_scrolling_enabled) if (!driver_data->options.horiz_scrolling_enabled)
goto out; goto out;
axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL; if (calculate_axis_value(driver_data,
if (libinput_event_pointer_has_axis(event, axis)) { LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
if (source == LIBINPUT_POINTER_AXIS_SOURCE_WHEEL) { event,
value = libinput_event_pointer_get_axis_value_discrete(event, axis); &value))
value *= driver_data->scroll.hdist;
} else {
value = libinput_event_pointer_get_axis_value(event, axis);
}
valuator_mask_set_double(mask, 2, value); valuator_mask_set_double(mask, 2, value);
}
out: out:
xf86PostMotionEventM(dev, Relative, mask); xf86PostMotionEventM(dev, Relative, mask);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment