[PATCH evdev] Add "Evdev Wheel Emulation Button Negate" property. #69055

Vitaly _Vi Shukela vi0oss at gmail.com
Fri Sep 6 14:53:04 PDT 2013


Makes wheel emulation active when the button is not pressed.

Signed-off-by: Vitaly _Vi Shukela <vi0oss at gmail.com>
---
 include/evdev-properties.h |  2 ++
 src/emuWheel.c             | 25 ++++++++++++++++++++++++-
 src/evdev.h                |  1 +
 3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/include/evdev-properties.h b/include/evdev-properties.h
index 745a1ba..b8fee66 100644
--- a/include/evdev-properties.h
+++ b/include/evdev-properties.h
@@ -45,6 +45,8 @@
 #define EVDEV_PROP_WHEEL_TIMEOUT "Evdev Wheel Emulation Timeout"
 /* CARD8, value range 0-32, 0 to always scroll */
 #define EVDEV_PROP_WHEEL_BUTTON "Evdev Wheel Emulation Button"
+/* CARD8, value range 0-1, 1 to always invert button meaning */
+#define EVDEV_PROP_WHEEL_BUTTON_NEGATE "Evdev Wheel Emulation Button Negate"
 
 /* Drag lock */
 /* CARD8, either 1 value or pairs, value range 0-32, 0 to disable a value*/
diff --git a/src/emuWheel.c b/src/emuWheel.c
index c0e92b1..6635703 100644
--- a/src/emuWheel.c
+++ b/src/emuWheel.c
@@ -49,6 +49,7 @@ static Atom prop_wheel_axismap  = 0;
 static Atom prop_wheel_inertia  = 0;
 static Atom prop_wheel_timeout  = 0;
 static Atom prop_wheel_button   = 0;
+static Atom prop_wheel_button_negate   = 0;
 
 /* Local Funciton Prototypes */
 static int EvdevWheelEmuInertia(InputInfoPtr pInfo, WheelAxisPtr axis, int value);
@@ -106,7 +107,7 @@ EvdevWheelEmuFilterMotion(InputInfoPtr pInfo, struct input_event *pEv)
     /* Handle our motion events if the emuWheel button is pressed
      * wheel button of 0 means always emulate wheel.
      */
-    if (pEvdev->emulateWheel.button_state || !pEvdev->emulateWheel.button) {
+    if (((!!pEvdev->emulateWheel.button_state) ^ pEvdev->emulateWheel.button_negate) || !pEvdev->emulateWheel.button) {
         /* Just return if the timeout hasn't expired yet */
         if (pEvdev->emulateWheel.button)
         {
@@ -370,6 +371,20 @@ EvdevWheelEmuSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val,
 
         if (!checkonly)
             pEvdev->emulateWheel.button = bt;
+    } else if (atom == prop_wheel_button_negate)
+    {
+        int bt;
+
+        if (val->format != 8 || val->size != 1 || val->type != XA_INTEGER)
+            return BadMatch;
+
+        bt = *((CARD8*)val->data);
+
+        if (bt < 0 || bt > 1)
+            return BadValue;
+
+        if (!checkonly)
+            pEvdev->emulateWheel.button_negate = bt;
     } else if (atom == prop_wheel_axismap)
     {
         if (val->format != 8 || val->size != 4 || val->type != XA_INTEGER)
@@ -472,6 +487,14 @@ EvdevWheelEmuInitProperty(DeviceIntPtr dev)
                                 &pEvdev->emulateWheel.button, FALSE);
     if (rc != Success)
         return;
+    
+    
+    prop_wheel_button_negate = MakeAtom(EVDEV_PROP_WHEEL_BUTTON_NEGATE, strlen(EVDEV_PROP_WHEEL_BUTTON_NEGATE), TRUE);
+    rc = XIChangeDeviceProperty(dev, prop_wheel_button_negate, XA_INTEGER, 8,
+                                PropModeReplace, 1,
+                                &pEvdev->emulateWheel.button_negate, FALSE);
+    if (rc != Success)
+        return;
 
     XISetDevicePropertyDeletable(dev, prop_wheel_button, FALSE);
 
diff --git a/src/evdev.h b/src/evdev.h
index 4742b43..afa8f0d 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -219,6 +219,7 @@ typedef struct {
         WheelAxis           Y;
         Time                expires;     /* time of expiry */
         Time                timeout;
+        int                 button_negate;
     } emulateWheel;
     /* run-time calibration */
     struct {
-- 
1.8.3.2.10.g43d11f4



More information about the xorg-devel mailing list