Repository navigation
Fix touch Click not raised after a tap opens a modal dialog - #11999
amarinov-msft wants to merge 9 commits into
Conversation
When a touch tap promotes a mouse down that opens a modal dialog (e.g. via a binding setter on LostFocus), the tapping touch device stays active while its up is processed inside the nested pump. New touches in the dialog then activate as non-primary and are never promoted to mouse, so Click is not raised until WISP reuses the cursor id. Track touch devices whose up is being processed (up-pending), exclude them when choosing the primary/mouse-promotion device, and drop the stale promoted mouse press of the up-pending device when a new device takes over promotion. Fixes dotnet#194 Co-authored-by: Copilot <[email protected]> Copilot-Session: 1fea3d60-9fff-49a1-8eb6-84f04d7d0fa7
…ndow (dotnet#194) If a touch promotes a mouse down before its up (e.g. a slower tap) and that mouse down opens a modal dialog, the up is delivered to the now-disabled window. That path reset the device's promoted mouse state but left WispLogic's mouse button state Pressed, so the first tap in the dialog had its mouse down dropped and Click needed a second tap. Co-authored-by: Copilot <[email protected]> Copilot-Session: 1fea3d60-9fff-49a1-8eb6-84f04d7d0fa7
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Promotion handoff can still suppress clicks or leave enabled controls captured and pressed.
Review effort: Balanced
Findings: 2
Open (2)
What changed in this PR
Addresses #194 by allowing new WISP touch contacts to promote mouse input while an earlier touch-up is paused in a modal dialog.
Changes:
- Tracks active devices with pending touch-up processing.
- Excludes pending devices when selecting the mouse-promotion owner.
- Clears stale promoted mouse-button state during handoff and disabled-window cleanup.
| File | Description |
|---|---|
| src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispStylusTouchDevice.cs | Updates promotion ownership and handoff cleanup. |
| src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispStylusDevice.cs | Adds internal promoted-button release. |
| src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispLogic.cs | Marks pending touch-ups and clears disabled-window button state. |
| src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusTouchDeviceBase.cs | Tracks pending devices and adjusts primary selection. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…otnet#194 review) Address review feedback: - Excluding a device from primary selection as soon as its up arrives could transfer mouse promotion away from a device whose window is still enabled (e.g. a TouchUp handler pumping a DispatcherFrame), silently abandoning its mouse press and leaving the element captured and pressed. Now a device is only excluded (orphaned) when its window is disabled. Disabling sends WM_CANCELMODE, which already releases mouse capture, so dropping the promoted press is safe. - Restore clearing the promotion owner only when no device at all is active, so a secondary contact lifting does not clear the owner prematurely. Co-authored-by: Copilot <[email protected]> Copilot-Session: 1fea3d60-9fff-49a1-8eb6-84f04d7d0fa7
|
LGTM as whole. However IMO there is one potential state mismatch: re-enabling the window can restore the shared mouse state to |
Skip legacy mouse-state reconstruction for active orphaned WISP contacts. Cover held-contact re-enable, newer-contact ownership, late-up cleanup and unchanged non-orphaned stylus behavior. Co-authored-by: Copilot <[email protected]> Copilot-Session: 1fe51848-46fe-4323-8746-5267d21e7788
|
Addressed the re-enable concern from #11999 (comment) in a128349. The existing active-touch IsOrphaned state now prevents OnWindowEnableChanged from reconstructing an abandoned press or overwriting a newer contact's mouse state. It does not unconditionally release buttons or change non-orphaned stylus re-enable behavior. No additional cancellation flag was needed. Added 16 deterministic bookkeeping cases. On the previous PR product, 6 failed: both left/right abandoned-press resurrection cases and four other-button newer-contact cases. After the correction, all 219 Core input cases pass, including all 16 regressions. Coverage includes late normal/disabled-window Up cleanup, preservation of the newer promotion owner, device reuse, and the existing non-orphaned stylus rules. These tests confirm the state mismatch through the production bookkeeping paths; they are not a physical Drag/dialog reproduction. Updated the description to identify native window disabling (including EnableWindow callers such as ElementHost.Enabled=false) as the trigger, keep enabled-window nested Dispatcher loops outside scope, and acknowledge that disabled-window Up abandonment also affects pen/stylus input. Exact validation commands and limitations are in the Testing section. The completed-touch replay receipts in #12034 do not cover this still-down contact sequence. |
wnvko-msft
left a comment
There was a problem hiding this comment.
The update addresses my previous concerns about restoring an abandoned mouse press on re-enable and preserving a newer contact’s press and promotion ownership. The added regression coverage looks appropriate, and I found no remaining blocking code issues for the #194 fix. Looks good to me.
subhajitm
left a comment
There was a problem hiding this comment.
lgtm. make sure we run the WPF regression test using the app.
|
|
||
| if (_stylusLogic.CurrentMousePromotionStylusDevice == StylusDevice) | ||
| { | ||
| _stylusLogic.CurrentMousePromotionStylusDevice = |
There was a problem hiding this comment.
Important: an orphaned contact isn't fully demoted, so it can still promote to mouse.
When it's the last active contact, CurrentMousePromotionStylusDevice becomes null, and ShouldPromoteToMouse treats null as "anyone can promote", including this orphan. Its StoredStagingAreaItems and PromotingToOther are also left as they were. Two ways this can bite:
- Window still disabled. The disabled-window up path calls
OnDeactivate(). Releasing capture cancels the manipulation, andOnManipulationEnded(cancel)then callsPromoteStoredItemsToMousesynchronously. A stored drag could replay a mouse down into the disabled owner and leave the left button Pressed, which is Click event is rarely raised when using touch #194 again. I haven't reproduced this; it needs a stored drag while the manipulation is still pending. - Owner re-enabled before the finger lifts (e.g. the dialog closes itself). With Fix completed WISP touch promotion across modal dialogs #12034, the orphan's up goes through
PromoteMainUpToTouch, which builds a completed promotion and replays down+up onto the opener. That's a ghost Click that could reopen the dialog.
Suggested fix: here, clear _storedStagingAreaItems (bumping its version) and set PromotingToOther = false. You could also make ShouldPromoteToMouse return false when TouchDevice.IsOrphaned.
There was a problem hiding this comment.
Addressed in b61ef3f
OnOrphanedImpl now clears StoredStagingAreaItems and bumps its version, so an in-flight PromoteStoredItemsToMouse loop aborts even if it already detached the queue. It also sets PromotingToOther = false.
• OnManipulationEnded no longer takes the cancel/replay branch for an orphaned contact.
• ShouldPromoteToMouse returns false for orphaned contacts, so a null CurrentMousePromotionStylusDevice no longer lets the orphan promote. With #12034, this also means it's up never builds a completed promotion, so there's no ghost Click.
• Because the orphan's up is no longer promoted, ResetStateForStylusUp wouldn't run on the re-enabled path. Tap state such as _fBlockMouseMoveChanges could then leak into the next contact that reuses the device. PromoteMainUpToTouch now resets it for orphaned contacts. The check runs after OnUp, since a TouchUp handler can orphan the contact too.
Also added regression tests.
| // An orphaned contact has abandoned its press. Re-enabling must not restore it | ||
| // or overwrite a newer contact's mouse state. | ||
| if (!disabled && _currentStylusDevice != null && | ||
| _currentStylusDevice.ActiveTouchDevice?.IsOrphaned != true) |
There was a problem hiding this comment.
Important (when combined with #12034): this guard is fine on its own. But after merging with #12034 it wraps the whole re-enable block, which then includes RetireCompletedTouchMousePresses and the UpdateMouseState() resync for buttons held by the physical mouse. If the current device is orphaned, that reconciliation is skipped too, and _mouseButtonsOwnedByMouse and the button state can stay stale (e.g. a physical button changed during a MessageBox).
Whichever PR merges second should apply the orphan check only to the last two stylus-derived assignments, not the whole block.
There was a problem hiding this comment.
Fixed in 45e2f65
Now the orphan check wraps only the stylus-derived _mouseLeftButtonState/_mouseRightButtonState assignments, inside an outer !disabled && _currentStylusDevice != null block that matches #12034's. A trial merge now conflicts only on those assignments. The resolution keeps RetireCompletedTouchMousePresses and the UpdateMouseState()/InvalidateMouseButtonOwnership step unconditional and applies the orphan check only to the per-button assignments.
|
|
||
| if (disabled) | ||
| { | ||
| OrphanTouchDevices(sourceHit); |
There was a problem hiding this comment.
Minor: orphaning only happens on WM_ENABLE.
- Child
HwndSources (HwndHost / interop-hosted content) never get WM_ENABLE when the top-level window is disabled, so contacts on them are never orphaned. UnRegisterHwndForInputdoesn't orphan contacts that are active on the source being torn down.
Both gaps existed before this PR, but they're worth a comment or a follow-up issue.
Also, with #12034, the order here matters: CancelCompletedTouchPromotionsForSource has to run before OrphanTouchDevices. Otherwise AbandonPromotedMouseButton bumps the button revision first, and RetireCompletedTouchMousePress skips ResetStateForStylusUp. A comment and a test that cover both in the same WM_ENABLE would protect that.
There was a problem hiding this comment.
Agreed, both gaps are pre-existing. Child sources don't get IsWindowDisabled either, so fixing them properly is more than orphaning and outside this PR. I documented both on OrphanTouchDevices and opened a follow-up issue: #12179 .
For the ordering: there's now a comment at the OrphanTouchDevices call that disable cleanup depending on the prior button state must run before it. A trial merge with #12034 places CancelCompletedTouchPromotionsForSource first. I'll add a test that covers both in the same WM_ENABLE in whichever PR merges second, since it needs #12034's completed-promotion state.
| if (_promotedMouseState == MouseButtonState.Pressed) | ||
| { | ||
| _promotedMouseState = MouseButtonState.Released; | ||
| _stylusLogic.UpdateMouseButtonState(_fLeftButtonDownTrigger ? RawMouseActions.Button1Release : RawMouseActions.Button2Release); |
There was a problem hiding this comment.
Minor: this can release a button press the device doesn't own.
- On the non-replay path,
_promotedMouseState = Pressedis set beforeUpdateMouseButtonStateruns. - If a physical mouse is holding the same button, abandoning releases the shared state anyway. With Fix completed WISP touch promotion across modal dialogs #12034 it also clears that button's bit in
_mouseButtonsOwnedByMouse. - Fix completed WISP touch promotion across modal dialogs #12034's
InvalidateMouseButtonOwnershipbumps the revision even when nothing changed. That can strip ownership from a completed promotion on another, still-enabled source.
This needs mouse and touch active at the same time, so it's an edge case. Suggest routing the abandon through a WispLogic helper that skips buttons owned by the physical mouse and only bumps the revision when the state actually changes.
There was a problem hiding this comment.
Fixed in 67aabe4:
The device now records whether its promoted press actually changed the shared button state (PromoteMouseButtonPress), and AbandonPromotedMouseButton only releases a press it owns. A button already held, e.g. by the physical mouse, is left alone. The release goes through a new WispLogic.AbandonPromotedMouseButton helper. When this is combined with #12034, that helper is where to skip _mouseButtonsOwnedByMouse buttons and bump the revision only on an actual change. I'll do that in whichever PR merges second. Added AbandonedPress_DoesNotReleaseButtonPressedByOthers.
| { | ||
| if (IsActive && !IsOrphaned) | ||
| { | ||
| IsOrphaned = true; |
There was a problem hiding this comment.
Minor / cosmetic: the base TouchDevice still keeps the orphan as _activeDevices[0], so GetPrimaryTouchPoint keeps reporting the orphan's point on the disabled window. Meanwhile the dialog's first contact also gets IsPrimary = true (via ActiveDeviceCountExcludingOrphaned), so two devices are "primary" at the same time.
There was a problem hiding this comment.
In 9996fa2, OnOrphaned now clears the stack's IsPrimary, so only the dialog's contact is primary in the touch stack. I left the base TouchDevice primary-point tracking alone: changing it means touching the shared base class used by every touch stack, and it only affects GetPrimaryTouchPoint on a window that can't take input until the orphan lifts. I documented that on OnOrphaned. Added OrphanedContact_IsNoLongerPrimary.
An orphaned contact kept its stored staging items and PromotingToOther, and ShouldPromoteToMouse allowed it to promote once it was the last active contact. A cancelled manipulation or a late up after re-enable could then replay a mouse down (and with dotnet#12034, a ghost click). - Clear and version-bump the stored items and reset PromotingToOther when a contact is orphaned. - Skip the cancel replay in OnManipulationEnded for orphaned contacts. - Never promote orphaned contacts to mouse. - Reset per-device stylus state on an orphaned contact's up, since its up is no longer promoted and would otherwise leak tap state into the next contact on the same device. Co-authored-by: Copilot <[email protected]> Copilot-Session: e694ab5e-6feb-41c2-b4ee-19f115e0cf54
b61ef3f
Keep the outer re-enable block unconditional and apply the orphaned contact check only to the stylus-derived button assignments, so other re-enable reconciliation (e.g. from dotnet#12034) is not skipped when the current device is orphaned. Co-authored-by: Copilot <[email protected]> Copilot-Session: e694ab5e-6feb-41c2-b4ee-19f115e0cf54
Note that orphaning must run after any per-source disable cleanup that depends on the prior mouse button state, and that child HwndSources and unregistered sources are not orphaned. Co-authored-by: Copilot <[email protected]> Copilot-Session: e694ab5e-6feb-41c2-b4ee-19f115e0cf54
The promoted mouse state was marked pressed even when the shared button was already pressed (e.g. by the physical mouse), so abandoning it released a press the device didn't make. Track whether the promoted press changed the shared state and only release it then, routing the release through a WispLogic helper. Co-authored-by: Copilot <[email protected]> Copilot-Session: e694ab5e-6feb-41c2-b4ee-19f115e0cf54
An orphaned contact stayed primary in the stylus touch stack while the next contact (e.g. in a modal dialog) also became primary. Document that the base TouchDevice still reports the orphan as the primary touch point until its up. Co-authored-by: Copilot <[email protected]> Copilot-Session: e694ab5e-6feb-41c2-b4ee-19f115e0cf54

Fixes #194
Main PR: Not applicable; this is the main-branch fix, not a backport.
Description
A touch contact can promote a mouse-down handler that opens a modal dialog while the contact is still active. The original contact can then prevent touches in the dialog from becoming the primary mouse-promoting contact, suppressing Click events.
When a window is disabled, mark its active WISP touch contacts as orphaned. They remain active until their Up is processed, but no longer block primary-contact selection in an enabled window. Abandon their promoted mouse press internally and give up promotion ownership. This relies on native window disabling already triggering mouse-capture cancellation; it does not silently cancel interactions in windows that remain enabled.
The trigger is native window disabling (
WM_ENABLE(false)), notShowDialog()specifically. Other callers ofEnableWindow, including settingElementHost.Enabled = false, can reach this path. Nested Dispatcher loops in a still-enabled window are outside this fix.Re-enabling a window must not reconstruct a mouse press from a still-down orphaned contact's
InAir,GestureWasFired, and active-button values. The re-enable path now skips that reconstruction for an active orphaned contact, preserving the shared state rather than unconditionally setting it to Released. The contact's late Up cannot release a newer contact's press. Re-enable behavior for non-orphaned stylus devices is unchanged.The separate completed-touch/manipulation-replay fix in #12034 does not cover this held-contact re-enable sequence; its ownership receipts apply only to completed-touch replay.
Customer Impact
Touch-operated applications, including LOB applications on tablets and industrial panels, can stop producing clicks after validation or confirmation dialogs open from data binding or input handlers.
Closing the dialog by keyboard or programmatically before the original finger lifts can also restore a shared Pressed state after the device-local press was abandoned, swallowing the next promoted mouse-down.
Regression
No known recent-release regression. The underlying issue is longstanding.
Testing
Added 16 deterministic
WispOrphanedTouchTestscases. They model held-contact and gesture bookkeeping, then call the production orphaning, re-enable, and mouse-up bookkeeping paths. No native input is injected. The re-enable call uses a nonzero unregistered HWND to isolate the state-reconstruction branch from native tablet enumeration.Before the re-enable correction, the unchanged PR product at
5f54e6051b42fa8f27ca1c1b5a67cdcc183570daproduced 6 failures and 10 passes:Coverage after the correction includes same- and different-button newer contacts, both normal and disabled-window Up cleanup, promotion-owner preservation, reuse of the old device for a new contact, and unchanged non-orphaned stylus re-enable rules.
Validated on Windows, x64 Debug, targeting
net11.0-windows, using.NET 12.0.0-alpha.1.26480.102, in an isolated standalone clone of this PR. No #12034 product changes were included.Result: passed, 0 warnings, 0 errors; exit 0. PresentationBuildTasks was explicitly restored/built and required hand-crafted reference assemblies were built with
Platform=AnyCPUfirst. Installed SDK/native tools were reused. Native tool bootstrap still logs missing optional/cache prerequisites, so this is not clean-machine bootstrap validation. The final build used the normal source-control metadata path; no product/build-script changes or assertion suppression were needed.Result: 219 passed, 0 failed, 0 skipped; exit 0. Includes all 16 new regression cases.
Result: passed.
Not run for this correction: physical touchscreen/pen/mouse testing, native touch injection, the full repository suite, or DRTs. These managed tests confirm the state mismatch and its correction, not end-to-end reproduction of a Drag-opened dialog on hardware.
This does not claim to resolve every modal input failure: the earlier controlled comparison with #12034's original native regressions found that this PR's previous product version improved initial responsiveness but still missed a later dialog click. That broader completed-touch replay scenario has not been rerun with this re-enable correction.
Risk
Medium. The product changes affect WISP touch primary-selection and shared mouse-promotion state. The pointer implementation is unchanged.
Orphaning is limited to active touch contacts in a natively disabled window. The disabled-window Up call to
AbandonPromotedMouseButton()is not touch-only: it also affects pen/stylus devices that promoted a mouse press. Accordingly, pen input paths are not claimed to be untouched. The new re-enable guard itself only excludes active orphaned touch contacts and leaves the existing non-orphaned stylus rules in place.An abandoned press is not routed as a synthetic MouseUp. Its later cleanup must not release a newer contact's press or replace its promotion owner. The deterministic tests cover those state transitions but do not replace physical-device validation.
Microsoft Reviewers: Open in CodeFlow