wpf icon indicating copy to clipboard operation
wpf copied to clipboard

WPF will have a touch offset after trun on the WM_Pointer message

Open lindexi opened this issue 5 years ago • 4 comments

  • .NET Core Version: 3.1.301
  • Windows version: (winver)
  • Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes

Problem description:

~~I don’t know how to turn on WM_Pointer message under .NET Core 3.1, but I can turn on WM_Pointer message under .NET Framework 4.7.2~~

After the Pointer message is turned on, the coordinates of the GetStylusPoints points I obtained in the StylusMove event are incorrect, and there is a big error with the coordinates of the correct point.

Actual behavior:

My application works well at a resolution of 1920x1080, but at a resolution of 800x600, problems will occur.

The behavior of the application is that when using touch to draw handwriting, the handwriting drawn by the application does not coincide with my actual touch track

As shown below

Expected behavior:

I expect to draw the same effect under Pointer as without using Pointer

Minimal repro:

https://github.com/lindexi/lindexi_gd/tree/ae335e8d83a0fbc6297dc2a9196577e5c3319b22/KemjawyecawDurbahelal

lindexi avatar Aug 21 '20 01:08 lindexi

Hmm, not sure if this has anything to do with #2891. The pointer stack is, generally, always querying the active source for transformation matrices, so I am not sure why this would break with a resolution change.

If the ActiveSource was somehow incorrect, you'd end up with an identity matrix, which might be causing the issue, but I'd have to debug it to find out.

Just some rapid fire questions to help narrow down exactly what is happening:

  • Are you changing resolutions on a single monitor system and then re-running the application?
  • Changing resolutions on a single monitor system with the app still running?
  • In a multi-monitor setup with two resolutions and moving the window across?

rladuca avatar Aug 21 '20 02:08 rladuca

@rladuca Thank you.

I change the resolutions and then I reboot the device and then re-running the application on a single monitor.

lindexi avatar Aug 21 '20 02:08 lindexi

@rladuca How can I turn on the WM_Pointer in .NET Core application?

lindexi avatar Aug 21 '20 02:08 lindexi

@lindexi This is probably the best set of instructions for enabling AppContext flags on core that I have seen. You can set any AppContext flags that might be useful (including Switch.System.Windows.Input.Stylus.EnablePointerSupport).

It's really odd that just a resolution change causes this problem. I'm not sure exactly what is going on, perhaps there is an error in the initial creation of the stylus points for inking. Most of that work is done here: https://github.com/dotnet/wpf/blob/1ee75871a1b30d7930982ddd03c27a8f7f61219c/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndPointerInputProvider.cs#L141

It's possible the origin offset are incorrect: https://github.com/dotnet/wpf/blob/1ee75871a1b30d7930982ddd03c27a8f7f61219c/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/InterOp/HwndPointerInputProvider.cs#L326

I'd have to dig a lot deeper into the code and debug to understand exactly what is going on though. There are multiple places where the matrix may be incorrectly created, but that's where I would start.

rladuca avatar Aug 21 '20 04:08 rladuca