[gtk+] gdk: Move XGetEventData() call to GdkEventSource



commit 53d77a829aa82163aaf81e12d9b1366fb407cc22
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed May 18 19:37:34 2011 +0200

    gdk: Move XGetEventData() call to GdkEventSource
    
    This function should be called just once across every possible
    event translator and GdkFilterFunc that wants to deal with
    any cookie event.

 gdk/x11/gdkdevicemanager-xi2.c |   24 ++----------------
 gdk/x11/gdkeventsource.c       |   50 +++++++++++++++++++++------------------
 2 files changed, 30 insertions(+), 44 deletions(-)
---
diff --git a/gdk/x11/gdkdevicemanager-xi2.c b/gdk/x11/gdkdevicemanager-xi2.c
index 3a520c1..f8d5e70 100644
--- a/gdk/x11/gdkdevicemanager-xi2.c
+++ b/gdk/x11/gdkdevicemanager-xi2.c
@@ -1007,43 +1007,27 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
   gboolean return_val = TRUE;
   GdkWindow *window;
   XIEvent *ev;
-  Display *dpy;
 
-  dpy = GDK_DISPLAY_XDISPLAY (display);
   device_manager = (GdkX11DeviceManagerXI2 *) translator;
   cookie = &xevent->xcookie;
 
   if (xevent->type != GenericEvent)
     return gdk_x11_device_manager_xi2_translate_core_event (translator, display, event, xevent);
-
-  if (!XGetEventData (dpy, cookie))
+  else if (cookie->extension != device_manager->opcode)
     return FALSE;
 
-  if (cookie->type != GenericEvent ||
-      cookie->extension != device_manager->opcode)
-    {
-      XFreeEventData (dpy, cookie);
-      return FALSE;
-    }
-
   ev = (XIEvent *) cookie->data;
 
   window = get_event_window (translator, ev);
 
   if (window && GDK_WINDOW_DESTROYED (window))
-    {
-      XFreeEventData (dpy, cookie);
-      return FALSE;
-    }
+    return FALSE;
 
   if (ev->evtype == XI_Motion ||
       ev->evtype == XI_ButtonRelease)
     {
       if (_gdk_x11_moveresize_handle_event (xevent))
-        {
-          XFreeEventData (dpy, cookie);
-          return FALSE;
-        }
+        return FALSE;
     }
 
   switch (ev->evtype)
@@ -1325,8 +1309,6 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
       event->any.type = GDK_NOTHING;
     }
 
-  XFreeEventData (dpy, cookie);
-
   return return_val;
 }
 
diff --git a/gdk/x11/gdkeventsource.c b/gdk/x11/gdkeventsource.c
index ec18202..cb6d1f2 100644
--- a/gdk/x11/gdkeventsource.c
+++ b/gdk/x11/gdkeventsource.c
@@ -152,8 +152,17 @@ gdk_event_source_translate_event (GdkEventSource *event_source,
 {
   GdkEvent *event = gdk_event_new (GDK_NOTHING);
   GList *list = event_source->translators;
-  GdkFilterReturn result;
+  GdkFilterReturn result = GDK_FILTER_CONTINUE;
   GdkWindow *filter_window;
+  Display *dpy;
+
+  dpy = GDK_DISPLAY_XDISPLAY (event_source->display);
+
+  /* Get cookie data here so it's available
+   * to every event translator and event filter.
+   */
+  if (xevent->type == GenericEvent)
+    XGetEventData (dpy, &xevent->xcookie);
 
   filter_window = gdk_event_source_get_filter_window (event_source, xevent);
   if (filter_window)
@@ -163,38 +172,30 @@ gdk_event_source_translate_event (GdkEventSource *event_source,
   if (_gdk_default_filters)
     {
       /* Apply global filters */
-
       result = gdk_event_apply_filters (xevent, event, NULL);
+    }
+
+  if (result == GDK_FILTER_CONTINUE &&
+      filter_window && filter_window->filters)
+    {
+      /* Apply per-window filters */
+      result = gdk_event_apply_filters (xevent, event, filter_window);
+    }
+
+  if (result != GDK_FILTER_CONTINUE)
+    {
+      if (xevent->type == GenericEvent)
+        XFreeEventData (dpy, &xevent->xcookie);
 
       if (result == GDK_FILTER_REMOVE)
         {
           gdk_event_free (event);
           return NULL;
         }
-      else if (result == GDK_FILTER_TRANSLATE)
+      else /* GDK_FILTER_TRANSLATE */
         return event;
     }
 
-  if (filter_window)
-    {
-      /* Apply per-window filters */
-      GdkFilterReturn result;
-
-      if (filter_window->filters)
-	{
-	  result = gdk_event_apply_filters (xevent, event,
-					    filter_window);
-
-          if (result == GDK_FILTER_REMOVE)
-            {
-              gdk_event_free (event);
-              return NULL;
-            }
-          else if (result == GDK_FILTER_TRANSLATE)
-            return event;
-        }
-    }
-
   gdk_event_free (event);
   event = NULL;
 
@@ -217,6 +218,9 @@ gdk_event_source_translate_event (GdkEventSource *event_source,
       handle_focus_change (&event->crossing);
     }
 
+  if (xevent->type == GenericEvent)
+    XFreeEventData (dpy, &xevent->xcookie);
+
   return event;
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]