Skip to content

Commit

Permalink
MacOS: Implement EventLoopExtPumpEvents and EventLoopExtRunOnDemand
Browse files Browse the repository at this point in the history
The implementation of `pump_events` essentially works by hooking into the
`RunLoopObserver` and requesting that the app should be stopped the next time
that the `RunLoop` prepares to wait for new events.

Originally I had thought I would poke the `CFRunLoop` for the app directly and
I was originally going to implement `pump_events` based on a timeout which I'd
seen SDL doing.

I found that `[NSApp run]` wasn't actually being stopped by asking the RunLoop
to stop directly and inferred that `NSApp run` will actually catch this and
re-start the loop.

Hooking into the observer and calling `[NSApp stop]` actually seems like a
better solution that doesn't need a hacky constant timeout.

The end result is quite similar to what happens with existing apps that
call `run_return` inside an external loop and cause the loop to exit for
each iteration (that also results in the `NSApp` stopping each
iteration).
  • Loading branch information
rib committed Jun 26, 2023
1 parent 3ff905d commit ac89238
Show file tree
Hide file tree
Showing 3 changed files with 413 additions and 48 deletions.
8 changes: 4 additions & 4 deletions src/platform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
//!
//! And the following platform-specific modules:
//!
//! - `run_ondemand` (available on `windows`, `android`)
//! - `pump_events` (available on `windows`, `android`)
//! - `run_ondemand` (available on `windows`, `macos`, `android`)
//! - `pump_events` (available on `windows`, `macos`, `android`)
//! - `run_return` (available on `windows`, `unix`, `macos`, and `android`)
//!
//! However only the module corresponding to the platform you're compiling to will be available.
Expand All @@ -34,10 +34,10 @@ pub mod windows;
#[cfg(x11_platform)]
pub mod x11;

#[cfg(any(windows_platform, android_platform))]
#[cfg(any(windows_platform, macos_platform, android_platform))]
pub mod run_ondemand;

#[cfg(any(windows_platform, android_platform,))]
#[cfg(any(windows_platform, macos_platform, android_platform,))]
pub mod pump_events;

#[cfg(any(
Expand Down
Loading

0 comments on commit ac89238

Please sign in to comment.