hex/src/linux/remote_desktop
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Dax b5b5a27158
linux: send portal paste chords as evdev keycodes (#1941)
* linux: send portal paste chords as evdev keycodes (#1939)

KWin looks a keysym up in the desktop's active layout group. With a
non-Latin layout (Russian) active it can't find Latin `v` there, and its
fallback to a scratch keymap lost the held Ctrl: the app received a bare
`v` and Ctrl stayed down in the compositor.

NotifyKeyboardKeycode takes Linux evdev keycodes (KEY_LEFTCTRL 29,
KEY_LEFTSHIFT 42, KEY_A 30, KEY_C 46, KEY_V 47, KEY_ENTER 28), which name
the physical key, so the chord is the same in every layout. The session
already asks for the KEYBOARD device type, which keycode notifications
require, so only the method and its numbers change.

Not observed on a real KDE session.

* linux: resolve paste keycodes from the desktop keymap (#1939)

A fixed evdev code is wrong on a non-QWERTY Latin layout: Dvorak puts `v`
on KEY_DOT, so Ctrl+V would arrive as Ctrl+K, and AZERTY puts `a` on
KEY_Q, so select-all would be Ctrl+Q, which quits apps.

Paste now reads the compositor's keymap from a one-shot wl_seat keyboard
(bounded at 250 ms, the fd read through a File with a size cap, no
unsafe), parses it with xkbcommon, and resolves `a`, `c`, and `v` at level
1 across every layout group. A chord goes out as NotifyKeyboardKeycode
only when every group that has the letter agrees on one evdev code (the
xkb keycode minus 8); disagreeing groups such as `us,us(dvorak)`, an
ambiguous group, a missing letter, or no keymap at all send the whole
chord as keysyms, as before. Ctrl (29), Shift (42), and Enter (28) are
fixed codes, and Return never reads the keymap.

KWin 6.8's fake input answered a Latin `v` under a Russian layout from a
scratch keymap that lost the held Ctrl: the app got a bare `v` and Ctrl
stayed stuck (#1939). Mutter's keysym path drops the `v` the same way.

The keymap is read per chord because a portal session can outlive the
keymap it started under, and a layout or variant change replaces it.

Not observed on a real KDE or GNOME session.

* linux: read the shared keymap safely and check every fixed key (#1939)

Compositors hand every client the same keymap fd, and an fd's offset is
shared, so the sequential read left it at EOF: every later paste's read
came back empty, silently falling back to keysyms, and other clients
reading the same fd saw nothing. Read positionally instead
(`FileExt::read_exact_at`, never moving the offset) and strip the NUL the
desktop ends the keymap with.

Ctrl, Shift, and Return are only where the keymap says they are. Options
move them (`ctrl:swapcaps` puts Caps_Lock on 29, `ctrl:nocaps` leaves
Control_L on two keys), so keycode mode now requires Control_L on 29,
Shift_L on 42 when the chord holds shift, and Return on 28, each in every
layout group; otherwise the whole chord is keysyms. Return without a
keymap is a keysym again, as it was before.

The wait no longer spins: `guard.read()` returns Ok(0) when nothing is
ready, so the old loop retried without ever yielding. It now asks for a
wl_display sync once the keyboard exists and stops when that answers
(the keymap comes before it), stops at once when the seat has no
keyboard, and polls the Wayland fd with a deadline like `linux/clipboard`
does. The registry roundtrip before it keeps the comment saying what it
is: Wayland's unbounded startup roundtrip, as in `linux/paste.rs`.

Tests parse a self-contained inline keymap through xkbcommon (no
xkeyboard-config), read it twice through one fd, and cover the moved
modifier and Return fallbacks. The Cyrillic fixtures use the legacy
keysyms xkbcommon reports, in `ru,us` order.

Not observed on a real KDE or GNOME session.

* docs(linux): correct the keymap comments (#1939)

KEY_CAPSLOCK is 58, where `ctrl:swapcaps` puts Control_L, not a key no
keyboard has. The map now says what each key actually requires: a letter
needs one code across every group that has it, while Ctrl, Shift, and
Enter must be on 29, 42, and 28 in every group.

Mutter loses a keysym outside the active group, not `v` specifically.
The wtype paragraph keeps its original wrapping, and a paste that cannot
read the keymap says so at debug level.
2026-11-17 13:23:38 -05:00
..
keymap.rs linux: send portal paste chords as evdev keycodes (#1941) 2026-11-17 13:23:38 -05:00