A recurring limitation of the i3 window manager is examined: titlebar and tab colours are defined globally by window state rather than per window, which prevents individual tabs from being coloured to reflect the application they contain. The specific case considered is that of xfce4-terminal instances whose backgrounds are perturbed independently by the terminal's "vary the background colour for each tab" feature. Because the varied colour is computed internally and is not exposed through any queryable interface, the value cannot be read directly. A method is described in which the rendered background of each terminal window is recovered by sampling its pixels, and the recovered colour is mirrored into a per-window title format. A small daemon implementing the method is presented, and its limitations are discussed.
Within i3, the colours applied to window decorations are configured through a fixed set of classes — client.focused, client.unfocused, client.focused_inactive, and so forth. Each class is applied uniformly to every window occupying the corresponding state. Consequently, no facility is provided by which a distinct colour may be assigned to an individual window or tab. Where a titlebar or a tabbed-container header is desired to convey information particular to one window, this global model is found to be insufficient.
A complementary behaviour is provided by xfce4-terminal, in which the background colour of each new tab may be varied automatically. The variation is produced by applying a small random perturbation to the configured background colour. The resulting colour is held internally by the terminal widget and is rendered directly; it is not published as an X property, exposed over D-Bus, or otherwise made available to external processes. It is therefore observed that the two subsystems cannot be reconciled by inspection alone: the value that would be required to colour the tab is precisely the value that the terminal declines to report.
Two independent constraints are thus established. First, i3 provides no per-window colour channel for decorations. Second, the colour that is to be matched is not retrievable by query. Any solution must therefore supply a per-window colouring mechanism that i3 does not natively offer, and must obtain the target colour by means other than direct interrogation.
The first constraint is resolved by observing that, although decoration colours are global, the title format is not. The title_format directive accepts Pango markup, and it may be assigned to a single window at runtime through the i3 command interface using a container selector ([con_id=…] title_format …). A background colour applied through a Pango <span> therefore paints the region behind that one window's title text, yielding an effectively per-window colour without modification of the global decoration classes.
The second constraint is resolved by recovering the colour from the only surface on which it is reliably present: the rendered pixels of the terminal itself.
The rendered background of a mapped window is captured, and its dominant colour is taken to be the background. This inference is justified by the observation that, in a typical terminal, background pixels vastly outnumber foreground (text) pixels; the modal colour of the captured image therefore corresponds to the background with high reliability, irrespective of the position of any text.
For each terminal window, the following procedure is performed. The window is captured to an in-memory image. A colour histogram is computed, and the colour of greatest frequency is selected. A foreground colour is then derived from the luminance of the selected background so that the title text remains legible: a dark background is paired with light text and vice versa. Finally, the per-window title format is set to a Pango span carrying the recovered background and the derived foreground.
It should be noted that only mapped (visible) windows may be captured; a window residing on an inactive workspace cannot be sampled. Sampling is therefore deferred for such windows until they are next made visible.
A daemon was implemented in Python with no dependencies beyond the i3 command utility and ImageMagick. Window lifecycle events are received by subscribing to the i3 event stream. Events pertaining to windows of the class Xfce4-terminal are retained, and all others are discarded. Upon the creation of a qualifying window, a short delay is introduced to permit the terminal to complete its initial rendering, after which the window is sampled and its title format is set. Windows that were not yet capturable at creation are sampled instead upon first receiving focus.
The capture and histogram computation are delegated to import and magick respectively, the modal colour being extracted from the histogram output. The resulting assignment is idempotent per window: a colour already applied is not re-applied, so that ordinary title changes incur no additional work. The operation is non-destructive throughout — no terminal is modified, and every assignment may be reversed by restoring the default title format.
Several limitations are acknowledged. The Pango background spans only the extent of the title text, and does not fill the entire width of a titlebar; the effect is therefore most clearly observed in tabbed and stacked layouts, where the coloured region coincides with the tab label. Where a single i3 window contains multiple xfce4-terminal tabs, only one colour can be represented, as i3 resolves the title format at the granularity of the window rather than the terminal tab. Finally, the method is confined to the X11 session model, since the pixel capture on which it depends is not available for windows rendered under Wayland.
It has been shown that a per-window property absent from i3 may be synthesised through the per-window title format, and that a colour withheld by an application may nonetheless be recovered from the pixels it renders. The combination yields a faithful correspondence between each terminal's background and the colour of its tab, achieved without patching the window manager, without modification of the terminal, and without any dependency on values the terminal does not expose.