A cross-platform window, input, clipboard, drag-and-drop, and Vulkan surface library for C3.
- Linux (Wayland & X11, auto-detected at runtime via
dlopen) - macOS (Cocoa / AppKit / Metal)
- Windows (Win32)
- WebAssembly (HTML5 canvas +
c3w.js) - Android (no-op surface shim for NativeActivity / OpenXR builds)
Add window.c3l to your project's lib/ directory and reference "c3w" in project.json:
{
"dependencies": ["c3w"]
}On Linux, Wayland or X11 is detected automatically at runtime via XDG_SESSION_TYPE (with fallback probing). libwayland-client, libX11, libxcb, and libxkbcommon are loaded via dlopen, so no -dev packages are required at build time. Pass -D X11 or -D WAYLAND to force a specific backend.
import c3w;
fn void main()
{
c3w::Window win = c3w::new({ .width = 900, .height = 600 }, "My Window")!!;
defer win.free();
while (!win.should_close())
{
c3w::KeyState keys = win.poll();
if (keys.is_pressed(ESCAPE)) break;
}
}fn Window? c3w::new(Params params, String name)— Opens a window sized toparams.width×params.heightlogical content units. ReturnsFAILED_OPENING_WINDOWon failure.fn void Window.free(&self)— Unlocks the pointer (if locked) and releases all window and input resources.fn KeyState Window.poll(&self, bool wait = false)— Drains pending OS events and returns a snapshot of currently held keys and mouse buttons. Passwait: trueto block at ~0% CPU until an event orwake()arrives.fn void Window.wake(&self)— Thread-safe wakeup for a parkedpoll(wait: true).fn bool Window.should_close(&self)— True once the user or display server requested closing the window.
fn KeyState Window.keys(&self)— Current latchedKeyState(a 16-byte allocation-freeEnumSet {EventKey}bitset). Supportsis_pressed(key),set(key, down), and.@each(; key).fn Event[] Window.events(&self)— Borrowed slice of orderedKEY_PRESSED,KEY_RELEASED,MOUSE_PRESSED, andMOUSE_RELEASEDtransitions drained during the lastpoll().fn float[<2>] Window.mouse_pos(&self)— Window-relative pointer coordinates in logical units, bottom-left origin (+yup).fn float[<2>] Window.mouse_delta(&self)— Pointer movement over the lastpoll()in logical units (+xright,+yup).fn void Window.set_pointer_lock(&self, bool locked)/fn bool Window.pointer_locked(&self)— Hides the cursor and switchesmouse_delta()to unbounded relative movement.fn float Window.scroll(&self)/fn float Window.scroll_x(&self)/fn bool Window.scroll_precise(&self)— Accumulated scroll deltas (+= up / right) and continuous/trackpad flag for the lastpoll().fn String Window.text(&self)— Borrowed UTF-8 printable text typed during the lastpoll().
fn float Window.scale(&self)— Framebuffer pixels per logical unit (e.g.2.0on HiDPI / Retina).fn void Window.set_size(&self, int width, int height)— Requests a new logical content size:- macOS:
setFrame:display:, preserving the top edge - Win32:
SetWindowPos, adding window chrome back to the scaled client size - X11:
xcb_configure_window - Wayland:
xdg_surface.set_window_geometry+wp_viewport.set_destination+wl_surface.commit - WASM: resizes the HTML5 canvas directly
- macOS:
fn void Window.set_title(&self, String title)— Updates the window title (UTF-8).fn bool Window.fullscreen(&self)/fn void Window.set_fullscreen(&self, bool on)— Queries or toggles fullscreen.fn void Window.maximize(&self)— Maximizes the window with normal chrome kept.fn void Window.set_minimized(&self, bool minimized)— Minimizes or restores the window (minimized: falseis a no-op on Wayland perxdg-shelland on WASM).fn void Window.set_cursor(&self, CursorShape shape)— Sets the cursor shape (ARROW,POINTING_HAND,IBEAM,CROSSHAIR,OPEN_HAND,CLOSED_HAND,RESIZE_H,RESIZE_V).fn void Window.set_clipboard(&self, String text)/fn String Window.clipboard(&self, Allocator allocator)— System clipboard on Wayland/X11, in-process fallback elsewhere. Caller frees non-empty returned strings withString.free(allocator).fn String Window.take_drops(&self, Allocator allocator)— Returns newline-separated local paths dropped onto the window (Wayland, X11, macOS, and Windows), clearing the pending queue.fn VkSurface? Window.create_vk_surface(&self, void* vk_instance, VkGetInstanceProcAddrFn get_instance_proc_addr = null)— Creates aVkSurfaceKHR, usingget_instance_proc_addrwhen statically linked or dynamically loading the system Vulkan loader otherwise. ReturnsSURFACE_CREATION_FAILEDon failure.fn BackendType Window.backend(&self)(Linux only) — ReturnsWAYLAND,X11, orNONE.