Skip to content
modkitv0.2

window.h

#include <modkit/window.h>38 functions · 2 structs · 1 enums · 7 typedefs · 1 macros

Multi-window support for modkit.

Allows creating additional windows beyond the main application window. Each window can have its own callbacks and render to its own framebuffer. Views can be associated with specific windows via mk_view_set_window(). Example:

Functions

mk_get_main_windowfunction

mk_window_t mk_get_main_window(void)

Get the main application window.

This is the window created by mk_app_run() and uses the main backbuffer.

Returns Main window handle (always valid after mk_app_run starts)

mk_view_get_windowfunction

mk_window_t mk_view_get_window(mk_view_id_t view)

Get the window associated with a view.

Returns NULL if view renders to main backbuffer.

ParameterTypeDescription
viewmk_view_id_tValue for view.

Returns The resulting handle or value.

mk_view_set_windowfunction

void mk_view_set_window(mk_view_id_t view, mk_window_t window)

Associate a view with a window.

The view will render to the window's framebuffer. Pass NULL or MK_WINDOW_INVALID to render to the main backbuffer.

ParameterTypeDescription
viewmk_view_id_tView ID to associate
windowmk_window_tTarget window (NULL for main window backbuffer)

mk_window_createfunction

mk_window_t mk_window_create(const mk_window_desc *desc)

Create a new window.

The window will have its own framebuffer for rendering.

ParameterTypeDescription
descconst mk_window_desc *Window descriptor

Returns Window handle or MK_WINDOW_INVALID on failure

mk_window_destroyfunction

void mk_window_destroy(mk_window_t window)

Destroy a window and its associated framebuffer.

Any views associated with this window will revert to the main backbuffer. Cannot be used to destroy the main window.

ParameterTypeDescription
windowmk_window_tWindow to destroy

mk_window_focusfunction

void mk_window_focus(mk_window_t window)

Focus/raise the window.

ParameterTypeDescription
windowmk_window_tValue for window.

mk_window_get_display_scalefunction

float mk_window_get_display_scale(mk_window_t window)

Get desired physical pixels per portable content unit.

ParameterTypeDescription
windowmk_window_tValue for window.

Returns The resulting value.

mk_window_get_dpi_scalefunction

float mk_window_get_dpi_scale(mk_window_t window)

Get physical backbuffer pixels per native window-coordinate unit.

ParameterTypeDescription
windowmk_window_tValue for window.

Returns The resulting value.

mk_window_get_framebufferfunction

mk_framebuf_t mk_window_get_framebuffer(mk_window_t window)

Get the framebuffer handle for this window.

Returns MK_FRAMEBUF_INVALID for the main window (uses backbuffer).

ParameterTypeDescription
windowmk_window_tValue for window.

Returns The resulting handle or value.

mk_window_get_positionfunction

void mk_window_get_position(mk_window_t window, int *x, int *y)

Get the window's top-left position in screen coordinates.

ParameterTypeDescription
windowmk_window_tValue for window.
xint *Value for x.
yint *Value for y.

mk_window_get_safe_areafunction

bool mk_window_get_safe_area(mk_window_t window, mk_rect *area)

Get the safe rectangle for interactive content in native window units.

ParameterTypeDescription
windowmk_window_tValue for window.
areamk_rect *Value for area.

Returns True when the operation succeeds.

mk_window_get_safe_insetsfunction

bool mk_window_get_safe_insets(mk_window_t window, mk_insets *insets)

Get safe-area insets from each window edge in native window units.

ParameterTypeDescription
windowmk_window_tValue for window.
insetsmk_insets *Value for insets.

Returns True when the operation succeeds.

mk_window_get_sdlfunction

SDL_Window * mk_window_get_sdl(mk_window_t window)

Get underlying SDL window handle for advanced use.

ParameterTypeDescription
windowmk_window_tValue for window.

Returns A borrowed pointer, or NULL when unavailable.

mk_window_get_sizefunction

void mk_window_get_size(mk_window_t window, int *width, int *height)

Get size in SDL's native window-coordinate units.

This is the same coordinate space as mouse input and safe-area rectangles. Use mk_window_get_ui_scale() for portable UI/design dimensions.

ParameterTypeDescription
windowmk_window_tValue for window.
widthint *Value for width.
heightint *Value for height.

mk_window_get_size_pixelsfunction

void mk_window_get_size_pixels(mk_window_t window, int *width, int *height)

Get window size in physical pixels.

Use this for rendering dimensions.

ParameterTypeDescription
windowmk_window_tValue for window.
widthint *Value for width.
heightint *Value for height.

mk_window_get_ui_scalefunction

float mk_window_get_ui_scale(mk_window_t window)

Get native window-coordinate units per portable UI/design unit.

ParameterTypeDescription
windowmk_window_tValue for window.

Returns The resulting value.

mk_window_get_user_datafunction

void * mk_window_get_user_data(mk_window_t window)

Get window user data.

ParameterTypeDescription
windowmk_window_tValue for window.

Returns A borrowed pointer, or NULL when unavailable.

mk_window_is_fullscreenfunction

bool mk_window_is_fullscreen(mk_window_t window)

True if the window is currently fullscreen.

ParameterTypeDescription
windowmk_window_tValue for window.

Returns True when the condition holds.

mk_window_is_mainfunction

bool mk_window_is_main(mk_window_t window)

Check if this is the main window.

ParameterTypeDescription
windowmk_window_tValue for window.

Returns True when the condition holds.

mk_window_is_maximizedfunction

bool mk_window_is_maximized(mk_window_t window)

True if the window is currently maximized.

ParameterTypeDescription
windowmk_window_tValue for window.

Returns True when the condition holds.

mk_window_is_minimizedfunction

bool mk_window_is_minimized(mk_window_t window)

True if the window is currently minimized.

ParameterTypeDescription
windowmk_window_tValue for window.

Returns True when the condition holds.

mk_window_is_validfunction

bool mk_window_is_valid(mk_window_t window)

Check if window handle is valid.

ParameterTypeDescription
windowmk_window_tValue for window.

Returns True when the condition holds.

mk_window_is_visiblefunction

bool mk_window_is_visible(mk_window_t window)

Check if window is visible.

ParameterTypeDescription
windowmk_window_tValue for window.

Returns True when the condition holds.

mk_window_maximizefunction

void mk_window_maximize(mk_window_t window)

Maximize the window.

ParameterTypeDescription
windowmk_window_tValue for window.

mk_window_minimizefunction

void mk_window_minimize(mk_window_t window)

Minimize (iconify) the window.

ParameterTypeDescription
windowmk_window_tValue for window.

mk_window_restorefunction

void mk_window_restore(mk_window_t window)

Restore the window from a minimized/maximized state.

ParameterTypeDescription
windowmk_window_tValue for window.

mk_window_set_always_on_topfunction

void mk_window_set_always_on_top(mk_window_t window, bool on_top)

Toggle whether the window stays above others.

ParameterTypeDescription
windowmk_window_tValue for window.
on_topboolValue for on top.

mk_window_set_fullscreenfunction

void mk_window_set_fullscreen(mk_window_t window, bool fullscreen)

Enter or leave borderless (desktop) fullscreen.

ParameterTypeDescription
windowmk_window_tValue for window.
fullscreenboolValue for fullscreen.

mk_window_set_iconfunction

void mk_window_set_icon(mk_window_t window, const void *rgba_pixels, int width, int height)

Set the window icon from a 32-bit RGBA pixel buffer (8 bits/channel, row-major, top-left origin).

No effect on platforms without window icons.

ParameterTypeDescription
windowmk_window_tValue for window.
rgba_pixelsconst void *Value for RGBA pixels.
widthintValue for width.
heightintValue for height.

mk_window_set_max_sizefunction

void mk_window_set_max_size(mk_window_t window, int width, int height)

Constrain the largest the window may be resized to (0 to clear).

ParameterTypeDescription
windowmk_window_tValue for window.
widthintValue for width.
heightintValue for height.

mk_window_set_min_sizefunction

void mk_window_set_min_size(mk_window_t window, int width, int height)

Constrain the smallest the window may be resized to (0 to clear).

ParameterTypeDescription
windowmk_window_tValue for window.
widthintValue for width.
heightintValue for height.

mk_window_set_opacityfunction

void mk_window_set_opacity(mk_window_t window, float opacity)

Set window opacity in [0,1] (1 = opaque).

ParameterTypeDescription
windowmk_window_tValue for window.
opacityfloatValue for opacity.

mk_window_set_positionfunction

void mk_window_set_position(mk_window_t window, int x, int y)

Move the window's top-left to a screen coordinate.

ParameterTypeDescription
windowmk_window_tValue for window.
xintValue for x.
yintValue for y.

mk_window_set_resizablefunction

void mk_window_set_resizable(mk_window_t window, bool resizable)

Toggle whether the user can resize the window.

ParameterTypeDescription
windowmk_window_tValue for window.
resizableboolValue for resizable.

mk_window_set_sizefunction

void mk_window_set_size(mk_window_t window, int width, int height)

Resize the window (logical units / points).

ParameterTypeDescription
windowmk_window_tValue for window.
widthintValue for width.
heightintValue for height.

mk_window_set_titlefunction

void mk_window_set_title(mk_window_t window, const char *title)

Set window title.

ParameterTypeDescription
windowmk_window_tValue for window.
titleconst char *Value for title.

mk_window_set_user_datafunction

void mk_window_set_user_data(mk_window_t window, void *user_data)

Set window user data.

ParameterTypeDescription
windowmk_window_tValue for window.
user_datavoid *Caller-provided context.

mk_window_set_visiblefunction

void mk_window_set_visible(mk_window_t window, bool visible)

Show or hide the window.

ParameterTypeDescription
windowmk_window_tValue for window.
visibleboolValue for visible.

Structs

mk_window_descstruct

Window creation descriptor.

FieldTypeDescription
titleconst char *Window title (default: "modkit").
widthintInitial width in logical units (default: 800).
heightintInitial height in logical units (default: 600).
xintInitial x position (0 = system default).
yintInitial y position (0 = system default).
flagsuint32_tMK_WINDOW_* flags (same as mk_app_desc).
resize_cbmk_window_resize_fnCalled on window resize.
close_cbmk_window_close_fnCalled when close requested.
event_cbmk_window_event_fnCalled for focus/visibility/position events.
user_datavoid *Passed to all callbacks.

mk_window_eventstruct

Window event data.

FieldTypeDescription
typemk_window_event_type_tThe type.
moved.xintNew horizontal window position.
moved.yintNew vertical window position.
movedstruct mk_window_event::@047067111133052017340322012064275134141322021151::@214162041027050250044372344057067157343317165375New position for MK_WINDOW_EVENT_MOVED.

Enums

mk_window_event_typeenum

Window event types (for event callback).

ValueDescription
MK_WINDOW_EVENT_FOCUS_GAINEDWindow gained keyboard focus.
MK_WINDOW_EVENT_FOCUS_LOSTWindow lost keyboard focus.
MK_WINDOW_EVENT_SHOWNWindow became visible.
MK_WINDOW_EVENT_HIDDENWindow was hidden.
MK_WINDOW_EVENT_MOVEDWindow was moved.
MK_WINDOW_EVENT_MINIMIZEDWindow was minimized.
MK_WINDOW_EVENT_MAXIMIZEDWindow was maximized.
MK_WINDOW_EVENT_RESTOREDWindow was restored from minimized/maximized.

Typedefs

mk_window_close_fntypedef

typedef void(*) mk_window_close_fn(mk_window_t window, void *user_data)

Called when window close is requested (e.g., user clicks X button).

For secondary windows, the window is destroyed after this callback returns.

mk_window_desctypedef

typedef struct mk_window_desc mk_window_desc

Window creation descriptor.

mk_window_event_fntypedef

typedef void(*) mk_window_event_fn(mk_window_t window, const mk_window_event_t *event, void *user_data)

Called for window events (focus, visibility, position changes).

mk_window_event_ttypedef

typedef struct mk_window_event mk_window_event_t

Window event data.

mk_window_event_type_ttypedef

typedef enum mk_window_event_type mk_window_event_type_t

Window event types (for event callback).

mk_window_resize_fntypedef

typedef void(*) mk_window_resize_fn(mk_window_t window, int width, int height, void *user_data)

Called when window is resized.

mk_window_ttypedef

typedef struct mk_window_s* mk_window_t

Opaque window handle.

Use mk_window_is_valid() to check validity.

Macros

MK_WINDOW_INVALIDdefine

MK_WINDOW_INVALID

Invalid sentinel for window.