Commit 16bc38f
authored
Fix stale keysym entries when modifier changes while key is held (#4747)
`KeyboardStateTracker` used the keysym from the key-up event to erase
from `pressed_keysyms`, but that keysym can differ from what was stored
at key-down when a modifier changes mid-hold (e.g. `1` down → Shift down
→ key-up reports `XKB_KEY_exclam`, leaving `XKB_KEY_1` stranded).
Related: #4746
## What's new?
- **`scancode_to_keysym` map replaces the two separate sets**
(`pressed_keysyms` / `pressed_scancodes`). Scancode is the stable
identity of a physical key; the map stores the keysym recorded at
key-down against it.
- **Key-up erases by scancode** (`scancode_to_keysym.erase(scancode)`),
so mismatched key-up keysyms caused by held modifiers never leave stale
entries.
- **Shift transitions mutate map values in-place** via a range loop
applying `xkb_keysym_to_upper`/`xkb_keysym_to_lower`, replacing the
previous set-rebuild approach.
- **`keysym_is_pressed`** uses `std::ranges::any_of` over map values;
`scancode_is_pressed` uses `map.contains`. The linear scan for keysyms
is inconsequential given the physical bound on simultaneously held keys
(≤ ~20).
- **New test** `key_up_clears_key_when_modifier_changed_while_held`
exercises the exact failure scenario: `1` down → Shift down → `!` up →
neither `XKB_KEY_1` nor `XKB_KEY_exclam` remains pressed.
## How to test
Run the `KeyboardStateTrackerTest` suite:
```
./bin/mir_unit_tests.bin --gtest_filter="KeyboardStateTrackerTest.*"
```
All 17 tests should pass, including the new regression test.
## Checklist
- [x] Tests added and pass
- [x] Adequate documentation added
- [ ] ~(optional) Added Screenshots or videos~File tree
3 files changed
+51
-21
lines changed- src/server/frontend_wayland
- tests/unit-tests/frontend_wayland
3 files changed
+51
-21
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
53 | | - | |
| 52 | + | |
54 | 53 | | |
55 | 54 | | |
56 | 55 | | |
57 | 56 | | |
58 | | - | |
59 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
67 | | - | |
68 | | - | |
| 66 | + | |
| 67 | + | |
69 | 68 | | |
70 | 69 | | |
71 | 70 | | |
72 | 71 | | |
73 | | - | |
74 | | - | |
75 | | - | |
| 72 | + | |
| 73 | + | |
76 | 74 | | |
77 | 75 | | |
78 | 76 | | |
79 | 77 | | |
80 | 78 | | |
81 | 79 | | |
82 | 80 | | |
83 | | - | |
| 81 | + | |
| 82 | + | |
84 | 83 | | |
85 | | - | |
86 | | - | |
| 84 | + | |
| 85 | + | |
87 | 86 | | |
88 | 87 | | |
89 | 88 | | |
90 | 89 | | |
91 | | - | |
| 90 | + | |
| 91 | + | |
92 | 92 | | |
93 | | - | |
94 | | - | |
| 93 | + | |
95 | 94 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
43 | 48 | | |
44 | 49 | | |
45 | 50 | | |
| |||
56 | 61 | | |
57 | 62 | | |
58 | 63 | | |
59 | | - | |
60 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
61 | 67 | | |
62 | 68 | | |
63 | 69 | | |
| |||
Lines changed: 25 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
306 | 307 | | |
307 | 308 | | |
308 | 309 | | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
309 | 334 | | |
0 commit comments