Skip to content

input: separate input-method keyboard interception from routing grabs - #2147

Open
mikairyuu wants to merge 3 commits into
Smithay:masterfrom
mikairyuu:separate-interception-and-grab
Open

input: separate input-method keyboard interception from routing grabs#2147
mikairyuu wants to merge 3 commits into
Smithay:masterfrom
mikairyuu:separate-interception-and-grab

Conversation

@mikairyuu

@mikairyuu mikairyuu commented Aug 29, 2026

Copy link
Copy Markdown

It's a pain to use libreoffice on systems with IME on COSMIC right now. GTK popups do not open at all if IME is running. It's been quite infuriating, so I'm pretty desperate to fix the situation.

Summary

Input-method v2 currently implements grab_keyboard as a Smithay KeyboardGrab. This makes it mutually exclusive with compositor routing grabs, such as popup grabs: installing one replaces the other.

This PR moves the input-method keyboard grab to a post-routing input interceptor instead. Routing grabs still decide where keyboard input goes, while the input method can intercept physical keyboard events after that decision.

This allows popup and input-method grabs to coexist without changing KeyboardGrab semantics.

Changes

  • add a crate-internal post-routing keyboard input interceptor
  • move zwp_input_method_v2.grab_keyboard to that interceptor
  • keep KeyboardHandle::is_grabbed() describing Smithay routing grabs only
  • preserve press/release ownership across interceptor changes and multiple keyboard sources
  • clean up the interceptor when the input-method or keyboard-grab resource is destroyed
  • keep the new infrastructure behind wayland_frontend
  • add regression tests for grab ordering, focus changes, modifier synchronization, lifecycle cleanup, and press/release pairing

Issues

This addresses the overlapping popup/IME keyboard-grab limitation described in niri-wm/niri#3899, which can cause popups to stop working while an IME keyboard grab is active.

Testing

I have confirmed libreoffice popups work correctly with a running IME after the change. They also grab keyboard input and after closing return it properly.

Downstream note

Compositors that used KeyboardHandle::is_grabbed() to detect an input-method protocol grab should use InputMethodHandle::keyboard_grabbed() for that purpose instead.

In particular, I've found cosmic-comp's XWayland eavesdropping path to be requiring this, and this will need a companion PR.

niri already distinguishes the input-method protocol grab through InputMethodHandle::keyboard_grabbed(), but has a workaround that avoids installing popup keyboard grabs while an IME grab is active. That workaround can be removed once using this change.

AI disclosure

The code has been generated by ChatGPT, since Rust isn't my forte. But it's been thoroughly read, understood, and architecturally improved by me quite a few times before arriving here.

Checklist

AI-assisted: ChatGPT was used while preparing this change.
AI-assisted: ChatGPT was used while preparing this change.
AI-assisted: ChatGPT was used while preparing this change.
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 this pull request may close these issues.

1 participant