Skip to content

Latest commit

 

History

166 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Window.c3

A cross-platform window management library for C3, designed for use with Vulkan graphics applications.

Supported Platforms

  • Windows (Win32)
  • macOS (Cocoa)
  • Linux (Wayland, X11)

Installation

  1. Download the window.c3l file from releases
  2. Place it in your project's dependency directory
  3. Add it to your project.json:
{
    "dependencies": ["c3w"]
}

Linux Display Server

On Linux, the display server (Wayland or X11) is detected automatically at runtime. No feature flags are needed. The library loads libwayland-client and libX11/libxcb dynamically via dlopen, so neither development package is required at build time — only the runtime libraries that your system already has installed.

Quick Start

import c3w;

fn void main(String[] args)
{
    c3w::Window win = c3w::new(
        params: {
            .width = 900,
            .height = 600,
            .x = 0,
            .y = 0
        },
        name: "My Window"
    )!!;

    defer win.free();

    bool running = true;
    while (running) {
        c3w::EventMap event_map = win.getEvent();

        if (event_map.is_pressed(ESCAPE)) {
            running = false;
        }
    }
}

API Reference

c3w::new

Creates a new window.

fn Window? new(Params params, String name)
  • params - Window position and size (x, y, width, height)
  • name - Window title

Returns a Window or the fault FAILED_OPENING_WINDOW.

Window.getEvent

Polls for window events and returns the current input state.

fn EventMap Window.getEvent(&self)

Returns an EventMap (a hashmap of pressed keys/buttons). Use is_pressed() to query it.

Window.getMousePos

Returns the current mouse position relative to the window.

fn float[<2>] Window.getMousePos(self)

Window.set_size

Resizes the window, in the same units c3w::new took — the drawable/content size, not the outer frame, so macOS and Win32 add their chrome back for you.

fn void Window.set_size(&self, int width, int height)

The size that arrives is a request, not a result, and nothing is recorded on the Window. Read the size back the way you already do — off the surface, or from the resize event — because every platform is entitled to answer with a different one:

Platform What happens
macOS setFrame:display:, keeping the top edge in place
Win32 SetWindowPos, client size converted to window size
X11 xcb_configure_window; the window manager may adjust it
Wayland set_max_size + set_min_size, then the compositor answers with a configure
wasm the canvas is resized directly

Window.set_minimized

Minimizes the window, or restores it.

fn void Window.set_minimized(&self, bool minimized)

Restoring does not work on Wayland, and that is the protocol rather than an omission: xdg-shell has xdg_toplevel.set_minimized and no counterpart, because a client that could un-minimize itself could jump in front of whatever the user was doing. Passing false there is a no-op. It is also a no-op on wasm, where a page cannot minimize the browser running it.

Window.free

Releases window resources. Call when done with the window.

fn void Window.free(&self)

EventMap.is_pressed

Checks if a key or mouse button is currently pressed.

fn bool EventMap.is_pressed(self, EventKey key)

Event Types

The EventType enum indicates what kind of event occurred:

Event Description
KEY_PRESSED A keyboard key was pressed
KEY_RELEASED A keyboard key was released
MOUSE_PRESSED A mouse button was pressed
MOUSE_RELEASED A mouse button was released
MOUSE_MOTION The mouse moved
WINDOW_REFRESH The window needs redrawing
QUIT The window was closed

Event Keys

The EventKey enum covers keyboard keys and mouse buttons:

  • Letters: A - Z
  • Numbers: KEY_0 - KEY_9
  • Function keys: F1 - F20
  • Arrows: LEFT_ARROW, RIGHT_ARROW, UP_ARROW, DOWN_ARROW
  • Modifiers: LEFT_SHIFT, RIGHT_SHIFT, LEFT_CTRL, RIGHT_CTRL, LEFT_ALT, RIGHT_ALT, LEFT_SUPER, RIGHT_SUPER
  • Special: ESCAPE, RETURN, SPACE, TAB, BACKSPACE, DELETE, INSERT, CAPS_LOCK
  • Navigation: HOME, END, PAGE_UP, PAGE_DOWN
  • Mouse: LEFT_MOUSE, RIGHT_MOUSE, MIDDLE_MOUSE, MOUSE_SCROLL_UP, MOUSE_SCROLL_DOWN

About

Window manager for C3

Topics

Resources

Stars

6 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages