patch update 1.1, was: Re: draw applet without theme



Hi all,

on a hint from Predatory Kangaroo (nice name btw.) I've mananged to make
the left-click menu with my patch behave a little more like it does in
the original version.

In other words:
The patch now looks at the position of the applet. If it's in the upper
half of the screen, it will position the menu below the applet. If it's
in the lower half, it will try to position the menu above the applet. In
both cases will it try to align the menu's left edge with the applet's.

Of course this may all not work because there may not be enough space
for the menu in the determined position. In this case the menu will be
moved to fit on screen automatically by GTK as required ... that can
probably be regarded as standard behaviour and as desirable.

The other thing is that positioning relies on getting the menu height
with gtk_widget_size_requisition. This seems to work decently for me
here (though it causes segfaults for P.K.). However, I also remember
having encountered problems elsewhere because gtk_widget_size_request
returns the widget's DESIRED dimensions. Now, the dimensions actually
allocated may be quite different. Don't think this is problematic
because it will worst case make the positioning above the applet a
little inaccurate. I'm just elaborating in case somebody has an idea for
determining the menu's size accurately and deterministically before
actually showing it.

If you also experience segfaults with this version, go back to the
previous one and leave positioning to GTK. On my ubuntu breezy machine
it works alright.

Karl.


--- gnome/applet/applet.c	2005-10-18 16:51:22.000000000 +0200
+++ gnome/applet/applet.c.khb	2006-01-05 21:06:21.000000000 +0100
@@ -1948,7 +1948,34 @@
  * Pop up the wireless networks menu
  *
  */
-static void nmwa_dropdown_menu_show_cb (GtkWidget *menu, NMWirelessApplet *applet)
+void position_popup_menu (GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer user_data)
+{
+	GtkWidget *applet;
+	
+	applet = GTK_WIDGET(user_data);
+	g_assert (applet);
+	g_assert (x);
+	g_assert (y);
+
+	*x = *y = 0;
+	gdk_window_get_origin (GDK_WINDOW (applet->window), x, y);
+
+	if ( *y + applet->allocation.height / 2 > 
+			gdk_screen_get_height( gtk_widget_get_screen( GTK_WIDGET( menu ))) / 2 ) {
+		
+		GtkRequisition size;
+
+		// the following will not necessarily give the correct size of the menu as it has
+		// not been rendered yet, but it's prolly the best we can get
+		gtk_widget_size_request( GTK_WIDGET( menu ), &size );
+		*y -= size.height;
+	} else {
+		*y += applet->allocation.height;
+	}
+	*push_in = TRUE;
+}
+
+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 +1988,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, position_popup_menu, applet,
+                        event->button, event->time);
 	}
 
 	nmi_dbus_signal_user_interface_activated (applet->connection);
@@ -1973,7 +2002,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 +2011,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 +2128,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 +2144,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 +2172,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]