Skip to content

Commit caf64ad

Browse files
authored
Merge pull request #9 from kkwpsv/fix-pointer
修复开启 WM_Pointer 后,非主屏获取的 GetTouchPoint/GetStylusPoint 坐标错误
2 parents dc4a485 + 0f3be1e commit caf64ad

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndPointerInputProvider.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-

5+
66
using MS.Internal;
77
using MS.Internal.Interop;
88
using MS.Internal.PresentationCore;
@@ -223,7 +223,7 @@ private bool ProcessMessage(uint pointerId, RawStylusActions action, int timesta
223223
if (data.IsValid
224224
&& (data.Info.pointerType == UnsafeNativeMethods.POINTER_INPUT_TYPE.PT_TOUCH
225225
|| data.Info.pointerType == UnsafeNativeMethods.POINTER_INPUT_TYPE.PT_PEN))
226-
{
226+
{
227227
uint cursorId = 0;
228228

229229
if (UnsafeNativeMethods.GetPointerCursorId(pointerId, ref cursorId))
@@ -236,7 +236,7 @@ private bool ProcessMessage(uint pointerId, RawStylusActions action, int timesta
236236
{
237237
return false;
238238
}
239-
239+
240240
// Convert move to InAirMove if applicable
241241
if (action == RawStylusActions.Move
242242
&& (!data.Info.pointerFlags.HasFlag(UnsafeNativeMethods.POINTER_FLAGS.POINTER_FLAG_INCONTACT)
@@ -325,7 +325,20 @@ private bool ProcessMessage(uint pointerId, RawStylusActions action, int timesta
325325
/// <param name="originOffsetY">The Y offset in logical coordiantes</param>
326326
private void GetOriginOffsetsLogical(out int originOffsetX, out int originOffsetY)
327327
{
328-
Point originScreenCoord = _source.Value.RootVisual.PointToScreen(new Point(0, 0));
328+
Point originScreenCoord = new Point();
329+
330+
HwndSource hwndSource = PresentationSource.FromVisual(_source.Value.RootVisual) as HwndSource;
331+
if (hwndSource != null)
332+
{
333+
HandleRef handleRef = new HandleRef(hwndSource, hwndSource.CriticalHandle);
334+
335+
MS.Win32.NativeMethods.POINT point = new MS.Win32.NativeMethods.POINT();
336+
MS.Win32.UnsafeNativeMethods.ClientToScreen(handleRef, ref point);
337+
338+
var displayRect = _currentTabletDevice.DeviceInfo.DisplayRect;
339+
340+
originScreenCoord = new Point(point.x - displayRect.left, point.y - displayRect.top);
341+
}
329342

330343
// Use the inverse of our logical tablet to screen matrix to generate tablet coords
331344
MatrixTransform screenToTablet = new MatrixTransform(_currentTabletDevice.TabletToScreen);

0 commit comments

Comments
 (0)