[patch] redo tray icon, take two



Dan,

Here is Aaron Bockover's tray icon redo, this time highlighting the menu
item like before, as you wanted.

Quoted from my previous email:

                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.

May I commit?

Thanks,

	Robert Love

Index: gnome/applet/applet.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/gnome/applet/applet.c,v
retrieving revision 1.25
diff -u -u -r1.25 applet.c
--- gnome/applet/applet.c	13 Jul 2005 16:58:12 -0000	1.25
+++ gnome/applet/applet.c	14 Jul 2005 21:10:17 -0000
@@ -2076,28 +2076,78 @@
 }
 
 /*
- * nmwa_toplevel_menu_button_press_cb
+ * nmwa_menu_position_func
  *
- * Handle right-clicks for the context popup menu
+ * Position main dropdown menu, adapted from netapplet
  *
  */
-static gboolean nmwa_toplevel_menu_button_press_cb (GtkWidget *widget, GdkEventButton *event, gpointer user_data)
+static void nmwa_menu_position_func (GtkMenu *menu G_GNUC_UNUSED, int *x, int *y, gboolean *push_in, gpointer user_data)
 {
-	NMWirelessApplet	*applet = (NMWirelessApplet *)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;
 
-	g_return_val_if_fail (applet != NULL, FALSE);
+	*push_in = TRUE;
+}
 
-	if (event->button != 1)
-		g_signal_stop_emission_by_name (widget, "button_press_event");
+/*
+ * nmwa_toplevel_menu_button_press_cb
+ *
+ * Handle left/right-clicks for the dropdown and context popup menus
+ *
+ */
+static gboolean nmwa_toplevel_menu_button_press_cb (GtkWidget *widget, GdkEventButton *event, NMWirelessApplet *applet)
+{
+	g_return_val_if_fail (applet != NULL, FALSE);
 
-	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_widget_set_state (applet->event_box, GTK_STATE_SELECTED);
+			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;
+}
+
+
+/*
+ * nmwa_toplevel_menu_button_press_cb
+ *
+ * Handle left-unclick on the dropdown menu.
+ *
+ */
+static void nmwa_dropdown_menu_deactivate_cb (GtkWidget *menu, NMWirelessApplet *applet)
+{
+
+	g_return_if_fail (applet != NULL);
+
+	gtk_widget_set_state (applet->event_box, GTK_STATE_NORMAL);
 }
 
 
@@ -2110,19 +2160,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);
 
@@ -2131,16 +2175,15 @@
 
 	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->event_box), applet->pixmap);
 	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->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);
+	g_signal_connect (applet->dropdown_menu, "deactivate", G_CALLBACK (nmwa_dropdown_menu_deactivate_cb), applet);
+
 	applet->context_menu = nmwa_context_menu_create (applet);
 	applet->encryption_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
 }
@@ -2559,4 +2602,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]