WIP: fix(input): Mouse 4 and Mouse 5 can be bound on Linux #1172

Draft
TrashPanda wants to merge 1 commit from TrashPanda/Longshot:fix/linux-mouse-4-5 into main
Contributor

Type: fix · Risk: low · Tested on: Linux, RTX 4070 Ti (game-free checks) · Needs: Linux, a mouse with side buttons

Why

On Linux the Controls page offers Mouse 4 and Mouse 5, but the side buttons were never seen, so binding one did nothing and a saved binding to one never acted. Windows has them.

Restored from Hookshot 2961, by jarynclouatre, and split out of #286 so it can be reviewed and merged on its own.

How to reproduce

Seen on: Linux, a mouse with side buttons
Settings and switches: defaults
Steps: in Controls, bind an action to Mouse 4
Expected: the side button is taken
Actual: the listener never sees it

What changed

keys_update in host/posix/display_sdl.c sets VK_XBUTTON1 and VK_XBUTTON2 from SDL's X1 and X2 bits, and host/posix/windows.h defines them.

Commits, each with its original author and message:

944e4cef fix(input): Mouse 4 and Mouse 5 can be bound on Linux (jarynclouatre)

On Linux, keys_update in host/posix/display_sdl.c turned three of
SDL's five mouse buttons into virtual keys. The Controls page offers
Mouse 4 and Mouse 5 (0x05 and 0x06), and host/nn_hid.c reads them, but
on Linux the listener never saw a side button, and a saved binding to
one (key_zl=5,0) never acted. Windows has them.

Change

  • keys_update also sets VK_XBUTTON1 from SDL's X1 bit (8) and
    VK_XBUTTON2 from X2 (16). The bits are the same in SDL 2 and SDL 3,
    and hos_sdl_mouse_buttons passes SDL's mask through unchanged.
  • host/posix/windows.h defines VK_XBUTTON1 and VK_XBUTTON2 beside
    the other mouse keys (nn_hid.c's own definitions are under #ifndef).
  • The window guard around those lines stays.

Testing

  • tests/test_sdl_mouse_buttons.py (new): keys_update and the posix
    virtual keys cut from the sources, built with stand-ins for SDL. Each of
    SDL's five button bits sets only its own key (5 and 6 for the side
    buttons), both side buttons together set both, and nothing is set
    without a window. It fails on main (keys 5 and 6 stay 0) and passes
    here.
  • Full suite on Linux: 2 failures, each for a tool this machine lacks
    (test_bake_portability: zstandard;
    nx2/test_texture_init_barrier.py: clang++); both fail the same on
    main.
  • No side button was pressed in the game on Linux.

Restored-from: https://github.com/NotRexed/Hookshot/pull/2961

Measurements

Verdict: nothing to measure: a correctness fix off the frame path, covered by game-free checks.

Flags and settings

None.

Testing

Tested: On Linux (kernel 7.0), RTX 4070 Ti, main @ 71b1edd8, this PR @ 944e4cef: tests/test_sdl_mouse_buttons.py pass. The full suite (tests/run_all.py) has not been run on this branch yet; a comment will follow when it has.

Not tested: Pressing a side button in the game on Linux. Opened as work in progress until it runs in the game.

Must be tested:

  • Linux, a mouse with side buttons (Test Farm: @Beanstalk linux): bind an action to Mouse 4 and Mouse 5 and use it, expecting it to act

Risks

What could break: mouse buttons on Linux.

Turning it off: revert the commit.

Compatibility: Nothing changes.

Checklist

Everyone

  • One topic.
  • The title is a Conventional Commit (type(scope): description) of the status line's type.
  • Why gives the reason plainly and links the issues that fit (the tracker searched).
  • Measurements has a verdict, or one line saying why there is nothing to measure.
  • Testing names what was tested, what wasn't, and what must still be tested, where and how.
  • Rebased on current main.
  • No game files, dumps, build output or generated files.
  • third_party/ untouched (a new folder with a PROVENANCE.md instead).
  • The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled.
  • python -I -B tests/run_all.py passes (any failure that also fails on main is named).

When it applies

  • A game-free test added for the fix, failing on main and passing here.
**Type:** fix · **Risk:** low · **Tested on:** Linux, RTX 4070 Ti (game-free checks) · **Needs:** Linux, a mouse with side buttons ## Why On Linux the Controls page offers Mouse 4 and Mouse 5, but the side buttons were never seen, so binding one did nothing and a saved binding to one never acted. Windows has them. Restored from [Hookshot 2961](https://github.com/NotRexed/Hookshot/pull/2961), by jarynclouatre, and split out of [#286](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/286) so it can be reviewed and merged on its own. ## How to reproduce **Seen on:** Linux, a mouse with side buttons **Settings and switches:** defaults **Steps:** in Controls, bind an action to Mouse 4 **Expected:** the side button is taken **Actual:** the listener never sees it ## What changed `keys_update` in `host/posix/display_sdl.c` sets `VK_XBUTTON1` and `VK_XBUTTON2` from SDL's X1 and X2 bits, and `host/posix/windows.h` defines them. Commits, each with its original author and message: <details><summary><code>944e4cef</code> fix(input): Mouse 4 and Mouse 5 can be bound on Linux (jarynclouatre)</summary> On Linux, `keys_update` in `host/posix/display_sdl.c` turned three of SDL's five mouse buttons into virtual keys. The Controls page offers Mouse 4 and Mouse 5 (0x05 and 0x06), and `host/nn_hid.c` reads them, but on Linux the listener never saw a side button, and a saved binding to one (`key_zl=5,0`) never acted. Windows has them. #### Change - `keys_update` also sets `VK_XBUTTON1` from SDL's X1 bit (8) and `VK_XBUTTON2` from X2 (16). The bits are the same in SDL 2 and SDL 3, and `hos_sdl_mouse_buttons` passes SDL's mask through unchanged. - `host/posix/windows.h` defines `VK_XBUTTON1` and `VK_XBUTTON2` beside the other mouse keys (`nn_hid.c`'s own definitions are under `#ifndef`). - The window guard around those lines stays. #### Testing - `tests/test_sdl_mouse_buttons.py` (new): `keys_update` and the posix virtual keys cut from the sources, built with stand-ins for SDL. Each of SDL's five button bits sets only its own key (5 and 6 for the side buttons), both side buttons together set both, and nothing is set without a window. It fails on main (keys 5 and 6 stay 0) and passes here. - Full suite on Linux: 2 failures, each for a tool this machine lacks (`test_bake_portability`: `zstandard`; `nx2/test_texture_init_barrier.py`: `clang++`); both fail the same on main. - No side button was pressed in the game on Linux. Restored-from: https://github.com/NotRexed/Hookshot/pull/2961 </details> ## Measurements **Verdict:** nothing to measure: a correctness fix off the frame path, covered by game-free checks. ### Flags and settings None. ## Testing **Tested:** On Linux (kernel 7.0), RTX 4070 Ti, `main` @ 71b1edd8, this PR @ 944e4cef: `tests/test_sdl_mouse_buttons.py` pass. The full suite (`tests/run_all.py`) has not been run on this branch yet; a comment will follow when it has. **Not tested:** Pressing a side button in the game on Linux. Opened as work in progress until it runs in the game. **Must be tested:** - Linux, a mouse with side buttons (Test Farm: @Beanstalk linux): bind an action to Mouse 4 and Mouse 5 and use it, expecting it to act ## Risks **What could break:** mouse buttons on Linux. **Turning it off:** revert the commit. **Compatibility:** Nothing changes. ## Checklist ### Everyone - [x] One topic. - [x] The title is a Conventional Commit (`type(scope): description`) of the status line's type. - [x] Why gives the reason plainly and links the issues that fit (the tracker searched). - [x] Measurements has a verdict, or one line saying why there is nothing to measure. - [x] Testing names what was tested, what wasn't, and what must still be tested, where and how. - [x] Rebased on current `main`. - [x] No game files, dumps, build output or generated files. - [x] `third_party/` untouched (a new folder with a `PROVENANCE.md` instead). - [x] The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled. - [ ] `python -I -B tests/run_all.py` passes (any failure that also fails on `main` is named). ### When it applies - [x] A game-free test added for the fix, failing on `main` and passing here.
fix(input): Mouse 4 and Mouse 5 can be bound on Linux
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 7s
Website / Website on Cloudflare (pull_request_target) Has been skipped
944e4cefeb
On Linux, `keys_update` in `host/posix/display_sdl.c` turned three of
SDL's five mouse buttons into virtual keys. The Controls page offers
Mouse 4 and Mouse 5 (0x05 and 0x06), and `host/nn_hid.c` reads them, but
on Linux the listener never saw a side button, and a saved binding to
one (`key_zl=5,0`) never acted. Windows has them.

## Change

- `keys_update` also sets `VK_XBUTTON1` from SDL's X1 bit (8) and
`VK_XBUTTON2` from X2 (16). The bits are the same in SDL 2 and SDL 3,
and `hos_sdl_mouse_buttons` passes SDL's mask through unchanged.
- `host/posix/windows.h` defines `VK_XBUTTON1` and `VK_XBUTTON2` beside
the other mouse keys (`nn_hid.c`'s own definitions are under `#ifndef`).
- The window guard around those lines stays.

## Testing

- `tests/test_sdl_mouse_buttons.py` (new): `keys_update` and the posix
virtual keys cut from the sources, built with stand-ins for SDL. Each of
SDL's five button bits sets only its own key (5 and 6 for the side
buttons), both side buttons together set both, and nothing is set
without a window. It fails on main (keys 5 and 6 stay 0) and passes
here.
- Full suite on Linux: 2 failures, each for a tool this machine lacks
(`test_bake_portability`: `zstandard`;
`nx2/test_texture_init_barrier.py`: `clang++`); both fail the same on
main.
- No side button was pressed in the game on Linux.

Restored-from: https://github.com/NotRexed/Hookshot/pull/2961
Author
Contributor

Tested in game: Linux (Ubuntu 26.04.1, kernel 7.0.0-43), RTX 4070 Ti 12 GB, NVIDIA 595.99.02, Ryzen 7 9800X3D: this branch built together with the other 18 split from #218 and #284-#288, merged onto main @ 71b1edd8 (make_game.py --update, build v3.0.0-rc.5-82-g5952bb3d), then played by a scripted tour through the control bridge (scripts/memtour.py: a save loaded, Zora's Domain, the Market, Hyrule Field and Death Mountain Trail, 40 s each with walking and camera swings). All 4 stops reached, a clean quit, and no device loss or Vulkan error in the log. Only scripted input ran; binding Mouse 4 and 5 in Controls was not tried by hand.

Tested in game: Linux (Ubuntu 26.04.1, kernel 7.0.0-43), RTX 4070 Ti 12 GB, NVIDIA 595.99.02, Ryzen 7 9800X3D: this branch built together with the other 18 split from #218 and #284-#288, merged onto main @ 71b1edd8 (make_game.py --update, build v3.0.0-rc.5-82-g5952bb3d), then played by a scripted tour through the control bridge (scripts/memtour.py: a save loaded, Zora's Domain, the Market, Hyrule Field and Death Mountain Trail, 40 s each with walking and camera swings). All 4 stops reached, a clean quit, and no device loss or Vulkan error in the log. Only scripted input ran; binding Mouse 4 and 5 in Controls was not tried by hand.
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 7s
Website / Website on Cloudflare (pull_request_target) Has been skipped
This pull request is marked as a work in progress.
Some workflows are waiting to be reviewed.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'fix/linux-mouse-4-5:TrashPanda-fix/linux-mouse-4-5'
git switch 'TrashPanda-fix/linux-mouse-4-5'
Sign in to join this conversation.
No reviewers
No milestone
No project
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.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!1172
No description provided.