dnkl/foot
41
2.0k
Fork
You've already forked foot
242

input: rearm IME once after keyboard focus enter #2282

Open
stalkerg wants to merge 1 commit from stalkerg/foot:fix/ime-kwin-modifiers-rearm-pr into master
pull from: stalkerg/foot:fix/ime-kwin-modifiers-rearm-pr
merge into: dnkl:master
dnkl:master
dnkl:osc-5522
dnkl:sixel-heap-buffer-overflow
dnkl:releases/1.27
dnkl:releases/1.26
dnkl:releases/1.25
dnkl:releases/1.24
dnkl:multi-cursor
dnkl:releases/1.23
dnkl:pixman-16f-2
dnkl:releases/1.22
dnkl:releases/1.21
dnkl:releases/1.20
dnkl:releases/1.19
dnkl:releases/1.18
dnkl:releases/1.17
dnkl:releases/1.16
dnkl:releases/1.15
dnkl:releases/1.14
dnkl:releases/1.13
dnkl:releases/1.12
dnkl:releases/1.11
dnkl:releases/1.10
dnkl:releases/1.9
dnkl:releases/1.8
dnkl:releases/1.7
dnkl:releases/1.6
dnkl:releases/1.5
dnkl:releases/1.4
dnkl:releases/1.3
dnkl:releases/1.2
dnkl:releases/1.1
dnkl:releases/1.0
First-time contributor
Copy link

It fixes #2279

Problem

On KWin + fcitx5, after several workspace/focus switches, foot can enter a state where
zwp_text_input_v3 is focused/enabled but no longer receives commit_string events.
At that point input falls back to plain keyboard/XKB path only.

Why this change is protocol-aligned

The text-input-v3 protocol requires re-enabling when focused text input changes, and
defines enable as a state reset point:

  • "This request must be issued every time the focused text input changes"
  • "This request resets all state associated with previous enable/disable/... state"

So recovering by forcing a fresh disable+enable cycle is consistent with protocol intent
when the IME pipeline gets stuck after focus transitions.

What this patch does

  • Add a one-shot rearm_pending flag per seat.
  • Set it on keyboard_enter, clear it on keyboard_leave.
  • On the first post-focus keyboard_modifiers event, if IME focus is active:
    • call ime_disable()
    • call ime_enable()
    • clear rearm_pending

This keeps the workaround bounded to one rearm per focus session.

Why this is better than previous behavior

Previously, if KWin/fcitx5 ended up in a non-committing v3 state, foot stayed stuck
until another external state reset happened.
Now foot proactively performs a single local rearm at a stable post-focus point.

QtWayland follows a similar enter/leave state model for text-input-v3
(enter -> enable+state update, leave -> disable+commit), and also prefers v2 over v3
on KWin for compatibility reasons.

It fixes #2279 ## Problem On KWin + fcitx5, after several workspace/focus switches, foot can enter a state where `zwp_text_input_v3` is focused/enabled but no longer receives `commit_string` events. At that point input falls back to plain keyboard/XKB path only. ## Why this change is protocol-aligned The text-input-v3 protocol requires re-enabling when focused text input changes, and defines `enable` as a state reset point: - "This request must be issued every time the focused text input changes" - "This request resets all state associated with previous enable/disable/... state" So recovering by forcing a fresh disable+enable cycle is consistent with protocol intent when the IME pipeline gets stuck after focus transitions. ## What this patch does - Add a one-shot `rearm_pending` flag per seat. - Set it on `keyboard_enter`, clear it on `keyboard_leave`. - On the first post-focus `keyboard_modifiers` event, if IME focus is active: - call `ime_disable()` - call `ime_enable()` - clear `rearm_pending` This keeps the workaround bounded to one rearm per focus session. ## Why this is better than previous behavior Previously, if KWin/fcitx5 ended up in a non-committing v3 state, foot stayed stuck until another external state reset happened. Now foot proactively performs a single local rearm at a stable post-focus point. ## Related implementation notes QtWayland follows a similar enter/leave state model for text-input-v3 (enter -> enable+state update, leave -> disable+commit), and also prefers v2 over v3 on KWin for compatibility reasons.
input: rearm IME once after keyboard focus enter
All checks were successful
builds.sr.ht/freebsd-x64 Job completed
202fa4c3c8
dnkl left a comment
Copy link

Why wait until keyboard_modifiers() to re-arm? Why not just do it in keyboard_enter()?

Why wait until `keyboard_modifiers()` to re-arm? Why not just do it in `keyboard_enter()`?
Owner
Copy link

Also, I wonder why KDE isn't sending an ime::enter after a keyboard_enter()? Unless I'm reading the IME documentation wrong, it should. And if it isn't, it's a KDE bug:

Focus moving throughout surfaces will result in the emission of zwp_text_input_v3.enter and zwp_text_input_v3.leave events. The focused surface must commit zwp_text_input_v3.enable and zwp_text_input_v3.disable requests as the keyboard focus moves across editable and non-editable elements of the UI. Those two requests are not expected to be paired with each other, the compositor must be able to handle consecutive series of the same request.

Also, I wonder why KDE isn't sending an `ime::enter` after a `keyboard_enter()`? Unless I'm reading the IME documentation wrong, it should. And if it isn't, it's a KDE bug: > _Focus moving throughout surfaces will result in the emission of zwp_text_input_v3.enter and zwp_text_input_v3.leave events. The focused surface must commit zwp_text_input_v3.enable and zwp_text_input_v3.disable requests as the keyboard focus moves across editable and non-editable elements of the UI. Those two requests are not expected to be paired with each other, the compositor must be able to handle consecutive series of the same request._
Author
First-time contributor
Copy link

Also, I wonder why KDE isn't sending an ime::enter after a keyboard_enter()? Unless I'm reading the IME documentation wrong, it should. And if it isn't, it's a KDE bug:

Yes, it's absolutely a KDE bug; it seems they lose zwp_text_input_v3.enter in a few cases, such as when switching between workspaces or after other effects (maybe it's an effects issue in general).

Why wait until keyboard_modifiers() to re-arm? Why not just do it in keyboard_enter()?

Because I saw some activities in keyboard_modifiers, but not for keyboard_enter. But I will check again. This patch is more like a workaround. I have been using it for the past few weeks, and it has been working perfectly.

> Also, I wonder why KDE isn't sending an ime::enter after a keyboard_enter()? Unless I'm reading the IME documentation wrong, it should. And if it isn't, it's a KDE bug: Yes, it's absolutely a KDE bug; it seems they lose `zwp_text_input_v3.enter` in a few cases, such as when switching between workspaces or after other effects (maybe it's an effects issue in general). > Why wait until keyboard_modifiers() to re-arm? Why not just do it in keyboard_enter()? Because I saw some activities in keyboard_modifiers, but not for keyboard_enter. But I will check again. This patch is more like a workaround. I have been using it for the past few weeks, and it has been working perfectly.
Owner
Copy link

In general, I don't merge workarounds for compositor bugs. I can keep this MR around for a while if you want, but don't expect it to be merged.

In general, I don't merge workarounds for compositor bugs. I can keep this MR around for a while if you want, but don't expect it to be merged.
Author
First-time contributor
Copy link

Yes, please keep it here for a while, in the meantime, I will try to fix it from the KWin side.

Yes, please keep it here for a while, in the meantime, I will try to fix it from the KWin side.
All checks were successful
builds.sr.ht/freebsd-x64 Job completed
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u fix/ime-kwin-modifiers-rearm-pr:stalkerg-fix/ime-kwin-modifiers-rearm-pr
git switch stalkerg-fix/ime-kwin-modifiers-rearm-pr

Merge

Merge the changes and update on Forgejo.
git switch master
git merge --no-ff stalkerg-fix/ime-kwin-modifiers-rearm-pr
git switch stalkerg-fix/ime-kwin-modifiers-rearm-pr
git rebase master
git switch master
git merge --ff-only stalkerg-fix/ime-kwin-modifiers-rearm-pr
git switch stalkerg-fix/ime-kwin-modifiers-rearm-pr
git rebase master
git switch master
git merge --no-ff stalkerg-fix/ime-kwin-modifiers-rearm-pr
git switch master
git merge --squash stalkerg-fix/ime-kwin-modifiers-rearm-pr
git switch master
git merge --ff-only stalkerg-fix/ime-kwin-modifiers-rearm-pr
git switch master
git merge stalkerg-fix/ime-kwin-modifiers-rearm-pr
git push origin master
Sign in to join this conversation.
No reviewers
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dnkl/foot!2282
Reference in a new issue
dnkl/foot
No description provided.
Delete branch "stalkerg/foot:fix/ime-kwin-modifiers-rearm-pr"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?