From 3c28a29e132d6f73c36d4b64818d112b1c6e9a40 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 13 Oct 2010 15:53:59 +1000 Subject: xfree86: rename parameter names to xf86ScaleAxis. Maybe it's just me but every time I look at it I get confused again and need to work it out from scratch. Rename the parameters to something self-explanatory, to/from and min/max. No functional change. Signed-off-by: Peter Hutterer Reviewed-by: Julien Cristau --- hw/xfree86/common/xf86Xinput.c | 35 +++++++++++++++++++---------------- hw/xfree86/common/xf86Xinput.h | 2 +- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c index 877eb0382..e71b09cd2 100644 --- a/hw/xfree86/common/xf86Xinput.c +++ b/hw/xfree86/common/xf86Xinput.c @@ -1238,40 +1238,43 @@ xf86FirstLocalDevice(void) /* * Cx - raw data from touch screen - * Sxhigh - scaled highest dimension + * to_max - scaled highest dimension * (remember, this is of rows - 1 because of 0 origin) - * Sxlow - scaled lowest dimension - * Rxhigh - highest raw value from touch screen calibration - * Rxlow - lowest raw value from touch screen calibration + * to_min - scaled lowest dimension + * from_max - highest raw value from touch screen calibration + * from_min - lowest raw value from touch screen calibration * * This function is the same for X or Y coordinates. * You may have to reverse the high and low values to compensate for * different orgins on the touch screen vs X. + * + * e.g. to scale from device coordinates into screen coordinates, call + * xf86ScaleAxis(x, 0, screen_width, dev_min, dev_max); */ int xf86ScaleAxis(int Cx, - int Sxhigh, - int Sxlow, - int Rxhigh, - int Rxlow ) + int to_max, + int to_min, + int from_max, + int from_min ) { int X; - int64_t dSx = Sxhigh - Sxlow; - int64_t dRx = Rxhigh - Rxlow; + int64_t to_width = to_max - to_min; + int64_t from_width = from_max - from_min; - if (dRx) { - X = (int)(((dSx * (Cx - Rxlow)) / dRx) + Sxlow); + if (from_width) { + X = (int)(((to_width * (Cx - from_min)) / from_width) + to_min); } else { X = 0; ErrorF ("Divide by Zero in xf86ScaleAxis"); } - if (X > Sxhigh) - X = Sxhigh; - if (X < Sxlow) - X = Sxlow; + if (X > to_max) + X = to_max; + if (X < to_min) + X = to_min; return X; } diff --git a/hw/xfree86/common/xf86Xinput.h b/hw/xfree86/common/xf86Xinput.h index 7b60cdfea..1d013aa67 100644 --- a/hw/xfree86/common/xf86Xinput.h +++ b/hw/xfree86/common/xf86Xinput.h @@ -184,7 +184,7 @@ extern _X_EXPORT void xf86PostKeyboardEvent(DeviceIntPtr device, unsigned int ke int is_down); extern _X_EXPORT int xf86ActivateDevice(LocalDevicePtr local); extern _X_EXPORT LocalDevicePtr xf86FirstLocalDevice(void); -extern _X_EXPORT int xf86ScaleAxis(int Cx, int Sxhigh, int Sxlow, int Rxhigh, int Rxlow); +extern _X_EXPORT int xf86ScaleAxis(int Cx, int to_max, int to_min, int from_max, int from_min); extern _X_EXPORT void xf86XInputSetScreen(LocalDevicePtr local, 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, -- cgit v1.2.3 From 424b856e8e19f35c24bfc0a9fced9464d2f17c90 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 15 Oct 2010 14:35:22 +1000 Subject: dix: update comments for GetPointerEvents and friends All these now generate InternalEvents, point this out. Remove XKB/XI references, that's just confusing. This comment referred to the old-style event generation code from server 1.4 to including 1.6 but is now just confusing to newcomers. Remove comment about SwitchCoreKeyboard() for the same reason. Signed-off-by: Peter Hutterer Reviewed-by: Chase Douglas --- dix/getevents.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/dix/getevents.c b/dix/getevents.c index e5134d34b..ecbf416b1 100644 --- a/dix/getevents.c +++ b/dix/getevents.c @@ -894,20 +894,12 @@ GetKeyboardEvents(EventList *events, DeviceIntPtr pDev, int type, int key_code) /** - * Returns a set of keyboard events for KeyPress/KeyRelease, optionally - * also with valuator events. Handles Xi and XKB. - * - * DOES NOT GENERATE CORE EVENTS! Core events are created when processing the - * event (ProcessOtherEvent). + * Returns a set of InternalEvents for KeyPress/KeyRelease, optionally + * also with valuator events. * * events is not NULL-terminated; the return value is the number of events. * The DDX is responsible for allocating the event structure in the first * place via GetMaximumEventsNum(), and for freeing it. - * - * This function does not change the core keymap to that of the device; - * that is done by SwitchCoreKeyboard, which is called from - * mieqProcessInputEvents. If replacing that function, take care to call - * SetCoreKeyboard before processInputProc, so keymaps are altered to suit. */ int GetKeyboardValuatorEvents(EventList *events, DeviceIntPtr pDev, int type, @@ -1050,11 +1042,8 @@ transformAbsolute(DeviceIntPtr dev, int v[MAX_VALUATORS]) } /** - * Generate a series of xEvents (filled into the EventList) representing - * pointer motion, or button presses. Xi and XKB-aware. - * - * DOES NOT GENERATE CORE EVENTS! Core events are created when processing the - * event (ProcessOtherEvent). + * Generate a series of InternalEvents (filled into the EventList) + * representing pointer motion, or button presses. * * events is not NULL-terminated; the return value is the number of events. * The DDX is responsible for allocating the event structure in the first @@ -1183,7 +1172,8 @@ GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons, /** - * Post ProximityIn/ProximityOut events, accompanied by valuators. + * Generate ProximityIn/ProximityOut InternalEvents, accompanied by + * valuators. * * events is not NULL-terminated; the return value is the number of events. * The DDX is responsible for allocating the event structure in the first -- cgit v1.2.3 From e354ccac36a8ee3a23bdc845833c16a5646cc200 Mon Sep 17 00:00:00 2001 From: Joe Shaw Date: Thu, 14 Oct 2010 15:09:20 -0400 Subject: fix a sign problem with valuator data. Without this patch, any negative valuator value is wrong when returned from XQueryDeviceState(). This is a regression from at least xserver 1.4. Valuator data is set in dix/getevents.c:set_valuators() by copying signed int values into an unsigned int field DeviceEvent.valuators.data. That data is converted into a double with an implicit cast by assignment to axisVal[i] in Xi/exevents.c:UpdateDeviceState(). That double is converted back to a signed int in queryst.c:ProcXQueryDeviceState(). If the original value in set_valuators() is negative, the double value will be > 2^31 and the conversion back to a signed int is undefined. (Although I consistently see the value -2^31.) Fix this by changing the definition of DeviceEvent.valuators.data from uint32_t to int32_t. Signed-off-by: Joe Shaw Reviewed-by: Chase Douglas Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- dix/getevents.c | 2 +- include/eventstr.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dix/getevents.c b/dix/getevents.c index ecbf416b1..3731a4a38 100644 --- a/dix/getevents.c +++ b/dix/getevents.c @@ -210,7 +210,7 @@ set_valuators(DeviceIntPtr dev, DeviceEvent* event, int first_valuator, } memcpy(&event->valuators.data[first_valuator], - valuators, num_valuators * sizeof(uint32_t)); + valuators, num_valuators * sizeof(int32_t)); } diff --git a/include/eventstr.h b/include/eventstr.h index 433227e6e..377cceba2 100644 --- a/include/eventstr.h +++ b/include/eventstr.h @@ -99,7 +99,7 @@ struct _DeviceEvent struct { uint8_t mask[(MAX_VALUATORS + 7)/8]; /**< Valuator mask */ uint8_t mode[(MAX_VALUATORS + 7)/8]; /**< Valuator mode (Abs or Rel)*/ - uint32_t data[MAX_VALUATORS]; /**< Valuator data */ + int32_t data[MAX_VALUATORS]; /**< Valuator data */ int32_t data_frac[MAX_VALUATORS]; /**< Fractional part for data */ } valuators; struct { -- cgit v1.2.3