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::error::EventLoopError;
use crate::event_loop::{ActiveEventLoop, EventLoop};
use crate::event_loop::EventLoop;
#[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.
pub trait EventLoopExtRunOnDemand {
@ -63,18 +65,10 @@ pub trait EventLoopExtRunOnDemand {
impl EventLoopExtRunOnDemand for EventLoop {
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)
}
}
impl ActiveEventLoop {
/// Clear exit status.
pub(crate) fn clear_exit(&self) {
self.p.clear_exit()
}
}
/// ```compile_fail
/// use winit::event_loop::EventLoop;
/// use winit::platform::run_on_demand::EventLoopExtRunOnDemand;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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