-
Notifications
You must be signed in to change notification settings - Fork 903
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
wayland: Implement key repetition #371
Conversation
ping @vberger per talking to tomaka on IRC |
Thanks a lot for tackling this! I don't have much time right now, and being unfamiliar with tokio it'll take me some time to correctly review this. So this may have to wait for next week for a proper review. I gave a quick glance and saw nothing catching my eye negatively. But I want to be sure that @tomaka is okay with the added dependency on tokio? |
I don't mind adding a dependency on tokio, as long as none of the types of tokio or futures are re-exported in the API. |
Cargo.toml
Outdated
@@ -1,6 +1,6 @@ | |||
[package] | |||
name = "winit" | |||
version = "0.9.0" | |||
version = "0.10.0" |
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.
Please do not randomly bump the version in winit.
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 oops. Forgot I'd committed that in the PR. I'll remove it. I did it when I was working on getting alacritty
to use my branch.
9dc3769
to
4d48c26
Compare
Due to the use of tokio-timer and a dedicated tokio thread, this adds two new background threads. Is that really necessary? Given that every supported platform should support blocking for events with a timeout, this should be feasible to implement with no extraneous threads at all. |
@Ralith What thread do you suppose we should block while waiting for the timeout event? I think you're going to need one additional thread (the timer thread) regardless. Now, if we wrote our own timer implementation, we could potentially teach the timer thread to block and not run any timer operations while waiting on the lock for the |
After talking on IRC, @Ralith is totally right. Here's the chat log if anybody cares.
|
(just approving my change request about the version bump, so that it's not a blocker) |
@mcoffin @Ralith blocking with timeout on the wayland socket is going to be... complicated. The wayland C libs only offer two ways of reading the socket:
There is no provided way to block with timeout. However, we can take inspiration of what the weston apps do to handle key repeat info: they use a timerfd and epoll. They register both the timerfd and the wayland fd to an epoll watch, and process each accordingly by respectively dispatching key repeat events or doing an non-blocking read&dispatch of the wayland socket. I think we can adapt the wayland EventsLoop in winit to do that too, but it'll likely require some serious refactor. (though I believe it'd mostly affect the EventsLoop logic only, not the whole backend). |
epoll+timerfd seems like overkill here; if wayland gives you a fd, then you can just use |
I'm not very familiar with poll mechanisms tbh, but if we can easily block with timeout on a given fd for read-readiness, then yes, that'd absolutely work. |
This is going to be a complete re-write of this obviously, so you guys are welcome to close this and I can re-open when I get the time to flesh it out. |
@mcoffin Hey there, are you still working on this feature? |
Smithay/client-toolkit@1691329 Wanted to mention that upstream work has been done for this. |
This has been superseded by #628 |
NOTE: This still needs cleanup. I'm just getting the base implementation out there to get comments before I spend a bunch of time cleaning it up.
This implements key repitition for wayland. I could use some comments on the high-level approach, as there are plenty of cleanup tasks that came from code-churn while debugging.
I wound up having to pass an
EventsLoopProxy
handle through thewl_seat
andwl_keyboard
implementations so that the underlying timer event thread would be able to wake up theEventsLoop
that's reading from the sink.Comments appreciated. I'm using this locally with jwilm/alacritty (with a few patches to update glutin to use this version of winit), and it seems to work alright. The threading overhead is a bit of a bummer, but it seems to be fairly minimal.
TODO List
EventsLoop
.HashMap
usage for storing state in the timer thread, since we only track one key repeat at a time (I didn't know this initially until I actually played around with it in Xorg)KeyboardIData::new
tokio_timer::Timer
implementation based on the currentRepeatInfo
config. (This will just allow for more efficiency in the timer thread, and potentially more granular repeat intervals. 10ms is a decent preset, but dynamic-configuration is probably more correct).