[gtk+/gtk-3-0] gtk_window_present_with_time: fix when window is not initially visible



commit 00802c73e4295450353cf25c9d30c2c6beb624f9
Author: Dan Winship <danw gnome org>
Date:   Tue Apr 12 14:48:27 2011 -0400

    gtk_window_present_with_time: fix when window is not initially visible
    
    When called on a hidden window, gtk_window_present_with_time() would
    just fall back to gtk_widget_show(), completely ignoring the passed-in
    timestamp. This ended up working anyway if the timestamp came from
    in-process, since gdk_window_x11_show() would initialize its user_time
    from the time of the most recent event. But if the timestamp came from
    another process, this would result in the window being shown with an
    out-of-date timestamp.
    
    Fix this by remembering the timestamp from
    gtk_window_present_with_time(), and then setting the GdkWindow's
    user_time from that when it the window is realized.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=647275

 gtk/gtkwindow.c |   34 ++++++++++++++++++++++++++--------
 1 files changed, 26 insertions(+), 8 deletions(-)
---
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 43f4e18..9b885ae 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -126,6 +126,8 @@ struct _GtkWindowPrivate
 
   guint    keys_changed_handler;
 
+  guint32  initial_timestamp;
+
   guint16  configure_request_count;
 
   /* The following flags are initially TRUE (before a window is mapped).
@@ -1105,6 +1107,7 @@ gtk_window_init (GtkWindow *window)
   priv->type_hint = GDK_WINDOW_TYPE_HINT_NORMAL;
   priv->opacity = 1.0;
   priv->startup_id = NULL;
+  priv->initial_timestamp = GDK_CURRENT_TIME;
   priv->has_resize_grip = TRUE;
   priv->mnemonics_visible = TRUE;
 
@@ -5006,10 +5009,18 @@ gtk_window_realize (GtkWidget *widget)
             gdk_x11_window_set_user_time (gdk_window, timestamp);
         }
 #endif
-      if (!startup_id_is_fake (priv->startup_id)) 
-	gdk_window_set_startup_id (gdk_window, priv->startup_id);
+      if (!startup_id_is_fake (priv->startup_id))
+        gdk_window_set_startup_id (gdk_window, priv->startup_id);
     }
-  
+
+#ifdef GDK_WINDOWING_X11
+  if (priv->initial_timestamp != GDK_CURRENT_TIME)
+    {
+      if (GDK_IS_X11_WINDOW (gdk_window))
+        gdk_x11_window_set_user_time (gdk_window, priv->initial_timestamp);
+    }
+#endif
+
   /* Icons */
   gtk_window_realize_icon (window);
   
@@ -7359,11 +7370,13 @@ void
 gtk_window_present_with_time (GtkWindow *window,
 			      guint32    timestamp)
 {
+  GtkWindowPrivate *priv;
   GtkWidget *widget;
   GdkWindow *gdk_window;
 
   g_return_if_fail (GTK_IS_WINDOW (window));
 
+  priv = window->priv;
   widget = GTK_WIDGET (window);
 
   if (gtk_widget_get_visible (widget))
@@ -7378,19 +7391,24 @@ gtk_window_present_with_time (GtkWindow *window,
       if (timestamp == GDK_CURRENT_TIME)
         {
 #ifdef GDK_WINDOWING_X11
-          GdkDisplay *display;
+          if (GDK_IS_X11_WINDOW (gdk_window))
+            {
+              GdkDisplay *display;
 
-          display = gtk_widget_get_display (GTK_WIDGET (window));
-          timestamp = gdk_x11_display_get_user_time (display);
-#else
-          timestamp = gtk_get_current_event_time ();
+              display = gtk_widget_get_display (window);
+              timestamp = gdk_x11_display_get_user_time (display);
+            }
+          else
 #endif
+            timestamp = gtk_get_current_event_time ();
+
         }
 
       gdk_window_focus (gdk_window, timestamp);
     }
   else
     {
+      priv->initial_timestamp = timestamp;
       gtk_widget_show (widget);
     }
 }



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