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

Missing first Esc keypress after a window is focused #680

Open
jneem opened this issue Aug 3, 2024 · 6 comments · May be fixed by #1126
Open

Missing first Esc keypress after a window is focused #680

jneem opened this issue Aug 3, 2024 · 6 comments · May be fixed by #1126

Comments

@jneem
Copy link

jneem commented Aug 3, 2024

When I focus a window, the first time I press Esc I get a key release event but not a key press event. After that, each time I press Esc I get both a press and a release. Until I switch focus away and back again, and then once again the first time I press Esc I only get the release.

  • It happens both in tiled mode and floating mode
  • It happens whether I use the keyboard or the mouse to change focus
  • I've tested several different keys, and only Esc seems to have this behavior
  • I think this is cosmic-comp's fault because it doesn't happen under sway
@Drakulix
Copy link
Member

Drakulix commented Aug 5, 2024

Which commit is this on? Can't reproduce with latest master.

@jneem
Copy link
Author

jneem commented Aug 5, 2024

Thanks for looking into it! It's 2cef99ae783efb451bd9067b4d9e74c014615996, as packaged and configured by nixos-cosmic. I'll try to see if I can reproduce it with "vanilla" cosmic-comp.

@Drakulix
Copy link
Member

Drakulix commented Aug 5, 2024

Even on that commit I don't see any missing events. For testing I have been running clients with both WAYLAND_DEBUG=1 and xtrace and for wayland clients I get the correct wl_keyboard events as well for Xwayland clients the corresponding KeyPress and KeyRelease events.

Any particular application / test setup you are using?

@jneem
Copy link
Author

jneem commented Aug 6, 2024

I first ran into this "in the wild" using alacritty and helix. I tested it by modifying the winit window example to print out the key events it received. I just tried running that example with WAYLAND_DEBUG=1, and this is what I get:

[4171920.646] [email protected](1347465, wl_surface@29, array[4])
[4171920.687] [email protected](wl_surface@29)
[4171920.697] [email protected](1347465, 64, 0, 0, 0)
[4171920.705] [email protected](1917, 1025, array[20])
[4171920.713] [email protected](1347467)
[4171920.782]  -> [email protected]()
[4171920.794]  -> [email protected]_content_type(0, 0)
[4171920.800]  -> [email protected]()
[4171920.837]  -> [email protected]_configure(1347467)
2024-08-06T01:47:07.874840Z  INFO window: Window=WindowId(94358172653328) focused
2024-08-06T01:47:07.874888Z  INFO window: IME enabled for Window=WindowId(94358172653328)
2024-08-06T01:47:07.874895Z  INFO window: Modifiers changed to ModifiersState(SUPER)
[4171920.992] [email protected]()
[4171934.724]  -> [email protected](new id wl_callback@36)
[4171934.756]  -> [email protected](wl_buffer@39, 0, 0)
[4171934.764]  -> [email protected]_buffer(0, 0, 1917, 1025)
[4171934.768]  -> [email protected]()
[4171934.831] [email protected](1347468, 0, 0, 0, 0)
[4171934.841] [email protected](1347471, 64, 0, 0, 0)
2024-08-06T01:47:07.888812Z  INFO window: Modifiers changed to ModifiersState(0x0)
2024-08-06T01:47:07.888832Z  INFO window: Modifiers changed to ModifiersState(SUPER)
[4171946.700] [email protected]_id(36)
[4171946.716] [email protected](86934126)
[4172029.915] [email protected](1347473, 86934208, 36, 0)
2024-08-06T01:47:07.984018Z  INFO window: key Character("j"), state Released
[4172244.260] [email protected](1347475, 86934422, 125, 0)
[4172244.291] [email protected](1347476, 0, 0, 0, 0)
2024-08-06T01:47:08.198315Z  INFO window: key Named(Super), state Released
2024-08-06T01:47:08.198403Z  INFO window: Modifiers changed to ModifiersState(0x0)
[4172854.267] [email protected](1, fd 11, 64754)
[4172854.328] [email protected](1347479, 0, 0, 0, 0)
[4172854.339] [email protected](1347478, 86935029, 1, 0)
2024-08-06T01:47:08.810467Z  INFO window: Modifiers changed to ModifiersState(0x0)
2024-08-06T01:47:08.810499Z  INFO window: key Named(Escape), state Released
[4173193.542] [email protected](1347480, 86935372, 1, 1)
2024-08-06T01:47:09.147689Z  INFO window: key Named(Escape), state Pressed
[4173193.896] [email protected](1347481, 86935373, 1, 0)
2024-08-06T01:47:09.147914Z  INFO window: key Named(Escape), state Released

This is me focusing the window (using Super+j, so that explains the initial modifier state and the first 2 key releases) and then pressing Esc twice. The first press only sends the release; the second one sends both.

@jneem
Copy link
Author

jneem commented Aug 6, 2024

Ok, I just noticed something new: this only happens when I'm running fcitx. With fcitx turned off, I get

[ 771672.503] [email protected](8994, wl_surface@29, array[4])
[ 771672.547] [email protected](8994, 64, 0, 0, 0)
[ 771672.566] [email protected](1277, 1528, array[20])
[ 771672.575] [email protected](8996)
[ 771672.687]  -> [email protected]_configure(8996)
2024-08-06T02:02:02.593986Z  INFO window: Window=WindowId(94224799999760) focused
2024-08-06T02:02:02.594013Z  INFO window: Modifiers changed to ModifiersState(SUPER)
[ 771672.813] [email protected]()
[ 771687.008]  -> [email protected](new id wl_callback@36)
[ 771687.032]  -> [email protected](wl_buffer@39, 0, 0)
[ 771687.039]  -> [email protected]_buffer(0, 0, 1277, 1528)
[ 771687.044]  -> [email protected]()
[ 771691.886] [email protected]_id(36)
[ 771691.901] [email protected](87828838)
[ 771833.803] [email protected](8997, 87828980, 38, 0)
2024-08-06T02:02:02.755381Z  INFO window: key Character("l"), state Released
[ 771972.809] [email protected](8998, 87829119, 125, 0)
[ 771972.861] [email protected](8998, 0, 0, 0, 0)
2024-08-06T02:02:02.894412Z  INFO window: key Named(Super), state Released
2024-08-06T02:02:02.894463Z  INFO window: Modifiers changed to ModifiersState(0x0)
[ 772962.823] [email protected](8999, 87830109, 1, 1)
2024-08-06T02:02:03.884360Z  INFO window: key Named(Escape), state Pressed
[ 772963.288] [email protected](9000, 87830109, 1, 0)
2024-08-06T02:02:03.884615Z  INFO window: key Named(Escape), state Released

I did just go and check sway again, and I get the Esc press event whether or not fcitx is running

@jneem
Copy link
Author

jneem commented Jan 2, 2025

After a long hiatus, I've started digging into this again. Some print-debugging reveals that the escape keypress is being filtered out in State::filter_keyboard_input, because the keyboard is always grabbed for the first Escape keypress on a newly-focused window. The grab is always an InputMethodKeyboardGrab.

The only place that I see where this can come from is from a zwp_input_method_v2::Request::GrabKeyboard request, but I've tried running WAYLAND_DEBUG=1 for both the window that I'm switching to and the window that I'm switching from and I don't see any zwp_input_method_v2 events.

I see that the grab is unset when the ZwpInputMethodKeyboardGrabV2 is destroy()ed, but not when it gets a Release request. Maybe the grab should be unset there also?

@jneem jneem linked a pull request Jan 10, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants