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
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]>
ElGibbone force-pushed elgibbone/window-drag-capture from aac6fbfd26 to 52ab29c2f2 2026-12-05 10:58:29 +00:00 Compare
Author
Contributor

Rebased onto main (c8258f95) to clear the conflict.

The only conflict was in gameinput.rs, with #399 (now merged): both add a field to the native mouse capture changes log in host::overlay, and #399 now derives in_menu from menu_cause. Both are kept, menu_cause from #399 and dragging from this PR. Nothing else changed: the diff is the same as before (gameinput.rs and lifecycle.rs, +31/-9).

Checks on Windows (RTX 4070 Ti, Ryzen 7 7800X3D) at 52ab29c:

  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean
  • cargo test --locked -p darner-hle: 512 passed, 0 failed, 15 ignored (includes menu_and_pause_states_release_and_recapture_mouse)
  • cargo test --locked -p darner: 220 passed, 0 failed, 1 ignored
  • cargo xtask policy: ok
  • In game, on a local build of main with this PR, #402, #405 and an unrelated lighting patch: native mouse and key response were fine over a 9-minute session.

The full cargo test --workspace was not run for this update.


Generated by Claude Code

Rebased onto main (c8258f95) to clear the conflict. The only conflict was in `gameinput.rs`, with #399 (now merged): both add a field to the `native mouse capture changes` log in `host::overlay`, and #399 now derives `in_menu` from `menu_cause`. Both are kept, `menu_cause` from #399 and `dragging` from this PR. Nothing else changed: the diff is the same as before (`gameinput.rs` and `lifecycle.rs`, +31/-9). Checks on Windows (RTX 4070 Ti, Ryzen 7 7800X3D) at 52ab29c: - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: clean - `cargo test --locked -p darner-hle`: 512 passed, 0 failed, 15 ignored (includes `menu_and_pause_states_release_and_recapture_mouse`) - `cargo test --locked -p darner`: 220 passed, 0 failed, 1 ignored - `cargo xtask policy`: ok - In game, on a local build of main with this PR, #402, #405 and an unrelated lighting patch: native mouse and key response were fine over a 9-minute session. The full `cargo test --workspace` was not run for this update. --- _Generated by [Claude Code](https://claude.ai/code)_
TrustNo1 changed title from [pr-fix][input] Window drag: a title bar click that moves nothing ends it, and the native mouse waits for the move to end to Window drag: a title bar click that moves nothing ends it, and the native mouse waits for the move to end 2026-12-06 03:29:16 +00:00
Owner

Test needed — commit 52ab29c2; what to check:

  • 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 t

Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture.

Reply testing to take this run; it's free again after 24 h with no results.

**Test needed** — commit `52ab29c2`; what to check: - 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 t Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture. Reply `testing` to take this run; it's free again after 24 h with no results.
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 milestone
No project
No assignees
2 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
TrustNo1/Darner!421
No description provided.