Repository navigation
Conversation
reload_keybindings() unconditionally ungrabbed and regrabbed every per-window keybinding (Alt+F4, Super+arrows, etc.) on every window on every keyboard layout group switch. Each grab/ungrab is a synchronous XIGrabKeycode/XIUngrabKeycode round trip, so this blocks Cinnamon's main loop (the X11 compositor) for O(windows x per-window bindings) round trips per switch -- measured at 290ms-960ms with 32-149 open windows. Per-window bindings here typically use F-keys, arrows and Space, whose keycodes are identical in every layout, so the regrab does no useful work in the common case; it's only needed when a resolved combo's keycodes or modifier mask actually differ under the new layout (e.g. for non-Latin layouts, which use a secondary US layout). Add per_window_combos_will_change(), a read-only probe that resolves each per-window binding's combo under the incoming layout and compares it against its current resolved combo, without mutating any state. reload_keybindings() and the META_PREF_KEYBINDINGS preference-change path now only pay for the per-window ungrab/grab loop when this probe finds an actual difference. The always-cheap root-window grab/ungrab (ungrab_key_bindings()/grab_key_bindings()) is unchanged and still runs unconditionally on every reload. Fixes linuxmint#886 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #886 (every keyboard layout switch freezes the compositor for up to ~1s).
reload_keybindings()unconditionally ungrabbed and regrabbed every per-window keybinding (Alt+F4, Super+arrows, etc.) on every window, on every keyboard layout group switch. Each grab/ungrab is a synchronousXIGrabKeycode/XIUngrabKeycoderound trip, so this blocks Cinnamon's main loop (it's the X11 compositor) for O(windows × per-window bindings) round trips per switch — @ashvedovcds measured 290ms–960ms with 32–149 open windows in X11: every keyboard layout switch freezes the compositor for up to ~1 s (reload_keybindings regrabs per-window keybindings on every window) #886.Implementation
per_window_combos_will_change(): a read-only probe that resolves eachMETA_KEY_BINDING_PER_WINDOWbinding's combo under the incoming layout (afterreload_modmap(), beforereload_combos()overwrites anything) and compares it against the binding's current resolved combo via a newresolved_key_combo_equal()helper, without mutating any binding state.ungrab_key_bindings()/grab_key_bindings()(previously root window + full per-window loop) into the cheap root-only operation plus newungrab_per_window_key_bindings()/grab_per_window_key_bindings().reload_keybindings()now only calls the per-window variants when the probe finds a real difference. TheMETA_PREF_KEYBINDINGSpreference-change path (user edits a shortcut) keeps calling both unconditionally, since that's rare and not the perf-sensitive path.Test plan
pingsw.py) with ~100+ open windows on an X11 session with 2+ keyboard layouts; confirm the post-switch Cinnamon D-Bus freeze drops to near-baseline when per-window bindings use layout-independent keys (arrows/F-keys/Space)ru) with a per-window binding whose keysym needs the secondary US layout fallback, and confirm the per-window regrab still happens and the binding still works after the switchMETA_PREF_KEYBINDINGSpath) still correctly re-grabs both root and per-window bindings