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

xtk_toolwindow.h

A dockable panel: a header with a title and buttons over a scrollable content area, docked in a container or floating.

A tool window is a panel such as a file tree, an outline or a list of messages. It has a header (the title, an optional badge, a "..." options button, a close button and an optional pin button) and a content area below it, where the program puts its own widget. The panel is either docked (a child of a container window, which sizes it) or floating (a window of its own on the screen, without window manager decorations, which the user moves by its header and resizes by its bottom corners). xtk_dockframe.h arranges several tool windows into a docking layout; a program can also use one on its own.

The panel has one frame window for its whole life; docking and floating only change its parent. Its content area is a fixed viewport (xtk_toolwindow_get_viewport_window()) that holds a canvas (xtk_toolwindow_get_content_window()). A program that declares a canvas larger than the viewport (xtk_toolwindow_set_content_size()) gets scrollbars: the tool window scrolls by moving the canvas, so the program's widget lays itself out at its full size and needs no scrolling of its own. A widget that scrolls itself is put in the viewport instead.

Making it. Call xtk_toolwindow_create() with the parent window, the box, an id, a title and the toolwindow block of the XtkConfig. The panel starts docked in that parent and mapped. Make the program's widget with xtk_toolwindow_get_content_window() (or the viewport) as its parent. To dock the panel elsewhere, put its frame window (xtk_toolwindow_get_frame_window()) into a container, for example with xtk_splitpane_set_child(), then call xtk_toolwindow_mark_docked(); to float it, call xtk_toolwindow_float(). When the container resizes the frame, call xtk_toolwindow_resize() with the new size. The program owns the panel and frees it with xtk_toolwindow_destroy(), which destroys its windows and every window inside them.

Events. Pass each XEvent to xtk_toolwindow_handle_event(). It handles the frame (the header), the viewport, the scrollbars and the resize corners, and returns 0 for other windows, the canvas among them.

  • A click on the close button calls the close callback, and a click on the options button calls the options callback; the tool window does nothing else itself (the program shows a menu or hides the panel).
  • A click on the pin button locks the panel in place (no header drag) or unlocks it.
  • Dragging the header by 4 pixels or more makes a docked panel float in place and then moves it with the pointer, calling the drag callback on every motion and once more on the release. A plain click on the header does not drag; on a floating panel it raises the panel and gives it the keyboard focus.
  • The mouse wheel over the viewport or the vertical scrollbar scrolls 24 pixels up or down; over the horizontal scrollbar it scrolls sideways. A scrollbar's thumb can be dragged, and a click on its track jumps there.
  • A widget in the canvas that takes button presses itself gets the wheel events first; it passes them on with xtk_toolwindow_scroll_by().

Theme keys. Section [toolwindow]:

  • font-family (or font): the header font. Default DejaVu Sans.
  • font-size: the header font size in pixels. Default 11.
  • header-background: the header (a gradient is allowed). Default #383838.
  • header-foreground: the title, and the current tab of a stack. Default #EBEBEB.
  • header-border: the line under the header, the panel's side and bottom borders, and the other tabs of a stack. Default #1F1F1F.
  • titlebar-border: the header's top and side edges; when it is too close to header-background to be seen, header-border is used instead. Default #171717.
  • content-background: the content area behind the program's widget (a gradient is allowed). Default #2E2E2E.
  • icon-foreground: the header buttons and the resize corners, and the labels of a stack's other tabs. Default #B3B3B3.
  • icon-hover-foreground: a header button under the pointer. Default #F2F2F2.
  • icon-hover-background: the square behind a header button under the pointer (a gradient is allowed). Default #4D4D4D.
  • scrollbar-track, scrollbar-thumb: the scrollbars (gradients are allowed); the thumb is drawn lighter under the pointer and while dragged. Defaults #141414 and #4D4D4D.
  • badge-background, badge-foreground: the badge pill (see xtk_toolwindow_set_badge()). Defaults #2E4C00 and #81EE00.

Section [toolwindow-widget] (pixels): header-height 28, icon-size 16, icon-padding 8 and border-width 1 (the side and bottom borders; 0 draws none). A tool window starts with these defaults; give it the config's values with xtk_toolwindow_set_geometry() (xtk_dockframe.h does this for its panels, at creation and in xtk_dockframe_set_theme()).

The defaults are those xtk_config_init_defaults() sets; a theme applied with xtk_theme_apply() replaces the colors.

Example.

static void on_close(XtkToolWindow *toolwindow, void *user_data) {
    Display *display = user_data;
    XUnmapWindow(display, xtk_toolwindow_get_frame_window(toolwindow));
}

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);

XtkToolWindow *panel = xtk_toolwindow_create(display, screen, window, 0, 0, 250, 400,
                                             "outline", "Outline", &config.toolwindow);
xtk_toolwindow_set_close_callback(panel, on_close, display);
Window canvas = xtk_toolwindow_get_content_window(panel);
// make the panel's widget with canvas as its parent, 250 by 1200 pixels
xtk_toolwindow_set_content_size(panel, 250, 1200);   // a vertical scrollbar appears

XEvent event;
while (running) {
    XNextEvent(display, &event);
    if (xtk_toolwindow_handle_event(panel, &event)) continue;
    // ... the panel's widget and the program's other windows
}
xtk_toolwindow_destroy(panel);
 * 

Limitations.

  • Floating panels are override-redirect windows: the window manager does not decorate, stack or focus them, and they do not appear in a taskbar. Hiding a docked panel automatically (auto-hide) is not supported.
  • Only the two bottom corners resize a floating panel (to at least 120 by 80 pixels), and no callback reports such a resize.
  • A canvas larger than 30000 pixels in either direction cannot be moved that far; see xtk_toolwindow_get_unrepresented_scroll().
  • The tool window keeps the ToolWindowBlock pointer, so the block must stay valid as long as the tool window does.
#include "xtk_toolwindow.h"

Types: XtkToolWindow, XtkToolWindowViewMode, XtkToolWindowScrollChangedCallback, XtkToolWindowUndockRequestedCallback, XtkToolWindowCloseCallback, XtkToolWindowOptionsRequestedCallback, XtkToolWindowStackTabClickedCallback

Constants: XTK_TOOLWINDOW_ID_MAX, XTK_TOOLWINDOW_TITLE_MAX, XTK_TOOLWINDOW_MAX_STACK_TABS

Functions: xtk_toolwindow_create, xtk_toolwindow_destroy, xtk_toolwindow_get_id, xtk_toolwindow_get_frame_window, xtk_toolwindow_get_content_window, xtk_toolwindow_get_viewport_window, xtk_toolwindow_set_content_size, xtk_toolwindow_scroll_by, xtk_toolwindow_scroll_by_x, xtk_toolwindow_get_scroll_offset, xtk_toolwindow_get_unrepresented_scroll, xtk_toolwindow_scroll_to, xtk_toolwindow_set_scroll_changed_callback, xtk_toolwindow_mark_docked, xtk_toolwindow_float, xtk_toolwindow_claim_focus, xtk_toolwindow_set_always_on_top, xtk_toolwindow_get_always_on_top, xtk_toolwindow_set_drag_enabled, xtk_toolwindow_set_geometry, xtk_toolwindow_get_drag_enabled, xtk_toolwindow_set_header_visible, xtk_toolwindow_set_side_border_top, xtk_toolwindow_get_header_visible, xtk_toolwindow_resize, xtk_toolwindow_get_view_mode, xtk_toolwindow_handle_event, xtk_toolwindow_draw, xtk_toolwindow_set_theme, xtk_toolwindow_set_title, xtk_toolwindow_set_badge, xtk_toolwindow_set_drag_callback, xtk_toolwindow_set_close_callback, xtk_toolwindow_set_options_callback, xtk_toolwindow_get_title, xtk_toolwindow_set_stack_tabs, xtk_toolwindow_set_stack_tab_clicked_callback, xtk_toolwindow_set_pin_visible, xtk_toolwindow_set_pinned, xtk_toolwindow_get_pinned, xtk_toolwindow_config_init_defaults, xtk_toolwindow_config_parse_styling, xtk_toolwindow_config_write_styling, xtk_toolwindow_widget_config_init_defaults, xtk_toolwindow_widget_config_parse, xtk_toolwindow_widget_config_write, xtk_toolwindow_get_hover_icon, xtk_toolwindow_set_hover_icon

Types

XtkToolWindow

typedef struct XtkToolWindow XtkToolWindow;

A tool window; opaque, made by xtk_toolwindow_create().

XtkToolWindowViewMode

Whether a tool window is docked or floating.

A panel as a normal top-level window with window manager decorations, and an auto-hiding docked panel, are not supported.

Name Value Description
XTK_TOOLWINDOW_DOCKED 0 A child of a container window, which places and sizes it.
XTK_TOOLWINDOW_FLOATING A child of the root window (override-redirect), moved and resized by the user.

XtkToolWindowScrollChangedCallback

typedef void (*XtkToolWindowScrollChangedCallback)(XtkToolWindow *toolwindow, int offset_x, int offset_y, void *user_data);

Called whenever the scroll offset changes.

It is called for every cause: the wheel, a scrollbar, the scroll calls, and the clamping after a resize or xtk_toolwindow_set_content_size(). It is meant for a widget in the viewport that draws its content shifted by the offset: that widget does not move, so it gets no Expose when the user scrolls, and redraws from this callback instead.

XtkToolWindowUndockRequestedCallback

typedef void (*XtkToolWindowUndockRequestedCallback)(XtkToolWindow *toolwindow, int root_x, int root_y, int is_drop, void *user_data);

Called while the user drags the panel by its header: on every motion, and once more on the release.

The first call comes when the pointer has moved 4 pixels or more from the press; a plain click calls nothing. By then the tool window has already made itself float in place, so a program that had it docked treats the first call as "the panel has left its dock" (for example it empties that split pane slot). The panel follows the pointer by itself. On the release (is_drop 1) the program decides whether the drop point is a place to dock: if so, it puts the frame window there and calls xtk_toolwindow_mark_docked(); if not, the panel stays floating where it was dropped. xtk_dockframe.h does all this for its panels.

XtkToolWindowCloseCallback

typedef void (*XtkToolWindowCloseCallback)(XtkToolWindow *toolwindow, void *user_data);

Called when the header's close button is clicked.

The tool window does not close itself: the program decides what closing means (hiding the panel, taking it out of a dock frame, destroying it).

XtkToolWindowOptionsRequestedCallback

typedef void (*XtkToolWindowOptionsRequestedCallback)(XtkToolWindow *toolwindow, int root_x, int root_y, void *user_data);

Called when the header's "..." options button is clicked.

The tool window has no options menu of its own: the program shows one (xtk_dockframe.h shows Move to, Float and so on) at the place given.

XtkToolWindowStackTabClickedCallback

typedef void (*XtkToolWindowStackTabClickedCallback)(XtkToolWindow *toolwindow, const char *clicked_id, void *user_data);

Called when a tab in the header's tab row is clicked (this panel's own tab or another one).

Constants

XTK_TOOLWINDOW_ID_MAX

#define XTK_TOOLWINDOW_ID_MAX 64

The size of a tool window's id buffer, terminator included.

XTK_TOOLWINDOW_TITLE_MAX

#define XTK_TOOLWINDOW_TITLE_MAX 128

The size of a tool window's title buffer, terminator included.

XTK_TOOLWINDOW_MAX_STACK_TABS

#define XTK_TOOLWINDOW_MAX_STACK_TABS 6

The most tool windows one stack's tabs hold (see xtk_toolwindow_set_stack_tabs())

Functions

xtk_toolwindow_create

XtkToolWindow *xtk_toolwindow_create(
    Display *display,
    int screen,
    Window initial_parent,
    int x,
    int y,
    int width,
    int height,
    const char *id,
    const char *title,
    const ToolWindowBlock *theme);

Create a tool window, docked in a parent window and mapped.

Parameter Description
display The X display
screen The screen number
initial_parent The window the frame is made in
x The X position in initial_parent, in pixels
y The Y position in initial_parent, in pixels
width The frame's width in pixels, the header included
height The frame's height in pixels, the header included
id A name that stays the same between runs, by which xtk_dockframe.h saves and restores layouts; copied (at most XTK_TOOLWINDOW_ID_MAX - 1 bytes)
title The header's title, copied (at most XTK_TOOLWINDOW_TITLE_MAX - 1 bytes); NULL for none
theme The style, usually &config.toolwindow. The tool window keeps the pointer, so the block must stay valid as long as the tool window does. May be NULL (black, and no header is drawn until xtk_toolwindow_set_theme()).

Returns: The new tool window, or NULL if display or id is NULL, a size is 0 or less, or a window cannot be made

xtk_toolwindow_destroy

void xtk_toolwindow_destroy(XtkToolWindow *toolwindow);

Destroy a tool window: its frame, viewport, canvas, scrollbars and every window the program put inside them.

Destroy the program's widget in it first.

Parameter Description
toolwindow The tool window (NULL does nothing)

xtk_toolwindow_get_id

const char *xtk_toolwindow_get_id(const XtkToolWindow *toolwindow);

Get the id the tool window was made with.

Parameter Description
toolwindow The tool window

Returns: The id, owned by the tool window (do not free it), or "" if toolwindow is NULL

xtk_toolwindow_get_frame_window

Window xtk_toolwindow_get_frame_window(const XtkToolWindow *toolwindow);

Get the frame window: the whole panel, header and content area.

To dock the panel, put this window into a container (for example with xtk_splitpane_set_child()) and call xtk_toolwindow_mark_docked(). The window stays the same for the tool window's whole life.

Parameter Description
toolwindow The tool window

Returns: The frame window, or None if toolwindow is NULL

xtk_toolwindow_get_content_window

Window xtk_toolwindow_get_content_window(const XtkToolWindow *toolwindow);

Get the canvas: the window to make the program's widget in.

The canvas is as large as the size given to xtk_toolwindow_set_content_size() (or as the visible area, until then, or when that size is smaller), and the tool window moves it inside the viewport to scroll. Its background is content-background. The window stays the same for the tool window's whole life.

Parameter Description
toolwindow The tool window

Returns: The canvas window, or None if toolwindow is NULL

xtk_toolwindow_get_viewport_window

Window xtk_toolwindow_get_viewport_window(const XtkToolWindow *toolwindow);

Get the viewport: the visible content area, the parent of the canvas.

Put a widget here instead of in the canvas when it scrolls itself (for example a notebook whose tabs must not scroll away). The viewport is always the size of the visible area and never moves; scrolling does not move what is in it (use the scroll-changed callback to follow the scroll offset). The window stays the same for the tool window's whole life.

Parameter Description
toolwindow The tool window

Returns: The viewport window, or None if toolwindow is NULL

xtk_toolwindow_set_content_size

void xtk_toolwindow_set_content_size(XtkToolWindow *toolwindow, int width, int height);

Set the full size of the canvas, and show the scrollbars it needs.

When the height is more than the visible area, a vertical scrollbar appears at the right edge; when the width is more, a horizontal one appears at the bottom (each makes the visible area 8 pixels smaller, which can make the other needed too). The program lays its widget out at the full size, as if it were all visible; the tool window moves the canvas to scroll. The scroll offset is clamped to the new size. Calling it again with the same size costs nothing.

Parameter Description
toolwindow The tool window (NULL does nothing)
width The full width in pixels; 0 (or not more than the visible width) for no horizontal scrolling
height The full height in pixels; 0 (or not more than the visible height) for no vertical scrolling

xtk_toolwindow_scroll_by

void xtk_toolwindow_scroll_by(XtkToolWindow *toolwindow, int delta_y);

Scroll the canvas vertically by a number of pixels.

A widget in the canvas that takes button presses on its own window gets the mouse wheel's presses itself, so the tool window never sees them; the program passes them on with this call (for example 24 pixels per wheel step). It does nothing while there is no vertical scrollbar. The offset is clamped to the canvas.

Parameter Description
toolwindow The tool window (NULL does nothing)
delta_y The pixels to scroll; positive scrolls down

xtk_toolwindow_scroll_by_x

void xtk_toolwindow_scroll_by_x(XtkToolWindow *toolwindow, int delta_x);

Scroll the canvas horizontally by a number of pixels.

It does nothing while there is no horizontal scrollbar. The offset is clamped to the canvas.

Parameter Description
toolwindow The tool window (NULL does nothing)
delta_x The pixels to scroll; positive scrolls right, negative left

xtk_toolwindow_get_scroll_offset

void xtk_toolwindow_get_scroll_offset(
    const XtkToolWindow *toolwindow,
    int *out_x,
    int *out_y);

Get the scroll offset: how far the canvas is scrolled.

Either pointer may be NULL.

Parameter Description
toolwindow The tool window; if NULL, both values are 0
out_x Receives the horizontal offset in pixels
out_y Receives the vertical offset in pixels

xtk_toolwindow_get_unrepresented_scroll

void xtk_toolwindow_get_unrepresented_scroll(
    const XtkToolWindow *toolwindow,
    int *out_x,
    int *out_y);

Get the part of the scroll offset that moving the canvas cannot show.

X window sizes and positions are 16-bit numbers, so the canvas is never made larger than 30000 pixels. Past that, the canvas stops moving and this call reports how much further the scroll offset goes; a widget with very large content (a tree of many thousand rows) shifts its own drawing by that amount. For content under 30000 pixels both values are always 0. Either pointer may be NULL.

Parameter Description
toolwindow The tool window; if NULL, both values are 0
out_x Receives the horizontal part in pixels
out_y Receives the vertical part in pixels

xtk_toolwindow_scroll_to

void xtk_toolwindow_scroll_to(XtkToolWindow *toolwindow, int x, int y);

Scroll the canvas to an offset, for example to bring a part of the content into view.

Each axis is clamped as xtk_toolwindow_scroll_by() clamps, and an axis without a scrollbar does not move.

Parameter Description
toolwindow The tool window (NULL does nothing)
x The horizontal offset in pixels
y The vertical offset in pixels

xtk_toolwindow_set_scroll_changed_callback

void xtk_toolwindow_set_scroll_changed_callback(
    XtkToolWindow *toolwindow,
    XtkToolWindowScrollChangedCallback callback,
    void *user_data);

Set the function called whenever the scroll offset changes.

Note: The function is called in the middle of scrolling or layout: it may read the tool window and redraw, but it must not destroy the tool window or change its content size.

Parameter Description
toolwindow The tool window (NULL does nothing)
callback The function, or NULL for none
user_data A pointer passed to the function

xtk_toolwindow_mark_docked

void xtk_toolwindow_mark_docked(XtkToolWindow *toolwindow);

Tell the tool window it is docked again.

It turns override-redirect off on the frame, hides the resize corners and sets the view mode to XTK_TOOLWINDOW_DOCKED. It does not move the frame: the program must already have put the frame window into its container (for example with xtk_splitpane_set_child()). Call xtk_toolwindow_resize() with the size the container gave it.

Parameter Description
toolwindow The tool window (NULL does nothing)

xtk_toolwindow_float

void xtk_toolwindow_float(
    XtkToolWindow *toolwindow,
    int screen_x,
    int screen_y,
    int width,
    int height);

Make the tool window float at a place on the screen.

The frame becomes an override-redirect child of the root window at that place and size, is mapped above other windows and shows its resize corners; the view mode becomes XTK_TOOLWINDOW_FLOATING. It does not take the keyboard focus: call xtk_toolwindow_claim_focus() after it when the user did not float the panel by dragging it.

Parameter Description
toolwindow The tool window (NULL does nothing)
screen_x The X position on the screen (root coordinates)
screen_y The Y position on the screen
width The frame's width in pixels; 0 or less does nothing
height The frame's height in pixels; 0 or less does nothing

xtk_toolwindow_claim_focus

void xtk_toolwindow_claim_focus(XtkToolWindow *toolwindow);

Give the tool window's frame the keyboard focus.

Call it after xtk_toolwindow_float() when the panel was floated by a command (a menu item) rather than by a drag. If the frame is not viewable yet, the call waits until it is mapped.

Parameter Description
toolwindow The tool window (NULL does nothing)

xtk_toolwindow_set_always_on_top

void xtk_toolwindow_set_always_on_top(XtkToolWindow *toolwindow, int always_on_top);

Keep a floating panel above other windows, or not.

With it on, whenever the floating panel loses the keyboard focus it raises itself again (and then raises the window that took the focus above itself, so a dialog the user is looking at stays on top). With it off (the default), xtk_dockframe_sync_floating_focus() lowers floating panels when another program takes the focus. A docked panel keeps the setting for when it floats.

Parameter Description
toolwindow The tool window (NULL does nothing)
always_on_top 1 to keep it raised, 0 for normal stacking

xtk_toolwindow_get_always_on_top

int xtk_toolwindow_get_always_on_top(const XtkToolWindow *toolwindow);

Tell whether the panel keeps itself above other windows when it floats.

Parameter Description
toolwindow The tool window

Returns: 1 if it does, 0 if not or toolwindow is NULL

xtk_toolwindow_set_drag_enabled

void xtk_toolwindow_set_drag_enabled(XtkToolWindow *toolwindow, int drag_enabled);

Allow or forbid dragging the panel by its header.

While dragging is allowed, the header shows a grabbing-hand cursor. This does not change the pin button's look. A pinned panel cannot be dragged whatever this says; unpinning it gives back what this allows.

Parameter Description
toolwindow The tool window (NULL does nothing)
drag_enabled 1 to allow dragging (the default); 0 to forbid it. A click on the header of a floating panel still raises it and gives it the focus.

xtk_toolwindow_set_geometry

void xtk_toolwindow_set_geometry(
    XtkToolWindow *toolwindow,
    int header_height,
    int icon_size,
    int icon_padding,
    int border_width);

Set the header's height, the size of its buttons, the room around them and the width of the side and bottom borders, and lay out and redraw.

These are the [toolwindow-widget] keys; a program passes config.toolwindow_widget's values (xtk_dockframe.h does it for its panels). A tool window starts with 28, 16, 8 and 1.

Parameter Description
toolwindow The tool window (NULL does nothing)
header_height The header's title row in pixels (at least 12)
icon_size A header button in pixels (at least 6, at most the header height less 2)
icon_padding The room between and around the buttons in pixels
border_width The side and bottom borders in pixels (0 for none, at most 16)

xtk_toolwindow_get_drag_enabled

int xtk_toolwindow_get_drag_enabled(const XtkToolWindow *toolwindow);

Tell whether the panel can be dragged by its header.

Parameter Description
toolwindow The tool window

Returns: 1 if it can (also if toolwindow is NULL), 0 if not: dragging is forbidden by xtk_toolwindow_set_drag_enabled() or the panel is pinned

xtk_toolwindow_set_header_visible

void xtk_toolwindow_set_header_visible(XtkToolWindow *toolwindow, int visible);

Show the header, or hide it so the content fills the whole frame.

Without a header, the panel cannot be dragged and its title, badge, tabs and buttons (and so the options menu and the close button) are gone: it is for a panel that stays fixed in its place. Use xtk_toolwindow_set_drag_enabled() instead to only stop dragging.

Parameter Description
toolwindow The tool window (NULL does nothing)
visible 1 to show the header (the default), 0 to hide it

xtk_toolwindow_set_side_border_top

void xtk_toolwindow_set_side_border_top(XtkToolWindow *toolwindow, int offset);

Start the left and right borders lower than the bottom of the header.

For a panel whose content has a row of its own at its top (for example a notebook's tabs under a hidden header): the side borders then frame only what is under that row.

Parameter Description
toolwindow The tool window (NULL does nothing)
offset How many pixels under the header the side borders start; 0 (the default) starts them at the header's bottom

xtk_toolwindow_get_header_visible

int xtk_toolwindow_get_header_visible(const XtkToolWindow *toolwindow);

Tell whether the header is shown.

Parameter Description
toolwindow The tool window

Returns: 1 if it is (also if toolwindow is NULL), 0 if it is hidden

xtk_toolwindow_resize

void xtk_toolwindow_resize(XtkToolWindow *toolwindow, int width, int height);

Resize the frame where it is, lay out the header and content again, and redraw.

When a container resizes the frame window itself (a split pane after its divider moved, for example), the tool window does not learn of it: call this afterwards with the frame's new size.

Parameter Description
toolwindow The tool window (NULL does nothing)
width The frame's width in pixels; 0 or less does nothing
height The frame's height in pixels; 0 or less does nothing

xtk_toolwindow_get_view_mode

XtkToolWindowViewMode xtk_toolwindow_get_view_mode(const XtkToolWindow *toolwindow);

Tell whether the tool window is docked or floating.

Parameter Description
toolwindow The tool window

Returns: The view mode, or XTK_TOOLWINDOW_DOCKED if toolwindow is NULL

xtk_toolwindow_handle_event

int xtk_toolwindow_handle_event(XtkToolWindow *toolwindow, XEvent *event);

Give an X event to the tool window.

Callbacks are called from inside this call. During a header drag, newer queued motion events of the frame are taken from the queue and only the latest is used.

Parameter Description
toolwindow The tool window
event The event (it may be replaced by a newer motion event)

Returns: 1 if the event was for the frame, the viewport, a scrollbar or a resize corner; 0 for any other window (the canvas and the program's widgets included) and if an argument is NULL

xtk_toolwindow_draw

void xtk_toolwindow_draw(XtkToolWindow *toolwindow);

Redraw the header now.

Parameter Description
toolwindow The tool window (NULL does nothing)

xtk_toolwindow_set_theme

void xtk_toolwindow_set_theme(XtkToolWindow *toolwindow, const ToolWindowBlock *theme);

Use a new style: open the font again, set the background colors of the content, scrollbars and borders, and redraw.

Call it after a new theme is applied to the configuration; the program re-themes its own widget in the panel separately.

Parameter Description
toolwindow The tool window (NULL does nothing)
theme The style, usually &config.toolwindow (NULL does nothing). The tool window keeps the pointer.

xtk_toolwindow_set_title

void xtk_toolwindow_set_title(XtkToolWindow *toolwindow, const char *title);

Change the header's title, and redraw.

A title too long for the header is cut short with an ellipsis before the buttons.

Parameter Description
toolwindow The tool window (NULL does nothing)
title The title, copied (at most XTK_TOOLWINDOW_TITLE_MAX - 1 bytes); NULL for none

xtk_toolwindow_set_badge

void xtk_toolwindow_set_badge(XtkToolWindow *toolwindow, const char *text);

Show a short note in a pill in the header, just before the buttons, and redraw.

It is for brief feedback such as "copied"; the program removes it again, for example a second later. The pill uses the badge-background and badge-foreground colors.

Parameter Description
toolwindow The tool window (NULL does nothing)
text The note, copied (at most 31 bytes), or NULL or "" for none

xtk_toolwindow_set_drag_callback

void xtk_toolwindow_set_drag_callback(
    XtkToolWindow *toolwindow,
    XtkToolWindowUndockRequestedCallback callback,
    void *user_data);

Set the function called while the panel is dragged by its header.

Note: On the release (is_drop 1) the call is the last thing the tool window does, so the function may move it into another parent or destroy it. During the motion it must not destroy it.

Parameter Description
toolwindow The tool window (NULL does nothing)
callback The function, or NULL for none
user_data A pointer passed to the function

xtk_toolwindow_set_close_callback

void xtk_toolwindow_set_close_callback(
    XtkToolWindow *toolwindow,
    XtkToolWindowCloseCallback callback,
    void *user_data);

Set the function called when the close button is clicked.

Parameter Description
toolwindow The tool window (NULL does nothing)
callback The function, or NULL for none
user_data A pointer passed to the function

xtk_toolwindow_set_options_callback

void xtk_toolwindow_set_options_callback(
    XtkToolWindow *toolwindow,
    XtkToolWindowOptionsRequestedCallback callback,
    void *user_data);

Set the function called when the options button is clicked.

Parameter Description
toolwindow The tool window (NULL does nothing)
callback The function, or NULL for none
user_data A pointer passed to the function

xtk_toolwindow_get_title

const char *xtk_toolwindow_get_title(const XtkToolWindow *toolwindow);

Get the tool window's title.

Parameter Description
toolwindow The tool window

Returns: The title last given to xtk_toolwindow_create() or xtk_toolwindow_set_title(), owned by the tool window; "" if toolwindow is NULL

xtk_toolwindow_set_stack_tabs

void xtk_toolwindow_set_stack_tabs(
    XtkToolWindow *toolwindow,
    const char **ids,
    const char **labels,
    int count,
    int active_index);

Show a row of tabs under the header's title row, or remove it.

The row is 22 pixels high; the header grows by that much and the content moves down. The title, the buttons and the header drag stay in the title row above it.

Parameter Description
toolwindow The tool window (NULL does nothing)
ids The id of each panel in the stack, this one included; copied (at most 63 bytes each)
labels The label of each tab, in the same order; copied (at most 63 bytes each)
count The number of tabs, at most XTK_TOOLWINDOW_MAX_STACK_TABS (more are ignored); 0 or 1 removes the row
active_index Which tab is this panel's own, drawn as the current one (an index out of range counts as 0)

xtk_toolwindow_set_stack_tab_clicked_callback

void xtk_toolwindow_set_stack_tab_clicked_callback(
    XtkToolWindow *toolwindow,
    XtkToolWindowStackTabClickedCallback callback,
    void *user_data);

Set the function called when a tab of the header's tab row is clicked.

Parameter Description
toolwindow The tool window (NULL does nothing)
callback The function, or NULL for none
user_data A pointer passed to the function

xtk_toolwindow_set_pin_visible

void xtk_toolwindow_set_pin_visible(XtkToolWindow *toolwindow, int visible);

Show or hide the pin button in the header, left of the options button, and redraw.

Parameter Description
toolwindow The tool window (NULL does nothing)
visible Not 0 to show it; 0 to hide it (the default)

xtk_toolwindow_set_pinned

void xtk_toolwindow_set_pinned(XtkToolWindow *toolwindow, int pinned);

Pin the panel in its place, or unpin it, and redraw.

Parameter Description
toolwindow The tool window (NULL does nothing)
pinned Not 0 to pin: the pin button shows a pushed-in pin and dragging is forbidden. 0 to unpin (the default): a loose pin, and dragging is allowed again if xtk_toolwindow_set_drag_enabled() allows it.

xtk_toolwindow_get_pinned

int xtk_toolwindow_get_pinned(const XtkToolWindow *toolwindow);

Tell whether the panel is pinned.

Parameter Description
toolwindow The tool window

Returns: Not 0 if it is pinned, 0 if not or toolwindow is NULL

xtk_toolwindow_config_init_defaults

void xtk_toolwindow_config_init_defaults(ToolWindowBlock *toolwindow_config);

Set a ToolWindowBlock to the [toolwindow] defaults (listed above).

xtk_config_init_defaults() already calls it for config.toolwindow.

Parameter Description
toolwindow_config The block to set (NULL does nothing)

xtk_toolwindow_config_parse_styling

int xtk_toolwindow_config_parse_styling(
    ToolWindowBlock *toolwindow_config,
    const char *key,
    const char *value);

Set one [toolwindow] key of a ToolWindowBlock from its text value.

It knows the font keys and the colors except titlebar-border, badge-background and badge-foreground, which the config reader sets as it sets every color key.

Parameter Description
toolwindow_config The block to change
key The key, for example "header-background"
value The value as written in the file

Returns: 1 if it knows the key, 0 if not or an argument is NULL

xtk_toolwindow_config_write_styling

int xtk_toolwindow_config_write_styling(
    FILE *file,
    const ToolWindowBlock *toolwindow_config);

Write a ToolWindowBlock as a [toolwindow] section.

It writes the keys xtk_toolwindow_config_parse_styling() knows.

Parameter Description
file The file to write to
toolwindow_config The block to write

Returns: 1 on success, 0 if an argument is NULL

xtk_toolwindow_widget_config_init_defaults

void xtk_toolwindow_widget_config_init_defaults(XtkConfig *config);

Set the [toolwindow-widget] defaults (listed above) in a configuration.

xtk_config_init_defaults() already calls it.

Parameter Description
config The configuration to change (NULL does nothing)

xtk_toolwindow_widget_config_parse

int xtk_toolwindow_widget_config_parse(
    XtkConfig *config,
    const char *key,
    const char *value);

Set one [toolwindow-widget] key of a configuration from its text value.

Parameter Description
config The configuration to change
key The key: "border-width", "header-height", "icon-padding" or "icon-size"
value The value as written in the file (a whole number)

Returns: 1 if the key is a [toolwindow-widget] key, 0 if not or an argument is NULL

xtk_toolwindow_widget_config_write

int xtk_toolwindow_widget_config_write(FILE *file, const XtkConfig *config);

Write a configuration's [toolwindow-widget] section, with every key.

Parameter Description
file The file to write to
config The configuration to write

Returns: 1 on success, 0 if an argument is NULL

xtk_toolwindow_get_hover_icon

int xtk_toolwindow_get_hover_icon(const XtkToolWindow *toolwindow);

Get the header button drawn as under the pointer.

The numbers are those xtk_toolwindow_set_hover_icon() takes.

Parameter Description
toolwindow The tool window

Returns: 1 for the close button, 2 for the options button, 3 for the pin button, 0 for none (also if toolwindow is NULL)

xtk_toolwindow_set_hover_icon

void xtk_toolwindow_set_hover_icon(XtkToolWindow *toolwindow, int which);

Draw a header button as under the pointer, without a pointer (for example for a screenshot), and redraw.

The next pointer motion over the header replaces it.

Parameter Description
toolwindow The tool window (NULL does nothing)
which 1 for the close button, 2 for the options button, 3 for the pin button (when it is shown), any other value for none