[PATCH 02/11] dix: split out client delivery from DeliverEventsToWindow

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


No functional changes, just for readability.

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

diff --git a/dix/events.c b/dix/events.c
index 92fd41d..efe596b 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -1978,6 +1978,74 @@ out:
     return rc;
 }
 
+/**
+ * Deliver events to clients registered on the window.
+ *
+ * @param client_return On successful delivery, set to the recipient.
+ * @param mask_return On successful delivery, set to the recipient's event
+ * mask for this event.
+ */
+static enum EventDeliveryState
+DeliverEventToClients(DeviceIntPtr dev, WindowPtr win, xEvent *events,
+                      int count, Mask filter, GrabPtr grab,
+                      ClientPtr *client_return, Mask *mask_return)
+{
+    int attempt;
+    enum EventDeliveryState rc = EVENT_SKIP;
+    InputClients *other;
+
+    if (CORE_EVENT(events))
+        other = (InputClients *)wOtherClients(win);
+    else if (XI2_EVENT(events))
+    {
+        OtherInputMasks *inputMasks = wOtherInputMasks(win);
+        /* Has any client selected for the event? */
+        if (!GetWindowXI2Mask(dev, win, events))
+            goto out;
+        other = inputMasks->inputClients;
+    } else {
+        OtherInputMasks *inputMasks = wOtherInputMasks(win);
+        /* Has any client selected for the event? */
+        if (!inputMasks ||
+            !(inputMasks->inputEvents[dev->id] & filter))
+            goto out;
+
+        other = inputMasks->inputClients;
+    }
+
+    rc = EVENT_NOT_DELIVERED;
+
+    for (; other; other = other->next)
+    {
+        Mask mask;
+
+        if (IsInterferingGrab(rClient(other), dev, events))
+            continue;
+
+        mask = GetEventMask(dev, events, other);
+
+        if (XaceHook(XACE_RECEIVE_ACCESS, rClient(other), win,
+                    events, count))
+            /* do nothing */;
+        else if ( (attempt = TryClientEvents(rClient(other), dev,
+                        events, count,
+                        mask, filter, grab)) )
+        {
+            if (attempt > 0)
+            {
+                rc = EVENT_DELIVERED;
+                *client_return = rClient(other);
+                *mask_return = mask;
+            } else
+                rc = EVENT_REJECTED;
+        }
+    }
+
+out:
+    return rc;
+}
+
+
 
 /**
  * Deliver events to a window. At this point, we do not yet know if the event
@@ -2004,14 +2072,11 @@ DeliverEventsToWindow(DeviceIntPtr pDev, WindowPtr pWin, xEvent
         *pEvents, int count, Mask filter, GrabPtr grab)
 {
     int deliveries = 0, nondeliveries = 0;
-    int attempt;
-    InputClients *other;
     ClientPtr client = NullClient;
     Mask deliveryMask = 0; /* If a grab occurs due to a button press, then
 		              this mask is the mask of the grab. */
     int type = pEvents->u.u.type;
 
-
     /* Deliver to window owner */
     if ((filter == CantBeFiltered) || CORE_EVENT(pEvents))
     {
@@ -2040,50 +2105,26 @@ DeliverEventsToWindow(DeviceIntPtr pDev, WindowPtr pWin, xEvent
     /* CantBeFiltered means only window owner gets the event */
     if (filter != CantBeFiltered)
     {
-        if (CORE_EVENT(pEvents))
-            other = (InputClients *)wOtherClients(pWin);
-        else if (XI2_EVENT(pEvents))
-        {
-            OtherInputMasks *inputMasks = wOtherInputMasks(pWin);
-            /* Has any client selected for the event? */
-            if (!GetWindowXI2Mask(pDev, pWin, pEvents))
-                return 0;
-            other = inputMasks->inputClients;
-        } else {
-            OtherInputMasks *inputMasks = wOtherInputMasks(pWin);
-            /* Has any client selected for the event? */
-            if (!inputMasks ||
-                !(inputMasks->inputEvents[pDev->id] & filter))
-                return 0;
+        enum EventDeliveryState rc;
 
-            other = inputMasks->inputClients;
-        }
+        rc = DeliverEventToClients(pDev, pWin, pEvents, count, filter, grab,
+                                   &client, &deliveryMask);
 
-        for (; other; other = other->next)
+        switch(rc)
         {
-            Mask mask;
-            if (IsInterferingGrab(rClient(other), pDev, pEvents))
-                continue;
-
-            mask = GetEventMask(pDev, pEvents, other);
-
-            if (XaceHook(XACE_RECEIVE_ACCESS, rClient(other), pWin,
-                        pEvents, count))
-                /* do nothing */;
-            else if ( (attempt = TryClientEvents(rClient(other), pDev,
-                            pEvents, count,
-                            mask, filter, grab)) )
-            {
-                if (attempt > 0)
-                {
-                    deliveries++;
-                    client = rClient(other);
-                    deliveryMask = mask;
-                } else
-                    nondeliveries--;
-            }
+            case EVENT_SKIP:
+                return 0;
+            case EVENT_REJECTED:
+                nondeliveries--;
+                break;
+            case EVENT_DELIVERED:
+                deliveries++;
+                break;
+            case EVENT_NOT_DELIVERED:
+                break;
         }
     }
+
     /*
      * Note that since core events are delivered first, an implicit grab may
      * be activated on a core grab, stopping the XI events.
-- 
1.7.4.4



More information about the xorg-devel mailing list