1 xtk_statusbar
liquibyte edited this page 2026-11-19 16:23:20 -06:00

xtk_statusbar.h

A thin bar that shows one line of status text.

A status bar is a child window, usually along the bottom of a program's window, that shows one line of text: the path of the open file, a URL, or any other short message. A line of the border color runs along its top edge. The text is drawn at the right side of the bar. A second, optional text (set with xtk_statusbar_set_drop_text()) is drawn in a small colored pill at the far right, for example the name of the place where a dragged item will drop; the main text then moves to the left of the pill.

The bar takes no input: it only draws.

Making it. Call xtk_statusbar_create() with the parent window, a position and size, and the whole XtkConfig (it reads the statusbar block). The bar maps its own window and is drawn at once. The text font is monospace at 11 pixels; xtk_statusbar_set_font() changes it. The program owns the bar and frees it with xtk_statusbar_destroy(), which also destroys its window. When the parent window changes size, call xtk_statusbar_resize() to keep the bar along its edge.

Events. Pass each XEvent to xtk_statusbar_handle_event(). It returns 1 for every event on the bar's own window (and redraws on the last Expose of a series) and 0 for events on other windows. xtk_statusbar_set_text(), xtk_statusbar_set_drop_text(), xtk_statusbar_set_font(), xtk_statusbar_resize() and xtk_statusbar_set_theme() redraw at once.

Theme keys. Section [statusbar], all colors:

  • background: the bar's fill (a gradient is allowed). Default #292929.
  • color: the status text. Default #BFBFBF.
  • border: the line along the top edge. Default #4D4D4D.
  • message-background: the pill behind the drop text (a gradient is allowed). Default #4D2E00.
  • message-foreground: the drop text. Default #FF8A00.

The defaults are those xtk_config_init_defaults() sets; a theme applied with xtk_theme_apply() replaces them. The font is not a theme key; set it with xtk_statusbar_set_font().

Example.

XtkConfig config;
xtk_config_init_defaults(&config);
XtkTheme *theme = xtk_theme_new();
if (theme && xtk_theme_builtin("Dark", theme)) xtk_theme_apply(&config, theme);
xtk_theme_free(theme);

XtkStatusbar *bar = xtk_statusbar_create(display, screen, window,
                                         0, window_height - 22, window_width, 22,
                                         &config);
xtk_statusbar_set_text(bar, "/home/user/notes.txt");

XEvent event;
while (running) {
    XNextEvent(display, &event);
    if (xtk_statusbar_handle_event(bar, &event)) continue;
    // ... the program's other windows
}
xtk_statusbar_destroy(bar);
 * 

Limitations.

  • The status text keeps at most 4095 bytes and the drop text at most 511; longer text is cut off.
  • Text that is wider than the bar starts at the left edge and is clipped at the right (at the pill, when there is one).
  • The alpha of the text colors is ignored; text is drawn opaque.
  • With a NULL config the bar has no colors: its fill is black and no text is drawn until xtk_statusbar_set_theme() is called.
#include "xtk_statusbar.h"

Types: XtkStatusbar

Functions: xtk_statusbar_create, xtk_statusbar_destroy, xtk_statusbar_set_text, xtk_statusbar_set_drop_text, xtk_statusbar_resize, xtk_statusbar_get_window, xtk_statusbar_handle_event, xtk_statusbar_set_theme, xtk_statusbar_set_font

Types

XtkStatusbar

typedef struct XtkStatusbar XtkStatusbar;

A one-line status bar; opaque, made by xtk_statusbar_create().

Functions

xtk_statusbar_create

XtkStatusbar *xtk_statusbar_create(
    Display *display,
    int screen,
    Window parent,
    int x,
    int y,
    int width,
    int height,
    const XtkConfig *config);

Create a status bar and map its window.

Parameter Description
display The X display
screen The screen number
parent The parent window
x, y The position within the parent, in pixels
width The width in pixels (usually the parent's width); values below 1 become 1
height The height in pixels (20 to 24 suits the default font); values below 1 become 1
config The configuration whose statusbar colors it uses; it is copied, so it need not outlive the bar. May be NULL (see the limitations above).

Returns: The new status bar, or NULL if display is NULL, memory runs out or the window cannot be made

xtk_statusbar_destroy

void xtk_statusbar_destroy(XtkStatusbar *statusbar);

Destroy the status bar, its window, font and colors.

Parameter Description
statusbar The status bar (NULL does nothing)

xtk_statusbar_set_text

void xtk_statusbar_set_text(XtkStatusbar *statusbar, const char *text);

Set the status text and redraw the bar at once.

The text is copied (at most 4095 bytes).

Parameter Description
statusbar The status bar (NULL does nothing)
text The text to show; NULL or "" shows an empty bar

xtk_statusbar_set_drop_text

void xtk_statusbar_set_drop_text(XtkStatusbar *statusbar, const char *text);

Set or clear the drop text, shown in a pill at the right edge, and redraw at once.

The pill uses the message-background and message-foreground colors. The text is copied (at most 511 bytes).

Parameter Description
statusbar The status bar (NULL does nothing)
text The text to show, or NULL or "" to remove the pill

xtk_statusbar_resize

void xtk_statusbar_resize(XtkStatusbar *statusbar, int x, int y, int width, int height);

Move and resize the status bar and redraw it.

Parameter Description
statusbar The status bar (NULL does nothing)
x, y The new position within the parent, in pixels
width, height The new size in pixels; values below 1 become 1

xtk_statusbar_get_window

Window xtk_statusbar_get_window(const XtkStatusbar *statusbar);

Get the status bar's X window.

Parameter Description
statusbar The status bar

Returns: The window, or None if statusbar is NULL

xtk_statusbar_handle_event

int xtk_statusbar_handle_event(XtkStatusbar *statusbar, const XEvent *event);

Give an X event to the status bar.

On the last Expose of a series (count 0) the bar redraws itself.

Parameter Description
statusbar The status bar
event The event; must not be NULL

Returns: 1 if the event was for the bar's window (the program need not handle it further), 0 if it was for another window or statusbar is NULL

xtk_statusbar_set_theme

void xtk_statusbar_set_theme(XtkStatusbar *statusbar, const XtkConfig *config);

Take new colors from a configuration and redraw.

Call it after a new theme is applied to the configuration.

Parameter Description
statusbar The status bar (NULL does nothing)
config The configuration whose statusbar colors to use (NULL does nothing)

xtk_statusbar_set_font

void xtk_statusbar_set_font(XtkStatusbar *statusbar, const char *family, int size);

Set the font of the status text and the drop text, and redraw.

If the font cannot be opened, the old font stays.

Parameter Description
statusbar The status bar (NULL does nothing)
family A font family name, or NULL or "" for monospace
size The size in pixels, or 0 (or less) for 11