1#![doc = include_str!("../README.md")]
2#![allow(clippy::missing_transmute_annotations)]
4
5mod device;
6mod error;
7mod map;
8mod runtime;
9mod tls;
10mod window;
11
12use crate::tls::runtime;
13use std::future::pending;
14use winit::error::OsError;
15use winit::event_loop::{DeviceEvents, OwnedDisplayHandle};
16use winit::monitor::MonitorHandle;
17use winit::window::{CustomCursor, CustomCursorSource, Theme, Window, WindowAttributes};
18
19pub use crate::device::DeviceEventListener;
20pub use async_local_executor::{JoinHandle, spawn_local};
21pub use error::Error;
22#[cfg(not(target_arch = "wasm32"))]
23pub use runtime::native::run_app;
24#[cfg(target_arch = "wasm32")]
25pub use runtime::web::run_app;
26pub use window::{WindowEventFuture, WindowEvents, WindowExtAsync};
27pub use winit;
28
29#[inline]
30pub fn create_window(window_attributes: WindowAttributes) -> Result<Window, OsError> {
31 runtime().event_loop().create_window(window_attributes)
32}
33
34#[inline]
35pub fn create_custom_cursor(custom_cursor: CustomCursorSource) -> CustomCursor {
36 runtime().event_loop().create_custom_cursor(custom_cursor)
37}
38
39#[inline]
40pub fn available_monitors() -> Vec<MonitorHandle> {
41 runtime().event_loop().available_monitors().collect()
42}
43
44#[inline]
45pub fn primary_monitor() -> Option<MonitorHandle> {
46 runtime().event_loop().primary_monitor()
47}
48
49#[inline]
50pub fn listen_device_events(allowed: DeviceEvents) {
51 runtime().event_loop().listen_device_events(allowed)
52}
53
54#[inline]
55pub fn system_theme() -> Option<Theme> {
56 runtime().event_loop().system_theme()
57}
58
59#[inline]
60pub async fn exit() -> ! {
61 runtime().event_loop().exit();
62 async_local_executor::exit();
63 pending::<()>().await;
64 unreachable!()
65}
66
67#[inline]
68pub fn owned_display_handle() -> OwnedDisplayHandle {
69 runtime().event_loop().owned_display_handle()
70}
71
72#[inline]
73pub async fn resumed() {
74 if let Some(rx) = { runtime().resumed_rx() } {
75 rx.recv().await.unwrap();
76 }
77}
78
79#[inline]
80pub async fn suspended() {
81 if let Some(rx) = { runtime().suspended_rx() } {
82 rx.recv().await.unwrap();
83 }
84}
85
86#[inline]
87pub fn device_events() -> Option<DeviceEventListener> {
88 DeviceEventListener::new()
89}