[pr-fix][input] Window drag: a title bar click that moves nothing ends it, and the native mouse waits for the move to end #421

Open
ElGibbone wants to merge 1 commit from elgibbone/window-drag-capture into main AGit
First-time contributor

What it changes

  • The problem on main: read from the code only, two cases in windowed mode.
    1. The drag flag stays set after a click on the title bar or frame that moves nothing. WM_NCLBUTTONDOWN sets MOUSE_DRAGGING, and only WM_EXITSIZEMOVE, a click in the window, a lost focus or a deactivation clear it. A press on the title bar with no drag, or on the minimise or maximise button, sends no WM_EXITSIZEMOVE. On the legacy path (DARNER_NATIVE_MOUSE=0) the capture then stays off and mnk::sample returns an empty pad, keys included, until the next click in the window.
    2. The native mouse captures during a move. should_capture_mouse doesn't look at the drag. A click on the title bar of the unfocused window focuses it, the next 8 ms poll captures, and the cursor clip (also renewed by refresh_cursor_clip on every WM_MOVE) can pull the cursor off the title bar into the window while the move goes on.

What this does:

  • WM_NCLBUTTONDOWN still sets the flag. It is what frees the cursor when the click that activates the window lands on the title bar. The system's move and size loop runs inside the default handling of that message, so once the title's procedure returns from it the drag is over. If no WM_EXITSIZEMOVE cleared the flag by then, window_proc clears it there and takes the legacy capture back, as WM_EXITSIZEMOVE does.
  • should_capture_mouse takes dragging (lifecycle::mouse_dragging()), in the overlay poll and in the F9 toggle. The native mouse is not captured while the window is moved or sized, and comes back on the first poll after.
  • The native mouse capture changes line logs dragging with the other reasons.

I didn't set the flag only between WM_ENTERSIZEMOVE and WM_EXITSIZEMOVE. Without the flag on WM_NCLBUTTONDOWN, the activation's capture would clip the cursor away from the title bar the player is holding.

How it was tested

  • Tested revision: aac6fbf (one commit on main f3840d7)
  • Commands and results: menu_and_pause_states_release_and_recapture_mouse covers the new dragging argument.
  • Changes a default: no
  • A/B result: not applicable.
  • Gates run on that revision: cargo clippy --workspace --all-targets --locked -- -D warnings clean, the same with --all-features clean, cargo xtask policy passed, cargo test -p darner-hle --locked 496 passed, 0 failed, 15 ignored, cargo test -p darner --locked 160 passed, 1 ignored. Not the whole cargo test --workspace.
  • Gameplay, when relevant: not run in the game yet. To check: windowed mode, click the title bar without moving and press a key (legacy path), and drag the unfocused window by its title bar (native path).
  • Hardware dependence: none expected; windowed mode only.
  • Coverage gaps: the message order (activation, WM_NCLBUTTONDOWN, the move loop) is read from the code and the Win32 documentation, not driven by a test.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: #34 and #154 also change lifecycle.rs, and #364, #399, #402 and #405 also change gameinput.rs; this merges with each of them without conflicts (git merge-tree). #75 also changes lifecycle.rs, but already conflicts with main there on its own.
  • Replaces or overlaps: none found
## What it changes - The problem on main: read from the code only, two cases in windowed mode. 1. **The drag flag stays set after a click on the title bar or frame that moves nothing.** `WM_NCLBUTTONDOWN` sets `MOUSE_DRAGGING`, and only `WM_EXITSIZEMOVE`, a click in the window, a lost focus or a deactivation clear it. A press on the title bar with no drag, or on the minimise or maximise button, sends no `WM_EXITSIZEMOVE`. On the legacy path (`DARNER_NATIVE_MOUSE=0`) the capture then stays off and `mnk::sample` returns an empty pad, keys included, until the next click in the window. 2. **The native mouse captures during a move.** `should_capture_mouse` doesn't look at the drag. A click on the title bar of the unfocused window focuses it, the next 8 ms poll captures, and the cursor clip (also renewed by `refresh_cursor_clip` on every `WM_MOVE`) can pull the cursor off the title bar into the window while the move goes on. What this does: - `WM_NCLBUTTONDOWN` still sets the flag. It is what frees the cursor when the click that activates the window lands on the title bar. The system's move and size loop runs inside the default handling of that message, so once the title's procedure returns from it the drag is over. If no `WM_EXITSIZEMOVE` cleared the flag by then, `window_proc` clears it there and takes the legacy capture back, as `WM_EXITSIZEMOVE` does. - `should_capture_mouse` takes `dragging` (`lifecycle::mouse_dragging()`), in the overlay poll and in the F9 toggle. The native mouse is not captured while the window is moved or sized, and comes back on the first poll after. - The `native mouse capture changes` line logs `dragging` with the other reasons. I didn't set the flag only between `WM_ENTERSIZEMOVE` and `WM_EXITSIZEMOVE`. Without the flag on `WM_NCLBUTTONDOWN`, the activation's capture would clip the cursor away from the title bar the player is holding. ## How it was tested - Tested revision: aac6fbf (one commit on main f3840d7) - Commands and results: `menu_and_pause_states_release_and_recapture_mouse` covers the new `dragging` argument. - Changes a default: no - A/B result: not applicable. - Gates run on that revision: `cargo clippy --workspace --all-targets --locked -- -D warnings` clean, the same with `--all-features` clean, `cargo xtask policy` passed, `cargo test -p darner-hle --locked` 496 passed, 0 failed, 15 ignored, `cargo test -p darner --locked` 160 passed, 1 ignored. Not the whole `cargo test --workspace`. - Gameplay, when relevant: not run in the game yet. To check: windowed mode, click the title bar without moving and press a key (legacy path), and drag the unfocused window by its title bar (native path). - Hardware dependence: none expected; windowed mode only. - Coverage gaps: the message order (activation, `WM_NCLBUTTONDOWN`, the move loop) is read from the code and the Win32 documentation, not driven by a test. ## Checklist - [ ] I ran this change in the game, or say below why it can't be (docs, tests only). - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: #34 and #154 also change `lifecycle.rs`, and #364, #399, #402 and #405 also change `gameinput.rs`; this merges with each of them without conflicts (`git merge-tree`). #75 also changes `lifecycle.rs`, but already conflicts with `main` there on its own. - Replaces or overlaps: none found
WM_NCLBUTTONDOWN sets MOUSE_DRAGGING, but a press on the title bar or
frame that starts no move or size loop sends no WM_EXITSIZEMOVE, so the
flag stayed set until the next click in the window: on the legacy path
no capture and an empty pad from mnk::sample, keys included. The loop
runs inside the default handling of that message, so window_proc now
clears the flag once the title's procedure returns from it and takes
the legacy capture back, as WM_EXITSIZEMOVE does.

should_capture_mouse also takes the drag: the native mouse is no longer
captured, and the cursor clipped into the window, while the window is
moved or sized. The capture-change log line names it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/421/head:elgibbone/window-drag-capture'
git switch 'elgibbone/window-drag-capture'

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 'elgibbone/window-drag-capture'
git switch 'elgibbone/window-drag-capture'
git rebase 'main'
git switch 'main'
git merge --ff-only 'elgibbone/window-drag-capture'
git switch 'elgibbone/window-drag-capture'
git rebase 'main'
git switch 'main'
git merge --no-ff 'elgibbone/window-drag-capture'
git switch 'main'
git merge --squash 'elgibbone/window-drag-capture'
git switch 'main'
git merge --ff-only 'elgibbone/window-drag-capture'
git switch 'main'
git merge 'elgibbone/window-drag-capture'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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
TrustNo1/Darner!421
No description provided.