Commit 08722208 authored by Peter Hutterer's avatar Peter Hutterer
Browse files

Use the new v120 API from libinput if available


Signed-off-by: Peter Hutterer's avatarPeter Hutterer <peter.hutterer@who-t.net>
parent 0b60b34d
Pipeline #148485 passed with stages
in 56 seconds
......@@ -62,6 +62,18 @@ AC_LINK_IFELSE(
[libinput_have_scroll_button_lock=yes]],
[AC_MSG_RESULT([no])
[libinput_have_scroll_button_lock=no]])
AC_MSG_CHECKING([if libinput_event_pointer_get_axis_value_v120 is available])
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([[#include <libinput.h>]],
[[libinput_event_pointer_get_axis_value_v120(NULL, 0)]])],
[AC_MSG_RESULT([yes])
AC_DEFINE(HAVE_LIBINPUT_AXIS_VALUE_V120, [1],
[libinput_event_pointer_get_axis_value_v120() is available])
[libinput_have_axis_value_v120=yes]],
[AC_MSG_RESULT([no])
[libinput_have_axis_value_v120=no]])
LIBS=$OLD_LIBS
CFLAGS=$OLD_CFLAGS
......
......@@ -1548,9 +1548,9 @@ xf86libinput_handle_key(InputInfoPtr pInfo, struct libinput_event_keyboard *even
* so the use-case above shouldn't matter anymore.
*/
static inline double
get_wheel_scroll_value(struct xf86libinput *driver_data,
struct libinput_event_pointer *event,
enum libinput_pointer_axis axis)
guess_wheel_scroll_value(struct xf86libinput *driver_data,
struct libinput_event_pointer *event,
enum libinput_pointer_axis axis)
{
struct scroll_axis *s;
double f;
......@@ -1610,6 +1610,43 @@ out:
return s->dist/s->fraction * discrete;
}
#if HAVE_LIBINPUT_AXIS_VALUE_V120
static inline double
get_wheel_120_value(struct xf86libinput *driver_data,
struct libinput_event_pointer *event,
enum libinput_pointer_axis axis)
{
struct scroll_axis *s;
double angle;
switch (axis) {
case LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL:
s = &driver_data->scroll.h;
break;
case LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL:
s = &driver_data->scroll.v;
break;
default:
return 0.0;
}
angle = libinput_event_pointer_get_axis_value_v120(event, axis);
return s->dist * angle/120;
}
#endif
static inline double
get_wheel_scroll_value(struct xf86libinput *driver_data,
struct libinput_event_pointer *event,
enum libinput_pointer_axis axis)
{
#if HAVE_LIBINPUT_AXIS_VALUE_V120
return get_wheel_120_value(driver_data, event, axis);
#else
return guess_wheel_scroll_value(driver_data, event, axis);
#endif
}
static inline bool
calculate_axis_value(struct xf86libinput *driver_data,
enum libinput_pointer_axis axis,
......@@ -1622,6 +1659,14 @@ calculate_axis_value(struct xf86libinput *driver_data,
if (!libinput_event_pointer_has_axis(event, axis))
return false;
/* Event may be LIBINPUT_POINTER_AXIS or
* LIBINPUT_EVENT_POINTER_{AXIS_WHEEL|FINGER|CONTINUOUS}, depending
* on the libinput version.
*
* libinput guarantees the axis source is set for the second set of
* events too but we can switch to the event type once we ditch
* libinput < 1.16 support.
*/
source = libinput_event_pointer_get_axis_source(event);
if (source == LIBINPUT_POINTER_AXIS_SOURCE_WHEEL) {
value = get_wheel_scroll_value(driver_data, event, axis);
......@@ -1642,34 +1687,27 @@ calculate_axis_value(struct xf86libinput *driver_data,
}
static void
xf86libinput_handle_axis(InputInfoPtr pInfo, struct libinput_event_pointer *event)
xf86libinput_handle_axis(InputInfoPtr pInfo, struct libinput_event *e)
{
struct libinput_event_pointer *event;
DeviceIntPtr dev = pInfo->dev;
struct xf86libinput *driver_data = pInfo->private;
ValuatorMask *mask = driver_data->valuators;
double value;
enum libinput_pointer_axis_source source;
if ((driver_data->capabilities & CAP_POINTER) == 0)
return;
valuator_mask_zero(mask);
source = libinput_event_pointer_get_axis_source(event);
switch(source) {
case LIBINPUT_POINTER_AXIS_SOURCE_FINGER:
case LIBINPUT_POINTER_AXIS_SOURCE_WHEEL:
case LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS:
break;
default:
return;
}
event = libinput_event_get_pointer_event(e);
if (calculate_axis_value(driver_data,
LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
event,
&value))
valuator_mask_set_double(mask, 3, value);
&value)) {
if (value != 0.0)
valuator_mask_set_double(mask, 3, value);
}
if (!driver_data->options.horiz_scrolling_enabled)
goto out;
......@@ -1677,8 +1715,14 @@ xf86libinput_handle_axis(InputInfoPtr pInfo, struct libinput_event_pointer *even
if (calculate_axis_value(driver_data,
LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
event,
&value))
valuator_mask_set_double(mask, 2, value);
&value)) {
if (value != 0.0)
valuator_mask_set_double(mask, 2, value);
}
if (!valuator_mask_isset(mask, 2) &&
!valuator_mask_isset(mask, 3))
return;
out:
xf86PostMotionEventM(dev, Relative, mask);
......@@ -2276,8 +2320,14 @@ xf86libinput_handle_event(struct libinput_event *event)
libinput_event_get_keyboard_event(event));
break;
case LIBINPUT_EVENT_POINTER_AXIS:
xf86libinput_handle_axis(pInfo,
libinput_event_get_pointer_event(event));
#if HAVE_LIBINPUT_AXIS_VALUE_V120
/* ignore POINTER_AXIS where we have libinput 1.16 and higher */
break;
case LIBINPUT_EVENT_POINTER_AXIS_WHEEL:
case LIBINPUT_EVENT_POINTER_AXIS_FINGER:
case LIBINPUT_EVENT_POINTER_AXIS_CONTINUOUS:
#endif
xf86libinput_handle_axis(pInfo, event);
break;
case LIBINPUT_EVENT_TOUCH_FRAME:
break;
......
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