Skip to content

feat: Support ContactRect in X11 and Windows platform #16498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Oct 6, 2024

Conversation

lindexi
Copy link
Contributor

@lindexi lindexi commented Jul 27, 2024

What does the pull request do?

Adding the touch size support, which know as ContactRect in X11 and Windows platform.

What is the current behavior?

Miss the touch size feature.

What is the updated/expected behavior with this PR?

We can get the touch size from X11 and Windows.

I test the Avalonia Windows version by my two demo, the TouchSizeAvalonia demo and the WinUI demo.

I use the same physics for touch, and I can get the same result from TouchSizeAvalonia demo and the WinUI demo. That means this PR can have the same implementation as WinUI. Here's a video I recorded on my phone:

7685EE57C31474648644D744B87A8AE0.mp4

How was the solution implemented (if it's not obvious)?

Checklist

Breaking changes

Add the ContactRect property to PointerPointProperties and changed the argument list in the constructor of PointerPointProperties.

Obsoletions / Deprecations

Fixed issues

Reference: #1477

@@ -155,17 +160,18 @@ public PointerPointProperties(RawInputModifiers modifiers, PointerUpdateKind kin
}

public PointerPointProperties(RawInputModifiers modifiers, PointerUpdateKind kind,
float twist, float pressure, float xTilt, float yTilt
float twist, float pressure, float xTilt, float yTilt, Rect contactRect
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to extend the API? Can't relevant XI2 properties be converted to existing ones? How other platforms expose the same information? How browsers are handling that?

Copy link
Member

@kekekeks kekekeks Jul 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is the same info exposed by UWP?

Copy link
Contributor Author

@lindexi lindexi Jul 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kekekeks

Why do we need to extend the API?

As a touch application, the touch area is an indispensable parameter.

Can't relevant XI2 properties be converted to existing ones?

Sorry, I can not find any existing ones can be converted to.

How other platforms expose the same information?

It can be implemented in Windows platform, see https://learn.microsoft.com/en-us/windows-hardware/design/component-guidelines/touchscreen-required-hid-top-level-collections

How is the same info exposed by UWP?

See https://learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.ui.input.pointerpointproperties.contactrect?view=windows-app-sdk-1.5

And we can get this info from WM_Pointer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, we can get the touch size in wpf by StylusPointProperties.Width and StylusPointProperties.Height

Copy link
Contributor Author

@lindexi lindexi Aug 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How other platforms expose the same information? How browsers are handling that?

I support the windows platform now. And I test my demo, and I find the behavior of Avalonia is same as WinUI and UWP.

@kekekeks
Copy link
Member

lindexi added a commit to lindexi/lindexi_gd that referenced this pull request Jul 27, 2024
/// <inheritdoc cref="PointerPointProperties.ContactRect" />
public Rect ContactRect
{
get => _contactRect ?? new Rect(Position, new Size());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be new Size(1,1) by default I believe

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxkatz6 Sorry, I do not think so. I think the size should be zero here as the WinUI do.

@lindexi
Copy link
Contributor Author

lindexi commented Aug 24, 2024

Thanks #16705

I can call the _platform.Screens.ScreenFromPoint.

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.2.999-cibuild0051457-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@lindexi lindexi changed the title feat: Support ContactRect in X11 platform feat: Support ContactRect in X11 and Windows platform Aug 24, 2024
@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.2.999-cibuild0051461-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.2.999-cibuild0051475-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.2.999-cibuild0051477-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

The XIValuatorClassInfo is struct, so the FirstOrDefault will return the default struct when not found.
@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.2.999-cibuild0051730-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@@ -436,14 +436,46 @@ protected virtual unsafe IntPtr AppWndProc(IntPtr hWnd, uint msg, IntPtr wParam,
{
foreach (var touchInput in touchInputs)
{
var position = PointToClient(new PixelPoint(touchInput.X / 100, touchInput.Y / 100));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to drop WM_TOUCH handling for ContactRect, as it's not going to be used anywhere on modern devices. WM_POINTER is the main way we handle touch/pen input.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxkatz6 There is the other issues in avalonia, that the RegisterTouchWindow will be call event enable the WM_POINTER.

And the win7 system still use the WM_TOUCH now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't support win7 at this point.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify, we try to keep Avalonia compatible with Win7, but we don't go extra miles to support some specific features. And if some code is only used on Win7, we don't really need it, as it only adds maintenance cost.

Copy link
Member

@maxkatz6 maxkatz6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside from unnecessary WM_TOUCH handling, Windows implementation and API looks good to me.

@maxkatz6
Copy link
Member

maxkatz6 commented Oct 6, 2024

Merging for 11.3 master branch. I will try to push more implementations over next months before 11.3 release.

@maxkatz6 maxkatz6 enabled auto-merge October 6, 2024 21:25
@maxkatz6 maxkatz6 disabled auto-merge October 6, 2024 21:25
@maxkatz6 maxkatz6 merged commit 3532889 into AvaloniaUI:master Oct 6, 2024
8 of 10 checks passed
@lindexi
Copy link
Contributor Author

lindexi commented Oct 8, 2024

Thank you @maxkatz6


// Why not use ptPixelLocationX and ptPixelLocationY to as leftTopPosition?
// Because ptPixelLocationX and ptPixelLocationY will be the center of the contact area.
pointerPoint.ContactRect = new Rect(leftTopPosition, bottomRightPosition);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addition: The behavior here is identical to that of WinUI 3, even when the DPI is not set to 100%.

walterlv pushed a commit to dotnet-campus/Avalonia that referenced this pull request Nov 6, 2024
* feat: Support ContactRect in X11 platform

* Provide compat value for ContactRect property

* Using touch position to get the screen.

* Try get the correct screen

* Remove the code of log.

* Improve performance avoid the GC stress.

* Add a second overload in PointerPointProperties to avoid break API change

* Support touch size in WM_Touch

* Support get ContactRect in WM_POINTER

* Fix the coordinate of touch contact area

* Fix the calcuate of WM_Touch contact area

* Fix the X11 area contact

* Fix the touch major and minor default value is not null.

The XIValuatorClassInfo is struct, so the FirstOrDefault will return the default struct when not found.
walterlv pushed a commit to dotnet-campus/Avalonia that referenced this pull request Feb 6, 2025
* feat: Support ContactRect in X11 platform

* Provide compat value for ContactRect property

* Using touch position to get the screen.

* Try get the correct screen

* Remove the code of log.

* Improve performance avoid the GC stress.

* Add a second overload in PointerPointProperties to avoid break API change

* Support touch size in WM_Touch

* Support get ContactRect in WM_POINTER

* Fix the coordinate of touch contact area

* Fix the calcuate of WM_Touch contact area

* Fix the X11 area contact

* Fix the touch major and minor default value is not null.

The XIValuatorClassInfo is struct, so the FirstOrDefault will return the default struct when not found.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants