Skip to main content

Documentation 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.

LWXGL (Lightweight X11 Graphics Library) is a C shared library that wraps Xlib to provide a minimal, straightforward API for building windowed GUI applications on Linux. Rather than exposing the full complexity of the X11 protocol, LWXGL distills it into a small set of functions for creating windows, placing UI elements by integer ID, drawing primitives onto image canvases, and wiring up keyboard and mouse callbacks — all without any runtime dependencies beyond libX11.

Design philosophy

LWXGL is built around three ideas that keep it small and predictable:
  • Palette-indexed 16-color rendering. Every color in LWXGL is an index into a 16-entry palette. The default palette ships with classic CGA-style colors, but every entry can be queried and replaced at runtime with GPaletteModify. This keeps color management explicit and the internal pixel format as a single byte per pixel.
  • Integer element IDs. Every on-screen element — text labels, buttons, input fields, consoles, image canvases — is created with a caller-chosen integer ID. That same ID is used to update, move, hide, or delete the element later. There is no heap-allocated handle to track; the library manages the storage.
  • Callback-based events. Input handling follows a registration model: you call GEventAttachKey, GEventAttachClick, or GEventAttachDelete once to register a function pointer, and LWXGL invokes it on the appropriate X11 event. Button elements take their onclick callback directly at creation time.

Installation

Build libLWXGL.so from source and install it system-wide.

Quickstart

Create your first window with a button and a frame loop in minutes.

Core Concepts

Understand the window lifecycle, rendering model, and element system.

API Reference

Browse the full public API for windows, elements, events, and drawing.

Key features

  • Window creation and double-buffered rendering via Xlib — frames are drawn to an off-screen Pixmap (back buffer) and blitted to the window each tick, eliminating flicker.
  • 16-color indexed palette with runtime modification — query any palette entry with GPaletteQuery, replace it with GPaletteModify, or restore all defaults with GPaletteReset.
  • Built-in UI elements: text labels, push buttons with three visual states (unpressed / hover / pressed), single-line text input fields, checkboxes, solid rectangles, scrollable consoles, and writable image canvases.
  • Primitive drawing into image canvases: filled/outlined rectangles (GPrimitiveRect), circles (GPrimitiveCircle), lines (GPrimitiveLine), and RLE-encoded monochrome sprites (GPrimitiveSprite).
  • Keyboard and mouse event callbacks — raw key codes, click coordinates and button number, and a persistent pressed-key array queryable with GQueryKeyboard / GQueryKeyDown.
  • Fixed-frame-rate game loop (GSimpleWindowLoop) — handles events, renders, invokes a per-frame callback, and sleeps the remainder of each frame to hit the requested FPS target.
  • TGA indexed-color image loading — load 8-bit paletted TGA files with GAllocateTGA / GCreateTGAImage, optionally importing the image’s palette into the active 16-color palette.
  • Screen/layer system — assign elements to numbered screens with GScreenApply and switch the active screen with GScreenActive, enabling simple multi-page UIs.
  • Modal dialogs — spawn confirmation or informational modal overlays with GSpawnModal and a confirm callback.
  • Region capture — read back a rectangular area of the current back buffer as a paletted TGA byte array with GCaptureRegion.
LWXGL targets the X11 display server and will not run on a pure Wayland session. On Wayland hosts, launch your application inside an XWayland environment (most desktop distributions provide this automatically when an X11 client is detected).

Language compatibility

LWXGL is implemented in C++ but its public header, libLWXGL.h, wraps every declaration in an extern "C" block. This means you can link against libLWXGL.so from either a C or a C++ translation unit — just #include <libLWXGL.h> and link with -lLWXGL.

Build docs developers (and LLMs) love