After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 725141 - Add shortcut to move focus to the GtkHeaderBar
Add shortcut to move focus to the GtkHeaderBar
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: Other
3.10.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2014-02-25 13:11 UTC by Joanmarie Diggs (IRC: joanie)
Modified: 2014-03-10 00:46 UTC
See Also:
GNOME target: 3.12
GNOME version: ---


Attachments
The attached patch that does this by adding a keybinding signal to (5.59 KB, patch)
2014-03-04 11:27 UTC, Phillip Wood
none Details | Review
Window: Focus custom titlebar with F10 (5.79 KB, patch)
2014-03-04 13:13 UTC, Phillip Wood
needs-work Details | Review
F10 cycling with headerbars (5.66 KB, patch)
2014-03-08 03:42 UTC, Matthias Clasen
none Details | Review
Window: Focus custom titlebar with F10 (7.18 KB, patch)
2014-03-08 10:08 UTC, Phillip Wood
committed Details | Review
gtk3-demo: run button should be able to focus. (931 bytes, patch)
2014-03-08 10:17 UTC, Phillip Wood
committed Details | Review

Description Joanmarie Diggs (IRC: joanie) 2014-02-25 13:11:31 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
Comment 1 Phillip Wood 2014-03-04 11:27:27 UTC
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
Comment 2 Phillip Wood 2014-03-04 13:13:59 UTC
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
Comment 3 Matthias Clasen 2014-03-05 23:59:34 UTC
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.
Comment 4 Phillip Wood 2014-03-06 11:27:47 UTC
(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.
Comment 5 Carlos Garnacho 2014-03-06 23:47:38 UTC
(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
Comment 6 Matthias Clasen 2014-03-08 03:42:29 UTC
Created attachment 271290 [details] [review]
F10 cycling with headerbars
Comment 7 Matthias Clasen 2014-03-08 03:45:04 UTC
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
Comment 8 Phillip Wood 2014-03-08 10:08:34 UTC
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.
Comment 9 Phillip Wood 2014-03-08 10:14:28 UTC
(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
Comment 10 Phillip Wood 2014-03-08 10:15:12 UTC
(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.
Comment 11 Phillip Wood 2014-03-08 10:17:17 UTC
Created attachment 271302 [details] [review]
gtk3-demo: run button should be able to focus.

This make F10 work in gtk3-demo
Comment 12 Matthias Clasen 2014-03-10 00:13:05 UTC
Review of attachment 271302 [details] [review]:

sure
Comment 13 Matthias Clasen 2014-03-10 00:46:07 UTC
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.