dotnet / wpf

WPF is a .NET Core UI framework for building Windows desktop applications.
MIT License
7.06k stars 1.17k forks source link

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

Open lindexi opened 4 years ago

lindexi commented 4 years ago

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

rladuca commented 4 years ago

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:

lindexi commented 4 years ago

@rladuca Thank you.

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

lindexi commented 4 years ago

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

rladuca commented 4 years ago

@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.