LWXGL processes X11 events throughDocumentation 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, called each frame. You can attach callbacks that fire on specific input events, or poll real-time keyboard and mouse state at any point in your frame logic. The two approaches are complementary: callbacks are ideal for discrete events (a key was pressed, a click landed), while the polling functions let you sample continuous state — which keys are held, where the cursor is — at any point during your frame update.
Key Constants
LWXGL defines named constants inlibLWXGL.h for non-printable keys that have no ASCII representation. Use these constants wherever an API accepts or returns a key code.
| Constant | Value | Key |
|---|---|---|
GKeyLeft | 170 | Left arrow |
GKeyRight | 171 | Right arrow |
GKeyUp | 172 | Up arrow |
GKeyDown | 173 | Down arrow |
GKeyFnBase | 150 | Base offset for function keys (see below) |
GKeyFnBase + N, where N is the function key number:
| Key | Value |
|---|---|
| F1 | GKeyFnBase + 1 = 151 |
| F2 | GKeyFnBase + 2 = 152 |
| … | … |
| F12 | GKeyFnBase + 12 = 162 |
Event Callbacks
Callbacks are registered once (typically at startup) and are invoked automatically byGHandleWindowEvents as the matching X11 events arrive. Only one callback of each type can be registered at a time.
GEventAttachKey
Key for each KeyPress X11 event, subject to the following conditions:
- No modal dialog is currently open.
- The cursor is not positioned inside an input widget at the time of the keypress. When the cursor is inside an input widget, that widget consumes the keypress instead.
key argument passed to your callback is the ASCII code for printable characters (e.g. 'a', '1', ' ') or one of the GKey* constants for arrow and function keys.
Pointer to the callback function to invoke on keypress. Pass
NULL to detach any previously registered callback. Calling GEventAttachKey again with a new function pointer replaces the previous callback — only one callback is active at a time.Calling
GEventAttachKey a second time silently replaces the previously registered callback. There is no way to stack multiple key callbacks.GEventAttachClick
Click on every mouse button release event, subject to these conditions:
- No modal dialog is currently open.
- The release did not occur inside a button widget. When the release lands on a button, that button’s
onclickhandler fires instead and the global click callback is suppressed for that event.
Pointer to the callback function to invoke on mouse button release. Pass
NULL to detach. Only one click callback is active at a time; calling again replaces the previous one.Horizontal cursor position (in pixels, relative to the window’s top-left corner) at the moment the button was released.
Vertical cursor position (in pixels, relative to the window’s top-left corner) at the moment the button was released.
The mouse button that was released:
1 = left, 2 = middle, 3 = right.GEventAttachDelete
on_exit when the user clicks the window manager’s close button (the WM WM_DELETE_WINDOW client message) or when GDeleteWindow is called programmatically.
Your callback controls whether the close proceeds:
- Return non-zero to allow the window to close.
- Return 0 to block the close (the window stays open).
Pointer to the callback function to invoke when a close is requested. Pass
NULL to detach. Only one delete callback is active at a time.Input Polling
The polling functions query LWXGL’s internal input state synchronously. Call them at any point in your frame logic — they do not depend onGHandleWindowEvents having been called in any particular order within the frame.
GQueryKeyboard
unsigned char array of currently pressed key codes. Each element holds the key code (ASCII value or GKey* constant) of a key that is currently held down. Slots are cleared to 0 when the corresponding key is released. Up to 8 simultaneous keys are tracked; additional keys beyond the eighth are silently ignored.
The returned pointer points directly into LWXGL’s internal state. Do not
free it and do not store it across frames — the contents change as keys are pressed and released.GQueryKeyDown
1 if the key identified by ch is currently held down, 0 otherwise. This is a convenience wrapper around GQueryKeyboard that avoids manually iterating the pressed-keys array. It is especially useful for smooth, continuous movement in a per-frame callback.
The key to test. Use an ASCII character code for printable keys (e.g.
'a', 'w') or a GKey* constant for arrow and function keys.GQueryMouse
int pointers with the current mouse state. All three output values are updated atomically from the same internal snapshot.
Receives the cursor’s current X position in pixels, relative to the window’s top-left corner. Set to
-1 when the cursor is outside the window.Receives the cursor’s current Y position in pixels, relative to the window’s top-left corner. Set to
-1 when the cursor is outside the window.Receives the currently held mouse button:
0 = none, 1 = left, 2 = middle, 3 = right. Only the most recently pressed button is tracked; releasing it resets this to 0.Both
x and y are set to -1 together when the cursor leaves the window (LeaveNotify event). Always check mx >= 0 (or my >= 0) before using the coordinates.Event Priority
When multiple handlers could respond to the same event, LWXGL applies a fixed dispatch priority. Understanding this order prevents surprises when callbacks are suppressed.-
Modal open — all non-modal input is suppressed. If a modal dialog is active, only clicks on the modal’s own buttons are processed. All widget
onclickhandlers, the globalClickcallback, and the globalKeycallback are skipped until the modal is dismissed. -
Button
onclickfires before the globalClickcallback. On a mouse button release, LWXGL checks every button widget first. If the release lands inside a button, that button’sonclickis called and the globalClickcallback is not called for that event. -
Input widgets consume keypresses before the
Keycallback. If the cursor is inside an input widget when a key is pressed, the widget receives the character and the globalKeycallback is not called for that event. -
Ctrl+Escape closes the window unconditionally. This check runs before any user callback, including the delete callback registered with
GEventAttachDelete. The window will close regardless. -
F12 toggles the debug overlay unconditionally. This check runs before the key callback. F12 is never forwarded to your
Keycallback.