[PATCH xserver 06/10] Make CheckPassiveGrabsOnWindow return grab, export

Peter Hutterer peter.hutterer at who-t.net
Tue Dec 21 17:50:43 PST 2010


On Fri, Dec 17, 2010 at 05:13:31PM +0000, Daniel Stone wrote:
> Change CheckPassiveGrabsOnWindow to return the GrabPtr it used (or NULL
> if none) rather than a boolean, and export it.  Also add an additional
> boolean 'activate' parameter; use TRUE for existing behaviour, or FALSE
> to only find the grab and then return it.
> 
> This will be used in forthcoming touch patches to find the grabs, rather
> than open-coding same.
> 
> Signed-off-by: Daniel Stone <daniel at fooishbar.org>
> ---
>  dix/events.c  |   44 ++++++++++++++++++++++++--------------------
>  include/dix.h |    7 +++++++
>  2 files changed, 31 insertions(+), 20 deletions(-)
> 
> diff --git a/dix/events.c b/dix/events.c
> index cb98daf..77e76ac 100644
> --- a/dix/events.c
> +++ b/dix/events.c
> @@ -209,10 +209,6 @@ static void CheckPhysLimits(DeviceIntPtr pDev,
>                              Bool generateEvents,
>                              Bool confineToScreen,
>                              ScreenPtr pScreen);
> -static Bool CheckPassiveGrabsOnWindow(WindowPtr pWin,
> -                                      DeviceIntPtr device,
> -                                      DeviceEvent *event,
> -                                      BOOL checkCore);
>  
>  /** Key repeat hack. Do not use but in TryClientEvents */
>  extern BOOL EventIsKeyRepeat(xEvent *event);
> @@ -2607,7 +2603,6 @@ XYToWindow(SpritePtr pSprite, int x, int y)
>  BOOL
>  ActivateFocusInGrab(DeviceIntPtr dev, WindowPtr old, WindowPtr win)
>  {
> -    BOOL rc = FALSE;
>      DeviceEvent event;
>  
>      if (dev->deviceGrab.grab)
> @@ -2632,10 +2627,13 @@ ActivateFocusInGrab(DeviceIntPtr dev, WindowPtr old, WindowPtr win)
>      event.deviceid = dev->id;
>      event.sourceid = dev->id;
>      event.detail.button = 0;
> -    rc = CheckPassiveGrabsOnWindow(win, dev, &event, FALSE);

same result could be achieved with 
    rc = (CheckPassiveGrabsOnWindow() != NULL);

to reduce the patch diff and have a single return statement only.

> -    if (rc)
> +    if (CheckPassiveGrabsOnWindow(win, dev, &event, FALSE, TRUE))
> +    {
>          DoEnterLeaveEvents(dev, dev->id, old, win, XINotifyPassiveUngrab);
> -    return rc;
> +        return TRUE;
> +    }
> +
> +    return FALSE;
>  }
>  
>  /**
> @@ -2647,7 +2645,6 @@ ActivateFocusInGrab(DeviceIntPtr dev, WindowPtr old, WindowPtr win)
>  static BOOL
>  ActivateEnterGrab(DeviceIntPtr dev, WindowPtr old, WindowPtr win)
>  {
> -    BOOL rc = FALSE;
>      DeviceEvent event;
>  
>      if (dev->deviceGrab.grab)
> @@ -2669,11 +2666,13 @@ ActivateEnterGrab(DeviceIntPtr dev, WindowPtr old, WindowPtr win)
>      event.deviceid = dev->id;
>      event.sourceid = dev->id;
>      event.detail.button = 0;
> -    rc = CheckPassiveGrabsOnWindow(win, dev, &event, FALSE);
> -    if (rc)
> +    if (CheckPassiveGrabsOnWindow(win, dev, &event, FALSE, TRUE))
> +    {
>          DoEnterLeaveEvents(dev, dev->id, old, win, XINotifyPassiveGrab);
> +        return TRUE;
> +    }
>  
> -    return rc;
> +    return FALSE;
>  }
>  

same as above.

Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
otherwise.

Cheers,
  Peter

>  /**
> @@ -3342,20 +3341,23 @@ BorderSizeNotEmpty(DeviceIntPtr pDev, WindowPtr pWin)
>  /**
>   * "CheckPassiveGrabsOnWindow" checks to see if the event passed in causes a
>   * passive grab set on the window to be activated.
> - * If a passive grab is activated, the event will be delivered to the client.
> + * If activate is true and a passive grab is found, it will be activated,
> + * and the event will be delivered to the client.
>   *
>   * @param pWin The window that may be subject to a passive grab.
>   * @param device Device that caused the event.
>   * @param event The current device event.
>   * @param checkCore Check for core grabs too.
> + * @param activate If a grab is found, activate it and deliver the event.
>   */
>  
> -static Bool
> +GrabPtr
>  CheckPassiveGrabsOnWindow(
>      WindowPtr pWin,
>      DeviceIntPtr device,
>      DeviceEvent *event,
> -    BOOL checkCore)
> +    BOOL checkCore,
> +    BOOL activate)
>  {
>      SpritePtr pSprite = device->spriteInfo->sprite;
>      GrabPtr grab = wPassiveGrabs(pWin);
> @@ -3367,7 +3369,7 @@ CheckPassiveGrabsOnWindow(
>      int match = 0;
>  
>      if (!grab)
> -	return FALSE;
> +	return NULL;
>      /* Fill out the grab details, but leave the type for later before
>       * comparing */
>      tempGrab.window = pWin;
> @@ -3481,6 +3483,8 @@ CheckPassiveGrabsOnWindow(
>                      continue;
>              }
>  
> +            if (!activate)
> +                return grab;
>  
>              if (match & CORE_MATCH)
>              {
> @@ -3538,10 +3542,10 @@ CheckPassiveGrabsOnWindow(
>  
>              if (match & (XI_MATCH | XI2_MATCH))
>                  free(xE); /* on core match xE == &core */
> -	    return TRUE;
> +	    return grab;
>  	}
>      }
> -    return FALSE;
> +    return NULL;
>  #undef CORE_MATCH
>  #undef XI_MATCH
>  #undef XI2_MATCH
> @@ -3607,7 +3611,7 @@ CheckDeviceGrabs(DeviceIntPtr device, DeviceEvent *event, WindowPtr ancestor)
>  	for (; i < focus->traceGood; i++)
>  	{
>  	    pWin = focus->trace[i];
> -	    if (CheckPassiveGrabsOnWindow(pWin, device, event, sendCore))
> +	    if (CheckPassiveGrabsOnWindow(pWin, device, event, sendCore, TRUE))
>  		return TRUE;
>  	}
>  
> @@ -3620,7 +3624,7 @@ CheckDeviceGrabs(DeviceIntPtr device, DeviceEvent *event, WindowPtr ancestor)
>      for (; i < device->spriteInfo->sprite->spriteTraceGood; i++)
>      {
>  	pWin = device->spriteInfo->sprite->spriteTrace[i];
> -	if (CheckPassiveGrabsOnWindow(pWin, device, event, sendCore))
> +	if (CheckPassiveGrabsOnWindow(pWin, device, event, sendCore, TRUE))
>  	    return TRUE;
>      }
>  
> diff --git a/include/dix.h b/include/dix.h
> index 7485e8e..12e4b59 100644
> --- a/include/dix.h
> +++ b/include/dix.h
> @@ -372,6 +372,13 @@ extern void AllowSome(
>  extern void ReleaseActiveGrabs(
>      ClientPtr client);
>  
> +extern GrabPtr CheckPassiveGrabsOnWindow(
> +    WindowPtr /* pWin */,
> +    DeviceIntPtr /* device */,
> +    DeviceEvent * /* event */,
> +    BOOL /* checkCore */,
> +    BOOL /* activate */);
> +
>  extern _X_EXPORT int DeliverEventsToWindow(
>      DeviceIntPtr /* pWin */,
>      WindowPtr /* pWin */,
> -- 
> 1.7.2.3


More information about the xorg-devel mailing list