可以通过GTK发布gtk_menu_popup重点显示菜单? [英] Can gtk menus displayed via gtk_menu_popup release focus?
问题描述
我重构一些code,通常需要用户点击一个按钮,弹出菜单出现(它出现在按钮旁),我想要做的是显示弹出菜单,如果用户把鼠标停留在为preSET时间按钮图标,如果用户移动到另一个按钮图标再次隐藏它。
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.
然而,通过 gtk_menu_popup
激活菜单抢断鼠标和键盘焦点,我已经没有什么进展试图抓住重点,为按钮组件。
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?
推荐答案
调试这被证明是相当麻烦,为 gtk_menu_popup
抓住GDK键盘和指针的焦点,这从通过code使用gdb步进prevents之一,我最终通过运行在一个虚拟的code和使用用gdb通过SSH远程调试会话管理它。
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
- 经短暂窗口的关系(只有在你通过
parent_menu_shell
) - 通过
gdk_pointer_grab
- 通过
gtk_grab_add
- Via transient window relationships (only if you pass
parent_menu_shell
) - Via
gdk_pointer_grab
- Via
gtk_grab_add
由于我设置了 parent_menu_shell
外壳参数设置为NULL,这意味着我不得不撤消最后两个'抓住',像这样:
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
这篇关于可以通过GTK发布gtk_menu_popup重点显示菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!