Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On Unix, expose a way to register file descriptors into the polling loop #3592

Open
notgull opened this issue Mar 17, 2024 · 4 comments
Open
Labels
D - hard Likely harder than most tasks here DS - wayland DS - x11 S - api Design and usability

Comments

@notgull
Copy link
Member

notgull commented Mar 17, 2024

Under the hood both Unix backends use calloop, which supports registering arbitrary file descriptors through the polling crate. However, winit usually isn't the only thing running in the GUI system; there's also zbus, accesskit and other things. It would be nice if you could register these systems into winit and poll them without needing to spawn another thread.

Two potential options here:

  • Expose a way to register file descriptors in calloop, then receive events as normal through the winit event loop. Then expose a higher-level I/O mechanism in another crate.
  • Port from calloop to async-io. This would take a lot more work and be more controversial, but it would allow for seamless integration with zbus.

cc AccessKit/accesskit#337 (comment), @mwcampbell

@notgull notgull added D - hard Likely harder than most tasks here DS - wayland DS - x11 S - api Design and usability labels Mar 17, 2024
@notgull notgull added this to the Version 0.31.0 milestone Mar 17, 2024
@kchibisov
Copy link
Member

This would take a lot more work and be more controversial, but it would allow for seamless integration with zbus.

zbus is a really poor argument to all of that, since it's the most complicated and bizarre library I've ever used. But generally allowing inserting sources into winit's event loop is a desired solution.

I'd also say that winit should be the one controlling the loop on all the platforms in one way or another, thus it should allow registration of sources on all of them. Otherwise it should be left to a specific backend.

@mwcampbell
Copy link

Unfortunately for what we want to do here, zbus doesn't let you get a file descriptor for the connection and drive the I/O yourself; it can only use async-io or tokio. But I've come to appreciate the calloop style of event handling and async I/O in Rust, where the application controls the event loop and maintains sole ownership of mutable state. So ideally I'd like a pure-Rust D-Bus implementation that integrates easily with calloop, without necessarily being coupled to it, just as wayland-rs isn't tightly coupled to calloop. But that would be too much of a distraction from my current work. Anyway, I think winit's support for FD event sources should be designed such that it would work well with such a D-Bus implementation.

@kchibisov
Copy link
Member

The current state of winit allows you to plug its fd into your own event loop and poll it on demand, however I'd also like to have some kind of executor eventually, so you can plug things into winit itself.

@mwcampbell
Copy link

Yes, plugging things into winit is what I'd prefer, because that way AccessKit could handle D-Bus events on the main thread, possibly with access to the same mutable application state as the regular winit event handler, without requiring the application to replace its event loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
D - hard Likely harder than most tasks here DS - wayland DS - x11 S - api Design and usability
Development

No branches or pull requests

3 participants