tpt-window

Rust

Engine-first windowing, input and surface management in Rust. Caller-owned main loop, zero-allocation event hot path, ECS-friendly window state, and a permissive-only dependency tree.

0 stars0 forks0 watchersApache License 2.0
imerustwindow-managementwindowing

Languages

Rust99.0%Python0.6%JavaScript0.4%HTML0.1%
README

tpt-window

Engine-first windowing, input and surface management for the TPT AV Stack (tpt-nova, tpt-appfront, tpt-shell, tpt-archon). It is written in Rust and runs on Windows, macOS, Linux (X11 and Wayland) and the web (wasm32).

  • You own the main loop. There is no run(closure) that takes over main. You call poll_events (or step) once per frame and drain the events.
  • No allocation on the event hot path. Events go into a queue you allocate up front. A full queue returns EventStatus::BufferFull and counts the drop.
  • Window state is data. Size, scale factor, position and focus are cached snapshots, so reading them does not call the OS. Setters are queued and applied on the next poll, so they are safe from any thread.
  • Explicit AI-agent yield points. Each step produces a YieldPoint, so local inference can run between frames without losing display sync.
  • Permissive dependencies only. cargo-deny checks the tree in CI.

Status: pre-release (0.1.0), not yet on crates.io. Per-platform verification is tracked in todo.md.

Quick start

Depend on the facade crate straight from the repository:

[dependencies]
tpt-window = { git = "https://github.com/tpt-solutions/tpt-window" }
use tpt_window::*;

fn main() {
    let mut event_loop = new_event_loop().expect("no windowing backend");
    let _window = WindowBuilder::new()
        .with_title("hello")
        .build(&event_loop)
        .expect("failed to create window");

    let mut queue = EventQueue::with_capacity(DEFAULT_CAPACITY);

    'main: loop {
        let status = event_loop.poll_events(&mut EventSink::new(&mut queue));

        for ev in queue.drain() {
            if ev.event == WindowEvent::CloseRequested {
                break 'main;
            }
        }

        if status == PollStatus::Exit {
            break;
        }
    }
}

First 10 minutes

Run the examples. Each one opens a window; set TPT_EXAMPLE_SECONDS=5 to have it exit by itself.

cargo run -p tpt-window --example hello_window   # the smallest loop
cargo run -p tpt-window --example event_dump     # every event, printed
cargo run -p tpt-window --example input_state    # held keys and buttons, folded from events
cargo run -p tpt-window --example multi_window   # two windows, one queue

Then read the three things that differ from most window libraries:

  1. You own the loop. Call poll_events or step yourself. step(timeout) waits its full timeout when nothing happens, so when a display paces your loop, pass Duration::ZERO.
  2. Events go through a queue you own. queue.dropped() counts every event lost on the way. Check it while you develop.
  3. Modifiers are events. WindowEvent::ModifiersChanged reports Shift, Control, Alt and Super. Keys are reported by physical position (physical_key) and by layout (key_code).

Pitfalls to know before you ship: on Windows the window is modal while the user drags or resizes it, so your loop stops; on the web the page must drive tick from requestAnimationFrame.

Which crate do I need

You wantUse
A window and events on a desktop or the webtpt-window (the facade)
Tests without a displaytpt-window-test-utils (headless backend)
Game controllers, kept out of the window streamtpt-window-gamepad
Capability-gated, signed input for tpt-archontpt-window-archon
Passing frames between processes on Linuxtpt-window-memfd
wgpu surface and device setuptpt-window-wgpu
Bevy ECS integrationtpt-window-bevy
An app written against winit 0.30tpt-window-winit-compat
Passing frames between processes on Windowstpt-window-shm with tpt-window-core::channel
ecs resources (WindowResource, InputEventQueue)tpt-window-core with its ecs feature

Platform support

TargetBackend crateStatus
Windows (x86_64, i686)tpt-window-sys-win32Implemented and tested, including touch, raw mouse and IME placement. Pen and transparency are not implemented.
macOStpt-window-sys-cocoaImplemented. Compile-checked only; not run on a Mac yet.
Linux, X11tpt-window-sys-x11Implemented, including key repeat. Lifecycle test runs under Xvfb in CI. Compile-checked from Windows.
Linux, Waylandtpt-window-sys-waylandImplemented, including key repeat. Tested under headless Weston in CI, not on a real compositor. Compile-checked from Windows.
Web (wasm32-unknown-unknown)tpt-window-sys-wasmRendering checked in Edge with WebGPU. Input and resize checked in Chromium. Firefox and Safari not checked.
Anything elsenonenew_event_loop() returns WindowError::Unsupported.

On Linux, new_event_loop() uses Wayland when WAYLAND_DISPLAY is set and the connection succeeds, and X11 otherwise.

Feature status

Each cell says how the feature was checked. Tested means a test ran the real code on that platform (the X11 and Wayland tests run in CI). Compiled means it type-checks and lints for the target, but has not run. Partial means it works with a stated limit. No means it is not implemented, and the call is accepted and has no effect.

FeatureWindowsmacOSX11WaylandWeb
Windows, events, closeTestedCompiledTestedTestedTested
Redraw requestsCompiledCompiledCompiledNoCompiled
Key repeatCompiledCompiledTestedCompiledCompiled
Layout key codes (key_code)TestedCompiledCompiledCompiledCompiled
Modifier stateTestedCompiledCompiledCompiledCompiled
IME commitTestedCompiledPartial (keysym, no IME)CompiledCompiled
IME composition and placementPartial (placement tested, real input method not)NoNoNoNo
Raw mouse motionTestedNoNoNoNo
TouchPartial (down and move tested)NoNoNoNo
Monitors and current monitorTestedCompiledPartial (one screen)NoPartial (one screen)
Theme (light or dark)TestedNoNoNoCompiled
Cursor visibilityTestedCompiledCompiledNoCompiled
Cursor grabTested (confine)NoCompiledNoPartial (lock only)
Window iconTestedNoCompiledNoNo
Size limits, resizablePartial (resizable tested; limits not)CompiledCompiledPartialNo
Maximize and minimizeTestedCompiledCompiledPartialNo
Decorations and fullscreenTestedCompiledCompiledPartialNo
Always on topTestedCompiledCompiledNoNo
File dropPartial (drop tested by chunking only; no hover)NoNoNoNo
Cross-thread wake (EventLoopProxy)TestedNoCompiledCompiledNo
Menu (Quit, Cmd+Q)NoCompiledNoNoNo

Crates in this workspace

CratePurpose
tpt-windowFacade. Re-exports core and selects the backend for the target. Start here.
tpt-window-corePlatform-agnostic events, window types, traits, the event queue, and the version 1 display protocol wire format.
tpt-window-sys-win32Windows backend.
tpt-window-sys-cocoamacOS backend.
tpt-window-sys-x11X11 backend.
tpt-window-sys-waylandWayland backend.
tpt-window-sys-wasmWeb backend.
tpt-window-test-utilsHeadless backend for tests, CI and fuzzing.
tpt-window-gamepadOptional gamepad input over gilrs. Not part of the windowing layer.
tpt-window-archonCapability bridge to tpt-archon: scope mapping, signed input events and a gated router. Works without tpt-archon.
tpt-window-shmShared-memory transport for the display protocol (Windows).
tpt-window-winit-compatA winit 0.30 style ApplicationHandler and run_app over tpt-window's step loop, for migrating winit apps.
tpt-window-memfdShared-memory transport for the display protocol (Linux).
tpt-window-wgpuwgpu surface and device helpers for a window.
tpt-window-bevyBevy ECS integration: the window, input and event loop as resources.
tpt-window-benchBenchmark against winit 0.30 on the same loop. Not published.

Each crate has its own README and CHANGELOG.

Building and testing

cargo test --workspace
cargo deny check

Platform-specific tests need the matching desktop, so run the Win32 tests on Windows and the X11 and Wayland tests on Linux. CI covers the rest. The web backend builds with cargo check -p tpt-window-sys-wasm --target wasm32-unknown-unknown, and its Chromium check is in tpt-window-sys-wasm/browser-check/.

Documentation

  • Migrating from winit 0.30: MIGRATION.md, covering the event and window mapping and the known gaps.
  • Design specification: spec.txt.
  • Implementation status and open decisions: todo.md.
  • API docs: cargo doc --workspace --open.

Scope

tpt-window is not a GUI toolkit (no widgets, layout or theming), not a compositor, and not a game framework. It is not a general-purpose winit replacement. It targets engine and compositor workloads.

Contributing

This project accepts issues only. Open one at https://github.com/tpt-solutions/tpt-window/issues. See CONTRIBUTING.md.

License

Licensed under either of

at your option.