summaryrefslogtreecommitdiffstats
path: root/winit/src
diff options
context:
space:
mode:
Diffstat (limited to 'winit/src')
-rw-r--r--winit/src/application.rs64
-rw-r--r--winit/src/clipboard.rs8
-rw-r--r--winit/src/settings.rs6
3 files changed, 72 insertions, 6 deletions
diff --git a/winit/src/application.rs b/winit/src/application.rs
index e9212b5e..ed077507 100644
--- a/winit/src/application.rs
+++ b/winit/src/application.rs
@@ -115,12 +115,11 @@ where
use futures::task;
use futures::Future;
use winit::event_loop::EventLoop;
- use winit::platform::run_return::EventLoopExtRunReturn;
let mut debug = Debug::new();
debug.startup_started();
- let mut event_loop = EventLoop::with_user_event();
+ let event_loop = EventLoop::with_user_event();
let mut proxy = event_loop.create_proxy();
let mut runtime = {
@@ -149,6 +148,21 @@ where
.build(&event_loop)
.map_err(Error::WindowCreationFailed)?;
+ #[cfg(target_arch = "wasm32")]
+ {
+ use winit::platform::web::WindowExtWebSys;
+
+ let canvas = window.canvas();
+
+ let window = web_sys::window().unwrap();
+ let document = window.document().unwrap();
+ let body = document.body().unwrap();
+
+ let _ = body
+ .append_child(&canvas)
+ .expect("Append canvas to HTML body");
+ }
+
let mut clipboard = Clipboard::connect(&window);
run_command(
@@ -179,7 +193,7 @@ where
let mut context = task::Context::from_waker(task::noop_waker_ref());
- event_loop.run_return(move |event, _, control_flow| {
+ platform::run(event_loop, move |event, _, control_flow| {
use winit::event_loop::ControlFlow;
if let ControlFlow::Exit = control_flow {
@@ -211,9 +225,7 @@ where
task::Poll::Ready(_) => ControlFlow::Exit,
};
}
- });
-
- Ok(())
+ })
}
async fn run_instance<A, E, C>(
@@ -562,3 +574,43 @@ pub fn run_command<Message: 'static + std::fmt::Debug + Send, E: Executor>(
}
}
}
+
+#[cfg(not(target_arch = "wasm32"))]
+mod platform {
+ pub fn run<T, F>(
+ mut event_loop: winit::event_loop::EventLoop<T>,
+ event_handler: F,
+ ) -> Result<(), super::Error>
+ where
+ F: 'static
+ + FnMut(
+ winit::event::Event<'_, T>,
+ &winit::event_loop::EventLoopWindowTarget<T>,
+ &mut winit::event_loop::ControlFlow,
+ ),
+ {
+ use winit::platform::run_return::EventLoopExtRunReturn;
+
+ let _ = event_loop.run_return(event_handler);
+
+ Ok(())
+ }
+}
+
+#[cfg(target_arch = "wasm32")]
+mod platform {
+ pub fn run<T, F>(
+ event_loop: winit::event_loop::EventLoop<T>,
+ event_handler: F,
+ ) -> !
+ where
+ F: 'static
+ + FnMut(
+ winit::event::Event<'_, T>,
+ &winit::event_loop::EventLoopWindowTarget<T>,
+ &mut winit::event_loop::ControlFlow,
+ ),
+ {
+ event_loop.run(event_handler)
+ }
+}
diff --git a/winit/src/clipboard.rs b/winit/src/clipboard.rs
index 1b92b28d..c1fd8813 100644
--- a/winit/src/clipboard.rs
+++ b/winit/src/clipboard.rs
@@ -26,6 +26,14 @@ impl Clipboard {
Clipboard { state }
}
+ /// Creates a new [`Clipboard`] that isn't associated with a window.
+ /// This clipboard will never contain a copied value.
+ pub fn unconnected() -> Clipboard {
+ Clipboard {
+ state: State::Unavailable,
+ }
+ }
+
/// Reads the current content of the [`Clipboard`] as text.
pub fn read(&self) -> Option<String> {
match &self.state {
diff --git a/winit/src/settings.rs b/winit/src/settings.rs
index 045cb156..9a93824a 100644
--- a/winit/src/settings.rs
+++ b/winit/src/settings.rs
@@ -38,6 +38,12 @@ pub struct Settings<Flags> {
/// Whether the [`Application`] should exit when the user requests the
/// window to close (e.g. the user presses the close button).
pub exit_on_close_request: bool,
+
+ /// Whether the [`Application`] should try to build the context
+ /// using OpenGL ES first then OpenGL.
+ ///
+ /// NOTE: Only works for the `glow` backend.
+ pub try_opengles_first: bool,
}
/// The window settings of an application.