Skip to content

fix(keybindings): look up the bound keyval before the ASCII fallback - #2365

Open
shaktimaan00 wants to merge 1 commit into
Guake:masterfrom
shaktimaan00:fix/2351-numpad-keybindings
Open

shaktimaan00 wants to merge 1 commit into
Guake:masterfrom
shaktimaan00:fix/2351-numpad-keybindings

Conversation

@shaktimaan00

Copy link
Copy Markdown

Keypad shortcuts never fire: try the bound keyval before the ASCII fallback

Keybindings.activate() rewrites every keyval above 126 to the first ASCII keysym found on the same
hardware keycode, so that shortcuts keep working on non-latin layouts (#1946). Every keypad keysym is
above 126, so the rewrite also hit them: a shortcut bound to <Primary>KP_Divide was looked up as
slash (47), a keyval load_accelerators() had never registered, and the keystroke was handed to
VTE — / got typed. When the ASCII key on that keycode happened to carry a default binding, the
wrong action ran instead: Ctrl+KP_Subtract rewrote to minus and triggered zoom-out.

The rewritten keysym becomes a fallback instead of a replacement. The keyval itself is looked up
first, the ASCII one second, so:

  • keypad bindings fire again (<Primary>KP_Divide on split-tab-vertical splits),
  • a keypad binding is no longer shadowed by the ASCII binding sharing its keycode,
  • Keybindings does not work with not English layout. #1946 stays fixed, because a non-latin keysym still falls back to its English keysym.

The second lookup only happens when the rewrite actually ran (ascii_key is not None), so the
latin-layout path — one keyval, one case-fold, one lookup — is unchanged. That is also why I did not
use the unconditional lookup[event.keyval] or lookup[key] form: it would additionally make an
uppercase registration such as <Control>A start firing on Ctrl+Shift+A, a behaviour change this
issue does not ask for.

Changes

  • guake/keybindings.py — activate(): keep the rewritten keysym in ascii_key, look up
    event.keyval first when it exists, then ascii_key.
  • guake/tests/test_keybindings.py (new) — four tests, one per acceptance item; they drive
    activate() with a stub Gdk.Keymap and the fr pc105 keyvals from the report
    (106: KP_Divide, slash, division, 82: KP_Subtract, minus, 28: е, t).
  • releasenotes/notes/bugfix-numpad-keybindings-0e21c8e24e6fb5a4.yaml (new) — the reno note
    CONTRIBUTING asks for.

Acceptance

  • A shortcut bound to a numpad key triggers its action.
    test_keypad_binding_fires: <Primary>KP_Divide on split-tab-vertical, event keyval 65455
    on keycode 106 → activate() returns True and the action runs.
  • split-tab-vertical = <Primary>KP_Divide + Ctrl+KP_Divide splits the terminal vertically,
    instead of / reaching the terminal. Same test: activate() returning True is what stops
    the event being propagated to VTE, and the bound callable is the split_v() action
    (Keybindings.__init__ binds split-tab-vertical to ...split_v()).
  • The rewrite no longer triggers the wrong action.
    test_keypad_binding_is_not_shadowed_by_the_ascii_keysym_on_its_keycode: with both
    <Primary>KP_Subtract and <Primary>minus registered, Ctrl+KP_Subtract runs the former and
    zoom-out is never called.
  • Keybindings does not work with not English layout. #1946 is not regressed. test_non_latin_keyval_falls_back_to_the_english_keysym: keyval 1077
    (Cyrillic е) on keycode 28 still reaches <Control>t.
  • <Primary>slash keeps working from the keypad key when nothing is bound to the KP keysym.
    test_ascii_keysym_still_fires_when_the_keypad_key_has_no_binding.

The two regression cases fail with the old activate() (git stash push -- guake/keybindings.py):

FAILED guake/tests/test_keybindings.py::test_keypad_binding_fires - assert False
FAILED guake/tests/test_keybindings.py::test_keypad_binding_is_not_shadowed_by_the_ascii_keysym_on_its_keycode
2 failed, 2 passed

What I could not check here: a real X session with a physical numpad and an fr pc105 layout. The
tests replay the keyvals/keycodes the report dumped from that keymap, but nobody has pressed the key
on the patched build.

Commands run

Container: python:3.11-bookworm + gir1.2-gtk-3.0, gir1.2-keybinder-3.0, gir1.2-wnck-3.0,
gir1.2-notify-0.7, libutempter0, gsettings-desktop-schemas, xvfb, xauth,
libglib2.0-bin; pip install pycairo "pygobject<3.52" pytest==8.3.4 pytest-mock pyfakefs, and
make generate-paths, make compile-glib-schemas-dev, pip install -e . --no-deps (their CI's
make dev-actions equivalent). Run as GSETTINGS_SCHEMA_DIR=/work/guake/data xvfb-run -a …, i.e.
their make test-actions xvfb path.

command result
pytest guake/tests/test_keybindings.py -q 4 passed
same file with keybindings.py stashed 2 failed, 2 passed
pytest guake -q 34 passed (30 on the unmodified tree)
black --check guake --extend-exclude guake/_version.py 35 files unchanged
flake8 guake clean
pylint --rcfile=.pylintrc guake 10.00/10
reno -q lint exit 0 (one pre-existing warning on tab_activity_indication-be54b262d370a96b.yaml, not touched here)

Keypad shortcuts never fired: activate() rewrote every keyval above 126 to the
first ASCII keysym on the same keycode, so a shortcut bound to <Primary>KP_Divide
(65455) was looked up as slash (47), which load_accelerators() had never
registered. Worse, a binding on that ASCII key was triggered instead, so
Ctrl+KP_Subtract ran zoom-out.

The rewritten keysym is now only a fallback: the keyval itself is looked up
first, which restores keypad bindings while keeping Guake#1946 fixed, as non-latin
layouts still reach their English keysym through the second lookup.

Fixes Guake#2351

sem-ver: bugfix
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.

1 participant