LWXGL processes all X11 events insideDocumentation 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.
MainWindowLoop at the start of each frame tick. Pending events are drained from the Xlib event queue and dispatched through a handler table to built-in logic (element interaction, modal handling, scroll) and then to any user-registered callbacks. Your application hooks into this pipeline by registering callbacks before calling MainWindowLoop, or by polling input state inside the on_every per-frame function.
Registering Callbacks
| Function | Callback Signature | Description |
|---|---|---|
EventAttachKey(callback) | void callback(int key) | Called on each key press. Receives the ASCII character code or a special key constant. Not called when a focused element (Input, Console) consumes the keystroke. |
EventAttachClick(callback) | void callback(int x, int y, int btn) | Called on mouse button release when no element claims the click. x and y are the cursor position; btn is the button index (1=left, 2=middle, 3=right). |
EventAttachDelete(callback) | int callback() | Called when the window’s close button is pressed (WM_DELETE_WINDOW). Return 1 to allow the window to close, or 0 to cancel and keep the window open. If no callback is registered the window always closes immediately. |
EnableResizing(callback) | void callback(int x, int y) | Called when the window is resized. Must be called after CreateWindow. Receives the new pixel width and height. |
Special Key Constants
Printable ASCII characters (space through~, codes 32–126) are delivered to the key callback directly. The Enter/Return key is normalized to 10 (line feed). Non-printable keys use the constants defined in libLWXGL.h:
| Constant | Value | Description |
|---|---|---|
KEY_LEFT | 170 | Left arrow key |
KEY_RIGHT | 171 | Right arrow key |
KEY_UP | 172 | Up arrow key |
KEY_DOWN | 173 | Down arrow key |
KEY_FN | 150 | Base value for function keys |
KEY_FN + n, where n is the function key number (1–12). For example, F1 = 151, F5 = 155, F12 = 162.
Querying Mouse State
Rather than relying solely on the click callback, you can poll the current mouse position and button state at any point duringon_every using QueryMouse:
x and y are set to -1 when the cursor is outside the window. btn reflects the button currently held down, matching the X11 button numbering.
Querying Keyboard State
For actions that depend on keys being held rather than just tapped, use the keyboard state functions. LWXGL tracks up to 8 simultaneously held keys:QueryKeyDown accepts the same character codes and special key constants that the key callback receives, making it easy to share logic between the two input models. Xlib auto-repeat is explicitly disabled by LWXGL (XkbSetDetectableAutoRepeat), so held keys appear exactly once in the state array rather than generating repeated press events.
Built-in Element Event Handling
Several element types consume input events before they reach your registered callbacks. This processing happens automatically insideMainWindowLoop:
- Button (type 1): On a left mouse button release over the button’s bounding box, the element’s
onclickfunction is called. The click is consumed and does not reachEventAttachClick. - Checkbox (type 5): On a left mouse button release over the checkbox, the checked state toggles. The click is consumed.
- Input (type 2): When the cursor is inside an Input element, key presses are routed to the element’s character buffer. Printable characters (32–126) are appended up to the configured maximum length; Backspace (
8) removes the last character. Key events are consumed and do not reachEventAttachKey. - Console (type 6): Scroll wheel events (buttons 4 and 5) over a Console element scroll its content by 3 lines. Pressing Space while hovering scrolls to the bottom. These events are consumed before the user callback.