From 5995c63a8886153df06d2fe6dcd6d37f667b046b Mon Sep 17 00:00:00 2001 From: Sam Bent Date: Mon, 2 Aug 2021 17:11:17 -0700 Subject: [PATCH] Port stylus shutdown fix from 4.8 --- .../System/Windows/InterOp/HwndSource.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndSource.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndSource.cs index 6d5a542e3eb..3b86ba8dfed 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndSource.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndSource.cs @@ -1565,6 +1565,22 @@ private IntPtr InputFilterMessage(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lP IntPtr result = IntPtr.Zero ; WindowMessage message = (WindowMessage)msg; + if (message == WindowMessage.WM_DESTROY) + { + // shut down the stylus stack on WM_DESTROY. This is normally done + // in PublicHooksFilterMessage (see remarks there), but that won't + // get called if no public hooks have ever been installed. Do it + // here as a backup for that case. + // For maintenance, there are three workflows to consider: + // 1. The normal case - public hooks are present, none of them + // handle WM_DESTROY. DisposeStylusInputProvider gets + // called twice, but the second call is a no-op. + // 2. No public hooks present. Only this call happens. + // 3. Public hooks are present, one of them handles WM_DESTROY. + // Only the call in PublicHooksFilterMessage happens. + DisposeStylusInputProvider(); + } + // NOTE (alexz): invoke _stylus.FilterMessage before _mouse.FilterMessage // to give _stylus a chance to eat mouse message generated by stylus if (!_isDisposed && _stylus != null && !handled)