From a35419eab051e5adb4796da5e69edb589560c669 Mon Sep 17 00:00:00 2001 From: Peter De Wachter Date: Wed, 3 Oct 2012 22:08:12 +0200 Subject: [PATCH 2/2] Export smooth scroll settings as XInput properties. Signed-off-by: Peter De Wachter --- include/evdev-properties.h | 9 ++++ src/evdev.c | 108 ++++++++++++++++++++++++++++++++++++++------ 2 files changed, 103 insertions(+), 14 deletions(-) diff --git a/include/evdev-properties.h b/include/evdev-properties.h index 745a1ba..dd14ed1 100644 --- a/include/evdev-properties.h +++ b/include/evdev-properties.h @@ -87,4 +87,13 @@ */ #define EVDEV_PROP_FUNCTION_KEYS "Evdev Function Keys" +/* Smooth scroll */ +/* FLOAT */ +#define EVDEV_PROP_VERT_SCROLL_DELTA "Evdev Vert Scroll Delta" +/* FLOAT */ +#define EVDEV_PROP_HORIZ_SCROLL_DELTA "Evdev Horiz Scroll Delta" +/* FLOAT */ +#define EVDEV_PROP_DIAL_DELTA "Evdev Dial Delta" + + #endif diff --git a/src/evdev.c b/src/evdev.c index bc523e2..4071e76 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -137,6 +137,10 @@ static Atom prop_axis_label; static Atom prop_btn_label; static Atom prop_device; static Atom prop_virtual; +static Atom prop_vert_delta; +static Atom prop_horiz_delta; +static Atom prop_dial_delta; +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) @@ -1518,6 +1522,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->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; @@ -1599,22 +1638,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; @@ -2726,6 +2753,14 @@ EvdevInitProperty(DeviceIntPtr dev) CARD32 product[2]; + float_type = XIGetKnownProperty(XATOM_FLOAT); + if (!float_type) { + float_type = MakeAtom(XATOM_FLOAT, strlen(XATOM_FLOAT), TRUE); + if (!float_type) { + xf86Msg(X_ERROR, "evdev: Failed to init float atom. Property support is disabled.\n"); + } + } + prop_product_id = MakeAtom(XI_PROP_PRODUCT_ID, strlen(XI_PROP_PRODUCT_ID), TRUE); product[0] = pEvdev->id_vendor; product[1] = pEvdev->id_product; @@ -2841,6 +2876,33 @@ EvdevInitProperty(DeviceIntPtr dev) PropModeReplace, pEvdev->num_buttons, atoms, FALSE); XISetDevicePropertyDeletable(dev, prop_btn_label, FALSE); } + +#ifdef HAVE_SMOOTH_SCROLLING + prop_vert_delta = MakeAtom(EVDEV_PROP_VERT_SCROLL_DELTA, + strlen(EVDEV_PROP_VERT_SCROLL_DELTA), TRUE); + rc = XIChangeDeviceProperty(dev, prop_vert_delta, float_type, 32, + PropModeReplace, 1, &pEvdev->smoothScroll.vert_delta, FALSE); + if (rc != Success) + return; + XISetDevicePropertyDeletable(dev, prop_vert_delta, FALSE); + + prop_horiz_delta = MakeAtom(EVDEV_PROP_HORIZ_SCROLL_DELTA, + strlen(EVDEV_PROP_HORIZ_SCROLL_DELTA), TRUE); + rc = XIChangeDeviceProperty(dev, prop_horiz_delta, float_type, 32, + PropModeReplace, 1, &pEvdev->smoothScroll.horiz_delta, FALSE); + if (rc != Success) + return; + XISetDevicePropertyDeletable(dev, prop_horiz_delta, FALSE); + + prop_dial_delta = MakeAtom(EVDEV_PROP_DIAL_DELTA, + strlen(EVDEV_PROP_DIAL_DELTA), TRUE); + rc = XIChangeDeviceProperty(dev, prop_dial_delta, float_type, 32, + PropModeReplace, 1, &pEvdev->smoothScroll.dial_delta, FALSE); + if (rc != Success) + return; + XISetDevicePropertyDeletable(dev, prop_dial_delta, FALSE); +#endif + } } @@ -2880,6 +2942,24 @@ EvdevSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val, if (!checkonly) pEvdev->swap_axes = *((BOOL*)val->data); + } else if (atom == prop_vert_delta || + atom == prop_horiz_delta || + atom == prop_dial_delta) + { + if (val->format != 32 || val->type != float_type || val->size != 1) + return BadMatch; + + if (!checkonly) + { + float data = *(float *)val->data; + if (atom == prop_vert_delta) + pEvdev->smoothScroll.vert_delta = data; + else if (atom == prop_horiz_delta) + pEvdev->smoothScroll.horiz_delta = data; + else if (atom == prop_dial_delta) + pEvdev->smoothScroll.dial_delta = data; + 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