Index: src/display.c
===================================================================
RCS file: /cvs/gnome/metacity/src/display.c,v
retrieving revision 1.229
diff -p -u -r1.229 display.c
--- src/display.c	22 Sep 2004 18:57:36 -0000	1.229
+++ src/display.c	28 Sep 2004 17:12:27 -0000
@@ -77,6 +77,14 @@ typedef struct 
 typedef struct 
 {
   MetaDisplay *display;
+  MetaWindow *window;
+  Window xwindow;
+  Time timestamp;
+} MetaDndData;
+
+typedef struct 
+{
+  MetaDisplay *display;
   Window xwindow;
 } MetaAutoRaiseData;
 
@@ -95,10 +103,15 @@ static Window event_get_modified_window 
                                          XEvent         *event);
 static guint32 event_get_time           (MetaDisplay    *display,
                                          XEvent         *event);
+static void    queue_take_activity      (MetaDisplay       *display,
+                                         MetaWindow        *window,
+                                         Time               timestamp);
 static void    process_request_frame_extents (MetaDisplay    *display,
                                               XEvent         *event);
 static void    process_pong_message     (MetaDisplay    *display,
                                          XEvent         *event);
+static void    process_dnd_message      (MetaDisplay    *display,
+                                         XEvent         *event);
 static void    process_selection_request (MetaDisplay   *display,
                                           XEvent        *event);
 static void    process_selection_clear   (MetaDisplay   *display,
@@ -163,6 +176,35 @@ remove_pending_pings_for_window (MetaDis
   g_slist_free (dead);
 }
 
+static void
+remove_pending_dnds_for_window (MetaDisplay *display, Window xwindow)
+{
+  GSList *tmp;
+  GSList *dead;
+
+  /* could obviously be more efficient, don't care */
+  
+  /* build list to be removed */
+  dead = NULL;
+  for (tmp = display->pending_dnds; tmp; tmp = tmp->next)
+    {
+      MetaDndData *dnd_data = tmp->data;
+
+      if (dnd_data->xwindow == xwindow)
+        dead = g_slist_prepend (dead, dnd_data);
+    }
+
+  /* remove what we found */
+  for (tmp = dead; tmp; tmp = tmp->next)
+    {
+      MetaDndData *dnd_data = tmp->data;
+
+      display->pending_dnds = g_slist_remove (display->pending_dnds, dnd_data);
+      g_free (dnd_data);
+    }
+
+  g_slist_free (dead);
+}
 
 #ifdef HAVE_STARTUP_NOTIFICATION
 static void
@@ -289,7 +331,8 @@ meta_display_open (const char *name)
     "_NET_RESTACK_WINDOW",
     "_NET_MOVERESIZE_WINDOW",
     "_NET_DESKTOP_GEOMETRY",
-    "_NET_DESKTOP_VIEWPORT"
+    "_NET_DESKTOP_VIEWPORT",
+    "_NET_WM_TAKE_ACTIVITY"
   };
   Atom atoms[G_N_ELEMENTS(atom_names)];
   
@@ -327,6 +370,7 @@ meta_display_open (const char *name)
   display->server_grab_count = 0;
 
   display->pending_pings = NULL;
+  display->pending_dnds = NULL;
   display->autoraise_timeout_id = 0;
   display->focus_window = NULL;
   display->previously_focused_window = NULL;
@@ -443,6 +487,7 @@ meta_display_open (const char *name)
   display->atom_net_moveresize_window = atoms[88];
   display->atom_net_desktop_geometry = atoms[89];
   display->atom_net_desktop_viewport = atoms[90];
+  display->atom_net_wm_take_activity = atoms[91];
 
   display->prop_hooks = NULL;
   meta_display_init_window_prop_hooks (display);
@@ -1542,24 +1587,31 @@ event_callback (XEvent   *event,
                    * minimize/close button.
                    */
 
-                  /* Raise on clicking the client area always or only
-                   * in click to focus mode? The debate rages.
-                   * Feel free to change TRUE to FALSE or vice versa
-                   */
-                  if (TRUE /* meta_prefs_get_focus_mode () == META_FOCUS_MODE_CLICK */) 
+                  if (window->net_wm_take_activity)
                     {
-                      meta_window_raise (window);
-                      
-                      meta_topic (META_DEBUG_FOCUS,
-                                  "Focusing %s due to unmodified button %d press (display.c)\n",
-                                  window->desc, event->xbutton.button);
-                      meta_window_focus (window, event->xbutton.time);
+                      queue_take_activity (display, window, event->xbutton.time);
                     }
                   else
                     {
-                      meta_topic (META_DEBUG_FOCUS,
-                                  "Not raising window on click due to mouse/sloppy focus mode\n");
-                      meta_window_focus (window, event->xbutton.time);
+                      /* Raise on clicking the client area always or only
+                       * in click to focus mode? The debate rages.
+                       * Feel free to change TRUE to FALSE or vice versa
+                       */
+                      if (TRUE /* meta_prefs_get_focus_mode () == META_FOCUS_MODE_CLICK */)
+                        {
+                          meta_window_raise (window);
+    
+                          meta_topic (META_DEBUG_FOCUS,
+                                      "Focusing %s due to unmodified button %d press (display.c)\n",
+                                      window->desc, event->xbutton.button);
+                          meta_window_focus (window, event->xbutton.time);
+                        }
+                      else
+                        {
+                          meta_topic (META_DEBUG_FOCUS,
+                                      "Not raising window on click due to mouse/sloppy focus mode\n");
+                          meta_window_focus (window, event->xbutton.time);
+                        }
                     }
                 }
               
@@ -2175,6 +2227,22 @@ event_callback (XEvent   *event,
                       filter_out_event = TRUE;
                     }
 		}
+	      else if (event->xclient.message_type ==
+		       display->atom_net_wm_take_activity) 
+		{
+                  meta_verbose ("Received _NET_WM_TAKE_ACTIVITY message\n");
+                  
+		  if ((Atom)event->xclient.data.l[0] == display->atom_net_wm_take_activity)
+                    {
+                      process_dnd_message (display, event);
+
+                      /* We don't want dnd reply events going into
+                       * the GTK+ event loop because gtk+ will treat
+                       * them as dnd requests and send more replies.
+                       */
+                      filter_out_event = TRUE;
+                    }
+		}
             }
 
           if (event->xclient.message_type ==
@@ -2868,6 +2936,7 @@ meta_display_unregister_x_window (MetaDi
 
   /* Remove any pending pings */
   remove_pending_pings_for_window (display, xwindow);
+  remove_pending_dnds_for_window (display, xwindow);
 }
 
 Cursor
@@ -3767,6 +3836,41 @@ meta_display_ping_window (MetaDisplay   
 }
 
 static void
+queue_take_activity (MetaDisplay       *display,
+                     MetaWindow        *window,
+                     Time               timestamp)
+{
+  MetaDndData *dnd_data;
+
+  if (timestamp == CurrentTime)
+    {
+      meta_warning ("Tried to do a dnd with CurrentTime! Not allowed.\n");
+      return;
+    }
+
+  if (!window->net_wm_take_activity)
+    {
+      meta_warning ("Window %s doesn't support _NET_WM_TAKE_ACTIVITY!\n",
+                    window->desc);
+      return;
+    }
+  
+  dnd_data = g_new (MetaDndData, 1);
+  dnd_data->display = display;
+  dnd_data->window = window;
+  dnd_data->xwindow = window->xwindow;
+  dnd_data->timestamp = timestamp;
+  
+  display->pending_dnds = g_slist_prepend (display->pending_dnds, dnd_data);
+
+  meta_verbose ("Sending TAKE_ACTIVITY message with timestamp %lu to %s\n",
+                timestamp, window->desc);
+  meta_window_send_icccm_message (window,
+                                  display->atom_net_wm_take_activity,
+                                  timestamp);
+}
+
+static void
 process_request_frame_extents (MetaDisplay    *display,
                                XEvent         *event)
 {
@@ -3893,6 +3997,42 @@ meta_display_window_has_pending_pings (M
     }
 
   return FALSE;
+}
+
+/* process the replay to our dnd query message */
+static void
+process_dnd_message (MetaDisplay    *display,
+                     XEvent         *event)
+{
+  GSList *tmp;
+
+  meta_verbose ("Received a dnd pong with timestamp %lu\n",
+                (Time) event->xclient.data.l[1]);
+  
+  for (tmp = display->pending_dnds; tmp; tmp = tmp->next)
+    {
+      MetaDndData *dnd_data = tmp->data;
+			  
+      if ((Time)event->xclient.data.l[1] == dnd_data->timestamp)
+        {
+          meta_verbose ("Matching dnd request found for dnd response %lu\n",
+                        dnd_data->timestamp);
+
+          /* Remove the ping data from the list */
+          display->pending_dnds = g_slist_remove (display->pending_dnds,
+                                                  dnd_data);
+
+          /* Handle the response */
+          meta_verbose ("Raising %s due to dnd query response %lu\n",
+                        dnd_data->window->desc, event->xclient.data.l[1]);
+          meta_window_focus (dnd_data->window, dnd_data->timestamp);
+          meta_window_raise (dnd_data->window);
+			      
+          g_free (dnd_data);
+
+          break;
+        }
+    }
 }
 
 #define IN_TAB_CHAIN(w,t) (((t) == META_TAB_LIST_NORMAL && META_WINDOW_IN_NORMAL_TAB_CHAIN (w)) || ((t) == META_TAB_LIST_DOCKS && META_WINDOW_IN_DOCK_TAB_CHAIN (w)))
Index: src/display.h
===================================================================
RCS file: /cvs/gnome/metacity/src/display.h,v
retrieving revision 1.123
diff -p -u -r1.123 display.h
--- src/display.h	15 Sep 2004 15:38:09 -0000	1.123
+++ src/display.h	28 Sep 2004 17:12:27 -0000
@@ -182,6 +182,7 @@ struct _MetaDisplay
   Atom atom_net_moveresize_window;
   Atom atom_net_desktop_geometry;
   Atom atom_net_desktop_viewport;
+  Atom atom_net_wm_take_activity;
 
   /* This is the actual window from focus events,
    * not the one we last set
@@ -230,6 +231,9 @@ struct _MetaDisplay
 
   /* Pings which we're waiting for a reply from */
   GSList     *pending_pings;
+
+  /* Potential Drag-And-Drop operations we're waiting for a reply from */
+  GSList     *pending_dnds;
 
   /* Pending autoraise */
   guint       autoraise_timeout_id;
Index: src/window-props.c
===================================================================
RCS file: /cvs/gnome/metacity/src/window-props.c,v
retrieving revision 1.17
diff -p -u -r1.17 window-props.c
--- src/window-props.c	24 Jun 2004 15:47:05 -0000	1.17
+++ src/window-props.c	28 Sep 2004 17:12:27 -0000
@@ -746,6 +746,7 @@ reload_wm_protocols (MetaWindow    *wind
   window->take_focus = FALSE;
   window->delete_window = FALSE;
   window->net_wm_ping = FALSE;
+  window->net_wm_take_activity = FALSE;
   
   if (value->type == META_PROP_VALUE_INVALID)    
     return;
@@ -762,6 +763,9 @@ reload_wm_protocols (MetaWindow    *wind
       else if (value->v.atom_list.atoms[i] ==
                window->display->atom_net_wm_ping)
         window->net_wm_ping = TRUE;
+      else if (value->v.atom_list.atoms[i] ==
+               window->display->atom_net_wm_take_activity)
+        window->net_wm_take_activity = TRUE;
       ++i;
     }
   
Index: src/window.h
===================================================================
RCS file: /cvs/gnome/metacity/src/window.h,v
retrieving revision 1.107
diff -p -u -r1.107 window.h
--- src/window.h	19 Aug 2004 02:05:24 -0000	1.107
+++ src/window.h	28 Sep 2004 17:12:27 -0000
@@ -152,6 +152,7 @@ struct _MetaWindow
   guint take_focus : 1;
   guint delete_window : 1;
   guint net_wm_ping : 1;
+  guint net_wm_take_activity : 1;
   /* Globally active / No input */
   guint input : 1;
   
