Skip to content

fix: correct CapsLock state tracking in waylandim v2#1595

Merged
wengxt merged 1 commit into
fcitx:masterfrom
SHORiN-KiWATA:fix/capslock
Jun 25, 2026
Merged

fix: correct CapsLock state tracking in waylandim v2#1595
wengxt merged 1 commit into
fcitx:masterfrom
SHORiN-KiWATA:fix/capslock

Conversation

@SHORiN-KiWATA

@SHORiN-KiWATA SHORiN-KiWATA commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Environment

  • OS: Arch Linux, Linux 7.0
  • Display: Wayland + niri + xwayland-satellite 0.8.1
  • fcitx5: 5.1.20
  • IM engine: rime (may also affect other engines that use CapsLock state)

Reproduction

  1. Switch to rime (Chinese mode)
  2. Press CapsLock to enable caps lock
  3. Press CapsLock again to disable caps lock
  4. Rime remains stuck in English (ASCII) mode — only restarting the IM or manually toggling via F4 menu recovers
2026-06-25-195851-REGION

Root Cause

WaylandIMInputContextV2::modifiersCallback serializes the modifier state using XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LATCHED. These flags only query held-down (Depressed) and latched (Latch) modifiers, omitting locked modifiers — the category CapsLock belongs to.

Wayland correctly reports mods_locked changes, and xkb_state_update_mask() correctly updates the internal XKB state. However, xkb_state_serialize_mods() reads back only Depressed | Latched, so modifiers_ never contains KeyState::CapsLock. The engine receives key events with uppercase keysyms but no CapsLock modifier in the key states, confusing its internal state machine.

Fix

Replace XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LATCHED with XKB_STATE_MODS_EFFECTIVE. EFFECTIVE includes all three modifier categories (Depressed | Latched | Locked), correctly reflecting CapsLock transitions in modifiers_.

Summary by CodeRabbit

  • Bug Fixes
    • Improved modifier-state reporting so keyboard shortcuts and modifier keys are reflected more accurately, including cases like Shift, Caps Lock, Ctrl, Alt, and Num Lock.
    • Updated how modifier updates are forwarded to the virtual keyboard, reducing inconsistencies when input state changes.

Use XKB_STATE_MODS_EFFECTIVE instead of DEPRESSED|LATCHED to include
locked modifiers (CapsLock, NumLock) in the modifier state mask. This
fixes rime getting stuck in English mode after toggling CapsLock off.
@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

modifiersCallback now derives Wayland IM modifier updates from the XKB effective modifier state before forwarding them when the virtual keyboard is ready.

Changes

Wayland IM modifier serialization

Layer / File(s) Summary
Effective modifier mask
src/frontend/waylandim/waylandimserverv2.cpp
modifiersCallback now uses XKB_STATE_MODS_EFFECTIVE to populate server_->modifiers_ instead of combining depressed and latched modifier bits.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 I hopped through keys with twitching ears,
And found the mask that clears the gears.
Now effective mods dance bright and true,
With every chime of Shift in view.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main fix: WaylandIM v2 now tracks CapsLock state correctly.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@wengxt wengxt merged commit 06a688d into fcitx:master Jun 25, 2026
5 checks passed
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.

2 participants