#4737

IME passed-through key releases after ungrab dropped

Openpgaskinopened 6d ago

Originally reported by @precondition in https://github.com/niri-wm/niri/pull/4548#issuecomment-6349436549:

I believe I am encountering an issue due to this PR. As a niri + fcitx5 + noctalia user, I've noticed that very quick taps of the tab key (i.e. the duration between the press and the release is a small amount like 3ms) cause the tab key to be auto-repeated ad eternam.

My understanding of the issue is:

  1. When I type in a text field, niri hands my keys to fcitx5 first, and fcitx5 passes them on to noctalia.
  2. I tap Tab, and fcitx5 passes the press on to noctalia.
  3. That Tab moves me out of the text field, so niri tells fcitx5 that this "text input session", if I may say, is over.
  4. fcitx5 then passes on the Tab release. But niri now treats it as coming from a random keyboard (fcitx does weird stuff with virtual keyboards, so I am not very confident on this point), and it has no record of that keyboard pressing Tab. So it decides "this release makes no sense" and throws it away (<--- core of the problem).
  5. noctalia saw Tab pressed and never saw it released. Consequently, it naturally thinks I'm holding Tab down, so it keeps repeating Tab and cycles through everything.

It only happens on very fast taps because the release has to arrive in the tiny moment while niri is switching fcitx5 off. A slower press releases after the switch, and that works fine.

I was able to reproduce it on e19df12cf81ffe805609fee497da1a097066ad2f with a script with 20ms between press/release, but not at 3ms as described by @precondition since for extremely short taps, fcitx gets the release before it deactivates.

The bug is that fcitx's passed-through tab release is sent to niri after fcitx ungrabs the keyboard, which then results in smithay dropping the release since tab was never pressed by fcitx's virtual keyboard.

To fix it, I need to figure out a way to make fcitx's releases get handled the same way even after it drops the grab.

Activity

5
pgaskin6d ago

Also need to see how the fcitx PersistentVirtualKeyboard option affects this.

pgaskin5d ago

Random thought: I think it would be nicer (and avoid this whole class of bugs) if the input method protocol had the IME return whether a grabbed key was handled or not rather than having it re-emit them...

YaLTeR5d ago

How do sway and others avoid this problem?

Regarding IME protocol improvements, there's been some work on new protocols (e.g. https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/521) but unfortunately the active phase of that project had run out

Bot-wxt12215d ago

7. How do sway and others avoid this problem? Regarding IME protocol improvements, there's been some work on new protocols (e.g. https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/521) but unfortunately the active phase of that project had run out

According to my search, no WM can handle it smoothly. To be honest, this is a design fault on protocols.

pgaskin5d ago

Sway doesn't have this particular issue since wlroots doesn't track pressed-keys seat-wide to filter them. The keyboards all have their own state, including the IME's virtual keyboard, and press/release tracking goes through each device. In addition, grabbed keys passed through by the IME go through the normal route (but skipping the grab) rather than being special-cased and forwarded to the client.