API Reference
October 10, 2025 ยท View on GitHub
This document describes the public API of the GWindow library, structs and enums.
๐ Core Types
enum eAction
Represents input actions:
eUP = 0โ key/button releasedeDOWN = 1โ key/button pressedeMOVE = 2โ pointer moved
enum eKeycode
Represents keyboard keys (USB HID codes):
eKEY_A = 4โ A keyeKEY_B = 5โ B keyeKEY_C = 6โ C key- ... (See
keyboard.hfor full list.)
enum eGamepadBtn
Represents gamepad buttons:
eBTN_UNKNOWN = 0โ (Unknown button)eBTN_A = 1โ AeBTN_B = 2โ BeBTN_X = 3โ XeBTN_Y = 4โ YeBTN_TL = 5โ Sholder LefteBTN_TR = 6โ Sholder RighteBTN_THUMBL = 7โ Thumb LefteBTN_THUMBR = 8โ Thumb RighteDPAD_UP = 9โ DPad upeDPAD_DOWN = 10โ DPad downeDPAD_LEFT = 11โ DPad lefteDPAD_RIGHT = 12โ DPad righteBTN_SELECT = 13โ (reserved for system use)eBTN_START = 14โ Start buttoneBTN_MODE = 15โ (reserved for system use)
enum eGamepadAxis
Represents gamepad analog thumbsticks and triggers:
eAXIS_UNKNOWN = 0โ (Unknown button)eAXIS_LX = 1โ left thumbstick -1to1 (right is positive)eAXIS_LY = 2โ left thumbstick -1to1 (up is positive)eAXIS_RX = 3โ right thumbstick -1to1 (right is positive)eAXIS_RY = 4โ right thumbstick -1to1 (up is positive)eAXIS_TL = 5โ left trigger 0to1eAXIS_TR = 6โ right trigger 0to1
enum eCursor
Mouse cursor shapes supported by setCursor():
eArrow,eCaret,eResizeAll,eResizeNS,eResizeEW,eResizeNESW,eResizeNWSE,eHand,eWait,eProgress,eNotAllowed
Examples: eArrow (default arrow), eCaret (text selection), eHand (clickable link).
struct EventType
The event object returned by getEvent() and passed through the event loop.
struct EventType {
enum Tag { NONE, MOUSE, KEY, TEXT, MOVE, RESIZE, FOCUS, TOUCH,
CLOSE, GPAD_CONNECT, GPAD_BUTTON, GPAD_AXIS, UNKNOWN } tag;
union {
struct { eAction action; int16_t x; int16_t y; uint8_t btn; } mouse;
struct { eAction action; eKeycode keycode; } key;
struct { const char* str; } text;
struct { int16_t x; int16_t y; } move;
struct { uint16_t width; uint16_t height; } resize;
struct { bool has_focus; } focus;
struct { eAction action; float x; float y; uint8_t id; } touch;
struct { uint8_t pad; bool active; } gp_connect;
struct { uint8_t pad; uint8_t btn; bool down; } gp_button;
struct { uint8_t pad; uint8_t axis; float val; } gp_axis;
struct {} close;
};
operator bool() const;
};
Usage:
tagspecifies which union member is valid.operator bool()is true iftag != NONE.
struct Gamepad
Represents state of one gamepad.
struct Gamepad {
bool active; // True if this gamepad is connected
bool buttons[16]; // gamepad button states (true if pressed)
float axes[8]; // thumbsticks(-1 to 1) and triggers(0 to 1)
};
- Up to 4 gamepads are supported simultaneously.
struct Mouse
Represents mouse state:
struct Mouse {
struct { int16_t x; int16_t y; } pos; // mouse x,y position
bool btn[6]; // mouse button states
};
๐ผ๏ธ Class: GWindow
Lifecycle
GWindow();
virtual ~GWindow();
virtual void close(); // posts a window close event.
If window is closing (after clicking the close button or calling close()):
- isRunning() will return false
- Event loop functions will return false
- Run() function will exit
๐ State Queries
void getPosition(int16_t& x, int16_t& y)โ returns window x,y positionvoid getSize(int16_t& w, int16_t& h)โ returns window dimensionsvoid getSize(int32_t& w, int32_t& h)โ returns window dimensionsbool getKeyState(eKeycode key)โ returns true if keyboard key is pressedbool getBtnState(uint8_t btn)โ returns true if mouse button is pressedvoid getMousePos(int16_t& x, int16_t& y)โ returns mouse x,y positionGamepad& getGamepad(uint8_t pad)โ returns state of given gamepad(0-3)bool isRunning()โ returns false if window is closinguint width()โ returns window widthuint height()โ return window heightbool resized()โ returns true if window was resized since last callfloat getScale()โ returns the current window dpi scale setting (see setScale)float getDisplayScale()โ returns system dpi scale settingbool isFullscreen()โ returns true if window is fullscreen
๐ Clipboard (Copy/Paste)
const char* getClipboardText()โ return the clipboard contents as a stringvoid setClipboardText(const char* str)โ push text onto the clipboard
(Default implementation stores locally; platform-specific backends override.)
๐๏ธ Control Functions
void showKeyboard(bool enabled)โ show/hide Android soft-keyboard.void setTitle(const char* title)โ Set Window titlevoid setPosition(uint x, uint y)โ Set Window positionvoid setSize(uint w, uint h)โ Set Window width and heightvoid setScale(float val)โ Set HiDPI scaling override. (0 for system scaling)void setSizeScaled(uint w, uint h)โ applies display scale factor.const void* getNativeHandle()โ create Vulkan/OpenGL surface. (see: [VkWindow](../extras/for Vulkan/README.md) )void setCursor(eCursor id)โ Set mouse icon (pointer, caret, spinner, etc.)void setFullscreen(bool enable)โ Set fullscreen or windowed modevoid showImage(uint32_t* buf, uint32_t width, uint32_t height)โ show image buffer (for software rendering)
๐ฎ Event Handlers (override in subclass)
void onMouse(eAction action, int16_t x, int16_t y, uint8_t btn)โ mouse eventvoid onKey(eAction action, eKeycode keycode)โ keyboard key press/releasevoid onText(const char* str)โ text input from keyboard (typed characters)void onMove(int16_t x, int16_t y)โ window move to new position/void onResize(uint16_t width, uint16_t height)โ window resizedvoid onFocus(bool hasFocus)โ window gained or lost focus.void onTouch(eAction action, float x, float y, uint8_t id)โ touchscreen eventvoid onGpadConnect(uint8_t pad, bool active)โ gamepad (dis)connectvoid onGpadButton(uint8_t pad, uint8_t btn, bool down)โ gamepad button eventvoid onGpadAxis(uint8_t pad, uint8_t axis, float val)โ thumbstick/trigger eventvoid onClose()โ window close eventvoid onFrame()โ called once per frame, ideal for rendering
๐ Event Loop
GWindow supports three event processing styles.
Start simple, and move to manual if you need finer control.
If wait=true, the function blocks until an event arrives (power saving mode).
If wait=false, the function returns immediately, for continuous animations.
Non-blocking mode is suitable for games. Blocking is better for reactive GUIs.
- Automatic (simple):
void Run(bool wait=true)โ dispatch events continuously
- Batch processing:
bool processEvents(bool wait=false)โ dispatch all queued eventsbool pollEvents()โ short forprocessEvents(false)(non-blocking)bool waitEvents()โ short forprocessEvents(true)(blocking)
- Manual:
EventType getEvent(bool wait=false)โ fetch next event from queuebool processEvent(EventType e)โ dispatch event to its handler
Returned bool value is false if the window is closing. See examples below:
๐ Typical Usage
1. Automatic (Easiest)
Subclass GWindow, add event handlers, create the window, then simply call Run():
class MyWindow : public GWindow {
// EVENT HANDLERS:
void onResize(uint16_t w, uint16_t h) override {
printf("Resized: %dx%d\n", w, h);
}
void onFrame() override {
// Render a frame here
}
};
int main(int argc, char *argv[]) {
MyWindow win; // Create window
win.setTitle("Example"); // Set window title
win.setSize(800, 600); // Set window size
win.Run(true); // Run until window closed (blocking)
}
2. Batch processing (Keeps main loop)
If you prefer not hiding the processing loop, use this approach instead.
Create a main loop where you dispatch all waiting events, and render.
class MyWindow : public GWindow {
void onResize(uint16_t w, uint16_t h) override {
printf("Resized: %dx%d\n", w, h);
}
};
int main(int argc, char *argv[]) {
MyWindow win; // Create window
win.setTitle("Example"); // Set window title
win.setSize(800, 600); // Set window size
while(win.processEvents(false)) { // Loop until window closed (non-blocking)
// Render frame here. (eg. Vulkan / OpenGL / etc.)
}
}
3. Manual (Most Control)
Fetch events one-by-one, using getEvent() and either:
- Use
processEvent(e)to dispatch events to their handlers, or - Handle events directly with a switch statement.
Make sure to drain the event queue each frame before rendering:
int main(int argc, char *argv[]) {
GWindow win; // create window(no handlers)
win.setTitle("Manual Example"); // set window title
win.setSize(800, 600); // set window size
while (win.isRunning()) { // Run until window is closed
EventType e = win.getEvent(); // Fetch event from FIFO queue
while (e) { // While queue is not empty...
//win.processEvent(e); // Dispatch event to handler
switch (e.tag) { // OR: process event directly
case EventType::RESIZE: { // Window resized event
int w = e.resize.width;
int h = e.resize.height;
printf("Resize:(%d,%d)\n", w, h);
}break;
case EventType::MOUSE: { // mouse event
int a = e.mouse.action; // up=0 down=1 move=2
int x = e.mouse.x;
int y = e.mouse.y;
const char* action[]={"up","down","move"};
printf("Mouse:%s (%d,%d)\n", action[a], x, y);
}break;
default:
break;
}
e = win.getEvent(); // Fetch next event
}
// Render one frame here
}
}