makepad/libs/wayland_server/examples/serve.rs
Admin 9aadd43f22 platform: HAL-only on every platform; the old backends are deleted
Every native platform now runs on the HAL (makepad-hal) alone: macOS and
iOS/tvOS on Metal, Windows on D3D11 (with device-loss recovery), Linux on
Vulkan (X11, Wayland and direct KMS, multi-GPU laptops with per-output
modes, mirror/extended arrangements and pacing) plus a GLES backend, and
Android on Vulkan with media, camera, network, haptics and file access on
the HAL. The old per-OS backends, the hal cfg and OpenHarmony are gone.
GPU memory: the HAL reads the device budget, keeps a UI reserve and raises
GpuPressure; failed allocations wait for room. One font service per host,
a frame profiler, held events for hidden views, automation for tests. Our
own generated Vulkan, Wayland and Windows bindings replace vendored ones.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-13 12:26:21 +02:00

31 lines
1.7 KiB
Rust

//! Serves the compositor on a socket and prints what clients do; for trying real clients without a window manager.
//! Usage: serve <runtime dir> [seconds]. Configure requests are answered with a 800x600 window.
use std::time::{Duration, Instant};
use wayland_server::compositor::*;
use wayland_server::host::{Command, Host};
fn main() {
let args: Vec<String> = std::env::args().collect();
let dir = std::path::PathBuf::from(&args[1]);
let secs: u64 = args.get(2).and_then(|s| s.parse().ok()).unwrap_or(10);
let host = Host::spawn(&dir, "wayland-serve", OutputInfo::default(), &xkb_keymap::US, None, || {}).unwrap();
println!("socket {}", host.socket);
let end = Instant::now() + Duration::from_secs(secs);
let mut mapped = Vec::new();
while Instant::now() < end {
let Ok(ev) = host.events.recv_timeout(Duration::from_millis(100)) else { continue };
match &ev {
UiEvent::Commit { surface, buffer: BufferUpdate::Attach(f), .. } => {
let lit = f.data.chunks_exact(4).filter(|p| p[0] | p[1] | p[2] != 0).count();
println!("commit {surface:?} {}x{} rows {}..{} fmt {} lit {lit}", f.width, f.height, f.y0, f.y1, f.format);
}
UiEvent::ToplevelNew { surface } => {
println!("toplevel {surface:?}");
host.send(Command::ConfigureToplevel { surface: *surface, width: 800, height: 600, states: vec![xdg::STATE_ACTIVATED] });
}
UiEvent::Mapped { surface } => { println!("mapped {surface:?}"); mapped.push(*surface); }
other => println!("{other:?}").to_owned(),
}
for s in &mapped { host.send(Command::FrameDone { surface: *s, time_ms: 0 }); }
}
}