#![doc = include_str!("../README.md")]
#![allow(clippy::missing_transmute_annotations)]
mod device;
mod error;
mod map;
mod runtime;
mod tls;
mod window;
use crate::tls::runtime;
use std::future::pending;
use winit::error::OsError;
use winit::event_loop::{DeviceEvents, OwnedDisplayHandle};
use winit::monitor::MonitorHandle;
use winit::window::{CustomCursor, CustomCursorSource, Theme, Window, WindowAttributes};
pub use crate::device::DeviceEventListener;
pub use async_local_executor::{JoinHandle, spawn_local};
pub use error::Error;
#[cfg(not(target_arch = "wasm32"))]
pub use runtime::native::run_app;
#[cfg(target_arch = "wasm32")]
pub use runtime::web::run_app;
pub use window::{WindowEventFuture, WindowEvents, WindowExtAsync};
pub use winit;
#[inline]
pub fn create_window(window_attributes: WindowAttributes) -> Result<Window, OsError> {
runtime().event_loop().create_window(window_attributes)
}
#[inline]
pub fn create_custom_cursor(custom_cursor: CustomCursorSource) -> CustomCursor {
runtime().event_loop().create_custom_cursor(custom_cursor)
}
#[inline]
pub fn available_monitors() -> Vec<MonitorHandle> {
runtime().event_loop().available_monitors().collect()
}
#[inline]
pub fn primary_monitor() -> Option<MonitorHandle> {
runtime().event_loop().primary_monitor()
}
#[inline]
pub fn listen_device_events(allowed: DeviceEvents) {
runtime().event_loop().listen_device_events(allowed)
}
#[inline]
pub fn system_theme() -> Option<Theme> {
runtime().event_loop().system_theme()
}
#[inline]
pub async fn exit() -> ! {
runtime().event_loop().exit();
async_local_executor::exit();
pending::<()>().await;
unreachable!()
}
#[inline]
pub fn owned_display_handle() -> OwnedDisplayHandle {
runtime().event_loop().owned_display_handle()
}
#[inline]
pub async fn resumed() {
if let Some(rx) = { runtime().resumed_rx() } {
rx.recv().await.unwrap();
}
}
#[inline]
pub async fn suspended() {
if let Some(rx) = { runtime().suspended_rx() } {
rx.recv().await.unwrap();
}
}
#[inline]
pub fn device_events() -> Option<DeviceEventListener> {
DeviceEventListener::new()
}