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

WindowEvent::KeyInput lags on gnome X11, but not on i3 #3815

Closed
cfagot opened this issue Jul 23, 2024 · 8 comments · Fixed by #3940
Closed

WindowEvent::KeyInput lags on gnome X11, but not on i3 #3815

cfagot opened this issue Jul 23, 2024 · 8 comments · Fixed by #3940
Labels
B - bug Dang, that shouldn't have happened DS - x11

Comments

@cfagot
Copy link

cfagot commented Jul 23, 2024

Description

This issue most prominently displays itself in games when holding a key down for an action and repeat rate is faster than the frame rate. In that case when you stop pressing the key you will immediately get a device event for the key release, but the WindowEvent::KeyboardInput will continue for some time before the release event arrives. I haven't seen this on wayland, windows, or x11+i3, which is all I've tested on. But I have seen it on 2 ubuntu+gnome+x11 installs, and Johhn-Nagle saw it on same.

Note that nothing like this happens with mouse events even though they are generated at a much higher frequency, so has nothing to do with the app not draining events fast enough.

The following app demonstrates this and can be used to test on different platforms (visually with the animated triangles and also in the console output where you can see what events arrive between new_events and about_to_wait:

https://github.com/cfagot/test_winit_event

Even though this is most easily seen with repeat events, this also happens with any key events that happen in clumps, which is typical typing behavior. I test by just mashing on the keyboard which I find strangely satisfying.

Also important to note that when run with i3 instead of gnome, this does not happen.

Note: a lot of the details can be found in this thread (start after John-Nagle starts posting).

OS and window mananger

Ubuntu 22.04 LTS/Gnome. But as mentioned in the description, I tested with i3 and the issue does not occur there.

Winit version

0.30.3, but have also seen the same issue on 0.29.*

@cfagot cfagot added B - bug Dang, that shouldn't have happened DS - x11 labels Jul 23, 2024
@John-Nagle
Copy link

Thanks. I have a program that sometimes runs at low frame rates, and key events can get way behind. If key repeat is 15Hz and frame rate is 12Hz, and you hold down an arrow key, you can build up a huge backlog.

(Use case: I'm working on improving performance, and sometimes run in debug mode, which is why I hit this.)

@kchibisov
Copy link
Member

kchibisov commented Jul 23, 2024

Just for the clarity.

Repeat can not be disabled per application level on X11. If your app is not draining the loop, you're out of luck, so don't stall the connection and do batching, whatever.

single_iteration drains all the events from the X queue. If you read it, you'll see drain_events which has while loop over all the events inside the connection. If they are not there means that we haven't received them from the X server yet.

However on the gnome vs i3 is a completely different issue and is related to how input method works.

@kchibisov kchibisov changed the title WindowEvent::KeyboardInput lmited to one per single_iteration call (inside winit x11 platform implementation) WindowEvent::KeyInput lags on gnome X11, but not on i3 Jul 23, 2024
@cfagot
Copy link
Author

cfagot commented Jul 23, 2024

I understand what drain is doing, which is why I mention that mouse events don't have the same issue. So for whatever reason that key events arrive one per single_iteration call, it's surely not ideal (and also seems to be unique to x11 with gnome).

@John-Nagle
Copy link

Right, mouse events are fine. Only keyboard events have this problem. I see it on x11, but don't have other platforms for testing.

@kchibisov
Copy link
Member

As I said, they arrive normally, it's just they go through the input method and SendEvent one more time. The solution would probably to just straight disable this forwarding.

@kchibisov
Copy link
Member

Can someone test this #3940? It should be trivial to apply to 0.30.

@cfagot
Copy link
Author

cfagot commented Oct 8, 2024 via email

@cfagot
Copy link
Author

cfagot commented Oct 10, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B - bug Dang, that shouldn't have happened DS - x11
Development

Successfully merging a pull request may close this issue.

3 participants