Gtk.MenuShell.prototype.set_take_focus
function set_take_focus(take_focus:Boolean):void { // Gjs wrapper for gtk_menu_shell_set_take_focus() }
If take_focus is true (the default) the menu shell will take the keyboard focus so that it will receive all keyboard events which is needed to enable keyboard navigation in menus.
Setting take_focus to false is useful only for special applications like virtual keyboard implementations which should not take keyboard focus.
The take_focus state of a menu or menu bar is automatically propagated to submenus whenever a submenu is popped up, so you don't have to worry about recursively setting it for your entire menu hierarchy. Only when programmatically picking a submenu and popping it up manually, the take_focus property of the submenu needs to be set explicitely.
Note that setting it to false has side-effects:
If the focus is in some other app, it keeps the focus and keynav in the menu doesn't work. Consequently, keynav on the menu will only work if the focus is on some toplevel owned by the onscreen keyboard.
To avoid confusing the user, menus with take_focus set to false should not display mnemonics or accelerators, since it cannot be guaranteed that they will work.
See also Gdk.keyboard_grab
Since 2.8
- take_focus
true if the menu shell should take the keyboard focus on popup