use crate::platform::ControlFlow;
use crate::platform::event::Event;
use crate::platform::window::{Window, WindowAttributes};
pub mod headless;
#[cfg(target_os = "linux")]
pub mod wayland;
#[cfg(target_os = "linux")]
pub mod x11;
#[cfg(target_os = "windows")]
pub mod windows;
#[cfg(target_os = "macos")]
pub mod macos;
#[cfg(target_os = "ios")]
pub mod ios;
#[cfg(target_os = "android")]
pub mod android;
#[cfg_attr(
not(any(target_os = "linux", target_os = "windows", target_os = "macos")),
allow(unused_mut)
)]
pub fn run<H>(attrs: WindowAttributes, mut handler: H)
where
H: FnMut(Event, &dyn Window) -> ControlFlow,
{
#[cfg(target_os = "ios")]
{
let _ = ios::run(attrs, handler);
}
#[cfg(not(target_os = "ios"))]
{
#[cfg(target_os = "linux")]
{
if wayland::available() {
match wayland::run(attrs.clone(), &mut handler) {
Ok(()) => return,
Err(err) => {
eprintln!(
"stipple: Wayland backend unavailable ({err}); falling back to X11/headless"
);
}
}
}
if x11::available() {
match x11::run(attrs.clone(), &mut handler) {
Ok(()) => return,
Err(err) => {
eprintln!(
"stipple: X11 backend unavailable ({err}); falling back to headless"
);
}
}
}
}
#[cfg(target_os = "windows")]
{
match windows::run(attrs.clone(), &mut handler) {
Ok(()) => return,
Err(err) => {
eprintln!(
"stipple: Windows backend unavailable ({err}); falling back to headless"
);
}
}
}
#[cfg(target_os = "macos")]
{
match macos::run(attrs.clone(), &mut handler) {
Ok(()) => return,
Err(err) => {
eprintln!(
"stipple: macOS backend unavailable ({err}); falling back to headless"
);
}
}
}
let _ = headless::run(
attrs,
[Event::RedrawRequested, Event::CloseRequested],
handler,
);
}
}