Index: libwnck/selector.c
===================================================================
RCS file: /cvs/gnome/libwnck/libwnck/selector.c,v
retrieving revision 1.5
diff -u -r1.5 selector.c
--- libwnck/selector.c	20 Feb 2005 23:30:35 -0000	1.5
+++ libwnck/selector.c	1 Jun 2005 19:32:52 -0000
@@ -26,6 +26,7 @@
 
 #include <gtk/gtk.h>
 #include <glib/gi18n.h>
+#include <glib.h>
 
 #include "selector.h"
 #include "inlinepixbufs.h"
@@ -51,8 +52,8 @@
   WnckWindow *icon_window;
   GHashTable *window_hash;
 
+  gulong handler;
   int size;
-  WnckScreen *screen;
 };
 
 static void wnck_selector_init              (WnckSelector      *selector);
@@ -82,12 +83,8 @@
 wnck_selector_get_screen (WnckSelector *selector)
 {
   GdkScreen *screen;
-  WnckSelectorPrivate *priv;
-
-  priv = WNCK_SELECTOR_GET_PRIVATE (selector);
-  if (!gtk_widget_has_screen (GTK_WIDGET (selector)))
-    return priv->screen;
 
+  g_assert (gtk_widget_has_screen (GTK_WIDGET (selector)));
   screen = gtk_widget_get_screen (GTK_WIDGET (selector));
 
   return wnck_screen_get (gdk_screen_get_number (screen));
@@ -638,25 +635,31 @@
     }
 }
 
-static void
-wnck_selector_setup_menu (WnckSelector *selector)
+static gboolean
+wnck_selector_on_first_realize (GtkWidget *widget,
+                                gpointer data)
 {
+  WnckSelector *selector = data;
+  WnckSelectorPrivate *priv = WNCK_SELECTOR_GET_PRIVATE (selector);
   WnckScreen *screen;
-  GList *windows, *l;
 
-  screen = wnck_selector_get_screen (selector);
-  windows = wnck_screen_get_windows (screen);
-
-  for (l = windows; l; l = l->next)
-    if (wnck_window_is_active (l->data))
-      break;
+  g_signal_handler_disconnect (selector, priv->handler);
 
-  wnck_selector_set_active_window (selector, l ? l->data : NULL);
+  screen = wnck_selector_get_screen (selector);
+  wnck_selector_connect_to_screen (selector, screen);
+  wnck_selector_active_window_changed (screen, selector);
+  return TRUE;
+}
 
-  for (l = windows; l; l = l->next)
-    wnck_selector_connect_to_window (selector, l->data);
+static void
+wnck_selector_on_unrealize (GtkWidget *widget,
+                            gpointer data)
+{
+  WnckSelector *selector = data;
+  WnckSelectorPrivate *priv = WNCK_SELECTOR_GET_PRIVATE (selector);
 
-  wnck_selector_connect_to_screen (selector, screen);
+  priv->handler = g_signal_connect (G_OBJECT (selector), "realize",
+                                    G_CALLBACK (wnck_selector_on_first_realize), selector);
 }
 
 static void
@@ -684,6 +687,10 @@
                     G_CALLBACK (wnck_selector_destroy_menu), selector);
   g_signal_connect (priv->menu, "show",
                     G_CALLBACK (wnck_selector_on_show), selector);
+  priv->handler = g_signal_connect (G_OBJECT (selector), "realize",
+                    G_CALLBACK (wnck_selector_on_first_realize), selector);
+	g_signal_connect (G_OBJECT (selector), "unrealize",
+                    G_CALLBACK (wnck_selector_on_unrealize), selector);
 
   gtk_widget_set_name (GTK_WIDGET (selector),
                        "gnome-panel-window-menu-menu-bar-style");
@@ -694,7 +701,6 @@
                        "}\n"
                        "widget \"*gnome-panel-window-menu-menu-bar*\" style : highest \"gnome-panel-window-menu-menu-bar-style\"");
 
-  wnck_selector_setup_menu (selector);
   gtk_widget_show (GTK_WIDGET (selector));
 }
 
@@ -762,13 +768,10 @@
 }
 
 GtkWidget *
-wnck_selector_new (WnckScreen *screen)
+wnck_selector_new (void)
 {
   WnckSelector *selector;
-  WnckSelectorPrivate *priv;
   selector = g_object_new (WNCK_TYPE_SELECTOR, NULL);
-  priv = WNCK_SELECTOR_GET_PRIVATE (selector);
-  priv->screen = screen;
   wnck_selector_fill (selector);
   return GTK_WIDGET (selector);
 }
Index: libwnck/selector.h
===================================================================
RCS file: /cvs/gnome/libwnck/libwnck/selector.h,v
retrieving revision 1.1
diff -u -r1.1 selector.h
--- libwnck/selector.h	25 Jan 2005 14:49:02 -0000	1.1
+++ libwnck/selector.h	1 Jun 2005 19:32:52 -0000
@@ -47,7 +47,7 @@
   GtkMenuBarClass parent_class;
 };
 
-GtkWidget *wnck_selector_new      (WnckScreen *screen);
+GtkWidget *wnck_selector_new      (void);
 GType      wnck_selector_get_type (void);
 
 G_END_DECLS
