Skip to content

Commit

Permalink
Remove EventLoopError::AlreadyRunning
Browse files Browse the repository at this point in the history
This is already prevented by the type-system, and as such it doesn't
make sense to have an error case for this.
  • Loading branch information
madsmtm authored Jan 29, 2024
1 parent f204467 commit f526a47
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Unreleased` header.
- on Windows: add `with_system_backdrop`, `with_border_color`, `with_title_background_color`, `with_title_text_color` and `with_corner_preference`
- On Windows, Remove `WS_CAPTION`, `WS_BORDER` and `WS_EX_WINDOWEDGE` styles for child windows without decorations.
- On Windows, fixed a race condition when sending an event through the loop proxy.
- **Breaking:** Removed `EventLoopError::AlreadyRunning`, which can't happen as it is already prevented by the type system.

# 0.29.10

Expand Down
3 changes: 0 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ pub enum EventLoopError {
NotSupported(NotSupportedError),
/// The OS cannot perform the operation.
Os(OsError),
/// The event loop can't be re-run while it's already running
AlreadyRunning,
/// The event loop can't be re-created.
RecreationAttempt,
/// Application has exit with an error status.
Expand Down Expand Up @@ -105,7 +103,6 @@ impl fmt::Display for NotSupportedError {
impl fmt::Display for EventLoopError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
match self {
EventLoopError::AlreadyRunning => write!(f, "EventLoop is already running"),
EventLoopError::RecreationAttempt => write!(f, "EventLoop can't be recreated"),
EventLoopError::NotSupported(e) => e.fmt(f),
EventLoopError::Os(e) => e.fmt(f),
Expand Down
15 changes: 14 additions & 1 deletion src/platform/run_on_demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub trait EventLoopExtRunOnDemand {
/// loop that would block the browser and there is nothing that can be
/// polled to ask for new events. Events are delivered via callbacks based
/// on an event loop that is internal to the browser itself.
/// - **iOS:** It's not possible to stop and start an `NSApplication` repeatedly on iOS.
/// - **iOS:** It's not possible to stop and start an `UIApplication` repeatedly on iOS.
///
#[cfg_attr(
not(web_platform),
Expand Down Expand Up @@ -87,3 +87,16 @@ impl EventLoopWindowTarget {
self.p.clear_exit()
}
}

/// ```compile_fail
/// use winit::event_loop::EventLoop;
/// use winit::platform::run_on_demand::EventLoopExtRunOnDemand;
///
/// let mut event_loop = EventLoop::new().unwrap();
/// event_loop.run_on_demand(|_, _| {
/// // Attempt to run the event loop re-entrantly; this must fail.
/// event_loop.run_on_demand(|_, _| {});
/// });
/// ```
#[allow(dead_code)]
fn test_run_on_demand_cannot_access_event_loop() {}
4 changes: 0 additions & 4 deletions src/platform_impl/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,6 @@ impl<T: 'static> EventLoop<T> {
where
F: FnMut(event::Event<T>, &event_loop::EventLoopWindowTarget),
{
if self.loop_running {
return Err(EventLoopError::AlreadyRunning);
}

loop {
match self.pump_events(None, &mut event_handler) {
PumpStatus::Exit(0) => {
Expand Down
4 changes: 0 additions & 4 deletions src/platform_impl/linux/wayland/event_loop/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,6 @@ impl<T: 'static> EventLoop<T> {
where
F: FnMut(Event<T>, &RootEventLoopWindowTarget),
{
if self.loop_running {
return Err(EventLoopError::AlreadyRunning);
}

let exit = loop {
match self.pump_events(None, &mut event_handler) {
PumpStatus::Exit(0) => {
Expand Down
4 changes: 0 additions & 4 deletions src/platform_impl/linux/x11/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,6 @@ impl<T: 'static> EventLoop<T> {
where
F: FnMut(Event<T>, &RootELW),
{
if self.loop_running {
return Err(EventLoopError::AlreadyRunning);
}

let exit = loop {
match self.pump_events(None, &mut event_handler) {
PumpStatus::Exit(0) => {
Expand Down
4 changes: 0 additions & 4 deletions src/platform_impl/macos/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,6 @@ impl<T> EventLoop<T> {
where
F: FnMut(Event<T>, &RootWindowTarget),
{
if self.delegate.is_running() {
return Err(EventLoopError::AlreadyRunning);
}

let callback = map_user_event(callback, self.receiver.clone());

// # Safety
Expand Down
5 changes: 0 additions & 5 deletions src/platform_impl/windows/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ use crate::{
};
use runner::{EventLoopRunner, EventLoopRunnerShared};

use self::runner::RunnerState;

use super::{window::set_skip_taskbar, SelectedCursor};

/// some backends like macos uses an uninhabited `Never` type,
Expand Down Expand Up @@ -246,9 +244,6 @@ impl<T: 'static> EventLoop<T> {
{
{
let runner = &self.window_target.p.runner_shared;
if runner.state() != RunnerState::Uninitialized {
return Err(EventLoopError::AlreadyRunning);
}

let event_loop_windows_ref = &self.window_target;
let user_event_receiver = &self.user_event_receiver;
Expand Down
4 changes: 0 additions & 4 deletions src/platform_impl/windows/event_loop/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,6 @@ impl<T> EventLoopRunner<T> {
}
}

pub fn state(&self) -> RunnerState {
self.runner_state.get()
}

pub fn set_control_flow(&self, control_flow: ControlFlow) {
self.control_flow.set(control_flow)
}
Expand Down

0 comments on commit f526a47

Please sign in to comment.