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

Peter Hutterer peter.hutterer at who-t.net
Tue Jul 28 15:23:03 PDT 2009


On Tue, Jul 28, 2009 at 08:20:37AM +0300, oliver.mcfadden at nokia.com wrote:
> From: Oliver McFadden <oliver.mcfadden at nokia.com>
> 
> xf86PostKeyboardEvent also makes use of xf86PostKeyEventP to avoid code
> duplication, and the valuator verification has been split into the
> XI_VERIFY_VALUATORS macro.
> ---
> 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.
> 
>  hw/xfree86/common/xf86Xinput.c |  137 +++++++++++++++++++++++----------------
>  hw/xfree86/common/xf86Xinput.h |   16 +++++
>  2 files changed, 97 insertions(+), 56 deletions(-)
> 
> diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
> index b4169cf..9a75d67 100644
> --- a/hw/xfree86/common/xf86Xinput.c
> +++ b/hw/xfree86/common/xf86Xinput.c
> @@ -712,11 +712,7 @@ 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;
> -    }
> +    XI_VERIFY_VALUATORS(num_valuators);
>  
>      va_start(var, num_valuators);
>      for (i = 0; i < num_valuators; i++)
> @@ -740,11 +736,7 @@ 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;
> -    }
> +    XI_VERIFY_VALUATORS(num_valuators);
>  
>      if (is_absolute)
>          flags = POINTER_ABSOLUTE;
> @@ -800,21 +792,32 @@ 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;
> -    }
> +    XI_VERIFY_VALUATORS(num_valuators);
>  
>      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;
> +
> +    XI_VERIFY_VALUATORS(num_valuators);
> +
>      GetEventList(&xf86Events);
>      nevents = GetProximityEvents(xf86Events, device,
>                                   is_in ? ProximityIn : ProximityOut, 
> @@ -835,7 +838,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 +848,41 @@ xf86PostButtonEvent(DeviceIntPtr	device,
>              return;
>      }
>  #endif

As discussed on IRC, I'll remove the XFreeXDGA chunk here, it's not
necessary since it will get picked up by xf86PostButtonEventP will pick it
up.

> -    if (num_valuators > MAX_VALUATORS) {
> -	xf86Msg(X_ERROR, "%s: num_valuator %d is greater than"
> -	    " MAX_VALUATORS\n", __FUNCTION__, num_valuators);
> -	return;
> -    }
> +
> +    XI_VERIFY_VALUATORS(num_valuators);
>  
>      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
> +
> +    XI_VERIFY_VALUATORS(num_valuators);
> +
>      GetEventList(&xf86Events);
>      nevents = GetPointerEvents(xf86Events, device,
>                                 is_down ? ButtonPress : ButtonRelease, button,
> @@ -877,7 +904,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 +912,37 @@ 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;
> -    }
> +    XI_VERIFY_VALUATORS(num_valuators);
>  
> -    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");
> +
> +    XI_VERIFY_VALUATORS(num_valuators);
>  
> +    if (is_absolute) {
>          GetEventList(&xf86Events);
>          nevents = GetKeyboardValuatorEvents(xf86Events, device,
>                                              is_down ? KeyPress : KeyRelease,
> @@ -918,28 +964,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..b1b88ac 100644
> --- a/hw/xfree86/common/xf86Xinput.h
> +++ b/hw/xfree86/common/xf86Xinput.h
> @@ -80,6 +80,14 @@
>  #define XI_PRIVATE(dev) \
>  	(((LocalDevicePtr)((dev)->public.devicePrivate))->private)
>  
> +/* Valuator verification macro */
> +#define XI_VERIFY_VALUATORS(num_valuators)					\
> +	if (num_valuators > MAX_VALUATORS) {					\
> +		xf86Msg(X_ERROR, "%s: num_valuator %d is greater than"		\
> +			" MAX_VALUATORS\n", __FUNCTION__, num_valuators);	\
> +		return;								\
> +	}
> +
>  /* Stupid API backwards-compatibility. */
>  #define TS_Raw 60
>  #define TS_Scaled 61
> @@ -158,12 +166,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

merged locally, will be pushed soon. Thanks for your work.

Cheers,
  Peter


More information about the xorg-devel mailing list