[RFC] Provide abstraction to popup a menu on a widget on secondary button, menu key and F10+Shift
So I've bumped into this when looking a bit around GNOME/Incubator/papers#11 This issue comes from the fact that in GTK3 there was this GtkWidget.popup
virtual function that was used to trigger context menus on widgets. When we did the port of Papers from GTK3 to GTK4, that thing had been replaced, and we just hooked up a GtkGestureClick with secondary button when appropriate. However, then the Menu key did not work. When trying to look around how to implement it, I bumped into the fact that gdk_event_triggers_context_menu
which we used to filter events, does not actually consider the Menu key. So then I kept digging I found out that most uses of that key in gtk have the structure:
- Add a shortcut controller with F10+Shift and Menu key, and assign an action to it
- Add a gesture click controller with secondary button, and connect a callback to
pressed
- The callback and the action basically call the same function with
x, y
or-1, -1
. There are different variations of this, but all very similar, and with quite some duplicated code around.
I guess I could just copy that same structure to Papers and call it a day GtkWidget.popup
was removed for a reason, and I'm not experienced with API design. But maybe if the maintainers think this is a good idea, we can try to re-introduce something that helps? If we were to do so, something that I feel we're also doing wrong downstream is this thing of parenting the popup, and properly pointing it to where it should, so maybe incorporating that would help.