[gtk+/xi2: 1238/1239] GdkDeviceManagerXI: Store root X/Y info for windows with extended events.



commit b8703db4632cd142260ea685658e72c3c46d6c54
Author: Carlos Garnacho <carlos gnome org>
Date:   Tue Sep 29 00:21:52 2009 +0200

    GdkDeviceManagerXI: Store root X/Y info for windows with extended events.
    
    This will be used to determine X/Y axes in screen mode.

 gdk/x11/gdkdevice-xi.c        |   45 ++++++++++++++++++++++++++++++++++++++++-
 gdk/x11/gdkdevice-xi.h        |    4 +++
 gdk/x11/gdkdevicemanager-xi.c |   31 ++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+), 1 deletions(-)
---
diff --git a/gdk/x11/gdkdevice-xi.c b/gdk/x11/gdkdevice-xi.c
index 746c797..b4df4bd 100644
--- a/gdk/x11/gdkdevice-xi.c
+++ b/gdk/x11/gdkdevice-xi.c
@@ -26,6 +26,14 @@
 
 #define MAX_DEVICE_CLASSES 13
 
+static GQuark quark_window_input_info = 0;
+
+typedef struct
+{
+  gdouble root_x;
+  gdouble root_y;
+} GdkWindowInputInfo;
+
 static void gdk_device_xi_constructed  (GObject *object);
 static void gdk_device_xi_set_property (GObject      *object,
                                         guint         prop_id,
@@ -96,6 +104,8 @@ gdk_device_xi_class_init (GdkDeviceXIClass *klass)
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
   GdkDeviceClass *device_class = GDK_DEVICE_CLASS (klass);
 
+  quark_window_input_info = g_quark_from_static_string ("gdk-window-input-info");
+
   object_class->constructed = gdk_device_xi_constructed;
   object_class->set_property = gdk_device_xi_set_property;
   object_class->get_property = gdk_device_xi_get_property;
@@ -514,8 +524,11 @@ gdk_device_xi_select_window_events (GdkDevice    *device,
                                     GdkEventMask  event_mask)
 {
   XEventClass event_classes[MAX_DEVICE_CLASSES];
-  gint num_classes;
   GdkDeviceXI *device_xi;
+  gint num_classes;
+
+  event_mask |= (GDK_PROXIMITY_IN_MASK |
+                 GDK_PROXIMITY_OUT_MASK);
 
   device_xi = GDK_DEVICE_XI (device);
   find_events (device, event_mask, event_classes, &num_classes);
@@ -524,4 +537,34 @@ gdk_device_xi_select_window_events (GdkDevice    *device,
 			 GDK_WINDOW_XWINDOW (window),
 			 event_classes, num_classes);
 
+  if (event_mask)
+    {
+      GdkWindowInputInfo *info;
+
+      info = g_new0 (GdkWindowInputInfo, 1);
+      g_object_set_qdata_full (G_OBJECT (window),
+                               quark_window_input_info,
+                               info,
+                               (GDestroyNotify) g_free);
+    }
+  else
+    g_object_set_qdata (G_OBJECT (window),
+                        quark_window_input_info,
+                        NULL);
+}
+
+void
+gdk_device_xi_update_window_info (GdkWindow *window,
+                                  gdouble    root_x,
+                                  gdouble    root_y)
+{
+  GdkWindowInputInfo *info;
+
+  info = g_object_get_qdata (G_OBJECT (window),
+                             quark_window_input_info);
+  if (info)
+    {
+      info->root_x = root_x;
+      info->root_y = root_y;
+    }
 }
diff --git a/gdk/x11/gdkdevice-xi.h b/gdk/x11/gdkdevice-xi.h
index 98389bd..c7d99cb 100644
--- a/gdk/x11/gdkdevice-xi.h
+++ b/gdk/x11/gdkdevice-xi.h
@@ -64,6 +64,10 @@ struct _GdkDeviceXIClass
 
 GType gdk_device_xi_get_type (void) G_GNUC_CONST;
 
+void gdk_device_xi_update_window_info (GdkWindow *window,
+                                       gdouble    root_x,
+                                       gdouble    root_y);
+
 G_END_DECLS
 
 #endif /* __GDK_DEVICE_XI_H__ */
diff --git a/gdk/x11/gdkdevicemanager-xi.c b/gdk/x11/gdkdevicemanager-xi.c
index a9391b9..9454c40 100644
--- a/gdk/x11/gdkdevicemanager-xi.c
+++ b/gdk/x11/gdkdevicemanager-xi.c
@@ -90,6 +90,31 @@ gdk_device_manager_xi_class_init (GdkDeviceManagerXIClass *klass)
   g_type_class_add_private (object_class, sizeof (GdkDeviceManagerXIPrivate));
 }
 
+static GdkFilterReturn
+window_input_info_filter (GdkXEvent *xevent,
+                          GdkEvent  *event,
+                          gpointer   user_data)
+{
+  GdkDeviceManager *device_manager;
+  GdkDisplay *display;
+  GdkWindow *window;
+  XEvent *xev;
+
+  device_manager = user_data;
+  xev = (XEvent *) xevent;
+
+  display = gdk_device_manager_get_display (device_manager);
+  window = gdk_window_lookup_for_display (display, xev->xany.window);
+
+  if (window &&
+      xev->type == ConfigureNotify)
+    gdk_device_xi_update_window_info (window,
+                                      (gdouble) xev->xconfigure.x,
+                                      (gdouble) xev->xconfigure.y);
+
+  return GDK_FILTER_CONTINUE;
+}
+
 static void
 gdk_device_manager_xi_init (GdkDeviceManagerXI *device_manager)
 {
@@ -98,6 +123,8 @@ gdk_device_manager_xi_init (GdkDeviceManagerXI *device_manager)
   priv = GDK_DEVICE_MANAGER_XI_GET_PRIVATE (device_manager);
   priv->id_table = g_hash_table_new_full (NULL, NULL, NULL,
                                           (GDestroyNotify) g_object_unref);
+
+  gdk_window_add_filter (NULL, window_input_info_filter, device_manager);
 }
 
 static void
@@ -260,6 +287,10 @@ gdk_device_manager_xi_finalize (GObject *object)
   g_list_foreach (priv->devices, (GFunc) g_object_unref, NULL);
   g_list_free (priv->devices);
 
+  g_hash_table_destroy (priv->id_table);
+
+  gdk_window_remove_filter (NULL, window_input_info_filter, object);
+
   G_OBJECT_CLASS (gdk_device_manager_xi_parent_class)->finalize (object);
 }
 



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