[PATCH v2] xf86Xinput: Added the xf86Post(Proximity|Button|Key)EventP helper functions.

oliver.mcfadden at nokia.com oliver.mcfadden at nokia.com
Mon Jul 27 02:06:14 PDT 2009


From: Oliver McFadden <oliver.mcfadden at nokia.com>

I only intend to use xf86PostButtonEventP in xf86-input-evdev, however,
for the sake of symmetry (and possible future use) I have added pointer
versions of all the VA args functions.

xf86PostKeyboardEvent also makes use of xf86PostKeyEventP to avoid code
duplication, and the valuator verification has been split into a
separate static inline function, xf86VerifyValuators.
---
 hw/xfree86/common/xf86Xinput.c |  157 ++++++++++++++++++++++++++--------------
 hw/xfree86/common/xf86Xinput.h |    8 ++
 2 files changed, 109 insertions(+), 56 deletions(-)

diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index b4169cf..3b0bf58 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -701,6 +701,18 @@ DeleteInputDeviceRequest(DeviceIntPtr pDev)
  * convenient functions to post events
  */
 
+static inline Bool
+xf86VerifyValuators(int num_valuators)
+{
+    if (num_valuators > MAX_VALUATORS) {
+	xf86Msg(X_ERROR, "%s: num_valuator %d is greater than"
+		" MAX_VALUATORS\n", __FUNCTION__, num_valuators);
+	return FALSE;
+    }
+
+    return TRUE;
+}
+
 void
 xf86PostMotionEvent(DeviceIntPtr	device,
                     int			is_absolute,
@@ -712,11 +724,8 @@ xf86PostMotionEvent(DeviceIntPtr	device,
     int i = 0;
     static int valuators[MAX_VALUATORS];
 
-    if (num_valuators > MAX_VALUATORS) {
-	xf86Msg(X_ERROR, "%s: num_valuator %d is greater than"
-	    " MAX_VALUATORS\n", __FUNCTION__, num_valuators);
-	return;
-    }
+    if (!xf86VerifyValuators(num_valuators))
+        return;
 
     va_start(var, num_valuators);
     for (i = 0; i < num_valuators; i++)
@@ -740,11 +749,8 @@ xf86PostMotionEventP(DeviceIntPtr	device,
     int index;
     int flags = 0;
 
-    if (num_valuators > MAX_VALUATORS) {
-	xf86Msg(X_ERROR, "%s: num_valuator %d is greater than"
-	    " MAX_VALUATORS\n", __FUNCTION__, num_valuators);
-	return;
-    }
+    if (!xf86VerifyValuators(num_valuators))
+        return;
 
     if (is_absolute)
         flags = POINTER_ABSOLUTE;
@@ -800,21 +806,34 @@ xf86PostProximityEvent(DeviceIntPtr	device,
                        ...)
 {
     va_list var;
-    int i, nevents;
+    int i;
     int valuators[MAX_VALUATORS];
 
-
-    if (num_valuators > MAX_VALUATORS) {
-	xf86Msg(X_ERROR, "%s: num_valuator %d is greater than"
-	    " MAX_VALUATORS\n", __FUNCTION__, num_valuators);
-	return;
-    }
+    if (!xf86VerifyValuators(num_valuators))
+        return;
 
     va_start(var, num_valuators);
     for (i = 0; i < num_valuators; i++)
         valuators[i] = va_arg(var, int);
     va_end(var);
 
+    xf86PostProximityEventP(device, is_in, first_valuator, num_valuators,
+			    valuators);
+
+}
+
+void
+xf86PostProximityEventP(DeviceIntPtr	device,
+                        int		is_in,
+                        int		first_valuator,
+                        int		num_valuators,
+                        int		*valuators)
+{
+    int i, nevents;
+
+    if (!xf86VerifyValuators(num_valuators))
+        return;
+
     GetEventList(&xf86Events);
     nevents = GetProximityEvents(xf86Events, device,
                                  is_in ? ProximityIn : ProximityOut, 
@@ -835,7 +854,7 @@ xf86PostButtonEvent(DeviceIntPtr	device,
 {
     va_list var;
     int valuators[MAX_VALUATORS];
-    int i = 0, nevents = 0;
+    int i = 0;
     int index;
 
 #if XFreeXDGA
@@ -845,17 +864,43 @@ xf86PostButtonEvent(DeviceIntPtr	device,
             return;
     }
 #endif
-    if (num_valuators > MAX_VALUATORS) {
-	xf86Msg(X_ERROR, "%s: num_valuator %d is greater than"
-	    " MAX_VALUATORS\n", __FUNCTION__, num_valuators);
-	return;
-    }
+
+    if (!xf86VerifyValuators(num_valuators))
+        return;
 
     va_start(var, num_valuators);
     for (i = 0; i < num_valuators; i++)
         valuators[i] = va_arg(var, int);
     va_end(var);
 
+    xf86PostButtonEventP(device, is_absolute, button, is_down, first_valuator,
+			 num_valuators, valuators);
+
+}
+
+void
+xf86PostButtonEventP(DeviceIntPtr	device,
+                     int		is_absolute,
+                     int		button,
+                     int		is_down,
+                     int		first_valuator,
+                     int		num_valuators,
+                     int		*valuators)
+{
+    int i = 0, nevents = 0;
+    int index;
+
+#if XFreeXDGA
+    if (miPointerGetScreen(device)) {
+        index = miPointerGetScreen(device)->myNum;
+        if (DGAStealButtonEvent(device, index, button, is_down))
+            return;
+    }
+#endif
+
+    if (!xf86VerifyValuators(num_valuators))
+        return;
+
     GetEventList(&xf86Events);
     nevents = GetPointerEvents(xf86Events, device,
                                is_down ? ButtonPress : ButtonRelease, button,
@@ -877,7 +922,7 @@ xf86PostKeyEvent(DeviceIntPtr	device,
                  ...)
 {
     va_list var;
-    int i = 0, nevents = 0;
+    int i = 0;
     static int valuators[MAX_VALUATORS];
 
     /* instil confidence in the user */
@@ -885,18 +930,39 @@ xf86PostKeyEvent(DeviceIntPtr	device,
            "badly south after this message, then xf86PostKeyEvent is "
            "broken.\n");
 
-    if (num_valuators > MAX_VALUATORS) {
-	xf86Msg(X_ERROR, "%s: num_valuator %d is greater than"
-	    " MAX_VALUATORS\n", __FUNCTION__, num_valuators);
-	return;
-    }
+    if (!xf86VerifyValuators(num_valuators))
+        return;
 
-    if (is_absolute) {
-        va_start(var, num_valuators);
-        for (i = 0; i < num_valuators; i++)
-            valuators[i] = va_arg(var, int);
-        va_end(var);
+    va_start(var, num_valuators);
+    for (i = 0; i < num_valuators; i++)
+      valuators[i] = va_arg(var, int);
+    va_end(var);
+
+    xf86PostKeyEventP(device, key_code, is_down, is_absolute, first_valuator,
+		      num_valuators, valuators);
+
+}
 
+void
+xf86PostKeyEventP(DeviceIntPtr	device,
+                  unsigned int	key_code,
+                  int		is_down,
+                  int		is_absolute,
+                  int		first_valuator,
+                  int		num_valuators,
+                  int		*valuators)
+{
+    int i = 0, nevents = 0;
+
+    /* instil confidence in the user */
+    DebugF("this function has never been tested properly.  if things go quite "
+           "badly south after this message, then xf86PostKeyEvent is "
+           "broken.\n");
+
+    if (!xf86VerifyValuators(num_valuators))
+        return;
+
+    if (is_absolute) {
         GetEventList(&xf86Events);
         nevents = GetKeyboardValuatorEvents(xf86Events, device,
                                             is_down ? KeyPress : KeyRelease,
@@ -918,28 +984,7 @@ xf86PostKeyboardEvent(DeviceIntPtr      device,
                       unsigned int      key_code,
                       int               is_down)
 {
-    int nevents = 0, i = 0;
-    int index;
-
-#if XFreeXDGA
-    DeviceIntPtr pointer;
-
-    /* Some pointers send key events, paired device is wrong then. */
-    pointer = IsPointerDevice(device) ? device : GetPairedDevice(device);
-
-    if (miPointerGetScreen(pointer)) {
-        index = miPointerGetScreen(pointer)->myNum;
-        if (DGAStealKeyEvent(device, index, key_code, is_down))
-            return;
-    }
-#endif
-
-    GetEventList(&xf86Events);
-    nevents = GetKeyboardEvents(xf86Events, device,
-                                is_down ? KeyPress : KeyRelease, key_code);
-
-    for (i = 0; i < nevents; i++)
-        mieqEnqueue(device, (InternalEvent*)((xf86Events + i)->event));
+    xf86PostKeyEventP(device, key_code, is_down, 0, 0, 0, NULL);
 }
 
 LocalDevicePtr
diff --git a/hw/xfree86/common/xf86Xinput.h b/hw/xfree86/common/xf86Xinput.h
index 0ad5664..f8eb24d 100644
--- a/hw/xfree86/common/xf86Xinput.h
+++ b/hw/xfree86/common/xf86Xinput.h
@@ -158,12 +158,20 @@ extern _X_EXPORT void xf86PostMotionEventP(DeviceIntPtr device, int is_absolute,
 			 int first_valuator, int num_valuators, int *valuators);
 extern _X_EXPORT void xf86PostProximityEvent(DeviceIntPtr device, int is_in,
 			    int first_valuator, int num_valuators, ...);
+extern _X_EXPORT void xf86PostProximityEventP(DeviceIntPtr device, int is_in, int first_valuator,
+			     int num_valuators, int *valuators);
 extern _X_EXPORT void xf86PostButtonEvent(DeviceIntPtr device, int is_absolute, int button,
 		    	 int is_down, int first_valuator, int num_valuators,
 			 ...);
+extern _X_EXPORT void xf86PostButtonEventP(DeviceIntPtr device, int is_absolute, int button,
+			  int is_down, int first_valuator, int num_valuators,
+			  int *valuators);
 extern _X_EXPORT void xf86PostKeyEvent(DeviceIntPtr device, unsigned int key_code, int is_down,
 		      int is_absolute, int first_valuator, int num_valuators,
 		      ...);
+extern _X_EXPORT void xf86PostKeyEventP(DeviceIntPtr device, unsigned int key_code, int is_down,
+		       int is_absolute, int first_valuator, int num_valuators,
+		       int *valuators);
 extern _X_EXPORT void xf86PostKeyboardEvent(DeviceIntPtr device, unsigned int key_code,
                            int is_down);
 extern _X_EXPORT int xf86ActivateDevice(LocalDevicePtr local);
-- 
1.6.1



More information about the xorg-devel mailing list