GNOME Bugzilla – Bug 725141
Add shortcut to move focus to the GtkHeaderBar
Last modified: 2014-03-10 00:46:15 UTC
As being discussed on desktop-devel-list [1], "There should be an intuitive, consistent, immediate way to jump to the widgets that live in the header bar." I have proposed F10 with the associated behavior being to give focus to the first of the widgets. If this could be done by Gtk+ so that app developers get this behavior "for free," it would be awesome. [1] https://mail.gnome.org/archives/desktop-devel-list/2014-February/msg00176.html
Created attachment 270890 [details] [review] The attached patch that does this by adding a keybinding signal to GtkWindow. It would be nice to use this signal for focusing menubars as well in the future as they currently just connect to the window's key-pressed-event rather than having a proper binding. I'm not very familiar with the internals of GTK so there might be a better way of doing this. I've not implemented it but should pressing F10 while the focus is in the headerbar move the focus back to the widget that was focused before? Commit message: Window: Focus custom titlebar with F10 As discussed on desktop-devel-list [1], "There should be an intuitive, consistent, immediate way to jump to the widgets that live in the header bar." F10 has been suggested for this This patch adds a keybinding signal to GtkWindow to focus the first widget in the title bar if a custom titlebar is being used. Hopefully in the future this binding can also be used to focus menubars as currently they don't use a keybinding signal. [1] https://mail.gnome.org/archives/desktop-devel-list/2014-February/msg00176.html
Created attachment 270900 [details] [review] Window: Focus custom titlebar with F10 I've revised the patch to avoid potential NULL pointer dereferences. As discussed on desktop-devel-list [1], "There should be an intuitive, consistent, immediate way to jump to the widgets that live in the header bar." F10 has been suggested for this This patch adds a keybinding signal to GtkWindow to focus the first widget in the title bar if a custom titlebar is being used. Hopefully in the future this binding can also be used to focus menubars as currently they don't use a keybinding signal. [1] https://mail.gnome.org/archives/desktop-devel-list/2014-February/msg00176.html
Review of attachment 270900 [details] [review]: First of all, thanks for the patch! Second: I'm somewhat against making this a keybinding signal. We already have a configuration mechanism for this (the gtk-menu-bar-accel setting), and adding another (overridable bindings) will only make the mess bigger. Third: gtk_window_real_focus_menubar looks like a almost 1-1 copy of gtk_container_focus - we should reuse that instead of redoing it. Last, this needs to be synchronized with the code in gtkmenubar.c that is currently handling f10. I would suggest to move that code to gtkwindow.c and then extend it to handle headerbars in addition to menubars.
(In reply to comment #3) > Review of attachment 270900 [details] [review]: > > First of all, thanks for the patch! Thanks for the feedback, I'll try and post something new tomorrow. Unfortunately I'm going to be away from a computer from Monday until after GTK 3.12 is due to be released. > Second: I'm somewhat against making this a keybinding signal. We already have a > configuration mechanism for this (the gtk-menu-bar-accel setting), and adding > another (overridable bindings) will only make the mess bigger. > > Third: gtk_window_real_focus_menubar looks like a almost 1-1 copy of > gtk_container_focus - we should reuse that instead of redoing it. Right I'll have a look at that. > Last, this needs to be synchronized with the code in gtkmenubar.c that is > currently handling f10. I would suggest to move that code to gtkwindow.c and > then extend it to handle headerbars in addition to menubars. I'll move the code over from gtkmenubar.c as you suggest. What should happen if there are menubars and a headerbar? It would be nice to cycle the focus from the header bar and then through the menubars on successive F10 presses. I'm not sure it's possible to do that generically though as I think if the headerbar has a menu button the menu/popover opened by pressing the button are not direct descendants of the headerbar in the widget hierarchy. This means it is not possible to do gtk_widget_is_ancestor (gtk_window_get_focus (window), priv->title_box) to check if the headerbar has the focus. It is possible to cycle from a menubar to the headerbar though as the menus install their own binding for F10. I'm not sure if any applications are actually using menubars and a headerbar so it might not be a problem in practice. One thing I've noticed in testing this in gedit is that it doesn't play very well with modal popovers as it allows the keyboard focus to escape from the popover without the popover being closed as it would be if you clicked on the headerbar with the mouse. The problem is arguably worse with accelerators that open dialogs as the keyboard focus seems to be stuck in the main window (presumably due to the popover calling gtk_grab_add?) when the dialog opens. If I press Ctrl-O in a popover I haven't found a way to dismiss the open file dialog without using the mouse.
(In reply to comment #4) > One thing I've noticed in testing this in gedit is that it doesn't play very > well with modal popovers as it allows the keyboard focus to escape from the > popover without the popover being closed as it would be if you clicked on the > headerbar with the mouse. The problem is arguably worse with accelerators that > open dialogs as the keyboard focus seems to be stuck in the main window > (presumably due to the popover calling gtk_grab_add?) when the dialog opens. If > I press Ctrl-O in a popover I haven't found a way to dismiss the open file > dialog without using the mouse. I pushed a couple of minor fixes that will help there, dcba77fcc and 43e885282 most namely
Created attachment 271290 [details] [review] F10 cycling with headerbars
quick tryout patch. I'm not entirely convinced by this. The f10-cycling for menubars is a little different since it doesn't actually move the focus
Created attachment 271301 [details] [review] Window: Focus custom titlebar with F10 I revised my patch before I saw that you'd posted a new one, I thought I might as well post this anyway. It basically does what you suggested - it reuses the menubar code in gtkwindow and extends it to handle the header bar as well. F10 will focus the custom titlebar widget if the window has one and it isn't already focused. If the titlebar widget doesn't exist or is already focused then F10 focuses the menubar if there is one. The previous patch always focused the first widget in the header bar when F10 was pressed, I'm not sure if having a consistent point of reference is useful for accessibility. Now if there's no menubar pressing F10 while the focus is in the header bar does nothing.
(In reply to comment #7) > quick tryout patch. I'm not entirely convinced by this. The f10-cycling for > menubars is a little different since it doesn't actually move the focus I'm really sorry I didn't mean to obsolete your patch, git bz doesn't show the authors when you're editing the message. Does this work when there is more than one header bar? Gedit has two header bars in a GtkPaned for it's custom title bar
(In reply to comment #5) > (In reply to comment #4) > > One thing I've noticed in testing this in gedit is that it doesn't play very > > well with modal popovers as it allows the keyboard focus to escape from the > > popover without the popover being closed as it would be if you clicked on the > > headerbar with the mouse. The problem is arguably worse with accelerators that > > open dialogs as the keyboard focus seems to be stuck in the main window > > (presumably due to the popover calling gtk_grab_add?) when the dialog opens. If > > I press Ctrl-O in a popover I haven't found a way to dismiss the open file > > dialog without using the mouse. > > I pushed a couple of minor fixes that will help there, dcba77fcc and 43e885282 > most namely That's great, everything seems to be fine now.
Created attachment 271302 [details] [review] gtk3-demo: run button should be able to focus. This make F10 work in gtk3-demo
Review of attachment 271302 [details] [review]: sure
Attachment 271301 [details] pushed as beaba95 - Window: Focus custom titlebar with F10 Attachment 271302 [details] pushed as 5aa00e4 - gtk3-demo: run button should be able to focus.