Re: draw applet without theme



Am Donnerstag, den 15.12.2005, 18:35 -0500 schrieb Dan Williams:
> On Thu, 2005-12-15 at 18:09 -0500, Robert Love wrote:
> > On Thu, 2005-12-15 at 22:31 +0000, Antony Mee wrote:
> > > I'm using a fairly standard "Simple" theme and I see a very slightly 
> > > darker grey (relative to the notification area) in the background  of 
> > > the nm-applet icon when deactivated. It is very subtle, to the point of 
> > > making me wonder if it's an illusion.  I never found out why when I went 
> > > poking around the code but maybe that is a menu bar artefact too? Anyone 
> > > else see that?
> > 
> > Most of us  ;-)
> > 
> > Many themes draw a small gradient on the button of menu items, to set
> > the menu apart from the surrounding UI.  NM embeds its tray icon in a
> > menu (to get menu-like behavior -- see Dan's earlier email) and thus
> > your theme's gradient is drawn.
> > 
> > As Dan said, we'd like to get rid of the gradient, but want to keep the
> > menu-like behavior.
> 
> Really, just the slightly extended highlight area.  Perhaps sticking an
> alignment in the top-level applet widget, and setting padding on it?  As
> it stands, the applet's actual area is about 20x20.  It should be padded
> to be about 32x22 somehow.  I tried, but GTK+ made me angry.  Likely I
> just need to as Owen or Jonathan or somebody.
> 
> Dan
> 
> 

Hi all,
came up with the approach of using a image in an eventbox instead of the
menuitem. Then I made the left click menu another popup menu.

this means: the left click menu is positioned according to the mouse
pointer (haven't yet found a clever way of finding the absolute position
of an applet in the tray ... otherwise I'd position the menu to mimick a
normal menu) ... also I've not tried to mimick the highlighting or set
the width to 32 pixels (which is of couse easy to do)... I actually like
it when I can conserve space in a panel.

Feedback welcome, the patch is against 5.1

Karl.



--- NetworkManager-0.5.1/gnome/applet/applet.c	2005-10-18 16:51:22.000000000 +0200
+++ NetworkManager-0.5.1/gnome/applet/applet.c.khb	2005-12-16 23:45:45.000000000 +0100
@@ -1948,7 +1948,7 @@
  * Pop up the wireless networks menu
  *
  */
-static void nmwa_dropdown_menu_show_cb (GtkWidget *menu, NMWirelessApplet *applet)
+static void nmwa_dropdown_menu_show_cb (GtkWidget *menu, NMWirelessApplet *applet, GdkEventButton *event)
 {
 	g_return_if_fail (menu != NULL);
 	g_return_if_fail (applet != NULL);
@@ -1961,7 +1961,9 @@
 	{
 		nmwa_dropdown_menu_clear (applet->dropdown_menu);
 		nmwa_dropdown_menu_populate (applet->dropdown_menu, applet);
-		gtk_widget_show_all (applet->dropdown_menu);
+
+		gtk_menu_popup (GTK_MENU (applet->dropdown_menu), NULL, NULL, NULL, NULL,
+                        event->button, event->time);
 	}
 
 	nmi_dbus_signal_user_interface_activated (applet->connection);
@@ -1973,7 +1975,7 @@
  * Create the applet's dropdown menu
  *
  */
-static GtkWidget *nmwa_dropdown_menu_create (GtkMenuItem *parent, NMWirelessApplet *applet)
+static GtkWidget *nmwa_dropdown_menu_create (GtkWidget *parent, NMWirelessApplet *applet)
 {
 	GtkWidget	*menu;
 
@@ -1982,8 +1984,6 @@
 
 	menu = gtk_menu_new ();
 	gtk_container_set_border_width (GTK_CONTAINER (menu), 0);
-	gtk_menu_item_set_submenu (GTK_MENU_ITEM (parent), menu);
-	g_signal_connect (menu, "show", G_CALLBACK (nmwa_dropdown_menu_show_cb), applet);
 
 	return menu;
 }
@@ -2101,7 +2101,7 @@
 	if (applet->top_menu_item)
 	{
 		gtk_menu_item_remove_submenu (GTK_MENU_ITEM (applet->top_menu_item));
-		applet->dropdown_menu = nmwa_dropdown_menu_create (GTK_MENU_ITEM (applet->top_menu_item), applet);
+		applet->dropdown_menu = nmwa_dropdown_menu_create (GTK_WIDGET (applet->top_menu_item), applet);
 	}
 }
 
@@ -2117,9 +2117,14 @@
 
 	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 == 1)
+	{
+		nmwa_dropdown_menu_show_cb(applet->dropdown_menu, applet, event );
+		return (TRUE);
+	}
+
 	if (event->button == 3)
 	{
 		nmwa_context_menu_update (applet);
@@ -2140,31 +2145,19 @@
  */
 static void nmwa_setup_widgets (NMWirelessApplet *applet)
 {
-	GtkWidget      *menu_bar;
-
-	/* Event box for tooltips */
+	/* Event box not just 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);
-
 	applet->pixmap = gtk_image_new ();
+//	gtk_widget_set_size_request(GTK_WIDGET(applet->pixmap), 32, -1); 
 
-	applet->icon_box = gtk_hbox_new (FALSE, 3);
-	gtk_container_set_border_width (GTK_CONTAINER (applet->icon_box), 0);
+	applet->dropdown_menu = nmwa_dropdown_menu_create (GTK_WIDGET (applet->pixmap), applet); 
 
 	/* Set up the widget structure and show the applet */
-	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->event_box), applet->pixmap); 
+	g_signal_connect (applet->event_box, "button_press_event", G_CALLBACK (nmwa_toplevel_menu_button_press_cb), applet); 
+
 	gtk_container_add (GTK_CONTAINER (applet), applet->event_box);
 	gtk_widget_show_all (GTK_WIDGET (applet));
 


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