[gtk+] gdk: Add _gdk_x11_event_translator_get_window()



commit 55cc9f33399dab8b52ee071bab609680b66c4325
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed May 18 21:24:57 2011 +0200

    gdk: Add _gdk_x11_event_translator_get_window()
    
    This method can be implemented by event translators so they
    return the right window from XGenericEventCookie events, as
    ev->xany.window isn't meaningful for these.
    
    GdkEventSource now also uses this to find out the right window
    filters to apply.

 gdk/x11/gdkeventsource.c     |   50 ++++++++++++++++++++++++++++++++++-------
 gdk/x11/gdkeventtranslator.c |   23 ++++++++++++++++++-
 gdk/x11/gdkeventtranslator.h |    5 ++++
 3 files changed, 68 insertions(+), 10 deletions(-)
---
diff --git a/gdk/x11/gdkeventsource.c b/gdk/x11/gdkeventsource.c
index cb6d1f2..2c25c85 100644
--- a/gdk/x11/gdkeventsource.c
+++ b/gdk/x11/gdkeventsource.c
@@ -97,11 +97,30 @@ gdk_event_apply_filters (XEvent    *xevent,
 }
 
 static GdkWindow *
-gdk_event_source_get_filter_window (GdkEventSource *event_source,
-                                    XEvent         *xevent)
+gdk_event_source_get_filter_window (GdkEventSource      *event_source,
+                                    XEvent              *xevent,
+                                    GdkEventTranslator **event_translator)
 {
+  GList *list = event_source->translators;
   GdkWindow *window;
 
+  *event_translator = NULL;
+
+  while (list)
+    {
+      GdkEventTranslator *translator = list->data;
+
+      list = list->next;
+      window = _gdk_x11_event_translator_get_window (translator,
+                                                     event_source->display,
+                                                     xevent);
+      if (window)
+        {
+          *event_translator = translator;
+          return window;
+        }
+    }
+
   window = gdk_x11_window_lookup_for_display (event_source->display,
                                               xevent->xany.window);
 
@@ -151,8 +170,8 @@ gdk_event_source_translate_event (GdkEventSource *event_source,
                                   XEvent         *xevent)
 {
   GdkEvent *event = gdk_event_new (GDK_NOTHING);
-  GList *list = event_source->translators;
   GdkFilterReturn result = GDK_FILTER_CONTINUE;
+  GdkEventTranslator *event_translator;
   GdkWindow *filter_window;
   Display *dpy;
 
@@ -164,7 +183,8 @@ gdk_event_source_translate_event (GdkEventSource *event_source,
   if (xevent->type == GenericEvent)
     XGetEventData (dpy, &xevent->xcookie);
 
-  filter_window = gdk_event_source_get_filter_window (event_source, xevent);
+  filter_window = gdk_event_source_get_filter_window (event_source, xevent,
+                                                      &event_translator);
   if (filter_window)
     event->any.window = g_object_ref (filter_window);
 
@@ -199,15 +219,27 @@ gdk_event_source_translate_event (GdkEventSource *event_source,
   gdk_event_free (event);
   event = NULL;
 
-  while (list && !event)
+  if (event_translator)
     {
-      GdkEventTranslator *translator = list->data;
-
-      list = list->next;
-      event = _gdk_x11_event_translator_translate (translator,
+      /* Event translator was gotten before in get_filter_window() */
+      event = _gdk_x11_event_translator_translate (event_translator,
                                                    event_source->display,
                                                    xevent);
     }
+  else
+    {
+      GList *list = event_source->translators;
+
+      while (list && !event)
+        {
+          GdkEventTranslator *translator = list->data;
+
+          list = list->next;
+          event = _gdk_x11_event_translator_translate (translator,
+                                                       event_source->display,
+                                                       xevent);
+        }
+    }
 
   if (event &&
       (event->type == GDK_ENTER_NOTIFY ||
diff --git a/gdk/x11/gdkeventtranslator.c b/gdk/x11/gdkeventtranslator.c
index bbd79dc..4589b1d 100644
--- a/gdk/x11/gdkeventtranslator.c
+++ b/gdk/x11/gdkeventtranslator.c
@@ -20,7 +20,7 @@
 #include "config.h"
 
 #include "gdkeventtranslator.h"
-
+#include "gdkwindow-x11.h"
 
 typedef GdkEventTranslatorIface GdkEventTranslatorInterface;
 G_DEFINE_INTERFACE (GdkEventTranslator, _gdk_x11_event_translator, G_TYPE_OBJECT);
@@ -87,3 +87,24 @@ _gdk_x11_event_translator_select_window_events (GdkEventTranslator *translator,
   if (iface->select_window_events)
     iface->select_window_events (translator, window, event_mask);
 }
+
+GdkWindow *
+_gdk_x11_event_translator_get_window (GdkEventTranslator *translator,
+                                      GdkDisplay         *display,
+                                      XEvent             *xevent)
+{
+  GdkEventTranslatorIface *iface;
+  GdkWindow *window = NULL;
+
+  g_return_val_if_fail (GDK_IS_EVENT_TRANSLATOR (translator), NULL);
+
+  iface = GDK_EVENT_TRANSLATOR_GET_IFACE (translator);
+
+  if (iface->get_window)
+    window = iface->get_window (translator, xevent);
+
+  if (!window)
+    window = gdk_x11_window_lookup_for_display (display, xevent->xany.window);
+
+  return window;
+}
diff --git a/gdk/x11/gdkeventtranslator.h b/gdk/x11/gdkeventtranslator.h
index 933ad66..817e11f 100644
--- a/gdk/x11/gdkeventtranslator.h
+++ b/gdk/x11/gdkeventtranslator.h
@@ -49,6 +49,8 @@ struct _GdkEventTranslatorIface
   void         (* select_window_events) (GdkEventTranslator *translator,
                                          Window              window,
                                          GdkEventMask        event_mask);
+  GdkWindow *  (* get_window)           (GdkEventTranslator *translator,
+                                         XEvent             *xevent);
 };
 
 GType      _gdk_x11_event_translator_get_type (void) G_GNUC_CONST;
@@ -60,6 +62,9 @@ GdkEventMask _gdk_x11_event_translator_get_handled_events   (GdkEventTranslator
 void         _gdk_x11_event_translator_select_window_events (GdkEventTranslator *translator,
                                                              Window              window,
                                                              GdkEventMask        event_mask);
+GdkWindow *  _gdk_x11_event_translator_get_window           (GdkEventTranslator *translator,
+                                                             GdkDisplay         *display,
+                                                             XEvent             *xevent);
 
 G_END_DECLS
 



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