Index: libwnck/window.h
===================================================================
RCS file: /cvs/gnome/libwnck/libwnck/window.h,v
retrieving revision 1.21
diff -u -5 -r1.21 window.h
--- libwnck/window.h	6 May 2003 16:05:51 -0000	1.21
+++ libwnck/window.h	15 Jul 2003 16:41:06 -0000
@@ -131,13 +131,14 @@
 WnckScreen* wnck_window_get_screen    (WnckWindow *window);
 
 const char* wnck_window_get_name      (WnckWindow *window);
 const char* wnck_window_get_icon_name (WnckWindow *window);
 
-WnckApplication* wnck_window_get_application  (WnckWindow *window);
-gulong           wnck_window_get_group_leader (WnckWindow *window);
-gulong           wnck_window_get_xid          (WnckWindow *window);
+WnckApplication* wnck_window_get_application   (WnckWindow *window);
+gulong           wnck_window_get_group_leader  (WnckWindow *window);
+gulong           wnck_window_get_xid           (WnckWindow *window);
+gulong           wnck_window_get_transient_for (WnckWindow *window);
 
 const char* wnck_window_get_session_id        (WnckWindow *window);
 const char* wnck_window_get_session_id_utf8   (WnckWindow *window);
 int         wnck_window_get_pid               (WnckWindow *window);
 
Index: libwnck/window.c
===================================================================
RCS file: /cvs/gnome/libwnck/libwnck/window.c,v
retrieving revision 1.37
diff -u -5 -r1.37 window.c
--- libwnck/window.c	11 Jul 2003 19:37:33 -0000	1.37
+++ libwnck/window.c	15 Jul 2003 16:41:09 -0000
@@ -432,10 +432,27 @@
 
   return window->priv->name;
 }
 
 /**
+ * wnck_window_get_transient_for:
+ * @window: a #WnckWindow
+ *
+ * Gets the gulong id of the X-window that window
+ * is set as transient_for.
+ *
+ * Return: window's transient_for property
+ **/
+
+gulong
+wnck_window_get_transient_for (WnckWindow *window)
+{
+	g_return_val_if_fail (WNCK_IS_WINDOW (window), NULL);
+	return window->priv->transient_for;
+}
+
+/**
  * wnck_window_get_icon_name:
  * @window: a #WnckWindow
  *
  * Gets the name of the window, as it should be displayed for an
  * icon. Always returns some value, even if the window hasn't set a
Index: libwnck/tasklist.c
===================================================================
RCS file: /cvs/gnome/libwnck/libwnck/tasklist.c,v
retrieving revision 1.49
diff -u -5 -r1.49 tasklist.c
--- libwnck/tasklist.c	11 Jul 2003 19:37:33 -0000	1.49
+++ libwnck/tasklist.c	15 Jul 2003 16:41:15 -0000
@@ -215,10 +215,12 @@
 					     int            *n_cols_out,
 					     int            *n_rows_out);
 
 static void     wnck_tasklist_active_window_changed    (WnckScreen   *screen,
 							WnckTasklist *tasklist);
+static WnckWindow *wnck_tasklist_managed_window_from_window (WnckTasklist *tasklist,
+							WnckWindow		*window);
 static void     wnck_tasklist_active_workspace_changed (WnckScreen   *screen,
 							WnckTasklist *tasklist);
 static void     wnck_tasklist_window_added             (WnckScreen   *screen,
 							WnckWindow   *win,
 							WnckTasklist *tasklist);
@@ -1429,11 +1431,11 @@
 	  tasklist->priv->windows = g_list_prepend (tasklist->priv->windows, win_task);
 	  g_hash_table_insert (tasklist->priv->win_hash, win, win_task);
 	  
 	  gtk_widget_set_parent (win_task->button, GTK_WIDGET (tasklist));
 	  gtk_widget_show (win_task->button);
-	  
+
 	  app = wnck_window_get_application (win);
 	  app_task = g_hash_table_lookup (tasklist->priv->app_hash, app);
 
 	  if (app_task == NULL)
 	    {
@@ -1553,21 +1555,74 @@
 		wnck_window_set_icon_geometry (task->window,
 					       x, y, width, height);
 	}
 }
 
+/**
+ * wnck_tasklist_managed_window_from_window
+ * @tasklist: the #WnckTasklist 
+ * @window: the actual window whose tasklist-managed window is being sought
+ *
+ * Returns the tasklist-managed window associated with the given window. 
+ * If a window's SKIP_TASKLIST hint is set, it searches up the chain of 
+ * TRANSIENT_FOR windows until it finds one *without* the SKIP_TASKLIST 
+ * property and that window.
+ *
+ * Return value: Tasklist-managed window best associated with true_window, 
+ * or NULL if there is no such window.
+ *
+ */
+static WnckWindow *
+wnck_tasklist_managed_window_from_window (WnckTasklist *tasklist,
+				WnckWindow *window)
+{
+	WnckWindow *managed_window;
+
+	managed_window = window;
+
+	/* window can easily be NULL since the window manager may report NULL as active window.
+	 * this check prevents some annoying assertion errors, but the code works without it.
+	 */
+	if ( window )
+	{
+		WnckWindow *tmp_window;
+		WnckWindowState state;
+		guint sane;
+
+		tmp_window = window;
+
+		/* if we find more transient_for windows than windows on the screen,
+		 * there is a degenerate cycle of transients 
+		 */
+		sane = g_list_length (wnck_screen_get_windows (wnck_window_get_screen (window))) + 1;
+
+		do
+		{
+			managed_window = tmp_window;
+			state = wnck_window_get_state (managed_window);
+			tmp_window = wnck_window_get (wnck_window_get_transient_for(managed_window));
+			--sane;
+		} while ( (state & WNCK_WINDOW_STATE_SKIP_TASKLIST) && tmp_window && sane );
+
+		if (!sane)
+			managed_window = window;
+	}
+
+	return managed_window;
+}
+
 static void
 wnck_tasklist_active_window_changed (WnckScreen   *screen,
 				     WnckTasklist *tasklist)
 {
   WnckWindow *active_window;
   WnckTask *active_task;
   
   active_window = wnck_screen_get_active_window (screen);
+	active_window = wnck_tasklist_managed_window_from_window (tasklist, active_window);
 
-  active_task = g_hash_table_lookup (tasklist->priv->win_hash,
-				     active_window);
+  active_task =  g_hash_table_lookup (tasklist->priv->win_hash, active_window);
 
   wnck_tasklist_change_active_task (tasklist, active_task);
 }
 
 static void
@@ -1793,11 +1848,11 @@
             wnck_workspace_activate (window_ws);
 
 	  wnck_window_activate_transient (task->window);
 	}
     }
-  
+
 
   if (tasklist->priv->activate_timeout_id)
     gtk_timeout_remove (tasklist->priv->activate_timeout_id);
 
   tasklist->priv->activate_timeout_id = 
@@ -2245,15 +2300,12 @@
       break;
 
     case WNCK_TASK_WINDOW:
       if (event->button == 1)
         {
-          if (wnck_window_is_active (task->window))
-            task->was_active = TRUE;
-          else
-            task->was_active = FALSE;
-
+          task->was_active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (task->button));
+           
           return FALSE;
         } 
       else if (event->button == 3)
         {
           if (task->action_menu)
