-
Notifications
You must be signed in to change notification settings - Fork 948
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
Remove Sync and Clone from EventsLoop. Add EventsLoopProxy. #191
Conversation
This commit only updates the top-level API to get some early feedback. None of the platform-specific code has been updated yet. I'm hoping to get around to this over the next couple days however if someone more familiar with the windows backend would like to do a PR against this fork that would be a great help. Closes rust-windowing#187.
X11 and Wayland implementations are now half implemented, however both still do not correctly break from the inner blocking event dispatch functions when `wakeup` is called, which they should do.
c2d3941
to
f6587ae
Compare
…tch when wakeup is called
The wayland backend is now implemented and the x11 implementation is halfway there. |
…e updated to non-window-specific Event.
OK I believe all backends have been implemented now! windows, android and iOS are still using the This should now be ready for review. |
General design question, as the eventsloop is no longer intended to be shared and we have a proxy, wouldn't it make sense to:
Doing both of this could simplify greatly the internal implementation (it'd possibly remove a few synchronisation/locking primitives in the wayland backend, for example), while not really changing the ergonomics of the eventsloop. Given this PR is a breaking change any way... |
@vberger the ability to Now that you mention it though, I agree that both pub enum ControlFlow {
Continue,
Complete,
} Or something along these lines? That way |
@tomaka what are your thoughts on my previous comment ^ ? I'm happy to go ahead and make the change, but it would be nice to get some feedback before going ahead as the change will take a bit of time to implement across all backends. |
This removes the need for the EventsLoop::interrupt method by inroducing a ControlFlow type. This new type is to be returned by the user's callback and indicates whether the `EventsLoop` should continue waiting for events or break from the loop. Only the wayland, x11 and api_transition backends have been updated so far, and only the wayland backend has actually been tested.
+1 for |
OK I had some time tonight and went ahead with the extra changes. The general gist is:
I'm happy to roll this back to 38856b1 if folks would prefer to make this change in a future PR, however I think it makes sense to include it along with the removal of All backends have been updated and seem to work fine, though there is probably room for simplification in some backends (certainly in x11 as you mention @Ralith). This is ready for review. |
src/platform/linux/x11/mod.rs
Outdated
|
||
let mut control_flow = ControlFlow::Continue; | ||
|
||
if self.pending_wakeup.load(atomic::Ordering::Relaxed) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does the wakeup system implemented here cause xlib.XNextEvent
to return? Unless I'm missing something, this implementation of wakeup
does not cause a blocked loop to advance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pending_wakeup
flag is only an indicator of whether or not wakeup
has been called on an EventsLoopProxy
. It is EventsLoopProxy::wakeup
itself that should cause the next event function to return, though I could certainly be wrong on this - IIRC, I took this code from the old WindowProxy::wakeup
method.
If you're on x11, you can test if this is working or not by running the included proxy.rs
example. If it needs fiixing, please feel free to submit a PR to my fork, or let me know how I can go about fixing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh my, I'm so sorry. I didn't look at this as thoroughly as I should have when making this comment. I didn't see originally that the actual event loop bump was moved rather than deleted.
src/platform/linux/x11/mod.rs
Outdated
}; | ||
|
||
unsafe { | ||
(display.xlib.XSendEvent)(display.display, self.root, 0, 0, mem::transmute(&mut xev)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recall trying to implement this at some point using self.root as the window and missing some wakeup events. I'll test again with your branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK I just tested this on X11 and you are right, this does not seem to cause xlib.XNextEvent
to stop blocking at all (in the proxy.rs example). That said, I can't help but wonder if this code ever worked for the old WindowProxy
code either.
I'm not very familiar with the X11 backend but will see if I can get to the bottom of this. In the meantime, do you have any ideas on why this might not be working?
@jwilm you were right wrt |
@tomaka would you mind sharing your thoughts on this? |
@mitchmindtree Have you considered making the wakeup method accept a WindowId? This makes it possible to know specifically which window is being woken up, and it removes the need for a phantom window for wake ups. This was previously supported before EventsLoop became a thing. |
I'm personally not sure that it should be winit's job to do anything beyond waking up the event loop for a few reasons:
Before What are your thoughts on this @jwilm? |
Thanks for the perspective @mitchmindtree. Sounds like you've done the right thing! |
src/lib.rs
Outdated
/// Continue looping and waiting for events. | ||
Continue, | ||
/// Exit from the event loop. | ||
Complete, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this variant be Break
instead of Complete
to mirror the normal control flow keywords?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call! I've just added a commit that makes this change.
I really like this change set. Would love to see it land soon :) |
99acace
to
fe61d81
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes to the X11 backend look good to me, and I am strongly in favor of the API changes.
R+, thanks! |
Includes: - Recent removal of sync (breaking change) rust-windowing#191. - Wayland fixes: rust-windowing#190, rust-windowing#188, rust-windowing#181 - X11 fixes: rust-windowing#174, rust-windowing#178,
This opens the door to caching tiles at different zoom levels (issue rust-windowing#191).
This commit only updates the top-level API to get some early feedback.
None of the platform-specific code has been updated yet. I'm hoping to
get around to this over the next couple days however if someone more
familiar with the windows backend would like to do a PR against this
fork that would be a great help.
Closes #187.