Can gtk menus displayed via gtk_menu_popup release focus?

回眸只為那壹抹淺笑 提交于 2020-01-02 16:22:24

问题


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?


回答1:


Debugging this turned out to be quite troublesome, as gtk_menu_popup grabs 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

  1. Via transient window relationships (only if you pass parent_menu_shell)
  2. Via gdk_pointer_grab
  3. Via gtk_grab_add

As I set the parent_menu_shell shell parameter to NULL, this meant that I had to undo the last two 'grabs', like so:

gdk_pointer_ungrab(GDK_CURRENT_TIME);
gdk_keyboard_ungrab(GDK_CURRENT_TIME);
gtk_grab_remove(menu);

This did the trick but focus gets temporarily stolen by the popup, which causes problems too



来源:https://stackoverflow.com/questions/12731981/can-gtk-menus-displayed-via-gtk-menu-popup-release-focus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!