HeaderBars & layout

NOTE: This page is a recollection of what I've written previously. I do not guarantee it's accuracy.

Most browsers, as well as just about any GNOME3 or elementary app, have moved to combining their titlebars and toolbars, and Odysseus follows suit. GTK’s widget for this is the GtkHeaderBar.

A GtkWindow can reference a “titlebar” widget, which it manages alongside it’s normal child. And external code (including the rendering routines) can iterate over both of these “internal” children. If this “titlebar” is a GtkHeaderBar the window also syncs over it’s “title” property.

The GtkHeaderBar meanwhile tracks a list of children and optionally generates window buttons, an application menu, and/or title and subtitle. The latter of which Odysseus does not use. For the window buttons it parses a configuration string from an environment variable (for elementary it’s set to “close:maximize”), and handles the events by forwarding the message through the GTK and GDK Windows to the window manager.

The rest of the GtkHeaderBar is largely dedicated to laying out it’s children (akin to the deprecated GtkBox). To do so it first asks it’s children how big they’d like to be and then splitting any remaining space between them. These layout routines for some reason goes through a “CSS Gadget”.

All Container widgets are responsible for laying out their children recursively, with methods they can override to compute height-first or width-first. And a method to specify which it prefers.