LWXGL dispatches X11 events internally viaDocumentation 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(). Attach C function callbacks to receive keyboard, mouse, and window events before entering the loop, and query live input state mid-frame using the query functions.
Event Processing
GHandleWindowEvents calls XPending in a loop and processes every queued Xlib event — motion, key presses and releases, button presses and releases, WM messages, and resize notifications. It must be called once per frame in the manual loop. GSimpleWindowLoop calls it automatically.
Event handlers fire synchronously during this call.
Keyboard Events
key argument is:
- The ASCII value of the character for printable keys (e.g.,
'a'= 97,' '= 32). - A special constant for non-printable keys:
| Constant | Value | Key |
|---|---|---|
LWXGL_KEY_LEFT | 170 | Left arrow |
LWXGL_KEY_RIGHT | 171 | Right arrow |
LWXGL_KEY_UP | 172 | Up arrow |
LWXGL_KEY_DOWN | 173 | Down arrow |
LWXGL_KEY_FN+1 | 151 | F1 |
LWXGL_KEY_FN+2 | 152 | F2 |
| … | … | … |
LWXGL_KEY_FN+12 | 162 | F12 |
LWXGL_KEY_FN is defined as 150, so F-key N has value LWXGL_KEY_FN + N.
The key callback is not fired when Ctrl+Escape is pressed (that triggers
GDeleteWindow directly), nor when F12 is pressed (that toggles the debug overlay when using GSimpleWindowLoop). Input element keystrokes and modal dialogs also intercept key events before the callback fires.Mouse Events
- No modal dialog is currently open (
GQueryModalOpen()returns 0). - The release did not land on a button, checkbox, or scrollable console element — those widgets consume the event first.
| Parameter | Description |
|---|---|
x, y | Window-relative position of the cursor at the time of release. |
btn | X11 button number: 1 = left, 2 = middle, 3 = right, 4 = scroll up, 5 = scroll down. |
Querying Mouse State
MotionNotify and ButtonPress events seen by GHandleWindowEvents.
*x,*y— cursor position in window coordinates. Both are-1when the cursor is outside the window.*btn— the currently held button number (1/2/3), or0if no button is pressed.
Querying Keyboard State
GQueryKeyboard returns a pointer to an internal 8-element unsigned char array of currently held key values. Each slot holds the translated character value of a key that is currently pressed (same values as the Key callback). Empty slots are 0.
GQueryKeyDown scans the same array and returns 1 if ch is currently held, 0 otherwise. This is the convenient one-liner for polling a specific key.
Both functions reflect the state maintained by EKeyPress and EKeyRelease events — the array is updated inside GHandleWindowEvents.
Window Close Event
GDeleteWindow(), or Ctrl+Escape.
- Return
1to allow the close (sets the close flag,GWindowShouldClose()will return1). - Return
0to block the close (the window stays open).
Resize Events
After callingGEnableResizing, the resize callback registered there fires with the new w and h every time the window dimensions change:
ConfigureNotify events are queued, only the last one is processed. The internal back-buffer pixmap is automatically recreated at the new size before the callback fires.