Skip to content

fix(linux/input): send the ABNT2 slash key as VK_ABNT_C1 - #6217

Open
NestorBrasileiro wants to merge 1 commit into
SunshineStream:masterfrom
NestorBrasileiro:fix/linux-abnt2-slash-key
Open

NestorBrasileiro wants to merge 1 commit into
SunshineStream:masterfrom
NestorBrasileiro:fix/linux-abnt2-slash-key

Conversation

@NestorBrasileiro

Copy link
Copy Markdown

Description

On Linux hosts, the dedicated / ? key of a Brazilian ABNT2 keyboard types \ (and | with Shift) instead of / and ?.

Root cause. Moonlight doesn't send this key as VK_ABNT_C1 (0xC1). In moonlight-qt app/streaming/input/keyboard.cpp, SDL_SCANCODE_INTERNATIONAL1 falls through to SDL_SCANCODE_NONUSBACKSLASH with keyCode = 0xE2 (VK_OEM_102) and sets shouldNotConvertToScanCodeOnServer, i.e. SS_KBE_FLAG_NON_NORMALIZED. Windows hosts honor that flag. On other platforms keyboard_event() discarded the flags ((void) flags;), so both ABNT2 keys reached the host as KEY_102ND and couldn't be told apart.

Change. On non-Windows hosts, a 0xE2 key event with SS_KBE_FLAG_NON_NORMALIZED is forwarded as 0xC1. Unflagged 0xE2 (the real \ | key) and all other keys are unchanged. The Windows path is functionally the same (the flag test is just hoisted into a local).

Dependency. libvirtualhid's Linux backend needs a 0xC1 → KEY_RO mapping: LizardByte/libvirtualhid#246. Until the submodule includes it, a flagged 0xE2 would be rejected by libvirtualhid instead of typing \. So this should land together with, or after, the submodule bump.

Screenshot

Issues Fixed or Closed

Roadmap Issues

Testing

Unit test: extended VirtualHidDeviceTest.TranslatesMouseAndKeyboardInput (non-Windows branch). A flagged 0xE2 must be submitted as 0xC1, an unflagged 0xE2 must stay 0xE2, and 0x41 with all flags set keeps its code.

  • Without the fix it fails: test_virtualhid_input.cpp:874: Failure ... Which is: 226 / Which is: 193.
  • With the fix it passes, along with all 46 virtualhid tests (--gtest_filter='*VirtualHid*:*virtualhid*', Linux, GCC 16, -DSUNSHINE_ENABLE_CUDA=OFF).
  • uv run --locked lb-update-clang-format produced no changes to the touched files.

Real hardware: I tested the same change backported to 2026.914.233613 (built with CUDA 12.9 for a Pascal GPU), together with the libvirtualhid patch.

Host Omarchy 4.5 (Arch), kernel 7.2.15, Hyprland 0.56.2, capture = wlr, XKB layout br
CPU / GPU Intel i5-7400 / GeForce GTX 1050 (driver 580.178.04)
Client Ubuntu 26.04, Moonlight v6.2.0, physical ABNT2 keyboard

xkbcli interactive-wayland on the host:

BEFORE  "/?" key      -> [ LSGT ] backslash  \
        Shift + "/?"  -> [ LSGT ] bar        |
        "\|" key      -> [ LSGT ] backslash  \
AFTER   "/?" key      -> [ AB11 ] slash      /
        Shift + "/?"  -> [ AB11 ] question   ?
        "\|" key      -> [ LSGT ] backslash  \   (unchanged)

Not run: Windows/macOS/FreeBSD builds and the full CI matrix.

Type of Change

  • feat: New feature (non-breaking change which adds functionality)
  • fix: Bug fix (non-breaking change which fixes an issue)
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semicolons, etc.)
  • refactor: Code change that neither fixes a bug nor adds a feature
  • perf: Code change that improves performance
  • test: Adding missing tests or correcting existing tests
  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Other changes that don't modify src or test files
  • revert: Reverts a previous commit
  • BREAKING CHANGE: Introduces a breaking change (can be combined with any type above)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas
  • Code docstring/documentation-blocks for new or existing methods/components have been added or updated
  • Tests have been added or updated for new or modified functionality, including regression tests for bug fixes

AI Usage

See our AI usage policy.

  • AI tools were used while preparing this PR

Claude Code traced the key path (moonlight-qt → Sunshine → libvirtualhid → XKB), wrote the change, test and docs, and ran the local checks. I tested the result on my own hardware and ABNT2 keyboard.


This pull request was generated by Claude Code (agent) using Claude Opus 5.5 (claude-opus-5-5), low thinking level

🤖 Generated with Claude Code

Moonlight sends the dedicated "/ ?" key of ABNT2 keyboards as
VK_OEM_102 (0xE2) with SS_KBE_FLAG_NON_NORMALIZED. Windows honors the
flag, but on Linux the flags were discarded, so the key became
KEY_102ND and typed "\" like the real "\ |" key. Forward the flagged
code as VK_ABNT_C1 (0xC1) on non-Windows hosts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@NestorBrasileiro

Copy link
Copy Markdown
Author

This pull request was generated by Claude Code (agent) using Claude Opus 5.5 (claude-opus-5-5), low thinking level

@sonarqubecloud

sonarqubecloud Bot commented Dec 2, 2026

Copy link
Copy Markdown

@ReenigneArcher ReenigneArcher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The ABNT2 translation can override an explicit Sunshine keybindings target. The inline finding shows how to apply the compatibility rule only to an original client key with no configured mapping.

git diff --check passed. Isolated tests exercised the target, PR, and proposed ordering. GitHub Actions is awaiting maintainer approval, so the hosted build and test results are unavailable.

Review completed by Codex | Model: gpt-6.2-sol | Thinking: xhigh

(void) flags;
constexpr std::uint16_t vk_oem_102 = 0xE2;
constexpr std::uint16_t vk_abnt_c1 = 0xC1;
if (modcode == vk_oem_102 && non_normalized) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P2] Preserve explicit bindings to VK_OEM_102

keyboard_event() receives the result of map_keycode(). On a Linux host, keybindings = [0xDC, 0xE2] turns a non-normalized 0xDC into the ISO key on master. With this change the same press and release become 0xC1, which emits a different physical key even with the updated libvirtualhid. Moonlight Qt can send a flagged 0xDC from SDL_SCANCODE_INTERNATIONAL3.

Move the compatibility rule into map_keycode() in src/input.cpp, below the explicit binding lookup:

short map_keycode(short keycode, std::uint8_t flags) {
    if (auto it = config::input.keybindings.find(keycode); it != std::end(config::input.keybindings)) {
      return it->second;
    }

#ifndef _WIN32
    constexpr short vk_oem_102 = 0xE2;
    constexpr short vk_abnt_c1 = 0xC1;
    if (keycode == vk_oem_102 && (flags & SS_KBE_FLAG_NON_NORMALIZED) != 0) {
      return vk_abnt_c1;
    }
#else
    (void) flags;
#endif
    return keycode;
  }

Pass flags from send_key_and_modifiers() and flags_from_kpid(key) from reset_keyboard_keys(). Update map_keycode()'s @param docs and restore the original non-Windows branch of keyboard_event(). Move the ABNT2 assertions to KeyboardPassthroughTest in tests/unit/test_keyboard.cpp. Using the fake keyboard, cover a flagged 0xDC bound to 0xE2 on press and release, plus a raw flagged 0xE2 with no binding. An isolated Clang harness reproduced the regression and verified the proposed ordering. The full Sunshine test binary was unavailable locally.

Review completed by Codex | Model: gpt-6.2-sol | Thinking: xhigh

This branch has not been deployed

No deployments
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.

Linux keyboard backend has no mapping for VK_ABNT_C1 (ABNT2 dedicated / ? key) — key is silently dropped

2 participants