Index: gdk/gdkwindow.h
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/gdkwindow.h,v
retrieving revision 1.48
diff -u -r1.48 gdkwindow.h
--- gdk/gdkwindow.h	10 Dec 2003 23:57:40 -0000	1.48
+++ gdk/gdkwindow.h	16 Jan 2004 21:00:46 -0000
@@ -419,6 +419,9 @@
 					     GdkWindowHints    geom_mask);
 void          gdk_set_sm_client_id         (const gchar *sm_client_id);
 
+void          gdk_window_set_focus_on_map  (GdkWindow *window,
+					    gboolean  should_focus);
+
 void	      gdk_window_begin_paint_rect   (GdkWindow    *window,
 					     GdkRectangle *rectangle);
 void	      gdk_window_begin_paint_region (GdkWindow    *window,
Index: gdk/x11/gdkevents-x11.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkevents-x11.c,v
retrieving revision 1.121
diff -u -r1.121 gdkevents-x11.c
--- gdk/x11/gdkevents-x11.c	16 Dec 2003 00:56:48 -0000	1.121
+++ gdk/x11/gdkevents-x11.c	16 Jan 2004 21:00:46 -0000
@@ -785,6 +785,18 @@
 };
 #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));
+
+  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,
@@ -978,6 +990,7 @@
           break;
         }
       translate_key_event (display, event, xevent);
+      set_user_time (window, event);
       break;
 
     case KeyRelease:
@@ -1008,6 +1021,7 @@
 	}
 
       translate_key_event (display, event, xevent);
+      set_user_time (window, event);
       break;
       
     case ButtonPress:
@@ -1920,6 +1934,13 @@
 #endif
 	{
 	  /* something else - (e.g., a Xinput event) */
+
+          /* FIXME: I have no clue how to tell if this is an XInput
+	     event.  Is this if statement right?  Also, does the
+	     user_time really need to be updated for XInput
+	     events?  */
+	  if (window_private && (window_private->extension_events != 0))
+            set_user_time (window, event);
 	  
 	  if (window_private &&
 	      !GDK_WINDOW_DESTROYED (window_private) &&
Index: gdk/x11/gdkwindow-x11.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkwindow-x11.c,v
retrieving revision 1.198
diff -u -r1.198 gdkwindow-x11.c
--- gdk/x11/gdkwindow-x11.c	21 Dec 2003 16:37:43 -0000	1.198
+++ gdk/x11/gdkwindow-x11.c	16 Jan 2004 21:00:47 -0000
@@ -2184,6 +2184,65 @@
     }
 }
 
+/**
+ * gdk_window_set_focus_on_map:
+ * @window: a toplevel #GdkWindow
+ * @should_focus: %FALSE to hint that focus on map isn't useful
+ * 
+ * Windows may set a hint asking the desktop environment not to focus
+ * the window when mapped.  This is useful for windows that aren't
+ * triggered interactively, such as popups from network activity.
+ * receive the input focus.
+ * 
+ * Since: 2.4
+ **/
+void
+gdk_window_set_focus_on_map (GdkWindow *window,
+			     gboolean   should_focus)
+{
+  if (!should_focus)
+    gdk_x11_window_set_user_time(gdk_window_get_toplevel (window), 0);
+}
+
+/**
+ * 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
+ **/
+void             gdk_x11_window_set_user_time (GdkWindow *window,
+                                               guint32    timestamp)
+{
+  GdkDisplay *display;
+
+  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);
+
+  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);
+}
+
 static gboolean
 utf8_is_latin1 (const gchar *str)
 {
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	16 Jan 2004 21:00:47 -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.256
diff -u -r1.256 gtkwindow.c
--- gtk/gtkwindow.c	10 Dec 2003 23:45:51 -0000	1.256
+++ gtk/gtkwindow.c	16 Jan 2004 21:00:47 -0000
@@ -2103,6 +2103,25 @@
 }
 
 /**
+ * gtk_window_set_focus_on_map:
+ * @window: a #GtkWindow 
+ * @should_focus: %FALSE to hint that focus on map isn't useful
+ * 
+ * Windows may set a hint asking the desktop environment not to focus
+ * the window when mapped.  This is useful for windows that aren't
+ * triggered interactively, such as popups from network activity.
+ * receive the input focus.
+ * 
+ * Since: 2.4
+ **/
+void
+gtk_window_set_focus_on_map (GtkWindow *window,
+			     gboolean   should_focus)
+{
+  gdk_window_set_focus_on_map(GTK_WIDGET (window)->window, should_focus);
+}
+
+/**
  * gtk_window_set_accept_focus:
  * @window: a #GtkWindow 
  * @setting: %TRUE to let this window receive input focus
Index: gtk/gtkwindow.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkwindow.h,v
retrieving revision 1.73
diff -u -r1.73 gtkwindow.h
--- gtk/gtkwindow.h	10 Dec 2003 23:45:55 -0000	1.73
+++ gtk/gtkwindow.h	16 Jan 2004 21:00:47 -0000
@@ -201,6 +201,8 @@
 void       gtk_window_set_skip_pager_hint      (GtkWindow           *window,
                                                 gboolean             setting);
 gboolean   gtk_window_get_skip_pager_hint      (GtkWindow           *window);
+void       gtk_window_set_focus_on_map         (GtkWindow           *window,
+                                                gboolean           should_focus);
 void       gtk_window_set_accept_focus         (GtkWindow           *window,
                                                 gboolean             setting);
 gboolean   gtk_window_get_accept_focus         (GtkWindow           *window);
