Skip to content
tonis2Public

About

Window manager for C3

Topics

Resources

Stars

7 stars

Watchers

1 watching

Forks

Latest commit

 

History

182 Commits

Folders and files

Repository files navigation

Window.c3 (c3w)

A cross-platform window, input, clipboard, drag-and-drop, and Vulkan surface library for C3.

Supported Platforms

  • 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)

Installation

Add window.c3l to your project's lib/ directory and reference "c3w" in project.json:

{
    "dependencies": ["c3w"]
}

Linux Display Server

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.

Quick Start

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;
    }
}

API Reference

Lifecycle & Event Loop

  • fn Window? c3w::new(Params params, String name) — Opens a window sized to params.width × params.height logical content units. Returns FAILED_OPENING_WINDOW on 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. Pass wait: true to block at ~0% CPU until an event or wake() arrives.
  • fn void Window.wake(&self) — Thread-safe wakeup for a parked poll(wait: true).
  • fn bool Window.should_close(&self) — True once the user or display server requested closing the window.

Keyboard, Mouse & Text Input

  • fn KeyState Window.keys(&self) — Current latched KeyState (a 16-byte allocation-free EnumSet {EventKey} bitset). Supports is_pressed(key), set(key, down), and .@each(; key).
  • fn Event[] Window.events(&self) — Borrowed slice of ordered KEY_PRESSED, KEY_RELEASED, MOUSE_PRESSED, and MOUSE_RELEASED transitions drained during the last poll().
  • fn float[<2>] Window.mouse_pos(&self) — Window-relative pointer coordinates in logical units, bottom-left origin (+y up).
  • fn float[<2>] Window.mouse_delta(&self) — Pointer movement over the last poll() in logical units (+x right, +y up).
  • fn void Window.set_pointer_lock(&self, bool locked) / fn bool Window.pointer_locked(&self) — Hides the cursor and switches mouse_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 last poll().
  • fn String Window.text(&self) — Borrowed UTF-8 printable text typed during the last poll().

Window State, Cursor, Clipboard, Drops & Vulkan

  • fn float Window.scale(&self) — Framebuffer pixels per logical unit (e.g. 2.0 on 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
  • 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: false is a no-op on Wayland per xdg-shell and 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 with String.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 a VkSurfaceKHR, using get_instance_proc_addr when statically linked or dynamically loading the system Vulkan loader otherwise. Returns SURFACE_CREATION_FAILED on failure.
  • fn BackendType Window.backend(&self) (Linux only) — Returns WAYLAND, X11, or NONE.

About

Window manager for C3

Topics

Resources

Stars

7 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages