[PATCH] input: allow for max < min for relative axes on InitValuatorAxisStruct

Peter Hutterer peter.hutterer at who-t.net
Mon Aug 15 22:42:51 PDT 2011


And use this occasion to switch InitValuatorAxisStruct to return Bool
instead of just silently ignoring issues.

Relative axes are initialized with 0, -1 but so far this never had any
effect as all users of this function (for relative axes) just set it to the
defaults anyway.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
There's probably more work to be done in the input API to make it slightly
saner, but otoh that's been true for several years now...

 Xi/exevents.c                  |   10 ++++++----
 hw/xfree86/common/xf86Xinput.c |    8 ++++----
 hw/xfree86/common/xf86Xinput.h |    2 +-
 include/exevents.h             |    2 +-
 4 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/Xi/exevents.c b/Xi/exevents.c
index aca2d2d..3c36880 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -1068,16 +1068,16 @@ InitProximityClassDeviceStruct(DeviceIntPtr dev)
  *
  * @see InitValuatorClassDeviceStruct
  */
-void
+Bool
 InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, Atom label, int minval, int maxval,
 		       int resolution, int min_res, int max_res, int mode, int flags)
 {
     AxisInfoPtr ax;
 
-    if (!dev || !dev->valuator || minval > maxval)
-        return;
+    if (!dev || !dev->valuator || (minval > maxval && mode == Absolute))
+        return FALSE;
     if (axnum >= dev->valuator->numAxes)
-        return;
+        return FALSE;
 
     ax = dev->valuator->axes + axnum;
 
@@ -1097,6 +1097,8 @@ InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, Atom label, int minval, int
 
     if (mode & OutOfProximity)
         dev->proximity->in_proximity = FALSE;
+
+    return TRUE;
 }
 
 static void
diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index fa832a1..86c2e4a 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -1334,15 +1334,15 @@ xf86XInputSetScreen(InputInfoPtr	pInfo,
 }
 
 
-void
+Bool
 xf86InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, Atom label, int minval, int maxval,
 			   int resolution, int min_res, int max_res, int mode, int flags)
 {
     if (!dev || !dev->valuator)
-        return;
+        return FALSE;
 
-    InitValuatorAxisStruct(dev, axnum, label, minval, maxval, resolution, min_res,
-			   max_res, mode, flags);
+    return InitValuatorAxisStruct(dev, axnum, label, minval, maxval, resolution, min_res,
+				  max_res, mode, flags);
 }
 
 /*
diff --git a/hw/xfree86/common/xf86Xinput.h b/hw/xfree86/common/xf86Xinput.h
index 239bd37..40c0902 100644
--- a/hw/xfree86/common/xf86Xinput.h
+++ b/hw/xfree86/common/xf86Xinput.h
@@ -145,7 +145,7 @@ extern _X_EXPORT InputInfoPtr xf86FirstLocalDevice(void);
 extern _X_EXPORT int xf86ScaleAxis(int Cx, int to_max, int to_min, int from_max, int from_min);
 extern _X_EXPORT void xf86XInputSetScreen(InputInfoPtr pInfo, int screen_number, int x, int y);
 extern _X_EXPORT void xf86ProcessCommonOptions(InputInfoPtr pInfo, pointer options);
-extern _X_EXPORT void xf86InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, Atom label, int minval,
+extern _X_EXPORT Bool xf86InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, Atom label, int minval,
 				int maxval, int resolution, int min_res,
 				int max_res, int mode, int flags);
 extern _X_EXPORT void xf86InitValuatorDefaults(DeviceIntPtr dev, int axnum);
diff --git a/include/exevents.h b/include/exevents.h
index eefd897..2613a2a 100644
--- a/include/exevents.h
+++ b/include/exevents.h
@@ -40,7 +40,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 extern _X_EXPORT int InitProximityClassDeviceStruct(
 	DeviceIntPtr           /* dev */);
 
-extern _X_EXPORT void InitValuatorAxisStruct(
+extern _X_EXPORT Bool InitValuatorAxisStruct(
 	DeviceIntPtr           /* dev */,
 	int                    /* axnum */,
 	Atom                   /* label */,
-- 
1.7.6



More information about the xorg-devel mailing list