Skip to content

Commit

Permalink
Remove internal ActiveEventLoop::clear_exit
Browse files Browse the repository at this point in the history
How to store and clear the internal state should be internal to the
implementation on each backend.
  • Loading branch information
madsmtm authored Jul 14, 2024
1 parent 5b8f5cb commit ee3ab33
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 21 deletions.
14 changes: 4 additions & 10 deletions src/platform/run_on_demand.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/platform_impl/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
5 changes: 1 addition & 4 deletions src/platform_impl/apple/appkit/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions src/platform_impl/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand All @@ -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())
}
Expand Down
1 change: 1 addition & 0 deletions src/platform_impl/linux/wayland/event_loop/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
7 changes: 3 additions & 4 deletions src/platform_impl/linux/x11/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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()
}
}

Expand Down
1 change: 1 addition & 0 deletions src/platform_impl/windows/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit ee3ab33

Please sign in to comment.