Skip to content

Commit c2cd95f

Browse files
committed
Fix incorrect touch point coordinates when running application on secondary screen with WM_Pointer enabled
#8517
1 parent b4e470e commit c2cd95f

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44

@@ -315,7 +315,20 @@ private bool ProcessMessage(uint pointerId, RawStylusActions action, int timesta
315315
/// <param name="originOffsetY">The Y offset in logical coordiantes</param>
316316
private void GetOriginOffsetsLogical(out int originOffsetX, out int originOffsetY)
317317
{
318-
Point originScreenCoord = _source.RootVisual.PointToScreen(new Point(0, 0));
318+
Point originScreenCoord = new Point();
319+
320+
HwndSource hwndSource = PresentationSource.FromVisual(_source.RootVisual) as HwndSource;
321+
if (hwndSource != null)
322+
{
323+
HandleRef handleRef = new HandleRef(hwndSource, hwndSource.CriticalHandle);
324+
325+
MS.Win32.NativeMethods.POINT point = new MS.Win32.NativeMethods.POINT();
326+
MS.Win32.UnsafeNativeMethods.ClientToScreen(handleRef, ref point);
327+
328+
var displayRect = _currentTabletDevice.DeviceInfo.DisplayRect;
329+
330+
originScreenCoord = new Point(point.x - displayRect.left, point.y - displayRect.top);
331+
}
319332

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

0 commit comments

Comments
 (0)