[PATCH v3] dix: copy the valuators passed into GPE/GKVE/GProxE.

Peter Hutterer peter.hutterer at who-t.net
Thu Aug 12 23:47:46 PDT 2010


GPE and friends modify the valuators array passed in. Which means any driver
using e.g. xf86PostButtonEventP(..., valuators) twice to emulate a button
click will provide garbage data on the second run.

This is currently affecting the wacom driver, xf86PostButtonEventP() with
valuators is required to have input events with device-specific axis values.
Passing the same valuators in twice, once with press, once with release,
will see the valuators modified in the first call and garbage submitted in
the next one.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---

Changest to v2:
- use alloca instead of malloc as suggested by ajax.

May be too late for 1.9 though it shouldn't have any affect. as long as we
keep supporting multiple server versions in the drivers, no driver can
sanely rely on this anyway.
alloca could be replaced with a simple int valuators[MAX_VALUATOR] if
desired.

 dix/getevents.c |   17 +++++++++++++----
 1 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/dix/getevents.c b/dix/getevents.c
index a9b6e82..a829259 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -912,11 +912,12 @@ GetKeyboardEvents(EventList *events, DeviceIntPtr pDev, int type, int key_code)
 int
 GetKeyboardValuatorEvents(EventList *events, DeviceIntPtr pDev, int type,
                           int key_code, int first_valuator,
-                          int num_valuators, int *valuators) {
+                          int num_valuators, int *valuators_in) {
     int num_events = 0;
     CARD32 ms = 0;
     DeviceEvent *event;
     RawDeviceEvent *raw;
+    int *valuators = alloca(sizeof(int) * min(num_valuators, MAX_VALUATORS));
 
     /* refuse events from disabled devices */
     if (!pDev->enabled)
@@ -947,6 +948,8 @@ GetKeyboardValuatorEvents(EventList *events, DeviceIntPtr pDev, int type,
     events++;
     num_events++;
 
+    memcpy(valuators, valuators_in, num_valuators * sizeof(int));
+
     init_raw(pDev, raw, ms, type, key_code);
     set_raw_valuators(raw, first_valuator, num_valuators, valuators,
                       raw->valuators.data_raw);
@@ -1067,7 +1070,7 @@ transformAbsolute(DeviceIntPtr dev, int v[MAX_VALUATORS])
 int
 GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons,
                  int flags, int first_valuator, int num_valuators,
-                 int *valuators) {
+                 int *valuators_in) {
     int num_events = 1;
     CARD32 ms;
     DeviceEvent *event;
@@ -1076,6 +1079,7 @@ GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons,
         cx, cy; /* only screen coordinates */
     float x_frac = 0.0, y_frac = 0.0, cx_frac, cy_frac;
     ScreenPtr scr = miPointerGetScreen(pDev);
+    int *valuators = alloca(sizeof(int) * min(num_valuators, MAX_VALUATORS));
 
     /* refuse events from disabled devices */
     if (!pDev->enabled)
@@ -1097,6 +1101,8 @@ GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons,
     events++;
     num_events++;
 
+    memcpy(valuators, valuators_in, num_valuators * sizeof(int));
+
     init_raw(pDev, raw, ms, type, buttons);
     set_raw_valuators(raw, first_valuator, num_valuators, valuators,
                       raw->valuators.data_raw);
@@ -1183,10 +1189,11 @@ GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons,
  */
 int
 GetProximityEvents(EventList *events, DeviceIntPtr pDev, int type,
-                   int first_valuator, int num_valuators, int *valuators)
+                   int first_valuator, int num_valuators, int *valuators_in)
 {
     int num_events = 1;
     DeviceEvent *event;
+    int *valuators = alloca(sizeof(int) * min(num_valuators, MAX_VALUATORS));
 
     /* refuse events from disabled devices */
     if (!pDev->enabled)
@@ -1212,8 +1219,10 @@ GetProximityEvents(EventList *events, DeviceIntPtr pDev, int type,
     init_event(pDev, event, GetTimeInMillis());
     event->type = (type == ProximityIn) ? ET_ProximityIn : ET_ProximityOut;
 
-    if (num_valuators)
+    if (num_valuators) {
+        memcpy(valuators, valuators_in, num_valuators * sizeof(int));
         clipValuators(pDev, first_valuator, num_valuators, valuators);
+    }
 
     set_valuators(pDev, event, first_valuator, num_valuators, valuators);
 
-- 
1.7.2.1



More information about the xorg-devel mailing list