Skip to main content

fenestra_shell/
lib.rs

1//! OS glue for fenestra: the winit + wgpu windowed runner and the headless
2//! renderer. Everything that touches a display server lives here;
3//! `fenestra-core` and `fenestra-kit` stay windowless.
4
5use std::fmt;
6
7// Headless rendering, GPU readback, the OS clipboard, and the AccessKit
8// adapter are native-only; on the web only the windowed (canvas) runner
9// exists. `fenestra-core` and `fenestra-kit` compile everywhere.
10#[cfg(not(target_arch = "wasm32"))]
11mod access;
12#[cfg(not(target_arch = "wasm32"))]
13mod element_render;
14#[cfg(not(target_arch = "wasm32"))]
15mod headless;
16#[cfg(not(target_arch = "wasm32"))]
17mod os_clipboard;
18#[cfg(not(target_arch = "wasm32"))]
19mod synthetic;
20#[cfg(not(target_arch = "wasm32"))]
21pub mod testing;
22mod window;
23
24#[cfg(not(target_arch = "wasm32"))]
25pub use element_render::{
26    render_element, render_element_with, render_element_with_state, with_fonts, with_headless,
27};
28#[cfg(not(target_arch = "wasm32"))]
29pub use headless::Headless;
30#[cfg(not(target_arch = "wasm32"))]
31pub use os_clipboard::OsClipboard;
32#[cfg(not(target_arch = "wasm32"))]
33pub use synthetic::{SyntheticEvent, render_app};
34pub use window::{WindowOptions, run_app};
35#[cfg(not(target_arch = "wasm32"))]
36pub use window::{run_scene, run_static};
37
38/// Errors from the windowed or headless runners.
39#[derive(Debug)]
40pub enum ShellError {
41    /// No compute-capable wgpu adapter was found.
42    NoDevice,
43    /// The vello renderer failed to build or render.
44    Vello(vello::Error),
45    /// The winit event loop failed.
46    EventLoop(winit::error::EventLoopError),
47    /// GPU readback of the rendered image failed.
48    Readback,
49}
50
51impl fmt::Display for ShellError {
52    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
53        match self {
54            Self::NoDevice => write!(f, "no compute-capable wgpu adapter found"),
55            Self::Vello(e) => write!(f, "vello renderer error: {e}"),
56            Self::EventLoop(e) => write!(f, "winit event loop error: {e}"),
57            Self::Readback => write!(f, "GPU readback failed"),
58        }
59    }
60}
61
62impl std::error::Error for ShellError {}