The window management API is the entry point for every LWXGL application. These functions handle creating the X11 window, running the frame loop, and tearing everything down cleanly. All other elements and events operate within the context established byDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/DRESsedAlarm184/LWXGL/llms.txt
Use this file to discover all available pages before exploring further.
CreateWindow and driven by MainWindowLoop.
Constants
FLAG_* — Window Flags
Pass these as a bitmask to thef parameter of CreateWindow.
| Constant | Value | Description |
|---|---|---|
FLAG_NONE | 0 | Default — no special behaviour. |
FLAG_BYPASS | 1 << 0 | Skips the back-buffer rendering pipeline; your on_every callback is called directly with XSync, useful for custom rendering. |
FLAG_CANVAS | 1 << 1 | Automatically creates a full-window image element at ID 0, giving you a raw pixel canvas. |
FLAG_RESIZE | 1 << 2 | Allows the window to be resized by the user. Without this flag, WM resize hints lock the window to its creation dimensions. |
CLR_* — Color Palette Indices
LWXGL maintains a 16-color palette (indices0–F) allocated from the X colormap at startup. Use these constants wherever a color parameter is required.
| Constant | Index | Color |
|---|---|---|
CLR_BLACK | 0x0 | Black |
CLR_BLUE | 0x1 | Blue |
CLR_GREEN | 0x2 | Green |
CLR_CYAN | 0x3 | Cyan |
CLR_RED | 0x4 | Red |
CLR_MAGENTA | 0x5 | Magenta |
CLR_ORANGE | 0x6 | Orange |
CLR_LGRAY | 0x7 | Light gray |
CLR_GRAY | 0x8 | Gray |
CLR_LBLUE | 0x9 | Light blue |
CLR_LGREEN | 0xA | Light green |
CLR_LCYAN | 0xB | Light cyan |
CLR_LRED | 0xC | Light red |
CLR_LMAGENTA | 0xD | Light magenta |
CLR_YELLOW | 0xE | Yellow |
CLR_WHITE | 0xF | White |
CLR_NONE (-1) is a special sentinel meaning “no color / skip draw”, accepted by shape and element functions.
XConnectionData Struct
GetXConnection fills this struct with the raw Xlib handles managed by LWXGL. Defined only when XlibSpecificationRelease is available (i.e., when <X11/Xlib.h> has been included before libLWXGL.h).
Functions
CreateWindow
Opens a new X11 window, allocates the 16-color palette, loads the default font, and prepares the back-buffer pixmap. Must be called before any other LWXGL function.Width of the window in pixels.
Height of the window in pixels.
Title string shown in the window’s title bar. Passed directly to
XStoreName.Background clear color used every frame. One of the
CLR_* palette constants. This can be changed later with SetWindowColor.Bitmask of
FLAG_* constants. Pass FLAG_NONE (or 0) for default behaviour.| Code | Meaning |
|---|---|
0 | Success. |
1 | XOpenDisplay failed — no X display available. |
2 | Font 9x15 could not be loaded. |
3 | A window is already open (only one window is supported). |
127 + N | XAllocColor failed for palette index N. Any colors already allocated (indices 0 through N-1) are freed before returning. |
TerminateWindow
Destroys all elements, frees all allocated TGAs, releases the modal state, unloads the font, frees the graphics context and back-buffer pixmap, releases all 16 palette colors from the colormap, destroys the X window, and closes the display connection.MainWindowLoop
Runs the blocking frame loop at the requested frame rate. On each frame, X events are processed, the back-buffer is cleared, elements are rendered, your callback is invoked, and queued tasks are dispatched. The loop exits whenDeleteWindow (or the WM close button) signals a close.
Target frame rate in frames per second. LWXGL uses a sleep/yield strategy to stay close to this rate without busy-waiting.
Callback invoked once per frame.
tick is a monotonically increasing frame counter starting at 0. delta_time is the actual elapsed time since the previous frame, in seconds. May be NULL if you only need element rendering.DeleteWindow
Signals the frame loop to exit. If anEventAttachDelete callback has been registered, it is called first; if it returns 0 the close is cancelled.
SetWindowTitle
Updates the window title bar text at runtime.New title string. Passed to
XStoreName; the caller retains ownership.SetWindowColor
Changes the background clear color used at the start of every frame. The new color takes effect from the next frame.One of the
CLR_* palette constants.ChangeCursor
Sets the mouse cursor shown inside the window using an X cursor font glyph index.Glyph index from the X cursor font (see
<X11/cursorfont.h>). Common values: 68 = standard left-pointer arrow (set automatically by CreateWindow). The special value 255 hides the cursor entirely by creating a 1×1 blank pixmap cursor.SetGlobalBold
Switches the font used for all text rendering between the normal and bold variants. Affects allTextElement instances and immediate-mode text drawn in the current and future frames.
Pass
1 to load 9x15bold; pass 0 to revert to 9x15.1 on success, or 0 if the requested font could not be loaded (the previous font remains active).
GetXConnection
Fills a caller-providedXConnectionData struct with the Xlib handles currently managed by LWXGL. Use this to interoperate with raw Xlib code or third-party libraries that need the display/window/GC directly.
Pointer to a caller-allocated
XConnectionData struct. All fields are overwritten on return.