app_window
A cross-platform window management crate with async-first APIs.

app_window provides a modern alternative to winit for creating and managing windows across
Windows, macOS, Linux, and WebAssembly. The crate's primary goal is to provide a unified,
async-first API that works seamlessly across platforms with wildly different threading
requirements.
Key Features
- Async-first design: All APIs are async functions that can be called from any thread
- Modern platform backends: Win32 on Windows, AppKit on macOS, Wayland on Linux, Canvas on Web
- Unified threading model: Works correctly whether the platform requires UI on the main thread or not
- Graphics API integration: Provides
raw-window-handlefor wgpu, OpenGL, Vulkan, etc. - Built-in input handling: Cross-platform keyboard and mouse support
- Executor-agnostic: Works with any async runtime via
some_executor
Quick Start
First, initialize the application from your main function:
use application;
Then create windows from any async context:
use ;
// Create a window at a specific position
let window = new.await;
// The window stays open as long as the Window instance exists
// When dropped, the window automatically closes
Design Principles
1. Async-First API
Unlike traditional windowing libraries, app_window uses async functions throughout.
This design elegantly handles platform differences:
use Window;
// This works on any thread, on any platform
let window = default.await;
// Platform-specific threading is handled internally:
// - On macOS: dispatched to main thread
// - On Windows/Linux: may run on current thread
// - On Web: runs on the single thread
2. Window Lifetime Management
Windows are tied to their Rust object lifetime. No manual cleanup needed:
use Window;
// Window automatically closes when dropped
3. Platform-Specific Strategies
The crate provides platform-specific strategies for graphics APIs:
use ;
match WGPU_STRATEGY
Threading Model
This crate abstracts over platform threading differences:
- macOS: All UI operations dispatched to main thread via GCD
- Windows: UI operations can run on any thread
- Linux (Wayland): Compositor-dependent, handled per-connection
- WebAssembly: Single-threaded, operations run directly
You write the same async code for all platforms:
use application;
// This works everywhere, regardless of platform requirements
let result = on_main_thread.await;
Examples
Creating a fullscreen window
use Window;
match fullscreen.await
Handling window resize
use ;
let mut window = default.await;
let mut surface = window.surface.await;
// Register a callback for size changes
surface.size_update;
Input handling
use ;
// Create input handlers
let keyboard = coalesced.await;
let mut mouse = coalesced.await;
// Check keyboard state - KeyboardKey represents physical keys,
// not logical characters, making it ideal for game controls and shortcuts.
// Supports comprehensive key mappings including alphanumeric, function keys,
// numeric keypad, media controls, navigation keys, and international layouts.
if keyboard.is_pressed
if keyboard.is_pressed
if keyboard.is_pressed
// Media control keys
if keyboard.is_pressed
// Numeric keypad keys
if keyboard.is_pressed
// Check mouse state
if let Some = mouse.window_pos
if mouse.button_state
// Get scroll delta (clears after reading)
let = mouse.load_clear_scroll_delta;
if scroll_y != 0.0
Integrating with wgpu
For wgpu integration, use the platform-specific strategy:
use ;
let mut window = default.await;
let surface = window.surface.await;
// Use the appropriate strategy for your platform
match WGPU_STRATEGY
See examples/gpu.rs for a complete wgpu integration example.
Platform Support
| Platform | Backend | Status | Notes |
|---|---|---|---|
| Windows | Win32 API | ✅ Stable | Full async support, relaxed threading |
| macOS | AppKit via Swift | ✅ Stable | Main thread UI, Swift interop |
| Linux | Wayland | ✅ Stable | Client-side decorations, compositor-dependent |
| Web | Canvas API | ✅ Stable | Requires atomics & bulk memory features |
Performance Considerations
- Lazy surface creation: Surfaces are only allocated when requested via
window.surface() - Input coalescing: Input events can be coalesced for better performance in high-frequency scenarios
- Efficient executor: The main thread executor processes both async tasks and native events
- Platform optimizations: Each backend uses platform-specific optimizations
Integration with Graphics APIs
The crate implements raw-window-handle traits, enabling integration with:
- wgpu (recommended, see
examples/gpu.rs) - OpenGL/WebGL via glutin or similar
- Vulkan via ash or vulkano
- Metal (macOS) via metal-rs
- DirectX (Windows) via windows-rs
License
This project is licensed under the Mozilla Public License 2.0 (MPL-2.0).