Re: [gdm-list] opening context menu when clicking on an action label



Le mercredi 25 janvier 2006 à 15:09 -0800, Brian Cameron a écrit :
> Sebastien:
> 
> > I'm trying to open the menu created by make_menubar() (the one opened
> > when pressing F10) when clicking on one of theme action labels on the
> > graphical greeter. I've defined a new kind of action to greeter_system.c
> > and greeter_parser.c and modified the theme to use that new action, that
> > works fine. 
> > 
> > Now I would like to make associated ActionFunc open the menubar. Does
> > anybody has some hint on how to do that?
> 
> This sounds like a way cool feature.  I'd love to get this change into
> GDM CVS.  What did you name the new button?  "options_button" seems a
> good choice to me, although I'd accept any name that is reasonable.  

We started with "Advanced" but "Options" has the preference of the few
people who replied on IRC so we changed it.

> I think it is much nicer to have a single button with the menu choices
> instead of the 3 buttons.  You've probably registered the action in
> greeter_item_system_setup in greeter_system just like for the other
> buttons.

Right, I did it that way first and then moved it to
greeter_canvas_item.c so it can use some canvas paramaters for its
action


> There's no way to programatically pop-up a menu without calling
> gtk_widget_event or gtk_main_do_event to cause a "F10" key to be
> synthesized which is a hacky way to implement this.  You could
> make it work this way.  It's ugly, but no uglier than how the code
> is already written.

In fact I've hacked that with a call to gtk_menu_popup() to open the
menu and function to replace it on the top of the label


> It would probably be cleaner to get rid of the menu completely and
> replace it with a pop-up window that has a single column of buttons.

Right, doing it that way would be less hack, but a row of buttons would
not look really neither. Maybe using a list with an icons column (I've
made a patch to add some icons to the current menu too, it looks nicer,
I'll attach it to bugzilla) and a labels one and acting on selecting?


> your new "options_button" should be straightforward.  I think this
> would be a cleaner way to code the same solution, and would get
> rid of the current hacky code.  Currently the System, Session,
> and Language buttons pop-up windows like this, so you could
> probably use similar code to pop-up the new window.

I've a patch working with the "hack" method at the moment, I'm attaching
it to the mail. It may need some adjustements for the placement method
though. Should I open a bug about that? Bugzilla is probably the right
place to comment on the code changes for it. I made the patch reusing
the same menu to not divert too much from upstream but making a new
dialog for those actions would be nicer. What do you think about the
list idea for it?


> Regardless of which approach you take, it is probably necessary
> to add a new choice to the popup that says something like
> "Return to login" and makes the popup go away without doing
> anything. 

Usually pressing "esc" is an obvious way to close a dialog (that's how
GTK context menus do by example), an extra item is not required for
that.


Cheers,

Sebastien Bacher
=== modified file 'gui/greeter/greeter_canvas_item.c'
--- gui/greeter/greeter_canvas_item.c	
+++ gui/greeter/greeter_canvas_item.c	
@@ -200,6 +200,31 @@
 	c->blue = (rgb & 0xff) * 0x101;
 	c->pixel = 0;
 }
+
+static void
+menu_position_func (GtkMenu           *menu,
+                    int               *x,
+                    int               *y,
+                    gboolean          *push_in,
+                    GreeterItemInfo *item)
+{
+	 GtkAllocation rect;
+	 GtkRequisition  requisition;
+
+	 rect = item->allocation; 
+	 gtk_widget_size_request (GTK_WIDGET (menu), &requisition);
+	*x=rect.x;
+	*y=rect.y-requisition.height-4;
+	*push_in=TRUE;
+ }
+
+ static void
+ greeter_options_handler (GreeterItemInfo *item, GtkWidget *menubar)
+ {
+	 gtk_menu_popup(GTK_MENU(gtk_menu_item_get_submenu(gtk_container_get_children(GTK_CONTAINER(menubar))->data)), NULL, NULL, 
+			(GtkMenuPositionFunc)menu_position_func, 
+			item, 0, gtk_get_current_event_time());
+ }
 
 void
 greeter_item_create_canvas_item (GreeterItemInfo *item)
@@ -396,6 +421,9 @@
 				   "width", (double)rect.width,
 				   NULL);
 
+	    greeter_item_register_action_callback ("options_button",
+						   (ActionFunc)greeter_options_handler,
+						   menubar);
 	    /* Here add a tooltip, so that the user knows about F10 */
 	    tooltips = gtk_tooltips_new ();
 	    gtk_tooltips_set_tip (tooltips, GTK_WIDGET (entry),

=== modified file 'gui/greeter/greeter_parser.c'
--- gui/greeter/greeter_parser.c	
+++ gui/greeter/greeter_parser.c	
@@ -1094,6 +1094,11 @@
         {
 	  g_free (*translated_text);
 	  *translated_text = g_strdup (_("_Configure"));
+	}
+      else if (g_ascii_strcasecmp ((char *) prop, "options") == 0)
+        {
+	  g_free (*translated_text);
+	  *translated_text = g_strdup (_("_Options"));
 	}
       else if (g_ascii_strcasecmp ((char *) prop, "caps-lock-warning") == 0)
         {



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