summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter@cs.unisa.edu.au>2008-04-30 11:45:19 +0930
committerPeter Hutterer <peter@cs.unisa.edu.au>2008-04-30 11:49:11 +0930
commitffaccc2dc91f4ca4ea10da010206a0a7d2b5540c (patch)
treee43860833bbf53bf98ade1f81edae679cc2dbc93
parent00acb40f2bc5bb4a1977b9b08db75630677ff787 (diff)
input: replace -1 as default axis limit with NO_AXIS_LIMIT define.
This allows easier refacturing of the coordinate limit handling. Grepping for -1 is boring.
-rw-r--r--Xi/exevents.c13
-rw-r--r--dix/devices.c15
-rw-r--r--dix/getevents.c17
-rw-r--r--include/input.h2
4 files changed, 30 insertions, 17 deletions
diff --git a/Xi/exevents.c b/Xi/exevents.c
index 761950ead..d0c10d9da 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -1153,13 +1153,22 @@ InitProximityClassDeviceStruct(DeviceIntPtr dev)
return TRUE;
}
+/**
+ * Initialise the device's valuators. The memory must already be allocated,
+ * this function merely inits the matching axis (specified through axnum) to
+ * sane values.
+ *
+ * It is a condition that (minval < maxval).
+ *
+ * @see InitValuatorClassDeviceStruct
+ */
_X_EXPORT void
InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, int minval, int maxval,
int resolution, int min_res, int max_res)
{
AxisInfoPtr ax;
-
- if (!dev || !dev->valuator)
+
+ if (!dev || !dev->valuator || minval > maxval)
return;
ax = dev->valuator->axes + axnum;
diff --git a/dix/devices.c b/dix/devices.c
index 37feb34a3..abd3cb6d2 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -1187,7 +1187,8 @@ InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes,
AllocateMotionHistory(dev);
for (i=0; i<numAxes; i++) {
- InitValuatorAxisStruct(dev, i, -1, -1, 0, 0, 0);
+ InitValuatorAxisStruct(dev, i, NO_AXIS_LIMITS, NO_AXIS_LIMITS,
+ 0, 0, 0);
valc->axisVal[i]=0;
}
return TRUE;
@@ -1203,10 +1204,10 @@ InitAbsoluteClassDeviceStruct(DeviceIntPtr dev)
return FALSE;
/* we don't do anything sensible with these, but should */
- abs->min_x = -1;
- abs->min_y = -1;
- abs->max_x = -1;
- abs->max_y = -1;
+ abs->min_x = NO_AXIS_LIMITS;
+ abs->min_y = NO_AXIS_LIMITS;
+ abs->max_x = NO_AXIS_LIMITS;
+ abs->max_y = NO_AXIS_LIMITS;
abs->flip_x = 0;
abs->flip_y = 0;
abs->rotation = 0;
@@ -1214,8 +1215,8 @@ InitAbsoluteClassDeviceStruct(DeviceIntPtr dev)
abs->offset_x = 0;
abs->offset_y = 0;
- abs->width = -1;
- abs->height = -1;
+ abs->width = NO_AXIS_LIMITS;
+ abs->height = NO_AXIS_LIMITS;
abs->following = 0;
abs->screen = 0;
diff --git a/dix/getevents.c b/dix/getevents.c
index e9c1db0f5..a358bb3e9 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -358,14 +358,15 @@ clipAxis(DeviceIntPtr pDev, int axisNum, int *val)
{
AxisInfoPtr axes = pDev->valuator->axes + axisNum;
- /* Don't clip if min_value and max_value are the same, or if an invalid
- range is specified. */
- if(axes->min_value < axes->max_value) {
- if (*val < axes->min_value)
- *val = axes->min_value;
- if (*val > axes->max_value)
- *val = axes->max_value;
- }
+ /* InitValuatoraAxisStruct ensures that (min < max) */
+
+ if (axes->min_value != NO_AXIS_LIMITS &&
+ *val < axis->min_value)
+ *val = axes->min_value;
+
+ if (axes->max_value != NO_AXIS_LIMITS &&
+ *val > axes->max_value)
+ *val = axes->max_value;
}
/**
diff --git a/include/input.h b/include/input.h
index 10dadfebc..ec6ac90e1 100644
--- a/include/input.h
+++ b/include/input.h
@@ -63,6 +63,8 @@ SOFTWARE.
#define POINTER_ABSOLUTE (1 << 2)
#define POINTER_ACCELERATE (1 << 3)
+#define NO_AXIS_LIMITS -1
+
#define MAP_LENGTH 256
#define DOWN_LENGTH 32 /* 256/8 => number of bytes to hold 256 bits */
#define NullGrab ((GrabPtr)NULL)