? gtk-net-wm-user-time.patch
? just-2-4-1.patch
Index: gdk/gdkwindow.h
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/gdkwindow.h,v
retrieving revision 1.49
diff -u -r1.49 gdkwindow.h
--- gdk/gdkwindow.h	26 Jan 2004 20:20:42 -0000	1.49
+++ gdk/gdkwindow.h	14 Apr 2004 18:15:22 -0000
@@ -262,6 +262,7 @@
   guint destroyed : 2;
 
   guint accept_focus : 1;
+  guint focus_on_map : 1;
   
   GdkEventMask event_mask;
 };
Index: gdk/linux-fb/gdkwindow-fb.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/linux-fb/gdkwindow-fb.c,v
retrieving revision 1.57
diff -u -r1.57 gdkwindow-fb.c
--- gdk/linux-fb/gdkwindow-fb.c	6 Mar 2004 04:00:07 -0000	1.57
+++ gdk/linux-fb/gdkwindow-fb.c	14 Apr 2004 18:15:22 -0000
@@ -189,6 +189,7 @@
   private->parent = parent_private;
 
   private->accept_focus = TRUE;
+  private->focus_on_map = TRUE;
 
   if (attributes_mask & GDK_WA_X)
     x = attributes->x;
Index: gdk/win32/gdkwindow-win32.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/win32/gdkwindow-win32.c,v
retrieving revision 1.115
diff -u -r1.115 gdkwindow-win32.c
--- gdk/win32/gdkwindow-win32.c	13 Mar 2004 18:27:55 -0000	1.115
+++ gdk/win32/gdkwindow-win32.c	14 Apr 2004 18:15:22 -0000
@@ -508,6 +508,7 @@
   private->parent = (GdkWindowObject *)parent;
 
   private->accept_focus = TRUE;
+  private->focus_on_map = TRUE;
 
   if (attributes_mask & GDK_WA_X)
     private->x = attributes->x;
Index: gdk/x11/gdkdisplay-x11.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkdisplay-x11.c,v
retrieving revision 1.40
diff -u -r1.40 gdkdisplay-x11.c
--- gdk/x11/gdkdisplay-x11.c	2 Feb 2004 18:18:18 -0000	1.40
+++ gdk/x11/gdkdisplay-x11.c	14 Apr 2004 18:15:23 -0000
@@ -81,6 +81,7 @@
   "_NET_WM_STATE_FULLSCREEN",
   "_NET_WM_WINDOW_TYPE",
   "_NET_WM_WINDOW_TYPE_NORMAL",
+  "_NET_WM_USER_TIME",
 };
 
 GType
@@ -217,6 +218,9 @@
 		   display_x11->leader_window,
 		   gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PID"),
 		   XA_CARDINAL, 32, PropModeReplace, (guchar *) & pid, 1);
+
+  /* We don't yet know a valid time. */
+  display_x11->user_time = 0;
   
 #ifdef HAVE_XKB
   {
Index: gdk/x11/gdkdisplay-x11.h
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkdisplay-x11.h,v
retrieving revision 1.15
diff -u -r1.15 gdkdisplay-x11.h
--- gdk/x11/gdkdisplay-x11.h	2 Feb 2004 18:18:18 -0000	1.15
+++ gdk/x11/gdkdisplay-x11.h	14 Apr 2004 18:15:23 -0000
@@ -138,6 +138,9 @@
   /* Startup notification */
   gchar *startup_notification_id;
 
+  /* Time of most recent user interaction. */
+  gulong user_time;
+
   /* Sets of atoms for DND */
   guint base_dnd_atoms_precached : 1;
   guint xdnd_atoms_precached : 1;
Index: gdk/x11/gdkevents-x11.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkevents-x11.c,v
retrieving revision 1.128
diff -u -r1.128 gdkevents-x11.c
--- gdk/x11/gdkevents-x11.c	6 Mar 2004 03:37:18 -0000	1.128
+++ gdk/x11/gdkevents-x11.c	14 Apr 2004 18:15:23 -0000
@@ -802,6 +802,22 @@
 };
 #endif
 
+void
+set_user_time (GdkWindow* window, GdkEvent *event)
+{
+  g_return_if_fail (event != NULL);
+
+  window = gdk_window_get_toplevel (event->client.window);
+  g_return_if_fail (GDK_IS_WINDOW (window));
+
+  /* If an event doesn't have a valid timestamp, we shouldn't use it
+   * to update the latest user interaction time.
+   */
+  if (gdk_event_get_time (event) != GDK_CURRENT_TIME)
+    gdk_x11_window_set_user_time (gdk_window_get_toplevel (window),
+                                  gdk_event_get_time (event));
+}
+
 static gboolean
 gdk_event_translate (GdkDisplay *display,
 		     GdkEvent   *event,
@@ -995,6 +1011,7 @@
           break;
         }
       translate_key_event (display, event, xevent);
+      set_user_time (window, event);
       break;
 
     case KeyRelease:
@@ -1093,6 +1110,7 @@
           break;
 	}
 
+      set_user_time (window, event);
       break;
       
     case ButtonRelease:
Index: gdk/x11/gdkinput-x11.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkinput-x11.c,v
retrieving revision 1.34
diff -u -r1.34 gdkinput-x11.c
--- gdk/x11/gdkinput-x11.c	6 Mar 2004 03:37:18 -0000	1.34
+++ gdk/x11/gdkinput-x11.c	14 Apr 2004 18:15:23 -0000
@@ -584,6 +584,12 @@
 		 event->button.x, event->button.y,
 		 xdbe->button));
 
+      /* Update the timestamp of the latest user interaction, if the event has
+       * a valid timestamp.
+       */
+      if (gdk_event_get_time (event) != GDK_CURRENT_TIME)
+        gdk_x11_window_set_user_time (gdk_window_get_toplevel (input_window->window),
+                                      gdk_event_get_time (event));
       return TRUE;
   }
 
@@ -644,6 +650,12 @@
 		 event->key.keyval,
 		 event->key.state));
 
+      /* Update the timestamp of the latest user interaction, if the event has
+       * a valid timestamp.
+       */
+      if (gdk_event_get_time (event) != GDK_CURRENT_TIME)
+        gdk_x11_window_set_user_time (gdk_window_get_toplevel (input_window->window),
+                                      gdk_event_get_time (event));
       return TRUE;
     }
 
@@ -674,6 +686,12 @@
 		 (xdme->is_hint) ? "true" : "false"));
       
       
+      /* Update the timestamp of the latest user interaction, if the event has
+       * a valid timestamp.
+       */
+      if (gdk_event_get_time (event) != GDK_CURRENT_TIME)
+        gdk_x11_window_set_user_time (gdk_window_get_toplevel (input_window->window),
+                                      gdk_event_get_time (event));
       return TRUE;
     }
 
@@ -688,6 +706,12 @@
       event->proximity.window = input_window->window;
       event->proximity.time = xpne->time;
       
+      /* Update the timestamp of the latest user interaction, if the event has
+       * a valid timestamp.
+       */
+      if (gdk_event_get_time (event) != GDK_CURRENT_TIME)
+        gdk_x11_window_set_user_time (gdk_window_get_toplevel (input_window->window),
+                                      gdk_event_get_time (event));
       return TRUE;
   }
 
Index: gdk/x11/gdkwindow-x11.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkwindow-x11.c,v
retrieving revision 1.204
diff -u -r1.204 gdkwindow-x11.c
--- gdk/x11/gdkwindow-x11.c	13 Mar 2004 18:27:56 -0000	1.204
+++ gdk/x11/gdkwindow-x11.c	14 Apr 2004 18:15:23 -0000
@@ -457,6 +457,11 @@
 		   gdk_x11_get_xatom_by_name_for_display (screen_x11->display, "WM_CLIENT_LEADER"),
 		   XA_WINDOW, 32, PropModeReplace,
 		   (guchar *) &GDK_DISPLAY_X11 (screen_x11->display)->leader_window, 1);
+
+  if (!obj->focus_on_map)
+    gdk_x11_window_set_user_time(window, 0);
+  else if (GDK_DISPLAY_X11 (screen_x11->display)->user_time != 0)
+    gdk_x11_window_set_user_time(window, GDK_DISPLAY_X11 (screen_x11->display)->user_time);
 }
 
 /**
@@ -540,6 +545,7 @@
   private->parent = (GdkWindowObject *)parent;
 
   private->accept_focus = TRUE;
+  private->focus_on_map = TRUE;
 
   xattributes_mask = 0;
   
@@ -3308,6 +3314,49 @@
     }
 }
 
+/**
+ * gdk_x11_window_set_user_time:
+ * @window: A toplevel #GdkWindow
+ * @timestamp: An XServer timestamp to which the property should be set
+ *
+ * The application can use this call to update the _NET_WM_USER_TIME
+ * property on a toplevel window.  This property stores an Xserver
+ * time which represents the time of the last user input event
+ * received for this window.  This property may be used by the window
+ * manager to alter the focus, stacking, and/or placement behavior of
+ * windows when they are mapped depending on whether the new window
+ * was created by a user action or is a "pop-up" window activated by a
+ * timer or some other event.
+ *
+ * Note that this property is automatically updated by GDK, so this
+ * function should only be used by applications which handle input
+ * events bypassing GDK.
+ *
+ * Since: 2.4.1
+ **/
+void             gdk_x11_window_set_user_time (GdkWindow *window,
+                                               guint32    timestamp)
+{
+  GdkDisplay *display;
+  GdkDisplayX11 *display_x11;
+
+  g_return_if_fail (window != NULL);
+  g_return_if_fail (GDK_IS_WINDOW (window));
+
+  if (GDK_WINDOW_DESTROYED (window))
+    return;
+
+  display = gdk_drawable_get_display (window);
+  display_x11 = GDK_DISPLAY_X11 (display);
+
+  XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
+                   gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_USER_TIME"),
+                   XA_CARDINAL, 32, PropModeReplace,
+                   (guchar *)&timestamp, 1);
+
+  if (timestamp != GDK_CURRENT_TIME)
+    display_x11->user_time = timestamp;
+}
 
 /**
  * gdk_window_set_icon_list:
Index: gdk/x11/gdkwindow-x11.h
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkwindow-x11.h,v
retrieving revision 1.10
diff -u -r1.10 gdkwindow-x11.h
--- gdk/x11/gdkwindow-x11.h	21 Dec 2003 16:37:43 -0000	1.10
+++ gdk/x11/gdkwindow-x11.h	14 Apr 2004 18:15:23 -0000
@@ -124,6 +124,8 @@
 GType gdk_window_impl_x11_get_type (void);
 
 GdkToplevelX11 *_gdk_x11_window_get_toplevel (GdkWindow *window);
+void             gdk_x11_window_set_user_time (GdkWindow *window,
+                                               guint32    timestamp);
 
 G_END_DECLS
 
Index: gtk/gtkwindow.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkwindow.c,v
retrieving revision 1.264
diff -u -r1.264 gtkwindow.c
--- gtk/gtkwindow.c	13 Mar 2004 20:45:15 -0000	1.264
+++ gtk/gtkwindow.c	14 Apr 2004 18:15:23 -0000
@@ -75,6 +75,7 @@
   PROP_SKIP_TASKBAR_HINT,
   PROP_SKIP_PAGER_HINT,
   PROP_ACCEPT_FOCUS,
+  PROP_FOCUS_ON_MAP,
   PROP_DECORATED,
   PROP_GRAVITY,
   
@@ -162,6 +163,7 @@
   guint skips_taskbar : 1;
   guint skips_pager : 1;
   guint accept_focus : 1;
+  guint focus_on_map : 1;
 };
 
 static void gtk_window_class_init         (GtkWindowClass    *klass);
@@ -764,6 +766,7 @@
   window->screen = gdk_screen_get_default ();
 
   priv->accept_focus = TRUE;
+  priv->focus_on_map = TRUE;
 
   colormap = _gtk_widget_peek_colormap ();
   if (colormap)
