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; iaxisVal[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)