Next in the #WebKitGTK context menu saga: our hero tries to get back to usin GtkMenu on GTK3, keeping GtkPopoverMenu on GTK4. Unfortunately, there is no reliable way of popping up a GtkMenu which would work on Wayland and at the same time would not require a “reference” GdkEvent, and it's not always reasonably doable to know which one triggered the context menu through all the WebKit layering.
So I'm seriously considering to yak-shave the GTK code to see what does gtk_menu_popup_at_rect() use the event for, and synthesize the simplest possible event which will make it happy.
Or, alternatively, synthesize a pointer event for gtk_menu_popoup_at pointer().
Which option would be less cursed? The source code will tell!
Well, gtk_menu_popup_at_pointer() picks the mouse position from the passed event, makes a GdkRectangle at that position with 1×1 size, and passes it along to gtk_menu_popup_at_rect(); so the later is definitely where the interesting bits should be.
Well, well... Turns out gtk_menu_popup_at_rect() does not use the event for much at all, so maybe passing a GDK_NOTHING event may work, because for an event which does not have an associated GdkDevice, the internal code will pick the default pointer for the seat and use that instead. It seems doable to pick the last pointer event from inside WebKit, and when that is unavailable (in the case of the “menu” key being used, for example), pass a dummy event.
Well, this turned out to be less ugly than I initially thought. Let's build it and see whether it works^W explodes 🤷
@fireglow no problem at all 😄
@aperezdc Uuh, that may get you a g_warning from gdk_event_get_device().
You *can* pass a null event, but the code assumes that gtk_get_current_event() will work. Does it work in the context of webkit?
@federicomena it warns that the event might have been created outside of GDK, indeed. But then I came up with a better version which uses gdk_event_new() and gdk_event_set_device() after filling the keyboard event fields, and that works like a charm. I have an updated patch at https://bugs.webkit.org/show_bug.cgi?id=211557 — it's good to go, modulo unit tests, which need updating.
@federicomena personally I liked more using GtkPopoverMenu, and had the nice property of not needing anything special other than the rectangle the menu points to... but it was too much of a regression, and broke behaviour that people expected.
Server run by the main developers of the project It is not focused on any particular niche interest - everyone is welcome as long as you follow our code of conduct!