[PATCH 04/11] dix: split implicit grab activation into a separate function.

Jamey Sharp jamey at minilop.net
Wed May 11 14:08:28 PDT 2011


I'm not sure I like splitting the check for button-press event from the
code which makes assumptions about that check. How about replacing
patches 3 and 4 with this patch instead?

---
From b6f41db623516ca52d3c5977758c4f298beeee97 Mon Sep 17 00:00:00 2001
From: Jamey Sharp <jamey at minilop.net>
Date: Wed, 11 May 2011 13:58:50 -0700
Subject: [PATCH] dix: split implicit grab activation into a separate
 function.

No functional changes, just for readability. This patch was inspired by
a pair of similar patches by Peter Hutterer, but takes slightly
different boundaries between functions.

Signed-off-by: Jamey Sharp <jamey at minilop.net>
---
 dix/events.c |   91 ++++++++++++++++++++++++++++++++--------------------------
 1 files changed, 50 insertions(+), 41 deletions(-)

diff --git a/dix/events.c b/dix/events.c
index d70d62f..86192c2 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -1937,6 +1937,54 @@ TryClientEvents (ClientPtr client, DeviceIntPtr dev, xEvent *pEvents,
     return 1;
 }
 
+static BOOL
+ActivateImplicitGrab(DeviceIntPtr dev, ClientPtr client, WindowPtr win,
+                     xEvent *event, Mask deliveryMask)
+{
+    GrabRec tempGrab;
+    OtherInputMasks *inputMasks;
+    CARD8 type = event->u.u.type;
+    GrabType grabtype;
+
+    if (type == ButtonPress)
+        grabtype = GRABTYPE_CORE;
+    else if (type == DeviceButtonPress)
+        grabtype = GRABTYPE_XI;
+    else if (XI2_EVENT(event) && ((xGenericEvent*)event)->evtype == XI_ButtonPress)
+    {
+        type = ((xGenericEvent*)event)->evtype;
+        grabtype = GRABTYPE_XI2;
+    }
+    else
+        return FALSE;
+
+    memset(&tempGrab, 0, sizeof(GrabRec));
+    tempGrab.next = NULL;
+    tempGrab.device = dev;
+    tempGrab.resource = client->clientAsMask;
+    tempGrab.window = win;
+    tempGrab.ownerEvents = (deliveryMask & OwnerGrabButtonMask) ? TRUE : FALSE;
+    tempGrab.eventMask = deliveryMask;
+    tempGrab.keyboardMode = GrabModeAsync;
+    tempGrab.pointerMode = GrabModeAsync;
+    tempGrab.confineTo = NullWindow;
+    tempGrab.cursor = NullCursor;
+    tempGrab.type = type;
+    tempGrab.grabtype = grabtype;
+
+    /* get the XI and XI2 device mask */
+    inputMasks = wOtherInputMasks(win);
+    tempGrab.deviceMask = (inputMasks) ? inputMasks->inputEvents[dev->id]: 0;
+
+    if (inputMasks)
+        memcpy(tempGrab.xi2mask, inputMasks->xi2mask,
+               sizeof(tempGrab.xi2mask));
+
+    (*dev->deviceGrab.ActivateGrab)(dev, &tempGrab,
+                                    currentTime, TRUE | ImplicitGrabMask);
+    return TRUE;
+}
+
 /**
  * Deliver events to a window. At this point, we do not yet know if the event
  * actually needs to be delivered. May activate a grab if the event is a
@@ -2048,47 +2096,8 @@ DeliverEventsToWindow(DeviceIntPtr pDev, WindowPtr pWin, xEvent
      * Note that since core events are delivered first, an implicit grab may
      * be activated on a core grab, stopping the XI events.
      */
-    if ((type == DeviceButtonPress || type == ButtonPress ||
-        ((XI2_EVENT(pEvents) && ((xGenericEvent*)pEvents)->evtype == XI_ButtonPress)))
-            && deliveries
-            && (!grab))
-    {
-	GrabRec tempGrab;
-        OtherInputMasks *inputMasks;
-
-        memset(&tempGrab, 0, sizeof(GrabRec));
-        tempGrab.next = NULL;
-	tempGrab.device = pDev;
-	tempGrab.resource = client->clientAsMask;
-	tempGrab.window = pWin;
-	tempGrab.ownerEvents = (deliveryMask & OwnerGrabButtonMask) ? TRUE : FALSE;
-	tempGrab.eventMask = deliveryMask;
-	tempGrab.keyboardMode = GrabModeAsync;
-	tempGrab.pointerMode = GrabModeAsync;
-	tempGrab.confineTo = NullWindow;
-	tempGrab.cursor = NullCursor;
-        tempGrab.type = type;
-        if (type == ButtonPress)
-            tempGrab.grabtype = GRABTYPE_CORE;
-        else if (type == DeviceButtonPress)
-            tempGrab.grabtype = GRABTYPE_XI;
-        else
-        {
-            tempGrab.type = ((xGenericEvent*)pEvents)->evtype;
-            tempGrab.grabtype = GRABTYPE_XI2;
-        }
-
-        /* get the XI and XI2 device mask */
-        inputMasks = wOtherInputMasks(pWin);
-        tempGrab.deviceMask = (inputMasks) ? inputMasks->inputEvents[pDev->id]: 0;
-
-        if (inputMasks)
-            memcpy(tempGrab.xi2mask, inputMasks->xi2mask,
-                    sizeof(tempGrab.xi2mask));
-
-	(*pDev->deviceGrab.ActivateGrab)(pDev, &tempGrab,
-                                        currentTime, TRUE | ImplicitGrabMask);
-    }
+    if (deliveries && !grab && ActivateImplicitGrab(pDev, client, pWin, pEvents, deliveryMask))
+        /* grab activated */;
     else if ((type == MotionNotify) && deliveries)
 	pDev->valuator->motionHintWindow = pWin;
     else
-- 
1.7.4.4

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.x.org/archives/xorg-devel/attachments/20110511/ba78ff40/attachment.pgp>


More information about the xorg-devel mailing list