Re: [patch] redo tray icon.



On Thu, 2005-07-07 at 22:45 -0400, Dan Williams wrote:

> Ok, here's the 1 thing I don't like about it.  But I'm not particularly
> attached to this 1 thing.
>
> The old applet has the menu item highlight when you drop it down, at
> least under ClearLooks.  With the patch, nothing happens to the icon
> when you click on the menu.  It doesn't act like a menu in a menu bar.
> I'd prefer it if the patch kept the current behavior of highlighting the
> menu item in the panel when the menu is dropped down.
> 
> The patch correctly removes the all-the-time highlight underneath the
> icon though (again, at least under ClearLooks).  I'm thinking about the
> same behavior the volume applet has here, that works like I expect it
> to.

First, attached patch fixes a small one-line bug (forgot to pack the
progress bar into the new tray icon).

As to your question, I don't know how to do it, I am afraid.  The
easiest way would be to pack the icon in a GtkButton, but then the icon
is padded with a few pixels and it is quite a bit smaller and
correspondingly scaled down from its natural size.  I don't like that.

Another idea would be to draw a different icon--a highlighted
version--but that seems a lot of work.

There might be some highlight code in gtk.  I don't know it.

But I am not particularly attached to this thing, at all.

	Robert Love

Index: gnome/applet/applet.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/gnome/applet/applet.c,v
retrieving revision 1.24
diff -u -u -r1.24 applet.c
--- gnome/applet/applet.c	8 Jul 2005 02:37:10 -0000	1.24
+++ gnome/applet/applet.c	11 Jul 2005 14:42:45 -0000
@@ -2076,28 +2076,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;
 }
 
 
@@ -2110,19 +2147,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 +2162,14 @@
 
 	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);
+
 	applet->context_menu = nmwa_context_menu_create (applet);
 	applet->encryption_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
 }
@@ -2559,4 +2588,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]