shift+tab never fires a
key-pressed-event, but is instead gobbled up internally by GTK3 and used to switch the currently focused widget.
This is especially annoying when dealing with the
GtkNotebook widget, as the de-facto, cross-platform, standard for switching tabs involves, well, the tab button. The “alternative” shortcut GTK3 offers is
ctrl+pagedown but this is by all accounts, objectively inferior. It requires two hands, and switching between tab-forwards and tab-backwards mode requires moving a finger across keys (whereas the normal shortcut only requires lifting one finger).
GTK3 offers the
focus signal which is emitted by the currently focused widget every time
shift+tab is pressed. This is intended to be overridden if the programmer is creating their own widget, but we can use it for our purposes and instead of changing the focused widget, switch the active tab in our notebook. Since the actual tab switching has to happen inside the
focus callback we’ll also need
key-released-event callbacks to record inside a global variable whether the control key is currently pressed or not.
A full, runable, example is available here.