Repository navigation
Conversation
seedds
added a commit
that referenced
this pull request
Oct 25, 2026
…d (general, from PR #128). A window that is no longer key sees no key-up, mouse-up or controller release, so a key, a click or a controller button held when the window lost focus (another app, the software keyboard's text box, minimizing) stayed pressed in the game. Now front_mac.m releases what the front end itself pressed when the window resigns key or is minimized (input_release): the keyboard buttons and the WASD stick, the touch only while the mouse holds it (g_mouse_down), and the pad of each player a controller holds (in DM_PAD_MERGE mode player 1's, when a controller is connected); while out of focus the keyboard, the mouse and the controllers' value changes are ignored (g_input_on), and when the window is key again each held controller is read as it is now (input_resume), so a button still held or a stick still deflected counts again. From PR #128 (nocmt), with two changes: the PR released player 1's pad and the touch in every case, which are also DM_KEYS' and DM_CTL's paths (hle_hid.c), so a scripted hold or drag ended early at a focus change during a Mac run; and it took input up again only if NSApp.isActive held when the window became key, so if AppKit makes the window key before the app counts as active, the keyboard, the mouse and the controllers stayed off until the next focus change. Also left out: the handler queue set to the main queue (already GameController's default), the focus state 3 on resigning key while minimized (DidMiniaturize sets it), the release on deminiaturizing (nothing is held then), and the t_hid test, which checked only that dm_input_set / dm_pad_set_player with zeros clear the state, not the focus handling. Checked: the host unit tests pass (GAME=010015100B514000), the Mac host builds for Mario vs. Donkey Kong, and a DM_WINDOW run boots it with DM_CTL presses reaching the game. Not checked: an actual focus change (in that run the window never became key or resigned it: the shell's activation requests and Finder's activation left no focus line), a physical controller, the software keyboard's text box by hand Co-authored-by: nocmt <[email protected]>
Owner
|
Thank you for this, and for the clear write-up of what was and wasn't tested. It's in main as 787523f, credited to this PR (Co-authored-by), with two changes:
Also left out: setting Checked: the host unit tests, the Mac host build, and a windowed boot with scripted presses. Still not checked, as in your list: a real focus change by hand, physical controllers, and the software keyboard's text box. |
Know-It-All-Brother
pushed a commit
to Know-It-All-Brother/nxnative
that referenced
this pull request
Nov 9, 2026
…d (general, from PR seedds#128). A window that is no longer key sees no key-up, mouse-up or controller release, so a key, a click or a controller button held when the window lost focus (another app, the software keyboard's text box, minimizing) stayed pressed in the game. Now front_mac.m releases what the front end itself pressed when the window resigns key or is minimized (input_release): the keyboard buttons and the WASD stick, the touch only while the mouse holds it (g_mouse_down), and the pad of each player a controller holds (in DM_PAD_MERGE mode player 1's, when a controller is connected); while out of focus the keyboard, the mouse and the controllers' value changes are ignored (g_input_on), and when the window is key again each held controller is read as it is now (input_resume), so a button still held or a stick still deflected counts again. From PR seedds#128 (nocmt), with two changes: the PR released player 1's pad and the touch in every case, which are also DM_KEYS' and DM_CTL's paths (hle_hid.c), so a scripted hold or drag ended early at a focus change during a Mac run; and it took input up again only if NSApp.isActive held when the window became key, so if AppKit makes the window key before the app counts as active, the keyboard, the mouse and the controllers stayed off until the next focus change. Also left out: the handler queue set to the main queue (already GameController's default), the focus state 3 on resigning key while minimized (DidMiniaturize sets it), the release on deminiaturizing (nothing is held then), and the t_hid test, which checked only that dm_input_set / dm_pad_set_player with zeros clear the state, not the focus handling. Checked: the host unit tests pass (GAME=010015100B514000), the Mac host builds for Mario vs. Donkey Kong, and a DM_WINDOW run boots it with DM_CTL presses reaching the game. Not checked: an actual focus change (in that run the window never became key or resigned it: the shell's activation requests and Finder's activation left no focus line), a physical controller, the software keyboard's text box by hand Co-authored-by: nocmt <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Release Mac input when the game window loses focus
Draft: actual desktop focus transitions and physical-controller verification are still pending. Based on current main at
7a029f66d92c951ae6a86e38bb34eeb0cb7527e3; the targeted tests and Objective-C syntax check were rerun after updating to this baseline.Problem
When the Mac game window resigns key status or is minimized while keyboard, touch, or a physical controller input is held, the corresponding input can remain active in the guest. GameController callbacks may also arrive after the window has gone inactive and restore stale physical pad state.
Minimal change
On window focus loss and minimization, clear the Mac keyboard state and publish neutral states for the existing keyboard/touch and per-player controller input paths. Ignore keyboard/controller updates while inactive. When focus returns, resample each connected physical controller so its current state is reflected instead of relying on a callback that may not arrive.
This keeps the existing multi-player slot assignments and input API semantics. The normal input release path is retained, including its existing press-latch behavior. This change does not cover rounded windows, mouse-look, FPS display, language selection, or other local launcher features.
Tests
make -C dm/host/tests GAME=010015100B514000 build/t_hid build/t_touchdm/host/tests/build/t_hid— 64 checks passed.dm/host/tests/build/t_touch— 13 checks passed.clang -fobjc-arc -fsyntax-only -Wall -Wextra -Wno-deprecated-declarations -Wno-unused-but-set-variable -Idm/host -Idm/host/gen/010015100B514000 dm/host/front_mac.mThe automated checks cover neutral state publication through the existing HID release APIs and touch release/latching behavior. They do not exercise the Mac front end's focus gate, controller resampling on focus return, AppKit notifications, or actual desktop/physical-controller behavior.
Manual verification still needed
On macOS, hold keyboard keys, touch/mouse input, and buttons/sticks on multiple connected controllers; then switch away from the game window and minimize it. Confirm guest input stops immediately, background controller activity cannot reinstate input, and returning focus samples the controllers' current state. Repeat with supported one-player and multi-player games, including controller disconnect/reconnect.
Related PRs