[PATCH 01/11] dix: split out window owner event delivery from DeliverEventsToWindow

Peter Hutterer peter.hutterer at who-t.net
Tue May 10 21:49:40 PDT 2011


No functional changes, just for readability.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 dix/events.c |   78 +++++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 58 insertions(+), 20 deletions(-)

diff --git a/dix/events.c b/dix/events.c
index 276bc75..92fd41d 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -1939,6 +1939,46 @@ TryClientEvents (ClientPtr client, DeviceIntPtr dev, xEvent *pEvents,
     return 1;
 }
 
+enum EventDeliveryState {
+    EVENT_DELIVERED,     /**< Event has been delivered to a client  */
+    EVENT_NOT_DELIVERED, /**< Event was not delivered to any client */
+    EVENT_SKIP,          /**< Event can be discarded by the caller  */
+    EVENT_REJECTED,      /**< Event was rejected for delivery to the client */
+};
+
+/**
+ * Attempt event delivery to the client owning the window.
+ */
+static enum EventDeliveryState
+DeliverToWindowOwner(DeviceIntPtr dev, WindowPtr win,
+                     xEvent *events, int count, Mask filter,
+                     GrabPtr grab)
+{
+    int attempt;
+    enum EventDeliveryState rc = EVENT_SKIP;
+
+    /* if nobody ever wants to see this event, skip some work */
+    if (filter != CantBeFiltered &&
+            !((wOtherEventMasks(win)|win->eventMask) & filter))
+        goto out;
+
+    if (IsInterferingGrab(wClient(win), dev, events))
+        goto out;
+
+    rc = EVENT_NOT_DELIVERED;
+
+    if (XaceHook(XACE_RECEIVE_ACCESS, wClient(win), win, events, count))
+        /* do nothing */;
+    else if ((attempt = TryClientEvents(wClient(win), dev, events,
+                                        count, win->eventMask,
+                                        filter, grab)))
+        rc = (attempt > 0) ? EVENT_DELIVERED : EVENT_REJECTED;
+
+out:
+    return rc;
+}
+
+
 /**
  * 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
@@ -1975,28 +2015,26 @@ DeliverEventsToWindow(DeviceIntPtr pDev, WindowPtr pWin, xEvent
     /* Deliver to window owner */
     if ((filter == CantBeFiltered) || CORE_EVENT(pEvents))
     {
-	/* if nobody ever wants to see this event, skip some work */
-	if (filter != CantBeFiltered &&
-	    !((wOtherEventMasks(pWin)|pWin->eventMask) & filter))
-	    return 0;
+        enum EventDeliveryState rc;
 
-        if (IsInterferingGrab(wClient(pWin), pDev, pEvents))
-                return 0;
+        rc = DeliverToWindowOwner(pDev, pWin, pEvents, count, filter, grab);
 
-	if (XaceHook(XACE_RECEIVE_ACCESS, wClient(pWin), pWin, pEvents, count))
-	    /* do nothing */;
-        else if ( (attempt = TryClientEvents(wClient(pWin), pDev, pEvents,
-                                             count, pWin->eventMask,
-                                             filter, grab)) )
-	{
-	    if (attempt > 0)
-	    {
-		deliveries++;
-		client = wClient(pWin);
-		deliveryMask = pWin->eventMask;
-	    } else
-		nondeliveries--;
-	}
+        switch(rc)
+        {
+            case EVENT_SKIP:
+                return 0;
+            case EVENT_REJECTED:
+                nondeliveries--;
+                break;
+            case EVENT_DELIVERED:
+                /* We delivered to the owner, with our event mask */
+                deliveries++;
+                client = wClient(pWin);
+                deliveryMask = pWin->eventMask;
+                break;
+            case EVENT_NOT_DELIVERED:
+                break;
+        }
     }
 
     /* CantBeFiltered means only window owner gets the event */
-- 
1.7.4.4



More information about the xorg-devel mailing list