[gtk+/events-refactor: 325/1085] Add methods for getting event/filter window from the event, with default impl.



commit 1fa2f018efab1df718f95b963eb0b75020aca30a
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sat May 30 14:36:26 2009 +0200

    Add methods for getting event/filter window from the event, with default impl.

 gdk/x11/gdkeventtranslator.c |  100 ++++++++++++++++++++++++++++++++++++++++++
 gdk/x11/gdkeventtranslator.h |   12 +++++
 2 files changed, 112 insertions(+), 0 deletions(-)
---
diff --git a/gdk/x11/gdkeventtranslator.c b/gdk/x11/gdkeventtranslator.c
index 32ef901..39b3c8d 100644
--- a/gdk/x11/gdkeventtranslator.c
+++ b/gdk/x11/gdkeventtranslator.c
@@ -62,3 +62,103 @@ gdk_event_translator_translate (GdkEventTranslator *translator,
 
   return NULL;
 }
+
+static GdkWindow *
+get_gdk_window (GdkDisplay *display,
+                Window      xwindow)
+{
+  GdkWindow *window;
+
+  /* Now find out the corresponding GdkWindows */
+  window = gdk_window_lookup_for_display (display, xwindow);
+
+  /* We may receive events such as NoExpose/GraphicsExpose
+   * and ShmCompletion for pixmaps
+   */
+  if (window && !GDK_IS_WINDOW (window))
+    window = NULL;
+
+  return window;
+}
+
+GdkWindow *
+gdk_event_translator_get_event_window (GdkEventTranslator *translator,
+                                       GdkDisplay         *display,
+                                       XEvent             *xevent)
+{
+  GdkEventTranslatorIface *iface;
+  Window xwindow = None;
+
+  g_return_val_if_fail (GDK_IS_EVENT_TRANSLATOR (translator), NULL);
+
+  iface = GDK_EVENT_TRANSLATOR_GET_IFACE (translator);
+
+  if (iface->get_event_window)
+    xwindow = (iface->get_event_window) (translator, xevent);
+
+  if (xwindow == None)
+    {
+      /* Default implementation */
+      switch (xevent->type)
+	{
+	case CreateNotify:
+	  xwindow = xevent->xcreatewindow.window;
+	  break;
+	case DestroyNotify:
+	  xwindow = xevent->xdestroywindow.window;
+	  break;
+	case UnmapNotify:
+	  xwindow = xevent->xunmap.window;
+	  break;
+	case MapNotify:
+	  xwindow = xevent->xmap.window;
+	  break;
+	case MapRequest:
+	  xwindow = xevent->xmaprequest.window;
+	  break;
+	case ReparentNotify:
+	  xwindow = xevent->xreparent.window;
+	  break;
+	case ConfigureNotify:
+	  xwindow = xevent->xconfigure.window;
+	  break;
+	case ConfigureRequest:
+	  xwindow = xevent->xconfigurerequest.window;
+	  break;
+	case GravityNotify:
+	  xwindow = xevent->xgravity.window;
+	  break;
+	case CirculateNotify:
+	  xwindow = xevent->xcirculate.window;
+	  break;
+	case CirculateRequest:
+	  xwindow = xevent->xcirculaterequest.window;
+	  break;
+	default:
+	  xwindow = xevent->xany.window;
+	}
+    }
+
+  return get_gdk_window (display, xwindow);
+}
+
+GdkWindow *
+gdk_event_translator_get_filter_window (GdkEventTranslator *translator,
+                                        GdkDisplay         *display,
+                                        XEvent             *xevent)
+{
+  GdkEventTranslatorIface *iface;
+  Window xwindow = None;
+
+  g_return_val_if_fail (GDK_IS_EVENT_TRANSLATOR (translator), NULL);
+
+  iface = GDK_EVENT_TRANSLATOR_GET_IFACE (translator);
+
+  if (iface->get_filter_window)
+    xwindow = (iface->get_filter_window) (translator, xevent);
+
+  if (xwindow == None)
+    xwindow = xevent->xany.window;
+
+  return get_gdk_window (display, xwindow);
+}
diff --git a/gdk/x11/gdkeventtranslator.h b/gdk/x11/gdkeventtranslator.h
index 6ffe153..4ec6cfc 100644
--- a/gdk/x11/gdkeventtranslator.h
+++ b/gdk/x11/gdkeventtranslator.h
@@ -43,6 +43,11 @@ struct _GdkEventTranslatorIface
                                 GdkDisplay         *display,
                                 GdkEvent           *event,
                                 XEvent             *xevent);
+
+  Window (* get_event_window)  (GdkEventTranslator *translator,
+                                XEvent             *xevent);
+  Window (* get_filter_window) (GdkEventTranslator *translator,
+                                XEvent             *xevent);
 };
 
 GType      gdk_event_translator_get_type (void) G_GNUC_CONST;
@@ -51,6 +56,13 @@ GdkEvent * gdk_event_translator_translate (GdkEventTranslator *translator,
                                            GdkDisplay         *display,
                                            XEvent             *xevent);
 
+GdkWindow * gdk_event_translator_get_event_window  (GdkEventTranslator *translator,
+                                                    GdkDisplay         *display,
+                                                    XEvent             *xevent);
+GdkWindow * gdk_event_translator_get_filter_window (GdkEventTranslator *translator,
+                                                    GdkDisplay         *display,
+                                                    XEvent             *xevent);
+
 G_END_DECLS
 
 #endif /* __GDK_EVENT_TRANSLATOR_H__ */



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