From 4bae866aa0ce31cda9a23748c148289d3df72e10 Mon Sep 17 00:00:00 2001 From: Peter De Wachter Date: Wed, 3 Oct 2012 22:08:12 +0200 Subject: [PATCH 3/3] Export smooth scroll settings as an XInput property. A new property "Evdev Scrolling Distance" is created that holds three values (vertical, horizontal and dial). Signed-off-by: Peter De Wachter --- include/evdev-properties.h | 4 ++ man/evdev.man | 8 +++- src/evdev.c | 91 +++++++++++++++++++++++++++++++++++++------- 3 files changed, 87 insertions(+), 16 deletions(-) diff --git a/include/evdev-properties.h b/include/evdev-properties.h index 745a1ba..b09ca5c 100644 --- a/include/evdev-properties.h +++ b/include/evdev-properties.h @@ -87,4 +87,8 @@ */ #define EVDEV_PROP_FUNCTION_KEYS "Evdev Function Keys" +/* Smooth scroll */ +/* FLOAT, 3 values (vertical, horizontal, dial) */ +#define EVDEV_PROP_SCROLL_DISTANCE "Evdev Scrolling Distance" + #endif diff --git a/man/evdev.man b/man/evdev.man index 886d0ae..8b885bd 100644 --- a/man/evdev.man +++ b/man/evdev.man @@ -223,14 +223,15 @@ is mapped to the positive Y axis motion. Default: "4 5". Property: .TP 7 .BI "Option \*qVertScrollDelta\*q \*q" "float" \*q The amount of motion considered one unit of scrolling vertically. -Default: "1". +Default: "1". Property: "Evdev Scrolling Distance". .TP 7 .BI "Option \*qHorizScrollDelta\*q \*q" "float" \*q The amount of motion considered one unit of scrolling horizontally. -Default: "1". +Default: "1". Proprety: "Evdev Scrolling Distance". .TP 7 .BI "Option \*qDialDelta\*q \*q" "float" \*q The amount of motion considered one unit of turning the dial. Default: "1". +Property: "Evdev Scrolling Distance". .SH SUPPORTED PROPERTIES The following properties are provided by the @@ -271,6 +272,9 @@ value. .TP 7 .BI "Evdev Wheel Emulation Timeout" 1 16-bit positive value. +.TP 7 +.BI "Evdev Scrolling Distance" +3 float values: vertical, horizontal and dial. .SH AUTHORS Kristian Høgsberg, Peter Hutterer diff --git a/src/evdev.c b/src/evdev.c index decaee7..a9a3a6d 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -137,6 +137,8 @@ static Atom prop_axis_label; static Atom prop_btn_label; static Atom prop_device; static Atom prop_virtual; +static Atom prop_scroll_dist; +static Atom float_type; /* All devices the evdev driver has allocated and knows about. * MAXDEVICES is safe as null-terminated array, as two devices (VCP and VCK) @@ -1593,6 +1595,41 @@ out: } static int +EvdevSetScrollValuators(DeviceIntPtr device) +{ + InputInfoPtr pInfo; + EvdevPtr pEvdev; + int axis; + + pInfo = device->public.devicePrivate; + pEvdev = pInfo->private; + + for (axis = REL_X; axis <= REL_MAX; axis++) + { + int axnum = pEvdev->rel_axis_map[axis]; + if (axnum == -1) + continue; + +#ifdef HAVE_SMOOTH_SCROLLING + if (axis == REL_WHEEL) + SetScrollValuator(device, axnum, SCROLL_TYPE_VERTICAL, + -pEvdev->smoothScroll.vert_delta, + SCROLL_FLAG_PREFERRED); + else if (axis == REL_DIAL) + SetScrollValuator(device, axnum, SCROLL_TYPE_VERTICAL, + -pEvdev->smoothScroll.dial_delta, + SCROLL_FLAG_NONE); + else if (axis == REL_HWHEEL) + SetScrollValuator(device, axnum, SCROLL_TYPE_HORIZONTAL, + pEvdev->smoothScroll.horiz_delta, + SCROLL_FLAG_NONE); +#endif + } + + return Success; +} + +static int EvdevAddRelValuatorClass(DeviceIntPtr device) { InputInfoPtr pInfo; @@ -1674,22 +1711,10 @@ EvdevAddRelValuatorClass(DeviceIntPtr device) xf86InitValuatorAxisStruct(device, axnum, atoms[axnum], -1, -1, 1, 0, 1, Relative); xf86InitValuatorDefaults(device, axnum); -#ifdef HAVE_SMOOTH_SCROLLING - if (axis == REL_WHEEL) - SetScrollValuator(device, axnum, SCROLL_TYPE_VERTICAL, - -pEvdev->smoothScroll.vert_delta, - SCROLL_FLAG_PREFERRED); - else if (axis == REL_DIAL) - SetScrollValuator(device, axnum, SCROLL_TYPE_VERTICAL, - -pEvdev->smoothScroll.dial_delta, - SCROLL_FLAG_NONE); - else if (axis == REL_HWHEEL) - SetScrollValuator(device, axnum, SCROLL_TYPE_HORIZONTAL, - pEvdev->smoothScroll.horiz_delta, - SCROLL_FLAG_NONE); -#endif } + EvdevSetScrollValuators(device); + free(atoms); return Success; @@ -2821,6 +2846,11 @@ EvdevInitProperty(DeviceIntPtr dev) CARD32 product[2]; + float_type = XIGetKnownProperty(XATOM_FLOAT); + if (!float_type) { + float_type = MakeAtom(XATOM_FLOAT, strlen(XATOM_FLOAT), TRUE); + } + prop_product_id = MakeAtom(XI_PROP_PRODUCT_ID, strlen(XI_PROP_PRODUCT_ID), TRUE); product[0] = pEvdev->id_vendor; product[1] = pEvdev->id_product; @@ -2936,6 +2966,27 @@ EvdevInitProperty(DeviceIntPtr dev) PropModeReplace, pEvdev->num_buttons, atoms, FALSE); XISetDevicePropertyDeletable(dev, prop_btn_label, FALSE); } + +#ifdef HAVE_SMOOTH_SCROLLING + if (!float_type) { + xf86IDrvMsg(pInfo, X_WARNING, + "evdev: Failed to init float atom, \"" EVDEV_PROP_SCROLL_DISTANCE + "\" property is not available.\n"); + } + else { + float values[] = { + pEvdev->smoothScroll.vert_delta, + pEvdev->smoothScroll.horiz_delta, + pEvdev->smoothScroll.dial_delta + }; + prop_scroll_dist = MakeAtom(EVDEV_PROP_SCROLL_DISTANCE, + strlen(EVDEV_PROP_SCROLL_DISTANCE), TRUE); + XIChangeDeviceProperty(dev, prop_scroll_dist, float_type, 32, + PropModeReplace, 3, values, FALSE); + XISetDevicePropertyDeletable(dev, prop_scroll_dist, FALSE); + } +#endif + } } @@ -2975,6 +3026,18 @@ EvdevSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val, if (!checkonly) pEvdev->swap_axes = *((BOOL*)val->data); + } else if (atom == prop_scroll_dist) + { + if (val->format != 32 || val->type != float_type || val->size != 3) + return BadMatch; + + if (!checkonly) { + float* data = (float *)val->data; + pEvdev->smoothScroll.vert_delta = data[0]; + pEvdev->smoothScroll.horiz_delta = data[1]; + pEvdev->smoothScroll.dial_delta = data[2]; + EvdevSetScrollValuators(dev); + } } else if (atom == prop_axis_label || atom == prop_btn_label || atom == prop_product_id || atom == prop_device || atom == prop_virtual) -- 1.7.10.4