diff options
author | José Expósito <jose.exposito89@gmail.com> | 2021-11-14 22:52:47 +0000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2021-11-14 22:52:47 +0000 |
commit | 75cc87518b1ae611e7495be3a516a1395cef5891 (patch) | |
tree | c6f920b805b6cc266fa8016916b405b9e35f5178 | |
parent | 3951ce739def06c99df5d4669d2af5c74653ad66 (diff) | |
download | xorg-driver-xf86-input-libinput-75cc87518b1ae611e7495be3a516a1395cef5891.tar.gz |
Add an option to disable high-resolution wheel scroll
Starting on libinput 1.19 pointer axis events have been deprecated in
favor of their scroll equivalents, including support for high-resolution
wheel scroll.
While it is recommended to handle the new events, some applications
and/or frameworks might not be ready at the moment.
Provide an option to discard high-resolution wheel scroll events.
Fix #41
Signed-off-by: José Expósito <jose.exposito89@gmail.com>
-rw-r--r-- | include/libinput-properties.h | 4 | ||||
-rw-r--r-- | man/libinput.man | 9 | ||||
-rw-r--r-- | src/xf86libinput.c | 115 |
3 files changed, 108 insertions, 20 deletions
diff --git a/include/libinput-properties.h b/include/libinput-properties.h index 52ad6c9..d3832d8 100644 --- a/include/libinput-properties.h +++ b/include/libinput-properties.h @@ -207,4 +207,8 @@ /* Tablet tool area ratio: CARD32, 2 values, w and h */ #define LIBINPUT_PROP_TABLET_TOOL_AREA_RATIO "libinput Tablet Tool Area Ratio" +/* High-resolution wheel scroll events enabled: BOOL, 1 value (0 or 1). + * If disabled, high-resolution wheel scroll events are discarded */ +#define LIBINPUT_PROP_HIRES_WHEEL_SCROLL_ENABLED "libinput High Resolution Wheel Scroll Enabled" + #endif /* _LIBINPUT_PROPERTIES_H_ */ diff --git a/man/libinput.man b/man/libinput.man index 2f4bdc6..a069eec 100644 --- a/man/libinput.man +++ b/man/libinput.man @@ -114,6 +114,11 @@ device button numbers, i.e. the .B ButtonMapping applies after drag lock. .TP 7 +.BI "Option \*qHighResolutionWheelScrolling\*q \*q" bool \*q +Disables high-resolution wheel scroll events, enabled by default. When enabled, +the driver forwards only high-resolution wheel scroll events from libinput. +When disabled, the driver forwards legacy wheel scroll events instead. +.TP 7 .BI "Option \*qHorizontalScrolling\*q \*q" bool \*q Disables horizontal scrolling. When disabled, this driver will discard any horizontal scroll events from libinput. Note that this does not disable @@ -262,6 +267,10 @@ button pairs. See section .B BUTTON DRAG LOCK for details. .TP 7 +.BI "libinput High Resolution Wheel Scroll Enabled" +1 boolean value (8 bit, 0 or 1). Indicates whether high-resolution +wheel scroll events are enabled or not. +.TP 7 .BI "libinput Horizontal Scroll Enabled" 1 boolean value (8 bit, 0 or 1). Indicates whether horizontal scrolling events are enabled or not. diff --git a/src/xf86libinput.c b/src/xf86libinput.c index 00f1f2c..743a104 100644 --- a/src/xf86libinput.c +++ b/src/xf86libinput.c @@ -166,6 +166,7 @@ struct xf86libinput { unsigned char btnmap[MAX_BUTTONS + 1]; BOOL horiz_scrolling_enabled; + BOOL hires_scrolling_enabled; float rotation_angle; struct bezier_control_point pressurecurve[4]; @@ -1660,21 +1661,22 @@ get_wheel_scroll_value(struct xf86libinput *driver_data, 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); + if (driver_data->options.hires_scrolling_enabled) + return get_wheel_120_value(driver_data, event, axis); #endif + return guess_wheel_scroll_value(driver_data, event, axis); } static inline double -get_finger_or_continuous_scroll_value(struct libinput_event_pointer *event, +get_finger_or_continuous_scroll_value(struct xf86libinput *driver_data, + struct libinput_event_pointer *event, enum libinput_pointer_axis axis) { #if HAVE_LIBINPUT_AXIS_VALUE_V120 - return libinput_event_pointer_get_scroll_value(event, axis); -#else - return libinput_event_pointer_get_axis_value(event, axis); + if (driver_data->options.hires_scrolling_enabled) + return libinput_event_pointer_get_scroll_value(event, axis); #endif + return libinput_event_pointer_get_axis_value(event, axis); } static inline bool @@ -1703,7 +1705,10 @@ calculate_axis_value(struct xf86libinput *driver_data, double dist = driver_data->options.scroll_pixel_distance; assert(dist != 0.0); - value = get_finger_or_continuous_scroll_value(event, axis); + value = get_finger_or_continuous_scroll_value(driver_data, + event, + axis); + /* We need to scale this value into our scroll increment range * because that one is constant for the lifetime of the * device. The user may change the ScrollPixelDistance @@ -2404,6 +2409,7 @@ xf86libinput_handle_event(struct libinput_event *event) struct libinput_device *device; enum libinput_event_type type; InputInfoPtr pInfo; + struct xf86libinput *driver_data; enum event_handling event_handling = EVENT_HANDLED; type = libinput_event_get_type(event); @@ -2414,6 +2420,8 @@ xf86libinput_handle_event(struct libinput_event *event) if (!pInfo || !pInfo->dev->public.on) goto out; + driver_data = pInfo->private; + switch (type) { case LIBINPUT_EVENT_NONE: case LIBINPUT_EVENT_DEVICE_ADDED: @@ -2437,28 +2445,38 @@ xf86libinput_handle_event(struct libinput_event *event) libinput_event_get_keyboard_event(event)); break; case LIBINPUT_EVENT_POINTER_AXIS: -#if !HAVE_LIBINPUT_AXIS_VALUE_V120 - /* ignore POINTER_AXIS where we have libinput 1.19 and higher */ +#if HAVE_LIBINPUT_AXIS_VALUE_V120 + /* ignore POINTER_AXIS where we have libinput 1.19 and + higher and high-resolution scroll is enabled */ + if (driver_data->options.hires_scrolling_enabled) + break; +#endif + xf86libinput_handle_axis(pInfo, event, libinput_event_pointer_get_axis_source(event)); -#endif break; #if HAVE_LIBINPUT_AXIS_VALUE_V120 case LIBINPUT_EVENT_POINTER_SCROLL_WHEEL: - xf86libinput_handle_axis(pInfo, - event, - LIBINPUT_POINTER_AXIS_SOURCE_WHEEL); + if (driver_data->options.hires_scrolling_enabled) { + xf86libinput_handle_axis(pInfo, + event, + LIBINPUT_POINTER_AXIS_SOURCE_WHEEL); + } break; case LIBINPUT_EVENT_POINTER_SCROLL_FINGER: - xf86libinput_handle_axis(pInfo, - event, - LIBINPUT_POINTER_AXIS_SOURCE_FINGER); + if (driver_data->options.hires_scrolling_enabled) { + xf86libinput_handle_axis(pInfo, + event, + LIBINPUT_POINTER_AXIS_SOURCE_FINGER); + } break; case LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS: - xf86libinput_handle_axis(pInfo, - event, - LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS); + if (driver_data->options.hires_scrolling_enabled) { + xf86libinput_handle_axis(pInfo, + event, + LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS); + } break; #endif case LIBINPUT_EVENT_TOUCH_FRAME: @@ -3196,6 +3214,15 @@ xf86libinput_parse_horiz_scroll_option(InputInfoPtr pInfo) return xf86SetBoolOption(pInfo->options, "HorizontalScrolling", TRUE); } +static inline BOOL +xf86libinput_parse_hirescroll_option(InputInfoPtr pInfo, + struct libinput_device *device) +{ + return xf86SetBoolOption(pInfo->options, + "HighResolutionWheelScrolling", + TRUE); +} + static inline double xf86libinput_parse_rotation_angle_option(InputInfoPtr pInfo, struct libinput_device *device) @@ -3358,6 +3385,7 @@ xf86libinput_parse_options(InputInfoPtr pInfo, if (driver_data->capabilities & CAP_POINTER) { xf86libinput_parse_draglock_option(pInfo, driver_data); options->horiz_scrolling_enabled = xf86libinput_parse_horiz_scroll_option(pInfo); + options->hires_scrolling_enabled = xf86libinput_parse_hirescroll_option(pInfo, device); } xf86libinput_parse_pressurecurve_option(pInfo, @@ -3835,6 +3863,7 @@ static Atom prop_draglock; static Atom prop_horiz_scroll; static Atom prop_pressurecurve; static Atom prop_area_ratio; +static Atom prop_hires_scroll; /* general properties */ static Atom prop_float; @@ -4794,6 +4823,33 @@ LibinputSetPropertyAreaRatio(DeviceIntPtr dev, return Success; } +static inline int +LibinputSetPropertyHighResolutionScroll(DeviceIntPtr dev, + Atom atom, + XIPropertyValuePtr val, + BOOL checkonly) +{ + InputInfoPtr pInfo = dev->public.devicePrivate; + struct xf86libinput *driver_data = pInfo->private; + BOOL enabled; + + if (val->format != 8 || val->size != 1 || val->type != XA_INTEGER) + return BadMatch; + + enabled = *(BOOL*)val->data; + if (checkonly) { + if (enabled != 0 && enabled != 1) + return BadValue; + + if (!xf86libinput_check_device(dev, atom)) + return BadMatch; + } else { + driver_data->options.hires_scrolling_enabled = enabled; + } + + return Success; +} + static int LibinputSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val, BOOL checkonly) @@ -4854,6 +4910,8 @@ LibinputSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val, rc = LibinputSetPropertyPressureCurve(dev, atom, val, checkonly); else if (atom == prop_area_ratio) rc = LibinputSetPropertyAreaRatio(dev, atom, val, checkonly); + else if (atom == prop_hires_scroll) + rc = LibinputSetPropertyHighResolutionScroll(dev, atom, val, checkonly); else if (atom == prop_device || atom == prop_product_id || atom == prop_tap_default || atom == prop_tap_drag_default || @@ -5809,6 +5867,22 @@ LibinputInitTabletAreaRatioProperty(DeviceIntPtr dev, } static void +LibinputInitHighResolutionScrollProperty(DeviceIntPtr dev, + struct xf86libinput *driver_data, + struct libinput_device *device) +{ + BOOL enabled = driver_data->options.hires_scrolling_enabled; + + if ((driver_data->capabilities & CAP_POINTER) == 0) + return; + + prop_hires_scroll = LibinputMakeProperty(dev, + LIBINPUT_PROP_HIRES_WHEEL_SCROLL_ENABLED, + XA_INTEGER, 8, + 1, &enabled); +} + +static void LibinputInitProperty(DeviceIntPtr dev) { InputInfoPtr pInfo = dev->public.devicePrivate; @@ -5867,4 +5941,5 @@ LibinputInitProperty(DeviceIntPtr dev) LibinputInitScrollPixelDistanceProperty(dev, driver_data, device); LibinputInitPressureCurveProperty(dev, driver_data); LibinputInitTabletAreaRatioProperty(dev, driver_data); + LibinputInitHighResolutionScrollProperty(dev, driver_data, device); } |