[gtk+/xi2-playground: 11/12] GtkWidget: ensure device events are set on realize.



commit 8d0634e91578f9e973b823ef561da5f7188b56ee
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Jun 9 17:50:26 2010 +0200

    GtkWidget: ensure device events are set on realize.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=621690

 gtk/gtkwidget.c |   78 ++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 49 insertions(+), 29 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 8155ffe..3eefd87 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -371,6 +371,9 @@ static void gtk_widget_set_usize_internal (GtkWidget *widget,
 static void gtk_widget_get_draw_rectangle (GtkWidget    *widget,
 					   GdkRectangle *rect);
 
+static void gtk_widget_add_events_internal (GtkWidget *widget,
+                                            GdkDevice *device,
+                                            gint       events);
 
 /* --- variables --- */
 static gpointer         gtk_widget_parent_class = NULL;
@@ -3538,6 +3541,8 @@ gtk_widget_realize (GtkWidget *widget)
   
   if (!gtk_widget_get_realized (widget))
     {
+      GHashTable *device_events;
+
       /*
 	if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
 	  g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
@@ -3582,6 +3587,26 @@ gtk_widget_realize (GtkWidget *widget)
 
       if ((GTK_WIDGET_FLAGS (widget) & GTK_MULTIDEVICE) != 0)
         gdk_window_set_support_multidevice (widget->window, TRUE);
+
+      device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
+
+      if (device_events)
+        {
+          GHashTableIter iter;
+          gpointer key, value;
+
+          g_hash_table_iter_init (&iter, device_events);
+
+          while (g_hash_table_iter_next (&iter, &key, &value))
+            {
+              GdkDevice *device;
+              GdkEventMask event_mask;
+
+              device = key;
+              event_mask = GPOINTER_TO_UINT (value);
+              gtk_widget_add_events_internal (widget, device, event_mask);
+            }
+        }
     }
 }
 
@@ -8132,10 +8157,10 @@ gtk_widget_set_device_events (GtkWidget    *widget,
 }
 
 static void
-gtk_widget_add_events_internal (GtkWidget *widget,
-                                GdkDevice *device,
-                                gint       events,
-                                GList     *window_list)
+gtk_widget_add_events_internal_list (GtkWidget *widget,
+                                     GdkDevice *device,
+                                     gint       events,
+                                     GList     *window_list)
 {
   GList *l;
 
@@ -8155,12 +8180,29 @@ gtk_widget_add_events_internal (GtkWidget *widget,
             gdk_window_set_events (window, gdk_window_get_events (window) | events);
 
           children = gdk_window_get_children (window);
-          gtk_widget_add_events_internal (widget, device, events, children);
+          gtk_widget_add_events_internal_list (widget, device, events, children);
           g_list_free (children);
         }
     }
 }
 
+static void
+gtk_widget_add_events_internal (GtkWidget *widget,
+                                GdkDevice *device,
+                                gint       events)
+{
+  GList *window_list;
+
+  if (!gtk_widget_get_has_window (widget))
+    window_list = gdk_window_get_children (widget->window);
+  else
+    window_list = g_list_prepend (NULL, widget->window);
+
+  gtk_widget_add_events_internal_list (widget, device, events, window_list);
+
+  g_list_free (window_list);
+}
+
 /**
  * gtk_widget_add_events:
  * @widget: a #GtkWidget
@@ -8182,18 +8224,7 @@ gtk_widget_add_events (GtkWidget *widget,
                       GINT_TO_POINTER (old_events | events));
 
   if (gtk_widget_get_realized (widget))
-    {
-      GList *window_list;
-
-      if (!gtk_widget_get_has_window (widget))
-	window_list = gdk_window_get_children (widget->window);
-      else
-	window_list = g_list_prepend (NULL, widget->window);
-
-      gtk_widget_add_events_internal (widget, NULL, events, window_list);
-
-      g_list_free (window_list);
-    }
+    gtk_widget_add_events_internal (widget, NULL, events);
 
   g_object_notify (G_OBJECT (widget), "events");
 }
@@ -8235,18 +8266,7 @@ gtk_widget_add_device_events (GtkWidget    *widget,
                        GUINT_TO_POINTER (old_events | events));
 
   if (gtk_widget_get_realized (widget))
-    {
-      GList *window_list;
-
-      if (!gtk_widget_get_has_window (widget))
-        window_list = gdk_window_get_children (widget->window);
-      else
-        window_list = g_list_prepend (NULL, widget->window);
-
-      gtk_widget_add_events_internal (widget, device, events, window_list);
-
-      g_list_free (window_list);
-    }
+    gtk_widget_add_events_internal (widget, device, events);
 
   g_object_notify (G_OBJECT (widget), "events");
 }



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