? menuclamp.patch
? menuclamp2.patch
? menuclamp3.patch
Index: window-menu.c
===================================================================
RCS file: /cvs/gnome/gnome-panel/applets/wncklet/window-menu.c,v
retrieving revision 1.9
diff -u -r1.9 window-menu.c
--- window-menu.c	13 Oct 2003 19:32:20 -0000	1.9
+++ window-menu.c	21 Oct 2003 15:25:42 -0000
@@ -335,25 +335,59 @@
 	wnck_window_activate (window);
 }
 
+#define WINDOW_MENU_MAX_WIDTH 56	/* maximum width in characters */
+
+static gint
+get_max_width (GtkWidget *widget)
+{
+	PangoContext *context;
+	PangoFontMetrics *metrics;
+	gint char_width;
+
+	gtk_widget_ensure_style (widget);
+	context = gtk_widget_get_pango_context (widget);
+	metrics = pango_context_get_metrics (context,
+					     widget->style->font_desc,
+					     pango_context_get_language (context));
+	char_width = pango_font_metrics_get_approximate_char_width (metrics);
+	pango_font_metrics_unref (metrics);
+
+	return PANGO_PIXELS (WINDOW_MENU_MAX_WIDTH * char_width);
+}
+
+static gint
+get_natural_width (const char *text)
+{
+	GtkRequisition requisition;
+	GtkWidget *label = gtk_label_new (text);
+
+	gtk_widget_size_request (label, &requisition);
+	g_object_unref (G_OBJECT (label));
+	
+	return requisition.width;
+}
+
 static GtkWidget*
 window_menu_item_new (WindowMenu  *window_menu,
 		      const gchar *label)
 {
 	GtkWidget *item;
 	GtkWidget *ellipsizing_label;
-	int screen_width;
+	int natural_width, max_width;
 
 	item = gtk_image_menu_item_new ();
-
-	screen_width = gdk_screen_get_width (
-				gtk_widget_get_screen (window_menu->applet));
-	gtk_widget_set_size_request (item, screen_width / 6, -1);
-
+	
 	ellipsizing_label = eel_ellipsizing_label_new (label);
 	gtk_misc_set_alignment (GTK_MISC (ellipsizing_label), 0.0, 0.5);
 
 	gtk_container_add (GTK_CONTAINER (item), ellipsizing_label);
+
 	gtk_widget_show (ellipsizing_label);
+
+	natural_width = get_natural_width (label);
+	max_width = get_max_width (window_menu->applet);
+
+	gtk_widget_set_size_request (item, MIN (natural_width, max_width), -1);
 
 	return item;
 }
