[PATCH xf86-input-libinput 2/2] Add an option to disable horizontal scrolling

Hans de Goede hdegoede at redhat.com
Wed Aug 12 01:44:01 PDT 2015


Hi,

On 12-08-15 03:28, Peter Hutterer wrote:
> libinput always has horizontal scrolling enabled and punts the decision when
> to scroll horizontally to the toolkit/widget. This is the better approach, but
> while we have a stack that's not ready for that, and in the X case likely
> never will be fully ready provide an option to disable horizontal scrolling.
>
> This option doesn't really disable horizontal scrolling, it merely discards
> any horizontal scroll delta. libinput will still think it's scrolling.
>
> https://bugs.freedesktop.org/show_bug.cgi?id=91589
>
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

LGTM: Reviewed-by: Hans de Goede <hdegoede at redhat.com>

Regards,

Hans


> ---
>   include/libinput-properties.h |  4 +++
>   man/libinput.man              | 10 ++++++++
>   src/xf86libinput.c            | 60 ++++++++++++++++++++++++++++++++++++++++++-
>   3 files changed, 73 insertions(+), 1 deletion(-)
>
> diff --git a/include/libinput-properties.h b/include/libinput-properties.h
> index ed009d5..06fad7f 100644
> --- a/include/libinput-properties.h
> +++ b/include/libinput-properties.h
> @@ -120,4 +120,8 @@
>      the target button number */
>   #define LIBINPUT_PROP_DRAG_LOCK_BUTTONS "libinput Drag Lock Buttons"
>
> +/* Horizontal scroll events enabled: BOOL, 1 value (0 or 1).
> + * If disabled, horizontal scroll events are discarded */
> +#define LIBINPUT_PROP_HORIZ_SCROLL_ENABLED "libinput Horizonal Scroll Enabled"
> +
>   #endif /* _LIBINPUT_PROPERTIES_H_ */
> diff --git a/man/libinput.man b/man/libinput.man
> index ff7a411..3c35776 100644
> --- a/man/libinput.man
> +++ b/man/libinput.man
> @@ -107,6 +107,12 @@ Enables a scroll method. Permitted values are
>   Not all devices support all options, if an option is unsupported, the
>   default scroll option for this device is used.
>   .TP 7
> +.BI "Option \*qHorizontalScrolling\*q" bool \*q
> +Disables horizontal scrolling. When disabled, this driver will discard any
> +horizontal scroll events from libinput. Note that this does not disable
> +horizontal scrolling, it merely discards the horizontal axis from any scroll
> +events.
> +.TP 7
>   .BI "Option \*qSendEventsMode\*q \*q" (disabled|enabled|disabled-on-external-mouse) \*q
>   Sets the send events mode to disabled, enabled, or "disable when an external
>   mouse is connected".
> @@ -226,6 +232,10 @@ Either one 8-bit value specifying the meta drag lock button, or a list of
>   button pairs. See section
>   .B BUTTON DRAG LOCK
>   for details.
> +.TP 7
> +.BI "libinput Horizontal Scrolling Enabled"
> +1 boolean value (8 bit, 0 or 1). Indicates whether horizontal scrolling
> +events are enabled or not.
>
>   .SH BUTTON MAPPING
>   X clients receive events with logical button numbers, where 1, 2, 3
> diff --git a/src/xf86libinput.c b/src/xf86libinput.c
> index 8500792..8987518 100644
> --- a/src/xf86libinput.c
> +++ b/src/xf86libinput.c
> @@ -111,6 +111,8 @@ struct xf86libinput {
>   		enum libinput_config_click_method click_method;
>
>   		unsigned char btnmap[MAX_BUTTONS + 1];
> +
> +		BOOL horiz_scrolling_enabled;
>   	} options;
>
>   	struct draglock draglock;
> @@ -831,6 +833,10 @@ xf86libinput_handle_axis(InputInfoPtr pInfo, struct libinput_event_pointer *even
>   		}
>   		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) {
> @@ -842,6 +848,7 @@ xf86libinput_handle_axis(InputInfoPtr pInfo, struct libinput_event_pointer *even
>   		valuator_mask_set_double(mask, 2, value);
>   	}
>
> +out:
>   	xf86PostMotionEventM(dev, Relative, mask);
>   }
>
> @@ -1425,6 +1432,12 @@ xf86libinput_parse_draglock_option(InputInfoPtr pInfo,
>   	free(str);
>   }
>
> +static inline BOOL
> +xf86libinput_parse_horiz_scroll_option(InputInfoPtr pInfo)
> +{
> +	return xf86SetBoolOption(pInfo->options, "HorizontalScrolling", TRUE);
> +}
> +
>   static void
>   xf86libinput_parse_options(InputInfoPtr pInfo,
>   			   struct xf86libinput *driver_data,
> @@ -1450,8 +1463,10 @@ xf86libinput_parse_options(InputInfoPtr pInfo,
>   	xf86libinput_parse_buttonmap_option(pInfo,
>   					    options->btnmap,
>   					    sizeof(options->btnmap));
> -	if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
> +	if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER)) {
>   		xf86libinput_parse_draglock_option(pInfo, driver_data);
> +		options->horiz_scrolling_enabled = xf86libinput_parse_horiz_scroll_option(pInfo);
> +	}
>   }
>
>   static int
> @@ -1647,6 +1662,7 @@ static Atom prop_disable_while_typing_default;
>
>   /* driver properties */
>   static Atom prop_draglock;
> +static Atom prop_horiz_scroll;
>
>   /* general properties */
>   static Atom prop_float;
> @@ -2166,6 +2182,33 @@ LibinputSetPropertyDragLockButtons(DeviceIntPtr dev,
>   					       val->size, checkonly);
>   }
>
> +static inline int
> +LibinputSetPropertyHorizScroll(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->type != XA_INTEGER || val->size != 1)
> +		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.horiz_scrolling_enabled = enabled;
> +	}
> +
> +	return Success;
> + }
> +
>   static int
>   LibinputSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val,
>                    BOOL checkonly)
> @@ -2205,6 +2248,8 @@ LibinputSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val,
>   		rc = LibinputSetPropertyDisableWhileTyping(dev, atom, val, checkonly);
>   	else if (atom == prop_draglock)
>   		rc = LibinputSetPropertyDragLockButtons(dev, atom, val, checkonly);
> +	else if (atom == prop_horiz_scroll)
> +		rc = LibinputSetPropertyHorizScroll(dev, atom, val, checkonly);
>   	else if (atom == prop_device || atom == prop_product_id ||
>   		 atom == prop_tap_default ||
>   		 atom == prop_tap_drag_lock_default ||
> @@ -2704,6 +2749,18 @@ LibinputInitDragLockProperty(DeviceIntPtr dev,
>   }
>
>   static void
> +LibinputInitHorizScrollProperty(DeviceIntPtr dev,
> +				struct xf86libinput *driver_data)
> +{
> +	BOOL enabled = driver_data->options.horiz_scrolling_enabled;
> +
> +	prop_horiz_scroll = LibinputMakeProperty(dev,
> +						 LIBINPUT_PROP_HORIZ_SCROLL_ENABLED,
> +						 XA_INTEGER, 8,
> +						 1, &enabled);
> +}
> +
> +static void
>   LibinputInitProperty(DeviceIntPtr dev)
>   {
>   	InputInfoPtr pInfo  = dev->public.devicePrivate;
> @@ -2754,4 +2811,5 @@ LibinputInitProperty(DeviceIntPtr dev)
>   	XISetDevicePropertyDeletable(dev, prop_product_id, FALSE);
>
>   	LibinputInitDragLockProperty(dev, driver_data);
> +	LibinputInitHorizScrollProperty(dev, driver_data);
>   }
>


More information about the xorg-devel mailing list