dotnet / wpf

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

The first point in StylusPlugin is wrong when use the high DPI #6415

Closed lindexi closed 9 months ago

lindexi commented 2 years ago

After https://github.com/dotnet/wpf/pull/2891 , we call calculate the point with stylusDevice.CriticalActiveSource. But the stylusDevice.CriticalActiveSource must be null when first touch down, because the wpf do not touch any element and do not get the AcitveSource before first touch down.

Actual behavior:

All of the StylusPlugin will reviece the wrong coordinate point.

Expected behavior:

These points can be calculated correctly.

Minimal repro:

Before you try repro this issues, please make sure you own a touch screen.

Preparation:

  1. Set the touch screen DPI to 150% (Not 100% is enough)

Step:

  1. Create an empty WPF project.
  2. Add the InkCanvas control to WPF project.
  3. Run the project in the device with the touch screen and then try write an ink.

Actual behavior: you will find the first point in ink will skew, just as the image shows.

The other repro step: Create an empty WPF project and add the StylusPlugin and then output the point received.

cc @rladuca @singhashish-wpf

lindexi commented 2 years ago

And I think the StylusLogic.GetAndCacheTransformToDeviceMatrix should return the first Matrix when the source is null.

https://github.com/dotnet/wpf/blob/28205800de1d11595b6c598d0760af7dca1a49d3/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusLogic.cs#L417-L435

lindexi commented 2 years ago

When the wpf will set the stylusDevice.CriticalActiveSource ? The WispLogic.PreNotifyInput will call the stylusDevice.UpdateState method to calculate the ActiveSource in the Main UI Thread.

But the StylusPlugin is running in the Stylus Input thread and fast than the UI thread.

lindexi commented 2 years ago

I tested the my app for a week. This issue has been fixed and no new issues have been introduced.

lindexi commented 10 months ago

@karelz Can I ask any plan about this issues? It will affect all touch applications.

I have cherry-picked my two PRs, https://github.com/dotnet/wpf/pull/6428 and https://github.com/dotnet/wpf/issues/6829, to build my private version of WPF. My application, which utilizes this private WPF version, has been running for almost two years now. Moreover, it has been performing well on millions of touch devices. This stands as a testament to the reliability of my PRs.

singhashish-wpf commented 10 months ago

@lindexi Thanks a lot for your contributions. These PRs are currently not prioritized as the touch area isn't prioritized as of now from the team. We can prioritize it if the area receives more hits in terms of issues or more people running into this. Thanks again for the reliability data, I will try to get these 2 PRs in the next community test pass.

lindexi commented 10 months ago

Thank you @singhashish-wpf