Skip to content

Conversation

@marcpabst
Copy link

@marcpabst marcpabst commented Nov 17, 2025

These are the minimal code changes I could get away with to enable starting a EventLoop with an already-running UIApplication. The use case would be running winit-based apps inside any sort of already-running app on iOS, either from a native SwiftUI/Objective-C application or via Python/PyO3. Basically any case were you can't/don't want to control when UIApplicationMain is called.

Please treat this as a starting point for discussion! Feedback is very welcome.

There are some major limitations at the moment:

  1. Currently, run_app blocks indefinitely by parking the calling thread. This is obviously not great for several reasons, and it also means you can't create the EventLoop on the main thread.
  2. You need to provide your own (unchecked) MainThreadMarker. In my testing this did not cause problems (as the callbacks that contain the code that calls into UIKit still run on the main thread), but it is massively unsafe and likely invites potential unsoundness.
  3. There is no good way to return from an EventLoop. I'm actually not sure what the best approach is here. One could either:
    (a) Adopt a web-style register_app that returns immediately and then provide a way to signal that the app has finished running, or (b) provide a run_app that blocks for the duration of the app and then returns. The latter would obviously require calling it from a new thread.
  4. I believe you can't run multiple winit instances simultaneously because they name custom Objective-C classes the same way. Not problem when you can't run more than one EventLoop per UIApplication, but problematic once you lift that restriction. This could potentially be addressed by generating unique names at runtime (?).

Please let me know what you think!

  • Tested on all platforms changed
  • Added an entry to the changelog module if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • Created or updated an example program if it would help users understand this functionality

@marcpabst marcpabst requested a review from madsmtm as a code owner November 17, 2025 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant