Skip to content

fix(wayland): cache compiled XKB keymap per UI thread for layer-shell overlays (#3296) - #3309

Merged
Hona merged 1 commit into
devfrom
fix/wayland-layer-shell-keymap-cache
Dec 2, 2026
Merged

Hona merged 1 commit into
devfrom
fix/wayland-layer-shell-keymap-cache

Conversation

@Hona

@Hona Hona commented Dec 2, 2026

Copy link
Copy Markdown
Member

Summary

Caches the seat's last compiled XKB keymap and its resolved virtual-modifier bitmasks per UI thread so Wayland layer-shell overlays reuse the reference-counted xkb::Keymap handle across recreated keyboard surfaces instead of recompiling xkb::Keymap::new_from_string on every wl_keyboard.keymap event.

Fixes #3296.

Changes

  • crates/rune/src/platform/layer_shell_machine/keymap_cache.rs: Add a cross-platform, one-entry KeymapCache<T> keyed by (payload.len(), blake3::Hash) (40 bytes of key metadata instead of retaining the raw keymap text). Matching payloads return a cloned handle without compiling; different payloads replace the entry; failed compilations (None) leave any existing cached entry intact.
  • crates/rune/src/platform/layer_shell/keymap.rs: Wrap KeymapCache<CompiledKeymap> in a thread_local! cache (matching compose.rs, because libxkbcommon's reference counts are non-atomic) that caches both xkb::Keymap and ResolvedModMasks.
  • crates/rune/src/platform/layer_shell/devices.rs: Route wl_keyboard::Event::Keymap through keymap::compile_keymap(map) while keeping each surface's own xkb::State and modifier mask reapplication.
  • Tests:
    • crates/rune/src/platform/layer_shell_machine/keymap_cache_tests.rs: cross-platform unit tests covering cache hits, same-length and different-length layout-change invalidation, eviction of the replaced entry, compile-failure preservation, and cache clearing.
    • crates/rune/src/platform/layer_shell/keys_tests.rs: Linux xkbcommon test (a_keyboard_surface_reuses_the_compiled_keymap_until_the_seat_sends_another) covering handle reuse (get_raw_ptr), independent per-surface xkb::State, invalid-payload preservation, layout switching with updated keysyms and ResolvedModMasks, and thread-local isolation.
  • Changelog: changelog/unreleased/2026-12-03-wayland-layer-shell-keymap-cache.md.

Verification

  • Locally on Windows:
    • cargo test -j 1 -p rune --lib keymap_cache (2/2 passed)
    • cargo clippy -j 1 -p rune --lib --tests --no-deps (clean)
    • cargo check -j 1 -p rune --target wasm32-unknown-unknown (clean)
    • scripts/file-size.sh (0 errors)
  • Linux xkbcommon compilation and a_keyboard_surface_reuses_the_compiled_keymap_until_the_seat_sends_another are verified on Linux CI (check / clippy). A live Wayland compositor session was not tested locally on Windows.

Copilot AI balanced review requested due to automatic review settings December 2, 2026 15:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@Hona
Hona merged commit a48b983 into dev Dec 2, 2026
7 checks passed
@Hona
Hona deleted the fix/wayland-layer-shell-keymap-cache branch December 2, 2026 15:09
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.

Wayland layer-shell overlays compile the seat's XKB keymap again for every keyboard surface

2 participants