[patch] redo tray icon.



So...the NetworkManager tray icon is a bit weird, as it packs a top menu
bar into the tray.  Not sure why that route was chosen, unless someone
wanted to pack a container into an event box, which you cannot do.  The
problem with packing the menu bar into the tray is that many themes draw
gradients or other details under menu bars.  Thus, the icon looks funny.
Also, the packed menu bar takes up a lot of room, leaving a weird couple
pixels of spacing on either side of the icon.

Instead, "applet->pixmap" is packed into "applet->event_box", which is 
packed into "applet->icon_box", which is packed into the top of the
tray.  Looks and acts more natural.

Patch by Aaron Bockover.

May I apply?

	Robert Love

Index: gnome/applet/applet.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/gnome/applet/applet.c,v
retrieving revision 1.22
diff -u -u -r1.22 applet.c
--- gnome/applet/applet.c	7 Jul 2005 18:26:53 -0000	1.22
+++ gnome/applet/applet.c	7 Jul 2005 20:33:08 -0000
@@ -2073,28 +2073,65 @@
 }
 
 /*
+ * nmwa_menu_position_func
+ *
+ * Position main dropdown menu, adapted from netapplet
+ *
+ */
+static void nmwa_menu_position_func (GtkMenu *menu G_GNUC_UNUSED, int *x, int *y, gboolean *push_in, gpointer user_data)
+{
+	int screen_w, screen_h, button_x, button_y, panel_w, panel_h;
+	GtkRequisition requisition;
+	GdkScreen *screen;
+	NMWirelessApplet *applet = (NMWirelessApplet *)user_data;
+
+	screen = gtk_widget_get_screen (applet->icon_box);
+	screen_w = gdk_screen_get_width (screen);
+	screen_h = gdk_screen_get_height (screen);
+
+	gdk_window_get_origin (applet->icon_box->window, &button_x, &button_y);
+	gtk_window_get_size (GTK_WINDOW (gtk_widget_get_toplevel (applet->icon_box)), &panel_w, &panel_h);
+
+	*x = button_x;
+
+	/* Check to see if we would be placing the menu off of the end of the screen. */
+	gtk_widget_size_request (GTK_WIDGET (menu), &requisition);
+	if (button_y + panel_h + requisition.height >= screen_h)
+		*y = button_y - requisition.height;
+	else
+		*y = button_y + panel_h;
+
+	*push_in = TRUE;
+}
+
+/*
  * nmwa_toplevel_menu_button_press_cb
  *
- * Handle right-clicks for the context popup menu
+ * Handle left/right-clicks for the dropdown and context popup menus
  *
  */
 static gboolean nmwa_toplevel_menu_button_press_cb (GtkWidget *widget, GdkEventButton *event, gpointer user_data)
 {
-	NMWirelessApplet	*applet = (NMWirelessApplet *)user_data;
+	NMWirelessApplet *applet = (NMWirelessApplet *) user_data;
 
 	g_return_val_if_fail (applet != NULL, FALSE);
 
-	if (event->button != 1)
-		g_signal_stop_emission_by_name (widget, "button_press_event");
-
-	if (event->button == 3)
+	switch (event->button)
 	{
-		nmwa_context_menu_update (applet);
-		gtk_menu_popup (GTK_MENU (applet->context_menu), NULL, NULL, NULL, applet, event->button, event->time);
-		return (TRUE);
+		case 1:
+			gtk_menu_popup (GTK_MENU (applet->dropdown_menu), NULL, NULL,
+						 nmwa_menu_position_func, applet, event->button, event->time);
+			return TRUE;
+		case 3:
+			nmwa_context_menu_update (applet);
+			gtk_menu_popup (GTK_MENU (applet->context_menu), NULL, NULL, nmwa_menu_position_func, applet, event->button, event->time);
+			return TRUE;
+		default:
+			g_signal_stop_emission_by_name (widget, "button_press_event");
+			return FALSE;
 	}
 
-	return (FALSE);
+	return FALSE;
 }
 
 
@@ -2107,19 +2144,13 @@
  */
 static void nmwa_setup_widgets (NMWirelessApplet *applet)
 {
-	GtkWidget      *menu_bar;
-	GtkWidget		*event_box;
-
 	/* Event box for tooltips */
 	applet->event_box = gtk_event_box_new ();
 	gtk_container_set_border_width (GTK_CONTAINER (applet->event_box), 0);
 
-	menu_bar = gtk_menu_bar_new ();
-
 	applet->top_menu_item = gtk_menu_item_new();
 	gtk_widget_set_name (applet->top_menu_item, "ToplevelMenu");
 	gtk_container_set_border_width (GTK_CONTAINER (applet->top_menu_item), 0);
-	g_signal_connect (applet->top_menu_item, "button_press_event", G_CALLBACK (nmwa_toplevel_menu_button_press_cb), applet);
 
 	applet->dropdown_menu = nmwa_dropdown_menu_create (GTK_MENU_ITEM (applet->top_menu_item), applet);
 
@@ -2128,16 +2159,13 @@
 
 	applet->icon_box = gtk_hbox_new (FALSE, 3);
 	gtk_container_set_border_width (GTK_CONTAINER (applet->icon_box), 0);
-
-	/* Set up the widget structure and show the applet */
-	gtk_container_add (GTK_CONTAINER (applet->icon_box), applet->progress_bar);
-	gtk_container_add (GTK_CONTAINER (applet->icon_box), applet->pixmap);
-	gtk_container_add (GTK_CONTAINER (applet->top_menu_item), applet->icon_box);
-	gtk_menu_shell_append (GTK_MENU_SHELL (menu_bar), applet->top_menu_item);
-	gtk_container_add (GTK_CONTAINER (applet->event_box), menu_bar);
-	gtk_container_add (GTK_CONTAINER (applet), applet->event_box);
+	gtk_container_add (GTK_CONTAINER (applet->event_box), applet->pixmap);
+	gtk_container_add (GTK_CONTAINER (applet->icon_box), applet->event_box);
+	gtk_container_add (GTK_CONTAINER (applet), applet->icon_box);
 	gtk_widget_show_all (GTK_WIDGET (applet));
 
+	g_signal_connect (applet->event_box, "button_press_event", G_CALLBACK (nmwa_toplevel_menu_button_press_cb), applet);
+
 	applet->context_menu = nmwa_context_menu_create (applet);
 	applet->encryption_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
 }
@@ -2551,4 +2579,3 @@
 {
 	return g_object_new (NM_TYPE_WIRELESS_APPLET, "title", "NetworkManager", NULL);
 }
-


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]