diff --git a/examples/window_run_return.rs b/examples/window_run_return.rs deleted file mode 100644 index 2a2758d0..00000000 --- a/examples/window_run_return.rs +++ /dev/null @@ -1,71 +0,0 @@ -#![allow(clippy::single_match)] - -// Limit this example to only compatible platforms. -#[cfg(any( - windows_platform, - macos_platform, - x11_platform, - wayland_platform, - android_platform, - orbital_platform, -))] -fn main() { - use std::{thread::sleep, time::Duration}; - - use simple_logger::SimpleLogger; - use winit::{ - event::{Event, WindowEvent}, - event_loop::EventLoop, - platform::run_return::EventLoopExtRunReturn, - window::WindowBuilder, - }; - - #[path = "util/fill.rs"] - mod fill; - - let mut event_loop = EventLoop::new(); - - SimpleLogger::new().init().unwrap(); - let window = WindowBuilder::new() - .with_title("A fantastic window!") - .build(&event_loop) - .unwrap(); - - let mut quit = false; - - while !quit { - event_loop.run_return(|event, _, control_flow| { - control_flow.set_wait(); - - if let Event::WindowEvent { event, .. } = &event { - // Print only Window events to reduce noise - println!("{event:?}"); - } - - match event { - Event::WindowEvent { - event: WindowEvent::CloseRequested, - .. - } => { - quit = true; - } - Event::MainEventsCleared => { - control_flow.set_exit(); - } - Event::RedrawRequested(_) => { - fill::fill_window(&window); - } - _ => (), - } - }); - - // Sleep for 1/60 second to simulate rendering - println!("rendering"); - sleep(Duration::from_millis(16)); - } -} - -#[cfg(any(ios_platform, wasm_platform))] -fn main() { - println!("This platform doesn't support run_return."); -} diff --git a/src/event_loop.rs b/src/event_loop.rs index 1485069d..7e5a66f7 100644 --- a/src/event_loop.rs +++ b/src/event_loop.rs @@ -156,7 +156,7 @@ impl fmt::Debug for EventLoopWindowTarget { /// /// Almost every change is persistent between multiple calls to the event loop closure within a /// given run loop. The only exception to this is [`ExitWithCode`] which, once set, cannot be unset. -/// Changes are **not** persistent between multiple calls to `run_return` - issuing a new call will +/// Changes are **not** persistent between multiple calls to `run_ondemand` - issuing a new call will /// reset the control flow to [`Poll`]. /// /// [`ExitWithCode`]: Self::ExitWithCode diff --git a/src/lib.rs b/src/lib.rs index 9d2a93b8..ee08ec8c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -37,7 +37,7 @@ //! Winit no longer uses a `EventLoop::poll_events() -> impl Iterator`-based event loop //! model, since that can't be implemented properly on some platforms (e.g web, iOS) and works poorly on //! most other platforms. However, this model can be re-implemented to an extent with -//! [`EventLoopExtRunReturn::run_return`]. See that method's documentation for more reasons about why +//! [`EventLoopExtPumpEvents::pump_events`]. See that method's documentation for more reasons about why //! it's discouraged, beyond compatibility reasons. //! //! @@ -109,7 +109,7 @@ //! window visible only once you're ready to render into it. //! //! [`EventLoop`]: event_loop::EventLoop -//! [`EventLoopExtRunReturn::run_return`]: ./platform/run_return/trait.EventLoopExtRunReturn.html#tymethod.run_return +//! [`EventLoopExtPumpEvents::pump_events`]: ./platform/pump_events/trait.EventLoopExtPumpEvents.html#tymethod.pump_events //! [`EventLoop::new()`]: event_loop::EventLoop::new //! [event_loop_run]: event_loop::EventLoop::run //! [`ControlFlow`]: event_loop::ControlFlow diff --git a/src/platform/mod.rs b/src/platform/mod.rs index 9dd965be..40c2bce1 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -13,7 +13,6 @@ //! //! - `run_ondemand` (available on `windows`, `unix`, `macos`, `android`) //! - `pump_events` (available on `windows`, `unix`, `macos`, `android`) -//! - `run_return` (available on `windows`, `unix`, `macos`, and `android`) //! //! However only the module corresponding to the platform you're compiling to will be available. @@ -54,15 +53,5 @@ pub mod run_ondemand; ))] pub mod pump_events; -#[cfg(any( - windows_platform, - macos_platform, - android_platform, - x11_platform, - wayland_platform, - orbital_platform -))] -pub mod run_return; - pub mod modifier_supplement; pub mod scancode; diff --git a/src/platform/run_return.rs b/src/platform/run_return.rs deleted file mode 100644 index 750b0416..00000000 --- a/src/platform/run_return.rs +++ /dev/null @@ -1,53 +0,0 @@ -use crate::{ - event::Event, - event_loop::{ControlFlow, EventLoop, EventLoopWindowTarget}, -}; - -/// Additional methods on [`EventLoop`] to return control flow to the caller. -pub trait EventLoopExtRunReturn { - /// A type provided by the user that can be passed through [`Event::UserEvent`]. - type UserEvent; - - /// Initializes the `winit` event loop. - /// - /// Unlike [`EventLoop::run`], this function accepts non-`'static` (i.e. non-`move`) closures - /// and returns control flow to the caller when `control_flow` is set to [`ControlFlow::Exit`]. - /// - /// # Caveats - /// - /// Despite its appearance at first glance, this is *not* a perfect replacement for - /// `poll_events`. For example, this function will not return on Windows or macOS while a - /// window is getting resized, resulting in all application logic outside of the - /// `event_handler` closure not running until the resize operation ends. Other OS operations - /// may also result in such freezes. This behavior is caused by fundamental limitations in the - /// underlying OS APIs, which cannot be hidden by `winit` without severe stability repercussions. - /// - /// You are strongly encouraged to use `run`, unless the use of this is absolutely necessary. - /// - /// ## Platform-specific - /// - /// - **X11 / Wayland:** This function returns `1` upon disconnection from - /// the display server. - fn run_return(&mut self, event_handler: F) -> i32 - where - F: FnMut( - Event<'_, Self::UserEvent>, - &EventLoopWindowTarget, - &mut ControlFlow, - ); -} - -impl EventLoopExtRunReturn for EventLoop { - type UserEvent = T; - - fn run_return(&mut self, event_handler: F) -> i32 - where - F: FnMut( - Event<'_, Self::UserEvent>, - &EventLoopWindowTarget, - &mut ControlFlow, - ), - { - self.event_loop.run_return(event_handler) - } -} diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index 99af2a5d..cb45db05 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -539,17 +539,6 @@ impl EventLoop { ::std::process::exit(exit_code); } - pub fn run_return(&mut self, callback: F) -> i32 - where - F: FnMut(event::Event<'_, T>, &RootELW, &mut ControlFlow), - { - match self.run_ondemand(callback) { - Err(RunLoopError::ExitFailure(code)) => code, - Err(_err) => 1, - Ok(_) => 0, - } - } - pub fn run_ondemand(&mut self, mut event_handler: F) -> Result<(), RunLoopError> where F: FnMut(event::Event<'_, T>, &event_loop::EventLoopWindowTarget, &mut ControlFlow), diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index aa9db961..b4e77dc9 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -830,13 +830,6 @@ impl EventLoop { x11_or_wayland!(match self; EventLoop(evlp) => evlp.create_proxy(); as EventLoopProxy) } - pub fn run_return(&mut self, callback: F) -> i32 - where - F: FnMut(crate::event::Event<'_, T>, &RootELW, &mut ControlFlow), - { - x11_or_wayland!(match self; EventLoop(evlp) => evlp.run_return(callback)) - } - pub fn run(self, callback: F) -> ! where F: 'static + FnMut(crate::event::Event<'_, T>, &RootELW, &mut ControlFlow), diff --git a/src/platform_impl/linux/wayland/event_loop/mod.rs b/src/platform_impl/linux/wayland/event_loop/mod.rs index 157ebfe0..7bd04d9b 100644 --- a/src/platform_impl/linux/wayland/event_loop/mod.rs +++ b/src/platform_impl/linux/wayland/event_loop/mod.rs @@ -157,17 +157,6 @@ impl EventLoop { ::std::process::exit(exit_code) } - pub fn run_return(&mut self, callback: F) -> i32 - where - F: FnMut(Event<'_, T>, &RootEventLoopWindowTarget, &mut ControlFlow), - { - match self.run_ondemand(callback) { - Err(RunLoopError::ExitFailure(code)) => code, - Err(_err) => 1, - Ok(_) => 0, - } - } - pub fn run_ondemand(&mut self, mut event_handler: F) -> Result<(), RunLoopError> where F: FnMut(Event<'_, T>, &RootEventLoopWindowTarget, &mut ControlFlow), diff --git a/src/platform_impl/linux/x11/mod.rs b/src/platform_impl/linux/x11/mod.rs index fd374b21..81929519 100644 --- a/src/platform_impl/linux/x11/mod.rs +++ b/src/platform_impl/linux/x11/mod.rs @@ -444,17 +444,6 @@ impl EventLoop { ::std::process::exit(exit_code) } - pub fn run_return(&mut self, callback: F) -> i32 - where - F: FnMut(Event<'_, T>, &RootELW, &mut ControlFlow), - { - match self.run_ondemand(callback) { - Err(RunLoopError::ExitFailure(code)) => code, - Err(_err) => 1, - Ok(_) => 0, - } - } - pub fn run_ondemand(&mut self, mut event_handler: F) -> Result<(), RunLoopError> where F: FnMut(Event<'_, T>, &RootELW, &mut ControlFlow), diff --git a/src/platform_impl/macos/event_loop.rs b/src/platform_impl/macos/event_loop.rs index 00f93c4b..e058259a 100644 --- a/src/platform_impl/macos/event_loop.rs +++ b/src/platform_impl/macos/event_loop.rs @@ -204,17 +204,6 @@ impl EventLoop { process::exit(exit_code); } - pub fn run_return(&mut self, callback: F) -> i32 - where - F: FnMut(Event<'_, T>, &RootWindowTarget, &mut ControlFlow), - { - match self.run_ondemand(callback) { - Err(RunLoopError::ExitFailure(code)) => code, - Err(_err) => 1, - Ok(_) => 0, - } - } - // NB: we don't base this on `pump_events` because for `MacOs` we can't support // `pump_events` elegantly (we just ask to run the loop for a "short" amount of // time and so a layered implementation would end up using a lot of CPU due to diff --git a/src/platform_impl/orbital/event_loop.rs b/src/platform_impl/orbital/event_loop.rs index 16cf6f41..0b23e5d5 100644 --- a/src/platform_impl/orbital/event_loop.rs +++ b/src/platform_impl/orbital/event_loop.rs @@ -301,15 +301,6 @@ impl EventLoop { } } - pub fn run(mut self, event_handler: F) -> ! - where - F: 'static - + FnMut(event::Event<'_, T>, &event_loop::EventLoopWindowTarget, &mut ControlFlow), - { - let exit_code = self.run_return(event_handler); - ::std::process::exit(exit_code); - } - fn process_event( window_id: WindowId, event_option: EventOption, @@ -451,9 +442,10 @@ impl EventLoop { } } - pub fn run_return(&mut self, mut event_handler_inner: F) -> i32 + pub fn run(mut self, event_handler: F) -> ! where - F: FnMut(event::Event<'_, T>, &event_loop::EventLoopWindowTarget, &mut ControlFlow), + F: 'static + + FnMut(event::Event<'_, T>, &event_loop::EventLoopWindowTarget, &mut ControlFlow), { // Wrapper for event handler function that prevents ExitWithCode from being unset. let mut event_handler = @@ -696,7 +688,7 @@ impl EventLoop { &mut control_flow, ); - code + ::std::process::exit(code); } pub fn window_target(&self) -> &event_loop::EventLoopWindowTarget { diff --git a/src/platform_impl/windows/event_loop.rs b/src/platform_impl/windows/event_loop.rs index 5e8c9ca2..7c45cbac 100644 --- a/src/platform_impl/windows/event_loop.rs +++ b/src/platform_impl/windows/event_loop.rs @@ -255,17 +255,6 @@ impl EventLoop { ::std::process::exit(exit_code); } - pub fn run_return(&mut self, event_handler: F) -> i32 - where - F: FnMut(Event<'_, T>, &RootELW, &mut ControlFlow), - { - match self.run_ondemand(event_handler) { - Err(RunLoopError::ExitFailure(code)) => code, - Err(_err) => 1, - Ok(_) => 0, - } - } - pub fn run_ondemand(&mut self, mut event_handler: F) -> Result<(), RunLoopError> where F: FnMut(Event<'_, T>, &RootELW, &mut ControlFlow),