Index: gtk/gtkwidget.c
===================================================================
--- gtk/gtkwidget.c	(revision 17514)
+++ gtk/gtkwidget.c	(working copy)
@@ -2618,6 +2618,51 @@ gtk_widget_unmap (GtkWidget *widget)
     }
 }
 
+static void
+gtk_widget_set_extension_events_internal (GtkWidget        *widget,
+                                          GdkExtensionMode  mode,
+                                          GList            *window_list)
+{
+  GList *free_list = NULL;
+  GList *l;
+
+  if (window_list == NULL)
+    {
+      if (!GTK_WIDGET_NO_WINDOW (widget))
+        window_list = g_list_prepend (NULL, widget->window);
+      else
+        window_list = gdk_window_get_children (widget->window);
+
+      free_list = window_list;
+    }
+
+  for (l = window_list; l != NULL; l = l->next)
+    {
+      GdkWindow *window = l->data;
+      gpointer user_data;
+
+      gdk_window_get_user_data (window, &user_data);
+      if (user_data == widget)
+        {
+          GList *children;
+
+          gdk_input_set_extension_events (window,
+                                          gdk_window_get_events (window),
+                                          mode);
+
+          children = gdk_window_get_children (window);
+          if (children)
+            {
+              gtk_widget_set_extension_events_internal (widget, mode, children);
+              g_list_free (children);
+            }
+        }
+    }
+
+  if (free_list)
+    g_list_free (free_list);
+}
+
 /**
  * gtk_widget_realize:
  * @widget: a #GtkWidget
@@ -2645,7 +2690,6 @@ gtk_widget_unmap (GtkWidget *widget)
 void
 gtk_widget_realize (GtkWidget *widget)
 {
-  gint events;
   GdkExtensionMode mode;
   GtkWidgetShapeInfo *shape_info;
   
@@ -2691,16 +2735,9 @@ gtk_widget_realize (GtkWidget *widget)
 					     shape_info->offset_x,
 					     shape_info->offset_y);
 
-      if (!GTK_WIDGET_NO_WINDOW (widget))
-	{
-	  mode = gtk_widget_get_extension_events (widget);
-	  if (mode != GDK_EXTENSION_EVENTS_NONE)
-	    {
-	      events = gtk_widget_get_events (widget);
-	      gdk_input_set_extension_events (widget->window, events, mode);
-	    }
-	}
-      
+      mode = gtk_widget_get_extension_events (widget);
+      if (mode != GDK_EXTENSION_EVENTS_NONE)
+        gtk_widget_set_extension_events_internal (widget, mode, NULL);
     }
 }
 
@@ -6572,21 +6609,23 @@ gtk_widget_add_events (GtkWidget *widget
  *
  * Sets the extension events mask to @mode. See #GdkExtensionMode
  * and gdk_input_set_extension_events().
- * 
  **/
 void
 gtk_widget_set_extension_events (GtkWidget *widget,
 				 GdkExtensionMode mode)
 {
   GdkExtensionMode *modep;
-  
+
   g_return_if_fail (GTK_IS_WIDGET (widget));
-  
+
   modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
-  
+
   if (!modep)
     modep = g_slice_new (GdkExtensionMode);
-  
+
+  if (GTK_WIDGET_REALIZED (widget))
+    gtk_widget_set_extension_events_internal (widget, mode, NULL);
+
   *modep = mode;
   g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode, modep);
   g_object_notify (G_OBJECT (widget), "extension-events");
