LWXGL processes 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.
GHandleWindowEvents, which is called automatically on every frame by GSimpleWindowLoop. You register callback functions for the events you care about — keyboard presses, mouse clicks, and window-close requests. Polling APIs let you query the current mouse position and which keys are held at any point during your frame callback, without needing to install a persistent handler.
Keyboard Events
key argument is the ASCII character code for printable keys, or one of the LWXGL_KEY_* constants for special keys.
Special key constants
| Constant | Value | Key |
|---|---|---|
LWXGL_KEY_LEFT | 170 | ← Arrow |
LWXGL_KEY_RIGHT | 171 | → Arrow |
LWXGL_KEY_UP | 172 | ↑ Arrow |
LWXGL_KEY_DOWN | 173 | ↓ Arrow |
LWXGL_KEY_FN | 150 | Base offset for function keys |
LWXGL_KEY_FN: F1 = 151, F2 = 152, … F12 = 162.
Reserved key combinations
Two key combinations are handled by LWXGL before your callback is invoked:- Ctrl+Escape — immediately closes the window (
GDeleteWindow). - F12 — toggles the debug overlay (FPS and frame-time display). The user callback is not called for this key.
GQueryModalOpen() returns 1), the user key callback is not invoked at all — the key press is still tracked in the polling state, but GEventAttachKey callbacks are skipped until the modal is dismissed.
Example — WASD movement callback
Keyboard Polling
For smooth movement and other frame-rate-coupled logic it is often more convenient to query which keys are currently held rather than responding to discrete press events.unsigned char array of currently held key character codes (ASCII or LWXGL_KEY_* values). Slots that are not in use contain 0. Up to eight keys can be tracked simultaneously.
1 if the given character code is currently held, 0 otherwise. This is a convenience wrapper around the same 8-element array.
Example — polling the space bar in the frame callback
Mouse Events
Click callback
| Parameter | Description |
|---|---|
x, y | Cursor position at the time of release, in window pixels. |
btn | X11 button number: 1 = left, 2 = middle, 3 = right. |
The click callback is only reached if the release event was not consumed by a button or checkbox element. The event system checks all button and checkbox elements first; if the cursor is inside any of their bounds, their handler fires and the user click callback is not called.
Mouse polling
| Output | Description |
|---|---|
*x, *y | Current cursor position in window pixels. Set to -1, -1 when the cursor is outside the window. |
*btn | Currently held button number (1/2/3), or 0 when no button is pressed. |
Example
Window Close Event
WM_DELETE_WINDOW protocol message).
- Return
1to allow the close to proceed (GWindowShouldClosewill return true and the main loop will exit). - Return
0to cancel the close — the window stays open.
Example — confirm before closing
Button
onclick callbacks are invoked by the event system during a ButtonRelease X11 event — inside GHandleWindowEvents — and always fire before the user Click callback. If a button consumed the release event the Click callback is not called at all for that event.