GtkPopoverMenu – New widget for complex popovers

So, continuing my work on porting nautilus to gaction and gmenu, we found some problems that gtk+ could manage better.

For instance, creating menus with GMenu is very convenient only if your menu doesn’t have complex widgets like a GtkScale or if you want to really control how everything is displayed or you need to hide/show menu items on the fly.

That was the case of nautilus, which needs GtkScale and hide/show menu items on the fly.

So far I achieved a way to hide/show GMenu items on the fly, but it feels like a hack, so it was not very convenient.

After some discussion, Mathias Clasen created a new way to do complex popovers or menus, which is just a GtkWidget, so you are free for completely put and manage whatever you want in there, but with the advantatges of associating buttons to actions, so the button becomes a radio action, a simple item, or whatever based on the associated action.

Now we have a GtkPopoverMenu widget, which is the widget you have to use for associating directly to a button with gtk_menu_button_set_popover() and then, you have GtkModelButton which acts as a generic button which defines it’s looks based on the action associated and you can use it inside a GtkPopoverMenu. So for example, if you have a stateless action associated to a GtkModelButton, it becomes a single menu item, it the action is stateful and has no target, it becomes a check button, and finally if the action is stateful and has a target, it becomes a radio button.

Finally you can have iconic buttons, that is, buttons that looks like buttons 😉 with <property name=”iconic”>True</property> .

Other widgets can’t have actions associated, like GtkScale, at least for now. But since you can put it in the widget, is not a big deal, and you connect to the change signal of the widget and then in the handler trigger the action you want, and then is like you associated an action to that widget.

So far so good, I ported nautilus to this, and it looks promising!

So, my advice is:

Use GMenu always you can.

If you need buttons, that although they are supported in GMenu, you can’t manage its visuals; special widgets, or add/hide items on the fly; then, use GtkPopoverMenu and GtkModelButtons.

Not sure how this split is good or not, maybe we should find a common way to do things so new people are not confused about that. But for now, it’s a very nice solution.

Thanks Mathias for the work and the effort he put to find a solution for this.


4 thoughts on “GtkPopoverMenu – New widget for complex popovers

  1. A question: that popovermenu is, like popover, painted in the same canvas than the main window, or it has its own window? I ask this because I wanted to use popover in an indicator, but was unable because the popover can’t extend outside the window that contains the parent widget…

    1. correct: on X11, the popovers cannot extend outside the top-level’s area.

      on Wayland, they use sub-surfaces instead, so they behave a lot better.

      the main difference is that on Wayland we get the correct behaviours out of the box, whereas on X11 we would have to do what menus do, and that is a whole can of worms (e.g. input grabs, override-redirect windows that your window manager can’t touch, etc.)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s