Rename LoopDestroyed to LoopExiting

Considering the possibility of re-running an event loop via run_ondemand
then it's more correct to say that the loop is about to exit without
assuming it's going to be destroyed.
This commit is contained in:
Robert Bragg 2023-07-28 17:19:53 +01:00 committed by GitHub
parent 755c533b08
commit 935146d299
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 28 additions and 30 deletions

View file

@ -30,6 +30,7 @@ And please only add new entries to the top of this list, right below the `# Unre
- **Breaking** Removed `EventLoopExtRunReturn` / `run_return` in favor of `EventLoopExtPumpEvents` / `pump_events` and `EventLoopExtRunOnDemand` / `run_ondemand` ([#2767](https://github.com/rust-windowing/winit/pull/2767)) - **Breaking** Removed `EventLoopExtRunReturn` / `run_return` in favor of `EventLoopExtPumpEvents` / `pump_events` and `EventLoopExtRunOnDemand` / `run_ondemand` ([#2767](https://github.com/rust-windowing/winit/pull/2767))
- `RedrawRequested` is no longer guaranteed to be emitted after `MainEventsCleared`, it is now platform-specific when the event is emitted after being requested via `redraw_request()`. - `RedrawRequested` is no longer guaranteed to be emitted after `MainEventsCleared`, it is now platform-specific when the event is emitted after being requested via `redraw_request()`.
- On Windows, `RedrawRequested` is now driven by `WM_PAINT` messages which are requested via `redraw_request()` - On Windows, `RedrawRequested` is now driven by `WM_PAINT` messages which are requested via `redraw_request()`
- **Breaking** `LoopDestroyed` renamed to `LoopExiting` ([#2900](https://github.com/rust-windowing/winit/issues/2900))
# 0.29.0-beta.0 # 0.29.0-beta.0

View file

@ -26,7 +26,7 @@
//! start_cause = wait_if_necessary(control_flow); //! start_cause = wait_if_necessary(control_flow);
//! } //! }
//! //!
//! event_handler(LoopDestroyed, ..., &mut control_flow); //! event_handler(LoopExiting, ..., &mut control_flow);
//! ``` //! ```
//! //!
//! This leaves out timing details like [`ControlFlow::WaitUntil`] but hopefully //! This leaves out timing details like [`ControlFlow::WaitUntil`] but hopefully
@ -258,7 +258,7 @@ pub enum Event<'a, T: 'static> {
/// ///
/// This is irreversible - if this event is emitted, it is guaranteed to be the last event that /// This is irreversible - if this event is emitted, it is guaranteed to be the last event that
/// gets emitted. You generally want to treat this as a "do on quit" event. /// gets emitted. You generally want to treat this as a "do on quit" event.
LoopDestroyed, LoopExiting,
} }
impl<T: Clone> Clone for Event<'static, T> { impl<T: Clone> Clone for Event<'static, T> {
@ -278,7 +278,7 @@ impl<T: Clone> Clone for Event<'static, T> {
MainEventsCleared => MainEventsCleared, MainEventsCleared => MainEventsCleared,
RedrawRequested(wid) => RedrawRequested(*wid), RedrawRequested(wid) => RedrawRequested(*wid),
RedrawEventsCleared => RedrawEventsCleared, RedrawEventsCleared => RedrawEventsCleared,
LoopDestroyed => LoopDestroyed, LoopExiting => LoopExiting,
Suspended => Suspended, Suspended => Suspended,
Resumed => Resumed, Resumed => Resumed,
} }
@ -297,7 +297,7 @@ impl<'a, T> Event<'a, T> {
MainEventsCleared => Ok(MainEventsCleared), MainEventsCleared => Ok(MainEventsCleared),
RedrawRequested(wid) => Ok(RedrawRequested(wid)), RedrawRequested(wid) => Ok(RedrawRequested(wid)),
RedrawEventsCleared => Ok(RedrawEventsCleared), RedrawEventsCleared => Ok(RedrawEventsCleared),
LoopDestroyed => Ok(LoopDestroyed), LoopExiting => Ok(LoopExiting),
Suspended => Ok(Suspended), Suspended => Ok(Suspended),
Resumed => Ok(Resumed), Resumed => Ok(Resumed),
} }
@ -317,7 +317,7 @@ impl<'a, T> Event<'a, T> {
MainEventsCleared => Some(MainEventsCleared), MainEventsCleared => Some(MainEventsCleared),
RedrawRequested(wid) => Some(RedrawRequested(wid)), RedrawRequested(wid) => Some(RedrawRequested(wid)),
RedrawEventsCleared => Some(RedrawEventsCleared), RedrawEventsCleared => Some(RedrawEventsCleared),
LoopDestroyed => Some(LoopDestroyed), LoopExiting => Some(LoopExiting),
Suspended => Some(Suspended), Suspended => Some(Suspended),
Resumed => Some(Resumed), Resumed => Some(Resumed),
} }

View file

@ -181,7 +181,7 @@ pub enum ControlFlow {
/// [`Poll`]: Self::Poll /// [`Poll`]: Self::Poll
WaitUntil(Instant), WaitUntil(Instant),
/// Send a [`LoopDestroyed`] event and stop the event loop. This variant is *sticky* - once set, /// Send a [`LoopExiting`] event and stop the event loop. This variant is *sticky* - once set,
/// `control_flow` cannot be changed from `ExitWithCode`, and any future attempts to do so will /// `control_flow` cannot be changed from `ExitWithCode`, and any future attempts to do so will
/// result in the `control_flow` parameter being reset to `ExitWithCode`. /// result in the `control_flow` parameter being reset to `ExitWithCode`.
/// ///
@ -195,7 +195,7 @@ pub enum ControlFlow {
/// which can cause surprises with negative exit values (`-42` would end up as `214`). See /// which can cause surprises with negative exit values (`-42` would end up as `214`). See
/// [`std::process::exit`]. /// [`std::process::exit`].
/// ///
/// [`LoopDestroyed`]: Event::LoopDestroyed /// [`LoopExiting`]: Event::LoopExiting
/// [`Exit`]: ControlFlow::Exit /// [`Exit`]: ControlFlow::Exit
ExitWithCode(i32), ExitWithCode(i32),
} }

View file

@ -32,7 +32,7 @@
//! dispatch events for every [`Window`] that was created with that particular [`EventLoop`], and //! dispatch events for every [`Window`] that was created with that particular [`EventLoop`], and
//! will run until the `control_flow` argument given to the closure is set to //! will run until the `control_flow` argument given to the closure is set to
//! [`ControlFlow`]`::`[`ExitWithCode`] (which [`ControlFlow`]`::`[`Exit`] aliases to), at which //! [`ControlFlow`]`::`[`ExitWithCode`] (which [`ControlFlow`]`::`[`Exit`] aliases to), at which
//! point [`Event`]`::`[`LoopDestroyed`] is emitted and the entire program terminates. //! point [`Event`]`::`[`LoopExiting`] is emitted and the entire program terminates.
//! //!
//! Winit no longer uses a `EventLoop::poll_events() -> impl Iterator<Event>`-based event loop //! Winit no longer uses a `EventLoop::poll_events() -> impl Iterator<Event>`-based event loop
//! model, since that can't be implemented properly on some platforms (e.g web, iOS) and works poorly on //! model, since that can't be implemented properly on some platforms (e.g web, iOS) and works poorly on
@ -126,7 +126,7 @@
//! [`WindowEvent`]: event::WindowEvent //! [`WindowEvent`]: event::WindowEvent
//! [`DeviceEvent`]: event::DeviceEvent //! [`DeviceEvent`]: event::DeviceEvent
//! [`UserEvent`]: event::Event::UserEvent //! [`UserEvent`]: event::Event::UserEvent
//! [`LoopDestroyed`]: event::Event::LoopDestroyed //! [`LoopExiting`]: event::Event::LoopExiting
//! [`platform`]: platform //! [`platform`]: platform
//! [`raw_window_handle`]: ./window/struct.Window.html#method.raw_window_handle //! [`raw_window_handle`]: ./window/struct.Window.html#method.raw_window_handle
//! [`raw_display_handle`]: ./window/struct.Window.html#method.raw_display_handle //! [`raw_display_handle`]: ./window/struct.Window.html#method.raw_display_handle

View file

@ -585,7 +585,7 @@ impl<T: 'static> EventLoop<T> {
let mut dummy = self.control_flow; let mut dummy = self.control_flow;
sticky_exit_callback( sticky_exit_callback(
event::Event::LoopDestroyed, event::Event::LoopExiting,
self.window_target(), self.window_target(),
&mut dummy, &mut dummy,
&mut callback, &mut callback,

View file

@ -444,10 +444,7 @@ impl AppState {
fn terminated_transition(&mut self) -> Box<dyn EventHandler> { fn terminated_transition(&mut self) -> Box<dyn EventHandler> {
match self.replace_state(AppStateImpl::Terminated) { match self.replace_state(AppStateImpl::Terminated) {
AppStateImpl::ProcessingEvents { event_handler, .. } => event_handler, AppStateImpl::ProcessingEvents { event_handler, .. } => event_handler,
s => bug!( s => bug!("`LoopExiting` happened while not processing events {:?}", s),
"`LoopDestroyed` happened while not processing events {:?}",
s
),
} }
} }
} }
@ -785,7 +782,7 @@ pub unsafe fn terminated() {
let mut control_flow = this.control_flow; let mut control_flow = this.control_flow;
drop(this); drop(this);
event_handler.handle_nonuser_event(Event::LoopDestroyed, &mut control_flow) event_handler.handle_nonuser_event(Event::LoopExiting, &mut control_flow)
} }
fn handle_event_proxy( fn handle_event_proxy(

View file

@ -48,12 +48,12 @@
//! //!
//! - applicationDidBecomeActive is Resumed //! - applicationDidBecomeActive is Resumed
//! - applicationWillResignActive is Suspended //! - applicationWillResignActive is Suspended
//! - applicationWillTerminate is LoopDestroyed //! - applicationWillTerminate is LoopExiting
//! //!
//! Keep in mind that after LoopDestroyed event is received every attempt to draw with //! Keep in mind that after LoopExiting event is received every attempt to draw with
//! opengl will result in segfault. //! opengl will result in segfault.
//! //!
//! Also note that app may not receive the LoopDestroyed event if suspended; it might be SIGKILL'ed. //! Also note that app may not receive the LoopExiting event if suspended; it might be SIGKILL'ed.
#![cfg(ios_platform)] #![cfg(ios_platform)]
#![allow(clippy::let_unit_value)] #![allow(clippy::let_unit_value)]

View file

@ -202,7 +202,7 @@ impl<T: 'static> EventLoop<T> {
let mut dummy = self.control_flow; let mut dummy = self.control_flow;
sticky_exit_callback( sticky_exit_callback(
Event::LoopDestroyed, Event::LoopExiting,
self.window_target(), self.window_target(),
&mut dummy, &mut dummy,
&mut callback, &mut callback,

View file

@ -492,7 +492,7 @@ impl<T: 'static> EventLoop<T> {
let mut dummy = self.control_flow; let mut dummy = self.control_flow;
sticky_exit_callback( sticky_exit_callback(
Event::LoopDestroyed, Event::LoopExiting,
self.window_target(), self.window_target(),
&mut dummy, &mut dummy,
&mut callback, &mut callback,

View file

@ -436,7 +436,7 @@ impl AppState {
pub fn exit() -> i32 { pub fn exit() -> i32 {
HANDLER.set_in_callback(true); HANDLER.set_in_callback(true);
HANDLER.handle_nonuser_event(EventWrapper::StaticEvent(Event::LoopDestroyed)); HANDLER.handle_nonuser_event(EventWrapper::StaticEvent(Event::LoopExiting));
HANDLER.set_in_callback(false); HANDLER.set_in_callback(false);
HANDLER.exit(); HANDLER.exit();
Self::clear_callback(); Self::clear_callback();

View file

@ -64,7 +64,7 @@ extern "C" fn control_flow_begin_handler(
} }
// end is queued with the lowest priority to ensure it is processed after other observers // end is queued with the lowest priority to ensure it is processed after other observers
// without that, LoopDestroyed would get sent after MainEventsCleared // without that, LoopExiting would get sent after MainEventsCleared
extern "C" fn control_flow_end_handler( extern "C" fn control_flow_end_handler(
_: CFRunLoopObserverRef, _: CFRunLoopObserverRef,
activity: CFRunLoopActivity, activity: CFRunLoopActivity,

View file

@ -684,7 +684,7 @@ impl<T: 'static> EventLoop<T> {
}; };
event_handler( event_handler(
event::Event::LoopDestroyed, event::Event::LoopExiting,
&self.window_target, &self.window_target,
&mut control_flow, &mut control_flow,
); );

View file

@ -585,7 +585,7 @@ impl<T: 'static> Shared<T> {
let mut control = self.current_control_flow(); let mut control = self.current_control_flow();
// We don't call `handle_loop_destroyed` here because we don't need to // We don't call `handle_loop_destroyed` here because we don't need to
// perform cleanup when the web browser is going to destroy the page. // perform cleanup when the web browser is going to destroy the page.
self.handle_event(Event::LoopDestroyed, &mut control); self.handle_event(Event::LoopExiting, &mut control);
} }
// handle_event takes in events and either queues them or applies a callback // handle_event takes in events and either queues them or applies a callback
@ -665,7 +665,7 @@ impl<T: 'static> Shared<T> {
} }
fn handle_loop_destroyed(&self, control: &mut ControlFlow) { fn handle_loop_destroyed(&self, control: &mut ControlFlow) {
self.handle_event(Event::LoopDestroyed, control); self.handle_event(Event::LoopExiting, control);
let all_canvases = std::mem::take(&mut *self.0.all_canvases.borrow_mut()); let all_canvases = std::mem::take(&mut *self.0.all_canvases.borrow_mut());
*self.0.page_transition_event_handle.borrow_mut() = None; *self.0.page_transition_event_handle.borrow_mut() = None;
*self.0.on_mouse_move.borrow_mut() = None; *self.0.on_mouse_move.borrow_mut() = None;

View file

@ -341,7 +341,7 @@ impl<T: 'static> EventLoop<T> {
}; };
// We wait until we've checked for an exit status before clearing the // We wait until we've checked for an exit status before clearing the
// application callback, in case we need to dispatch a LoopDestroyed event // application callback, in case we need to dispatch a LoopExiting event
// //
// # Safety // # Safety
// This pairs up with our call to `runner.set_event_handler` and ensures // This pairs up with our call to `runner.set_event_handler` and ensures

View file

@ -251,7 +251,7 @@ impl<T> EventLoopRunner<T> {
} }
/// Dispatch control flow events (`NewEvents`, `MainEventsCleared`, `RedrawEventsCleared`, and /// Dispatch control flow events (`NewEvents`, `MainEventsCleared`, `RedrawEventsCleared`, and
/// `LoopDestroyed`) as necessary to bring the internal `RunnerState` to the new runner state. /// `LoopExiting`) as necessary to bring the internal `RunnerState` to the new runner state.
/// ///
/// The state transitions are defined as follows: /// The state transitions are defined as follows:
/// ///
@ -298,7 +298,7 @@ impl<T> EventLoopRunner<T> {
self.call_new_events(true); self.call_new_events(true);
self.call_event_handler(Event::MainEventsCleared); self.call_event_handler(Event::MainEventsCleared);
self.call_redraw_events_cleared(); self.call_redraw_events_cleared();
self.call_event_handler(Event::LoopDestroyed); self.call_event_handler(Event::LoopExiting);
} }
(_, Uninitialized) => panic!("cannot move state to Uninitialized"), (_, Uninitialized) => panic!("cannot move state to Uninitialized"),
@ -307,7 +307,7 @@ impl<T> EventLoopRunner<T> {
self.call_new_events(false); self.call_new_events(false);
} }
(Idle, Destroyed) => { (Idle, Destroyed) => {
self.call_event_handler(Event::LoopDestroyed); self.call_event_handler(Event::LoopExiting);
} }
(HandlingMainEvents, Idle) => { (HandlingMainEvents, Idle) => {
@ -317,7 +317,7 @@ impl<T> EventLoopRunner<T> {
(HandlingMainEvents, Destroyed) => { (HandlingMainEvents, Destroyed) => {
self.call_event_handler(Event::MainEventsCleared); self.call_event_handler(Event::MainEventsCleared);
self.call_redraw_events_cleared(); self.call_redraw_events_cleared();
self.call_event_handler(Event::LoopDestroyed); self.call_event_handler(Event::LoopExiting);
} }
(Destroyed, _) => panic!("cannot move state from Destroyed"), (Destroyed, _) => panic!("cannot move state from Destroyed"),