From 6e23ef8c4d4a5c10d7cadeda53290dc2d0020148 Mon Sep 17 00:00:00 2001 From: lindexi Date: Wed, 17 Sep 2025 17:56:39 +0800 Subject: [PATCH] Pass the HwndSource parameters directly The RegisterHwndForInput only be called by `HwndStylusInputProvider..ctor`. And the `HwndStylusInputProvider..ctor` will pass the `HwndSource source` to RegisterHwndForInput method. So that it unnecessary to use the PresentationSource in RegisterHwndForInput. --- .../System/Windows/Input/Stylus/Wisp/WispLogic.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispLogic.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispLogic.cs index cebca075a2d..a6a4b072706 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispLogic.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispLogic.cs @@ -3137,10 +3137,8 @@ internal bool Enabled } ///////////////////////////////////////////////////////////////////// - internal void RegisterHwndForInput(InputManager inputManager, PresentationSource inputSource) + internal void RegisterHwndForInput(InputManager inputManager, HwndSource hwndSource) { - HwndSource hwndSource = (HwndSource)inputSource; - GetAndCacheTransformToDeviceMatrix(hwndSource); // Keep track so we don't bother looking for changes if someone happened to query this before @@ -3152,14 +3150,14 @@ internal void RegisterHwndForInput(InputManager inputManager, PresentationSource lock (__penContextsLock) { - if (__penContextsMap.ContainsKey(inputSource)) + if (__penContextsMap.ContainsKey(hwndSource)) { throw new InvalidOperationException(SR.PenService_WindowAlreadyRegistered); } - PenContexts penContexts = new PenContexts(StylusLogic.GetCurrentStylusLogicAs(), inputSource); + PenContexts penContexts = new PenContexts(StylusLogic.GetCurrentStylusLogicAs(), hwndSource); - __penContextsMap[inputSource] = penContexts; + __penContextsMap[hwndSource] = penContexts; // If FIRST one set this as the one to manage TabletAdded/Removed notifications. if (__penContextsMap.Count == 1)