Remove internal ActiveEventLoop::clear_exit

How to store and clear the internal state should be internal to the
implementation on each backend.
This commit is contained in:
Mads Marquart 2024-07-14 20:51:38 +02:00 committed by GitHub
parent 5b8f5cb54a
commit ee3ab33a7c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 12 additions and 21 deletions

View file

@ -1,8 +1,10 @@
use crate::application::ApplicationHandler; use crate::application::ApplicationHandler;
use crate::error::EventLoopError; use crate::error::EventLoopError;
use crate::event_loop::{ActiveEventLoop, EventLoop}; use crate::event_loop::EventLoop;
#[cfg(doc)] #[cfg(doc)]
use crate::{platform::pump_events::EventLoopExtPumpEvents, window::Window}; use crate::{
event_loop::ActiveEventLoop, platform::pump_events::EventLoopExtPumpEvents, window::Window,
};
/// Additional methods on [`EventLoop`] to return control flow to the caller. /// Additional methods on [`EventLoop`] to return control flow to the caller.
pub trait EventLoopExtRunOnDemand { pub trait EventLoopExtRunOnDemand {
@ -63,18 +65,10 @@ pub trait EventLoopExtRunOnDemand {
impl EventLoopExtRunOnDemand for EventLoop { impl EventLoopExtRunOnDemand for EventLoop {
fn run_app_on_demand<A: ApplicationHandler>(&mut self, app: A) -> Result<(), EventLoopError> { fn run_app_on_demand<A: ApplicationHandler>(&mut self, app: A) -> Result<(), EventLoopError> {
self.event_loop.window_target().clear_exit();
self.event_loop.run_app_on_demand(app) self.event_loop.run_app_on_demand(app)
} }
} }
impl ActiveEventLoop {
/// Clear exit status.
pub(crate) fn clear_exit(&self) {
self.p.clear_exit()
}
}
/// ```compile_fail /// ```compile_fail
/// use winit::event_loop::EventLoop; /// use winit::event_loop::EventLoop;
/// use winit::platform::run_on_demand::EventLoopExtRunOnDemand; /// use winit::platform::run_on_demand::EventLoopExtRunOnDemand;

View file

@ -425,6 +425,7 @@ impl EventLoop {
&mut self, &mut self,
mut app: A, mut app: A,
) -> Result<(), EventLoopError> { ) -> Result<(), EventLoopError> {
self.window_target.p.clear_exit();
loop { loop {
match self.pump_app_events(None, &mut app) { match self.pump_app_events(None, &mut app) {
PumpStatus::Exit(0) => { PumpStatus::Exit(0) => {

View file

@ -129,10 +129,6 @@ impl ActiveEventLoop {
self.delegate.exit() self.delegate.exit()
} }
pub(crate) fn clear_exit(&self) {
self.delegate.clear_exit()
}
pub(crate) fn exiting(&self) -> bool { pub(crate) fn exiting(&self) -> bool {
self.delegate.exiting() self.delegate.exiting()
} }
@ -255,6 +251,7 @@ impl EventLoop {
&mut self, &mut self,
mut app: A, mut app: A,
) -> Result<(), EventLoopError> { ) -> Result<(), EventLoopError> {
self.delegate.clear_exit();
self.delegate.set_event_handler(&mut app, || { self.delegate.set_event_handler(&mut app, || {
autoreleasepool(|_| { autoreleasepool(|_| {
// clear / normalize pump_events state // clear / normalize pump_events state

View file

@ -904,7 +904,7 @@ impl ActiveEventLoop {
x11_or_wayland!(match self; Self(evlp) => evlp.control_flow()) x11_or_wayland!(match self; Self(evlp) => evlp.control_flow())
} }
pub(crate) fn clear_exit(&self) { fn clear_exit(&self) {
x11_or_wayland!(match self; Self(evlp) => evlp.clear_exit()) x11_or_wayland!(match self; Self(evlp) => evlp.clear_exit())
} }
@ -925,12 +925,10 @@ impl ActiveEventLoop {
} }
} }
#[allow(dead_code)]
fn set_exit_code(&self, code: i32) { fn set_exit_code(&self, code: i32) {
x11_or_wayland!(match self; Self(evlp) => evlp.set_exit_code(code)) x11_or_wayland!(match self; Self(evlp) => evlp.set_exit_code(code))
} }
#[allow(dead_code)]
fn exit_code(&self) -> Option<i32> { fn exit_code(&self) -> Option<i32> {
x11_or_wayland!(match self; Self(evlp) => evlp.exit_code()) x11_or_wayland!(match self; Self(evlp) => evlp.exit_code())
} }

View file

@ -168,6 +168,7 @@ impl EventLoop {
&mut self, &mut self,
mut app: A, mut app: A,
) -> Result<(), EventLoopError> { ) -> Result<(), EventLoopError> {
self.window_target.p.clear_exit();
let exit = loop { let exit = loop {
match self.pump_app_events(None, &mut app) { match self.pump_app_events(None, &mut app) {
PumpStatus::Exit(0) => { PumpStatus::Exit(0) => {

View file

@ -375,6 +375,7 @@ impl EventLoop {
&mut self, &mut self,
mut app: A, mut app: A,
) -> Result<(), EventLoopError> { ) -> Result<(), EventLoopError> {
self.event_processor.target.p.clear_exit();
let exit = loop { let exit = loop {
match self.pump_app_events(None, &mut app) { match self.pump_app_events(None, &mut app) {
PumpStatus::Exit(0) => { PumpStatus::Exit(0) => {
@ -600,13 +601,11 @@ impl EventLoop {
} }
fn set_exit_code(&self, code: i32) { fn set_exit_code(&self, code: i32) {
let window_target = EventProcessor::window_target(&self.event_processor.target); self.window_target().p.set_exit_code(code);
window_target.set_exit_code(code);
} }
fn exit_code(&self) -> Option<i32> { fn exit_code(&self) -> Option<i32> {
let window_target = EventProcessor::window_target(&self.event_processor.target); self.window_target().p.exit_code()
window_target.exit_code()
} }
} }

View file

@ -195,6 +195,7 @@ impl EventLoop {
&mut self, &mut self,
mut app: A, mut app: A,
) -> Result<(), EventLoopError> { ) -> Result<(), EventLoopError> {
self.window_target.p.clear_exit();
{ {
let runner = &self.window_target.p.runner_shared; let runner = &self.window_target.p.runner_shared;