Index: libwnck/screen.c
===================================================================
RCS file: /cvs/gnome/libwnck/libwnck/screen.c,v
retrieving revision 1.24
diff -p -u -r1.24 screen.c
--- libwnck/screen.c	22 Nov 2003 23:49:12 -0000	1.24
+++ libwnck/screen.c	6 Aug 2004 18:06:50 -0000
@@ -49,6 +49,7 @@ struct _WnckScreenPrivate
   GList *workspaces;
   
   WnckWindow *active_window;
+  WnckWindow *previously_active_window;
   WnckWorkspace *active_workspace;
 
   Pixmap bg_pixmap;
@@ -551,6 +552,24 @@ wnck_screen_get_active_window (WnckScree
 }
 
 /**
+ * wnck_screen_get_previously_active_window:
+ * @screen: a #WnckScreen
+ * 
+ * Gets the previously active window. May return %NULL
+ * sometimes, since not all window managers guarantee
+ * that a window is always active.
+ * 
+ * Return value: previously active window or %NULL
+ **/
+WnckWindow*
+wnck_screen_get_previously_active_window (WnckScreen *screen)
+{
+  g_return_val_if_fail (WNCK_IS_SCREEN (screen), NULL);
+
+  return screen->priv->previously_active_window;
+}
+
+/**
  * wnck_screen_get_windows:
  * @screen: a #WnckScreen
  * 
@@ -1038,6 +1057,7 @@ update_client_list (WnckScreen *screen)
 
       if (window == screen->priv->active_window)
         {
+          screen->priv->previously_active_window = screen->priv->active_window;
           screen->priv->active_window = NULL;
           active_changed = TRUE;
         }
@@ -1363,6 +1383,7 @@ update_active_window (WnckScreen *screen
   if (window == screen->priv->active_window)
     return;
 
+  screen->priv->previously_active_window = screen->priv->active_window;
   screen->priv->active_window = window;
 
   emit_active_window_changed (screen);
Index: libwnck/screen.h
===================================================================
RCS file: /cvs/gnome/libwnck/libwnck/screen.h,v
retrieving revision 1.14
diff -p -u -r1.14 screen.h
--- libwnck/screen.h	22 Nov 2003 23:49:12 -0000	1.14
+++ libwnck/screen.h	6 Aug 2004 18:06:50 -0000
@@ -119,6 +119,7 @@ WnckWorkspace* wnck_screen_get_workspace
                                                      int         workspace);
 WnckWorkspace* wnck_screen_get_active_workspace     (WnckScreen *screen);
 WnckWindow*    wnck_screen_get_active_window        (WnckScreen *screen);
+WnckWindow*    wnck_screen_get_previously_active_window (WnckScreen *screen);
 GList*         wnck_screen_get_windows              (WnckScreen *screen);
 GList*         wnck_screen_get_windows_stacked      (WnckScreen *screen);
 void           wnck_screen_force_update             (WnckScreen *screen);
Index: libwnck/tasklist.c
===================================================================
RCS file: /cvs/gnome/libwnck/libwnck/tasklist.c,v
retrieving revision 1.58
diff -p -u -r1.58 tasklist.c
--- libwnck/tasklist.c	25 Jul 2004 18:04:21 -0000	1.58
+++ libwnck/tasklist.c	6 Aug 2004 18:06:50 -0000
@@ -2345,7 +2345,7 @@ wnck_task_button_press_event (GtkWidget	
     case WNCK_TASK_WINDOW:
       if (event->button == 1)
         {
-          if (wnck_window_is_active (task->window))
+          if (wnck_window_was_most_recently_activated (task->window))
             task->was_active = TRUE;
           else
             task->was_active = FALSE;
Index: libwnck/window.c
===================================================================
RCS file: /cvs/gnome/libwnck/libwnck/window.c,v
retrieving revision 1.44
diff -p -u -r1.44 window.c
--- libwnck/window.c	25 Jul 2004 18:04:21 -0000	1.44
+++ libwnck/window.c	6 Aug 2004 18:06:50 -0000
@@ -1049,6 +1049,28 @@ wnck_window_is_active (WnckWindow *windo
   return window == wnck_screen_get_active_window (window->priv->screen);
 }
 
+/**
+ * wnck_window_was_most_recently_activated:
+ * @window: a #WnckWindow
+ *
+ * Determines whether @window was the most recently activated window.
+ * Note that the most recently activated window could be a window
+ * that no longer exists, so this is not quite the same as Metacity's
+ * "Most Recently Used"  window (nor should it be).
+ *
+ * Return value: %TRUE if window was the most recently activated window
+ **/
+gboolean
+wnck_window_was_most_recently_activated (WnckWindow *window)
+{
+  g_return_val_if_fail (WNCK_IS_WINDOW (window), FALSE);
+
+  WnckWindow * active_window;
+  active_window = wnck_screen_get_active_window (window->priv->screen);
+  return ((active_window == NULL) && (window == wnck_screen_get_previously_active_window (window->priv->screen)))
+          || (window == active_window);
+}
+
 
 static WnckWindow*
 find_last_transient_for (GList *windows,
Index: libwnck/window.h
===================================================================
RCS file: /cvs/gnome/libwnck/libwnck/window.h,v
retrieving revision 1.24
diff -p -u -r1.24 window.h
--- libwnck/window.h	25 Jul 2004 18:04:22 -0000	1.24
+++ libwnck/window.h	6 Aug 2004 18:06:50 -0000
@@ -189,6 +189,7 @@ void     wnck_window_unpin     (WnckWind
 
 void     wnck_window_activate  (WnckWindow *window);
 gboolean wnck_window_is_active (WnckWindow *window);
+gboolean wnck_window_was_most_recently_activated (WnckWindow *window);
 void     wnck_window_activate_transient (WnckWindow *window);
 
 
