-
Notifications
You must be signed in to change notification settings - Fork 5
fix: meta mod key on focus handling for gnome/x11 #1
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
fix: meta mod key on focus handling for gnome/x11 #1
Conversation
This patch addresses an issue in the modifier key handling appearing on gnome/x11 while focussing a winit window using a meta/super/logo key shortcut. As soon as the window gained focus via a shortcut using a meta key, gnome/x11 reports a meta modifier as pressed in the focus event, even though it was just released. No key release events were sent afterwards, so the meta modifier remained "stuck" in the winit state. This patch refactors the modifier key handling following this goals: - Only rely on winit's own modifier state tracking for key and focus events, do not mix it with x11's modifier reporting - Track modifiers only via non-raw key events, so winit does not track modifier changes when not focussed - Integrate modifier handling with the synthetic key events mechanism in order to report release of all currently held modifiers when unfocussed and report set for all currently held modifiers when focussed.
536f5b5 to
9fea819
Compare
|
I know I said I'd look at this today, and I didn't completely forget, but I ended up just getting distracted by other things. |
|
I've encountered what looks like a bug. I use Sway (and I'm running the test program under XWayland), so I am able to change the focused simply by moving the mouse. So I tried holding down the Shift key and flicking the mouse in and out of my test program's window. The problem is that I sporadically get |
|
Thanks a lot @maroider for looking into this. I tried to reproduce the issue you described and was not able to encounter it on my machine. Also, I think the issue that motivated me to submit this pull request is slightly different from the one you are describing. Let me summarize what I did and see on my platform (Gnome 40.4.0, X11, Arch Linux). Test programI am using the following test program (slightly modified version of Issue: missed modifiers using "mouse focus"This tests for the issue you described - as I understand it.
rust-windowing/winit masterOutput (lines starting with This does not change if I repeatedly leave and enter the window with the mouse. maroider/winit new-keyboard-linuxOutput (lines starting with This does not change if I repeatedly leave and enter the window with the mouse. ConclusionUnfortunately I cannot reproduce the issue you describe, neither on the current Issue: Hanging meta key on focus change via meta shortcut on Gnome/X11This is the issue I was initially encountering which also motivated me to open this pull request. I think this issue is actually really tied to Gnome on X11 and the meta key. So it is quite specific. I was not able to reproduce it on Gnome/Wayland nor on i3 nor XFCE. Here you can find some more information on the issue as I documented it over at neovide neovide/neovide#931 (comment). Another neovide user reported a similar issue. My patch seems to solve the problem for him as well (neovide/neovide#942). Actually, to me it looks a bit like gnome is misbehaving here. Still I wanted to fix the issue on the neovide/winit level, because others seem to be able to handle Gnome's weird behavior as well (e.g. SDL2 does not have the problem on Gnome/X11, I verified this with another test program).
rust-windowing/winit masterOutput (lines starting with As you can see in the output, the meta modifier is reported together with the shift modifier after the window got maximized, even though only the shift key is pressed. Another modifier change event is fired directly afterwards fixing the modifier state report, though, no key release event is fired to justify the modifier state change. This is not the behavior I'd expect as the meta key is reported while not pressed and the modifier state is not in sync with key press and release events. maroider/winit new-keyboard-linuxOutput (lines starting with As you can see in the output, the meta modifier is reported together with the shift modifier after the window got maximized, even though only the shift key is pressed. After releasing the shift key, still, the meta key is reported, even though it was released long before. The meta key hangs. This is the actual issue I am trying to fix. Comparing this behavior to the master branch, I'd even say this is a regression. As the master branch recovers from this state on it's own. This branch needs another re-focus or mouse move to recover. This is not the behavior I'd expect as the meta key is reported while not pressed and the modifier state is not in sync with key press and release events. rti/winit fix-gnome-x11-meta-mod-focus-maroiderOutput (lines starting with As you can see in the output, the key and modifier state is consistent. This is the behavior I'd expect. Please excuse the way too long comment. I hope it solved the purpose to share my thoughts and motivation with you. |
|
Please let me know if I can be of any further help on this topic. |
I've reproduced the bug on both branches, so it might just be a Sway bug. I've discovered another thing, though: I seem to have forgotten entirely about synthetic events when implementing this, as I can't seem to get any at all with the |
|
I'm apparently dumb. Synthetic events work fine for me on X11, and this PR has nothing to do with Furthermore, this PR appears to work fine for me with i3. |
|
Thanks a lot for merging this! |
This patch addresses an issue in the modifier key handling appearing on
gnome/x11 while focussing a winit window using a meta/super/logo key
shortcut.
As soon as the window gained focus via a shortcut using a meta key,
gnome/x11 reports a meta modifier as pressed in the focus event, even
though it was just released. No key release events were sent afterwards,
so the meta modifier remained "stuck" in the winit state.
This patch refactors the modifier key handling following this goals:
events, do not mix it with x11's modifier reporting
modifier changes when not focussed
in order to report release of all currently held modifiers when
unfocussed and report set for all currently held modifiers when
focussed.
If you wonder why somebody is creating a pull request for a branch currently being in a pull request for the upstream repo... For https://github.com/neovide/neovide @Kethku created a winit branch https://github.com/kethku/winit/tree/new-keyboard-all pulling in this very WIP branch already for the current neovide main branch. I am running neovide main and experienced the before mentioned problem on my platform. So I tried to fix it.
cargo fmthas been run on this branchcargo docbuilds successfullyCHANGELOG.mdif knowledge of this change could be valuable to users