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	13 Aug 2004 04:10:24 -0000
@@ -47,8 +47,12 @@ struct _WnckScreenPrivate
   GList *stacked_windows;
   /* in 0-to-N order */
   GList *workspaces;
-  
+
+  /* previously_active_window is used in tandem with active_window to
+   * determine return status of meta_window_is_most_recently_actived().
+   */
   WnckWindow *active_window;
+  WnckWindow *previously_active_window;
   WnckWorkspace *active_workspace;
 
   Pixmap bg_pixmap;
@@ -551,6 +555,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,9 +1060,15 @@ 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;
         }
+
+      if (window == screen->priv->previously_active_window)
+        {
+          screen->priv->previously_active_window = NULL;
+        }
       
       emit_window_closed (screen, window);
     }
@@ -1363,6 +1391,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	13 Aug 2004 04:10:25 -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	13 Aug 2004 04:10:27 -0000
@@ -2345,7 +2345,14 @@ wnck_task_button_press_event (GtkWidget	
     case WNCK_TASK_WINDOW:
       if (event->button == 1)
         {
-          if (wnck_window_is_active (task->window))
+          /* is_most_recently_activated == is_active for click &
+	   * sloppy focus methods.  We use the former here because
+	   * 'mouse' focus provides a special case.  In that case, no
+	   * window will be active, but if a window was the most
+	   * recently active one (i.e. user moves mouse straight from
+	   * window to tasklist), then we should still minimize it.
+           */
+          if (wnck_window_is_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.45
diff -p -u -r1.45 window.c
--- libwnck/window.c	8 Aug 2004 00:01:44 -0000	1.45
+++ libwnck/window.c	13 Aug 2004 04:10:30 -0000
@@ -1049,6 +1049,38 @@ wnck_window_is_active (WnckWindow *windo
   return window == wnck_screen_get_active_window (window->priv->screen);
 }
 
+/**
+ * wnck_window_is_most_recently_activated:
+ * @window: a #WnckWindow
+ *
+ * Determines whether @window is the most recently activated window.
+ * The most recently activated window is identical to the active
+ * window for click and sloppy focus methods (since a window is always
+ * active in those cases) but differs slightly for mouse focus since
+ * we often have no window active.
+ *
+ * Return value: %TRUE if window was the most recently activated window
+ **/
+gboolean
+wnck_window_is_most_recently_activated (WnckWindow *window)
+{
+  g_return_val_if_fail (WNCK_IS_WINDOW (window), FALSE);
+
+  WnckWindow * current;
+  WnckWindow * previous;
+  WnckWindow * most_recently_activated_window;
+
+  current  = wnck_screen_get_active_window (window->priv->screen);
+  previous = wnck_screen_get_previously_active_window (window->priv->screen);
+
+  if (current)
+    most_recently_activated_window = current;
+  else
+    most_recently_activated_window = previous;
+
+  return (window == most_recently_activated_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	13 Aug 2004 04:10:30 -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_is_most_recently_activated (WnckWindow *window);
 void     wnck_window_activate_transient (WnckWindow *window);
 
 
