Skip to content

[Mouse Highlighter] Keep ripple work off the low-level hook - #49699

Merged
Muyuan Li (MuyuanMS) merged 5 commits into
microsoft:mainfrom
crutkas:crutkas-fix-mouse-highlighter-input-sticking
Aug 11, 2026
Merged

Muyuan Li (MuyuanMS) merged 5 commits into
microsoft:mainfrom
crutkas:crutkas-fix-mouse-highlighter-input-sticking

Conversation

@crutkas

Copy link
Copy Markdown
Member

Summary of the Pull Request

Mouse Highlighter performed synchronous WinRT Composition work in its WH_MOUSE_LL callback. Slow low-level hook callbacks stall the shared mouse-hook chain and can be silently removed by Windows, causing a button-up event to be lost and leaving the ripple or pressed state stuck. FancyZones was inspected to confirm ownership but is not changed by this PR.

This moves Mouse Highlighter's visual, animation, timer, and Z-order work onto its module window thread. The hook now records events in a bounded, allocation-free FIFO and posts a window message. Adjacent high-rate mouse moves are coalesced, while button ordering, hook timestamps, and signed screen coordinates (including negative multi-monitor coordinates) are preserved. Stop, settings changes, and teardown clear pending events, pressed state, hold state, and timers. Settings application is also marshaled to the window thread so WinRT Composition remains thread-affine.

PR Checklist

  • Closes: #xxx
  • Communication: I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected
  • Tests: Added/updated and all pass
  • Localization: All end-user-facing strings can be localized
  • Dev docs: Added/updated
  • New binaries: Added on the required places
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

The low-level hook now does only constant-time event capture and queue signaling. A fixed-capacity FIFO preserves the sequence of button transitions and mouse positions without allocating in the hook. Only adjacent move events are coalesced, avoiding message flooding without moving a cursor update across a button boundary. Input timestamps keep quick-click versus hold classification based on the original 180 ms threshold even if window-thread processing is delayed.

All Composition access runs through the Mouse Highlighter window/message queue. Lifecycle paths unhook before clearing the queue and reset button, ripple-hold, spotlight, and timer state. If the bounded queue ever fills, recovery resets transient visual state before retaining the triggering button event rather than risking a dropped button-up.

Validation Steps Performed

  • Built src/modules/MouseUtils/MouseHighlighter/MouseHighlighter.vcxproj in Debug x64.
  • Built src/modules/FancyZones/FancyZonesLib/FancyZonesLib.vcxproj in Debug x64 to verify the unchanged hook-chain neighbor.
  • Ran git diff --check.
  • Performed a focused concurrency and event-ordering code review.

No focused native unit-test seam exists for this hook/Composition path without disproportionate refactoring, so no automated test was added. No end-to-end rapid-click/drag stress run across mixed-DPI multi-monitor layouts was performed.

Move mouse hook processing onto the module window thread, preserve ordered coordinates and click timing, coalesce moves, and reset queued input during lifecycle changes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6caaf738-168e-4b11-8efb-b155139dac31
@crutkas
Clint Rutkas (crutkas) marked this pull request as ready for review August 6, 2026 21:52
@crutkas Clint Rutkas (crutkas) added 0.101 Needs-Review This Pull Request awaits the review of a maintainer. labels Aug 7, 2026
Clint Rutkas (crutkas) and others added 4 commits August 7, 2026 18:15
Co-authored-by: Muyuan Li <116717757+MuyuanMS@users.noreply.github.com>
Co-authored-by: Muyuan Li <116717757+MuyuanMS@users.noreply.github.com>
Co-authored-by: Muyuan Li <116717757+MuyuanMS@users.noreply.github.com>
Keep queued mouse events when PostMessage fails and allow coalesced moves to retry delivery through the synchronized window handle.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 259addc8-304d-4595-83c8-bba3d76e0637
@crutkas

Copy link
Copy Markdown
Member Author

Muyuan Li (@MuyuanMS) updated, kicking of a build to do an e2e on it on monday but would love your eyes on it as well / do a manual on it for a few hours too

@MuyuanMS
Muyuan Li (MuyuanMS) merged commit dbff0e7 into microsoft:main Aug 11, 2026
15 checks passed
Boliang Zhang (LegendaryBlair) pushed a commit that referenced this pull request Aug 12, 2026
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request

Mouse Highlighter performed synchronous WinRT Composition work in its
`WH_MOUSE_LL` callback. Slow low-level hook callbacks stall the shared
mouse-hook chain and can be silently removed by Windows, causing a
button-up event to be lost and leaving the ripple or pressed state
stuck. FancyZones was inspected to confirm ownership but is not changed
by this PR.

This moves Mouse Highlighter's visual, animation, timer, and Z-order
work onto its module window thread. The hook now records events in a
bounded, allocation-free FIFO and posts a window message. Adjacent
high-rate mouse moves are coalesced, while button ordering, hook
timestamps, and signed screen coordinates (including negative
multi-monitor coordinates) are preserved. Stop, settings changes, and
teardown clear pending events, pressed state, hold state, and timers.
Settings application is also marshaled to the window thread so WinRT
Composition remains thread-affine.

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [ ] Closes: #xxx
<!-- - [ ] Closes: #yyy (add separate lines for additional resolved
issues) -->
- [x] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [x] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

The low-level hook now does only constant-time event capture and queue
signaling. A fixed-capacity FIFO preserves the sequence of button
transitions and mouse positions without allocating in the hook. Only
adjacent move events are coalesced, avoiding message flooding without
moving a cursor update across a button boundary. Input timestamps keep
quick-click versus hold classification based on the original 180 ms
threshold even if window-thread processing is delayed.

All Composition access runs through the Mouse Highlighter window/message
queue. Lifecycle paths unhook before clearing the queue and reset
button, ripple-hold, spotlight, and timer state. If the bounded queue
ever fills, recovery resets transient visual state before retaining the
triggering button event rather than risking a dropped button-up.

<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed

- Built
`src/modules/MouseUtils/MouseHighlighter/MouseHighlighter.vcxproj` in
Debug x64.
- Built `src/modules/FancyZones/FancyZonesLib/FancyZonesLib.vcxproj` in
Debug x64 to verify the unchanged hook-chain neighbor.
- Ran `git diff --check`.
- Performed a focused concurrency and event-ordering code review.

No focused native unit-test seam exists for this hook/Composition path
without disproportionate refactoring, so no automated test was added. No
end-to-end rapid-click/drag stress run across mixed-DPI multi-monitor
layouts was performed.

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Muyuan Li <116717757+MuyuanMS@users.noreply.github.com>
Copilot-Session: 6caaf738-168e-4b11-8efb-b155139dac31
Copilot-Session: 259addc8-304d-4595-83c8-bba3d76e0637
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 7b3fb20d-6e9d-4fef-a5cd-f8921d28c220
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

0.101 Needs-Review This Pull Request awaits the review of a maintainer.

2 participants