WIP: fix(input): the controller in the background stays out of the game while the Insert menu is open #1169

Draft
TrashPanda wants to merge 2 commits from TrashPanda/Longshot:fix/background-pad-menu-hold into main
Contributor

Type: fix · Risk: low · Tested on: Linux, RTX 4070 Ti (game-free checks) · Needs: any, a controller

Why

With "Controller in background" on, the Insert menu's hold on the controller only applied with the game in front: behind another window, a button pressed with the menu open, or still held after it closed, reached the game.

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

How to reproduce

Seen on: any OS, a controller
Settings and switches: Controller in background on
Steps: put another window in front, open the Insert menu, press B, close the menu while B is held
Expected: Link does nothing until B is let go
Actual: Link acts on B

What changed

The menu's hold, the read and the merge are one helper, pads_merge in host/nn_hid.c, used in front and behind. It keeps main's per-input rule: after the menu closes, only the inputs it had wait until they are let go, and the sticks are the game's at once.

Ported onto main, which since changed the in-front hold to wait per input (the inputs the menu had, not the whole pad): pads_merge is main's in-front block, now used behind too. The fixture's new pads-insert case drives main's menu_open and expects the sticks right after the close, as main gives them in front.

Commits, each with its original author and message:

9ded740c fix(input): the controller in the background stays out of the game while the Insert menu is open (jarynclouatre)

With "Controller in background" on (or HOS_INPUT_BACKGROUND=1),
read_input's branch for a window behind another merged the pads
straight into the game's input. The Insert menu's hold, which the branch
for the window in front applies (the pads are the menu's while it is
open, and after it closed until they are let go), was missing there. A
button pressed with the menu open behind another window, or still held
after it closed, reached the game.

The hold, the read and the merge are one helper, pads_merge, used by
both branches. The pads are still read while held back, so the letting
go is seen. player_used() is still called only in front, as before,
and the keyboard and mouse stay out behind other windows.

  • tests/test_input_background.py and its fixture: a new case behind
    another window with the pads allowed there. With the menu open, B and
    the sticks do not reach the game, though the pads are read; with the
    menu closed and B still held, nothing; after B is let go and pressed
    again, B and the sticks arrive. On main the first frame already carries
    B. The other 17 cases pass as before.
  • 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.
  • Not tested in the game.

Co-authored-by: NotRexed [email protected]
Restored-from: https://github.com/NotRexed/Hookshot/pull/2963

391b7c82 test: the pads-after-menu check cuts pads_merge, where read_input's pad block now is (Joey Magnus)

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 @ 391b7c82: tests/test_input_background.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: The game with a controller behind another window. Opened as work in progress until it runs in the game.

Must be tested:

  • Any OS, a controller (by hand): the steps under How to reproduce, expecting B to wait until it is let go

Risks

What could break: controller input around the Insert menu.

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).
  • Tested on my own PC where it runs (in the game, for a change the game runs), as Testing's Tested says; what
    can't be run by hand is in Testing's Not testable by hand, with why.
  • Measurements has a verdict, or one line saying why there is nothing to measure.
  • Nothing gets worse that I know of: any cost (speed, latency, memory, a setup that worked before) is measured and
    in Risks.
  • 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:** any, a controller ## Why With "Controller in background" on, the Insert menu's hold on the controller only applied with the game in front: behind another window, a button pressed with the menu open, or still held after it closed, reached the game. Restored from [Hookshot 2963](https://github.com/NotRexed/Hookshot/pull/2963), by Joey Magnus, 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:** any OS, a controller **Settings and switches:** Controller in background on **Steps:** put another window in front, open the Insert menu, press B, close the menu while B is held **Expected:** Link does nothing until B is let go **Actual:** Link acts on B ## What changed The menu's hold, the read and the merge are one helper, `pads_merge` in `host/nn_hid.c`, used in front and behind. It keeps `main`'s per-input rule: after the menu closes, only the inputs it had wait until they are let go, and the sticks are the game's at once. Ported onto `main`, which since changed the in-front hold to wait per input (the inputs the menu had, not the whole pad): `pads_merge` is `main`'s in-front block, now used behind too. The fixture's new `pads-insert` case drives `main`'s `menu_open` and expects the sticks right after the close, as `main` gives them in front. Commits, each with its original author and message: <details><summary><code>9ded740c</code> fix(input): the controller in the background stays out of the game while the Insert menu is open (jarynclouatre)</summary> With "Controller in background" on (or `HOS_INPUT_BACKGROUND=1`), `read_input`'s branch for a window behind another merged the pads straight into the game's input. The Insert menu's hold, which the branch for the window in front applies (the pads are the menu's while it is open, and after it closed until they are let go), was missing there. A button pressed with the menu open behind another window, or still held after it closed, reached the game. The hold, the read and the merge are one helper, `pads_merge`, used by both branches. The pads are still read while held back, so the letting go is seen. `player_used()` is still called only in front, as before, and the keyboard and mouse stay out behind other windows. - `tests/test_input_background.py` and its fixture: a new case behind another window with the pads allowed there. With the menu open, B and the sticks do not reach the game, though the pads are read; with the menu closed and B still held, nothing; after B is let go and pressed again, B and the sticks arrive. On main the first frame already carries B. The other 17 cases pass as before. - 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. - Not tested in the game. Co-authored-by: NotRexed <[email protected]> Restored-from: https://github.com/NotRexed/Hookshot/pull/2963 </details> <details><summary><code>391b7c82</code> test: the pads-after-menu check cuts pads_merge, where read_input's pad block now is (Joey Magnus)</summary> </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 @ 391b7c82: `tests/test_input_background.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:** The game with a controller behind another window. Opened as work in progress until it runs in the game. **Must be tested:** - Any OS, a controller (by hand): the steps under How to reproduce, expecting B to wait until it is let go ## Risks **What could break:** controller input around the Insert menu. **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] Tested on my own PC where it runs (in the game, for a change the game runs), as Testing's Tested says; what can't be run by hand is in Testing's Not testable by hand, with why. - [x] Measurements has a verdict, or one line saying why there is nothing to measure. - [x] Nothing gets worse that I know of: any cost (speed, latency, memory, a setup that worked before) is measured and in Risks. - [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.
With "Controller in background" on (or `HOS_INPUT_BACKGROUND=1`),
`read_input`'s branch for a window behind another merged the pads
straight into the game's input. The Insert menu's hold, which the branch
for the window in front applies (the pads are the menu's while it is
open, and after it closed until they are let go), was missing there. A
button pressed with the menu open behind another window, or still held
after it closed, reached the game.

The hold, the read and the merge are one helper, `pads_merge`, used by
both branches. The pads are still read while held back, so the letting
go is seen. `player_used()` is still called only in front, as before,
and the keyboard and mouse stay out behind other windows.

- `tests/test_input_background.py` and its fixture: a new case behind
another window with the pads allowed there. With the menu open, B and
the sticks do not reach the game, though the pads are read; with the
menu closed and B still held, nothing; after B is let go and pressed
again, B and the sticks arrive. On main the first frame already carries
B. The other 17 cases pass as before.
- 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.
- Not tested in the game.

Co-authored-by: NotRexed <[email protected]>
Restored-from: https://github.com/NotRexed/Hookshot/pull/2963
test: the pads-after-menu check cuts pads_merge, where read_input's pad block now is
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
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 9s
391b7c8249
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; no controller was connected, so the Insert menu with a pad in the background 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; no controller was connected, so the Insert menu with a pad in the background was not tried by hand.
Author
Contributor

This and #1168 both change tests/test_input_background.py (the functions the check cuts from host/nn_hid.c). Whichever merges second needs a one-line rebase there: cut pads_in_background, pads_behind and pads_merge, in that order. Both were built and run together that way (see the first comment).

This and #1168 both change `tests/test_input_background.py` (the functions the check cuts from `host/nn_hid.c`). Whichever merges second needs a one-line rebase there: cut `pads_in_background`, `pads_behind` and `pads_merge`, in that order. Both were built and run together that way (see the first comment).
Collaborator

Possibly related, for context:

  • PR #1171 WIP: fix(input): the gyro is at rest while the Insert menu is open — Related input handling: motion remains active while Insert menu is open
  • PR #1168 WIP: fix(input): custom ocarina note buttons count with the controller in the background — Related background-controller input fix for custom ocarina notes
Possibly related, for context: - PR #1171 WIP: fix(input): the gyro is at rest while the Insert menu is open — Related input handling: motion remains active while Insert menu is open - PR #1168 WIP: fix(input): custom ocarina note buttons count with the controller in the background — Related background-controller input fix for custom ocarina notes
Owner

Brought up to the ready-for-review standard (#1454): the checklist's Everyone list has two new boxes, added here from what this PR's description and comments show (please check they match what you know).

  • Tested on my own PC: ticked: Author's Tested in game comments describe an in-game run on Linux with an RTX 4070 Ti, though the Insert menu with a pad was not tried by hand.
  • Nothing gets worse that I know of: ticked: Measurements gives a verdict of nothing to measure for a correctness fix, and Risks names no slower, latency or memory cost.
Brought up to the [ready-for-review standard](https://git.magicbean.dev/MagicBeanDev/Longshot/src/branch/main/CONTRIBUTING.md#ready-for-review-out-of-wip) (#1454): the checklist's Everyone list has two new boxes, added here from what this PR's description and comments show (please check they match what you know). - *Tested on my own PC*: ticked: Author's Tested in game comments describe an in-game run on Linux with an RTX 4070 Ti, though the Insert menu with a pad was not tried by hand. - *Nothing gets worse that I know of*: ticked: Measurements gives a verdict of nothing to measure for a correctness fix, and Risks names no slower, latency or memory cost.
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
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 9s
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/background-pad-menu-hold:TrashPanda-fix/background-pad-menu-hold'
git switch 'TrashPanda-fix/background-pad-menu-hold'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
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!1169
No description provided.