kbm: swapped mouse buttons keep the primary one on the right trigger #1166

Open
emirduran707 wants to merge 2 commits from upstream-pr/1175 into main
emirduran707 commented 2026-11-24 12:52:25 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by emirduran707 on 2026-11-24T12:52:25Z.


Stacked on #1172; only the top commit (kbm: swapped mouse buttons keep the primary one on the right trigger) belongs here.

Keyboard and mouse as a gamepad read the mouse buttons with GetAsyncKeyState(VK_LBUTTON / VK_RBUTTON). Microsoft's documentation of GetAsyncKeyState says it checks the physical mouse buttons, not the logical buttons they are mapped to. So with the buttons swapped in Windows (left-handed, SM_SWAPBUTTON), the primary button pulled the left trigger and the secondary one the right trigger: the reverse of every other program on that PC.

mouse_button_vks now picks the primary and secondary button from GetSystemMetrics(SM_SWAPBUTTON). The primary one pulls the right trigger, as before for a right-handed mouse.

What is in it

  • crates/xcl/src/hle/kbm.rs: mouse_button_vks, used by apply; test swapped_mouse_buttons_keep_the_primary_on_the_right_trigger.

Tested

  • AMD Radeon RX 9060 XT (driver 32.0.31044.16), Ryzen 5 5600, Windows 11 Pro 26300, Rust 1.100.0; tests debug, smoke release
  • cargo test --workspace -- --test-threads=4 on 6213e47 (this commit on top of #1172): 743 passed, 0 failed, 41 ignored; no SKIPPED GPU tests
  • the new test fails with the old mapping (left: (1, 2), right: (2, 1) for swapped buttons); with the change cargo test -p xcl --lib hle::kbm passes, 8 passed

Regression run

main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: AMD Radeon RX 9060 XT
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1541 (PresentX 1541)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 19650 MB

this PR:

xcl-smoke v1
commit: 6213e4764824475b8a7d08ab281525610fd623c0
gpu: AMD Radeon RX 9060 XT
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1541 (PresentX 1541)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 19592 MB

Not tested

  • By hand with swapped buttons and a real mouse; the smoke run takes no input.
  • NVIDIA and Intel GPUs.

AI use

  • Claude Code with Claude Opus 5.5: found the problem, wrote the change, the test and this description; I reviewed the diff and ran the tests and smoke runs above.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ivall/xcl:issue:5472506616 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1175). Originally posted by [emirduran707](https://github.com/emirduran707) on 2026-11-24T12:52:25Z. --- Stacked on #1172; only the top commit (`kbm: swapped mouse buttons keep the primary one on the right trigger`) belongs here. Keyboard and mouse as a gamepad read the mouse buttons with `GetAsyncKeyState(VK_LBUTTON / VK_RBUTTON)`. Microsoft's documentation of `GetAsyncKeyState` says it checks the physical mouse buttons, not the logical buttons they are mapped to. So with the buttons swapped in Windows (left-handed, `SM_SWAPBUTTON`), the primary button pulled the left trigger and the secondary one the right trigger: the reverse of every other program on that PC. `mouse_button_vks` now picks the primary and secondary button from `GetSystemMetrics(SM_SWAPBUTTON)`. The primary one pulls the right trigger, as before for a right-handed mouse. **What is in it** - `crates/xcl/src/hle/kbm.rs`: `mouse_button_vks`, used by `apply`; test `swapped_mouse_buttons_keep_the_primary_on_the_right_trigger`. **Tested** - AMD Radeon RX 9060 XT (driver 32.0.31044.16), Ryzen 5 5600, Windows 11 Pro 26300, Rust 1.100.0; tests debug, smoke release - `cargo test --workspace -- --test-threads=4` on 6213e47 (this commit on top of #1172): 743 passed, 0 failed, 41 ignored; no SKIPPED GPU tests - the new test fails with the old mapping (`left: (1, 2)`, `right: (2, 1)` for swapped buttons); with the change `cargo test -p xcl --lib hle::kbm` passes, 8 passed **Regression run** main: ``` xcl-smoke v1 commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3 gpu: AMD Radeon RX 9060 XT title: retail-title seconds: 60 exit: 0x0 frames shown: 1541 (PresentX 1541) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 19650 MB ``` this PR: ``` xcl-smoke v1 commit: 6213e4764824475b8a7d08ab281525610fd623c0 gpu: AMD Radeon RX 9060 XT title: retail-title seconds: 60 exit: 0x0 frames shown: 1541 (PresentX 1541) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 19592 MB ``` **Not tested** - By hand with swapped buttons and a real mouse; the smoke run takes no input. - NVIDIA and Intel GPUs. **AI use** - Claude Code with Claude Opus 5.5: found the problem, wrote the change, the test and this description; I reviewed the diff and ran the tests and smoke runs above. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
DavidM1911 commented 2026-11-24 14:06:28 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T13:10:20Z.


Independent verification on current main 384f7f7 (branch already contains it — clean).

Machine: Windows 11, Ryzen 9 7900X; Rust stable MSVC, debug.

  • cargo test -p xcl --lib kbm: 9 passed, 0 failed — the swapped-button primary/secondary handling keeps the kbm suite green.

AI use: test runs by Devin (Cognition, SWE-2); no code changes.

<!-- greyfinch-sync:ivall/xcl:comment:7132450058 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1175#issuecomment-7132450058). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T13:10:20Z. --- Independent verification on current `main` `384f7f7` (branch already contains it — clean). **Machine:** Windows 11, Ryzen 9 7900X; Rust stable MSVC, debug. - `cargo test -p xcl --lib kbm`: **9 passed, 0 failed** — the swapped-button primary/secondary handling keeps the kbm suite green. AI use: test runs by Devin (Cognition, SWE-2); no code changes.
fromthemoonx commented 2026-11-24 15:06:00 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-11-24T14:40:34Z.


Whole-suite NVIDIA run, to go with the kbm run above.

Tested

  • NVIDIA GeForce RTX 3060 12 GB, driver 32.0.16.1088; AMD Ryzen 7 5700X; native Windows 11 Pro 26H2 (build 26300.9974); rustc 1.100.0 stable-x86_64-pc-windows-msvc; debug
  • Exact head 6213e4764824475b8a7d08ab281525610fd623c0 (this commit on #1172, base 47efa2e): cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4: 743 passed, 0 failed, 41 ignored, the same as yours
  • Merged onto current main 930e8b4 (no conflict): 753 passed, 0 failed, 41 ignored
  • Fails with the old mapping: with mouse_button_vks(true) returning (0x01, 0x02) again, swapped_mouse_buttons_keep_the_primary_on_the_right_trigger fails
  • hle::kbm tests, 10 runs: 10 of 10 passed (8 each)
  • SKIPPED (no wave64 on this adapter): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware

Not tested

  • A real XCL window with the buttons swapped in Windows; release build.

AI use

  • Claude Code (Claude Opus 5.5) ran the builds and tests on the machine above, including the old-mapping check, and wrote this report from the output.
<!-- greyfinch-sync:ivall/xcl:comment:7134764244 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1175#issuecomment-7134764244). Originally posted by [fromthemoonx](https://github.com/fromthemoonx) on 2026-11-24T14:40:34Z. --- Whole-suite NVIDIA run, to go with the `kbm` run above. **Tested** - NVIDIA GeForce RTX 3060 12 GB, driver 32.0.16.1088; AMD Ryzen 7 5700X; native Windows 11 Pro 26H2 (build 26300.9974); rustc 1.100.0 `stable-x86_64-pc-windows-msvc`; debug - **Exact head `6213e4764824475b8a7d08ab281525610fd623c0`** (this commit on #1172, base `47efa2e`): `cargo build --workspace`, then `cargo test --workspace --no-fail-fast -- --test-threads=4`: **743 passed, 0 failed, 41 ignored**, the same as yours - **Merged onto current `main` `930e8b4`** (no conflict): **753 passed, 0 failed, 41 ignored** - **Fails with the old mapping:** with `mouse_button_vks(true)` returning `(0x01, 0x02)` again, `swapped_mouse_buttons_keep_the_primary_on_the_right_trigger` fails - `hle::kbm` tests, 10 runs: **10 of 10 passed** (8 each) - SKIPPED (no wave64 on this adapter): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware` **Not tested** - A real XCL window with the buttons swapped in Windows; release build. **AI use** - Claude Code (Claude Opus 5.5) ran the builds and tests on the machine above, including the old-mapping check, and wrote this report from the output.
S1m0ne1997 commented 2026-11-25 15:07:55 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by S1m0ne1997 on 2026-11-25T14:40:01Z.


Test report for 6213e4764824475b8a7d08ab281525610fd623c0 (this PR's head), for #1607.

Tested

  • NVIDIA GeForce RTX 4090 24 GB (driver 621.40), AMD Ryzen 9 9950X3D, 47 GB RAM, Windows 11 Home 10.0.26300, rustc 1.100.0 (0ef1bc386 2026-11-09) x86_64-pc-windows-msvc, debug.
  • cargo build --workspace, then cargo test --workspace -- --test-threads=4 at the head: 743 passed, 0 failed, 41 ignored.
  • SKIPPED (2): gpu_geometry_wave32_prefix_count_over_a_mask (no wave64), gpu_wave32_program_in_wave64_hardware (no wave64).

Regression run (retail title, scripts/smoke.ps1 -Seconds 60, release; main built from the commit in its block, this PR from its head, no uncommitted changes)

main:

xcl-smoke v1
commit: 06c9f5505f63f10c5ec49ef932d75b2c28177324
gpu: NVIDIA GeForce RTX 4090
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1599 (PresentX 1599)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16384 MB

this PR:

xcl-smoke v1
commit: 6213e4764824475b8a7d08ab281525610fd623c0
gpu: NVIDIA GeForce RTX 4090
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1640 (PresentX 1640)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 21863 MB

Peak commit is over the 125 % rule: this PR's run peaked at 21 863 MB, 133 % of main's 16 384 MB (frames: within 80 %). I can't tell from this whether the PR causes it: this branch is based on 47efa2e, 490 commits older than the main commit (06c9f55) its run is compared with, and each side was run once. A smoke run of the base itself, or of this PR rebased onto current main, would separate the two.

Not tested

  • AMD, other NVIDIA cards and drivers, Linux. I did not review the diff; this report is the build, the suite and the regression run only.

AI use: Claude Code with Claude Opus 5.5 ran the build, the suite and the regression run and wrote this report at my request.

<!-- greyfinch-sync:ivall/xcl:comment:7165626802 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1175#issuecomment-7165626802). Originally posted by [S1m0ne1997](https://github.com/S1m0ne1997) on 2026-11-25T14:40:01Z. --- Test report for `6213e4764824475b8a7d08ab281525610fd623c0` (this PR's head), for #1607. **Tested** - NVIDIA GeForce RTX 4090 24 GB (driver 621.40), AMD Ryzen 9 9950X3D, 47 GB RAM, Windows 11 Home 10.0.26300, `rustc 1.100.0 (0ef1bc386 2026-11-09)` `x86_64-pc-windows-msvc`, debug. - `cargo build --workspace`, then `cargo test --workspace -- --test-threads=4` at the head: **743 passed, 0 failed, 41 ignored**. - SKIPPED (2): `gpu_geometry_wave32_prefix_count_over_a_mask` (no wave64), `gpu_wave32_program_in_wave64_hardware` (no wave64). **Regression run** (retail title, `scripts/smoke.ps1 -Seconds 60`, release; `main` built from the commit in its block, this PR from its head, no uncommitted changes) main: ``` xcl-smoke v1 commit: 06c9f5505f63f10c5ec49ef932d75b2c28177324 gpu: NVIDIA GeForce RTX 4090 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1599 (PresentX 1599) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 16384 MB ``` this PR: ``` xcl-smoke v1 commit: 6213e4764824475b8a7d08ab281525610fd623c0 gpu: NVIDIA GeForce RTX 4090 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1640 (PresentX 1640) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 21863 MB ``` **Peak commit is over the 125 % rule:** this PR's run peaked at 21 863 MB, 133 % of `main`'s 16 384 MB (frames: within 80 %). I can't tell from this whether the PR causes it: this branch is based on `47efa2e`, 490 commits older than the `main` commit (`06c9f55`) its run is compared with, and each side was run once. A smoke run of the base itself, or of this PR rebased onto current `main`, would separate the two. **Not tested** - AMD, other NVIDIA cards and drivers, Linux. I did not review the diff; this report is the build, the suite and the regression run only. *AI use: Claude Code with Claude Opus 5.5 ran the build, the suite and the regression run and wrote this report at my request.*
github-actions[bot] commented 2026-11-29 20:42:13 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-29T20:42:13Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7262290766 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1175#issuecomment-7262290766). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-29T20:42:13Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 04:59:40 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T04:59:40Z.


Triage (#1607) – head 6213e47

Stacked on #1172; only the top commit (SM_SWAPBUTTON handling in kbm.rs:mouse_button_vks) belongs here, the shared lines are #1172's commit. No other PR handles swapped mouse buttons.
The PR conflicts with main: #1824 maps the triggers through InputProfile bindings (MouseLeft = VK 0x01, MouseRight = 0x02), so the primary/secondary swap now has to happen where InputKey mouse buttons are read.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7301313337 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1175#issuecomment-7301313337). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T04:59:40Z. --- **Triage (#1607)** – head 6213e47 Stacked on #1172; only the top commit (SM_SWAPBUTTON handling in `kbm.rs:mouse_button_vks`) belongs here, the shared lines are #1172's commit. No other PR handles swapped mouse buttons. The PR conflicts with main: #1824 maps the triggers through `InputProfile` bindings (`MouseLeft` = VK 0x01, `MouseRight` = 0x02), so the primary/secondary swap now has to happen where `InputKey` mouse buttons are read. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1175:upstream-pr/1175'
git switch 'upstream-pr/1175'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1175'
git switch 'upstream-pr/1175'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1175'
git switch 'upstream-pr/1175'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1175'
git switch 'main'
git merge --squash 'upstream-pr/1175'
git switch 'main'
git merge --ff-only 'upstream-pr/1175'
git switch 'main'
git merge 'upstream-pr/1175'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!1166
No description provided.