I’m refactoring some code that normally requires the user to click a button for a popup menu to appear (it appears beside the button), what I’m trying to do is show the popup menu if the user hovers the mouse over the button icon for a preset duration and hide it again if the user moves onto another button icon.
However, activating the menu via gtk_menu_popup steals mouse and keyboard focus, I have made little progress trying to grab focus for the button widget.
Is it possible to return focus to the button icon?
Debugging this turned out to be quite troublesome, as
gtk_menu_popupgrabs the gdk keyboard and pointer focus, which prevents one from stepping through the code with gdb, I eventually managed it by running the code in a VM and using a remote debugging session with gdb over SSH.There are a few different mechanisms through which the popup may steal focus from the original widget
parent_menu_shell)gdk_pointer_grabgtk_grab_addAs I set the
parent_menu_shellshell parameter to NULL, this meant that I had to undo the last two ‘grabs’, like so:This did the trick but focus gets temporarily stolen by the popup, which causes problems too