-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
feat: Support ContactRect in X11 and Windows platform #16498
Conversation
@@ -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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
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?
And we can get this info from WM_Pointer.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Also, according to https://learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.ui.input.pointerpointproperties.contactrect?view=windows-app-sdk-1.5 the contact rect is supposed to be reported in DIPs |
8fd3083
to
d050f20
Compare
/// <inheritdoc cref="PointerPointProperties.ContactRect" /> | ||
public Rect ContactRect | ||
{ | ||
get => _contactRect ?? new Rect(Position, new Size()); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Thanks #16705 I can call the |
You can test this PR using the following package version. |
You can test this PR using the following package version. |
You can test this PR using the following package version. |
You can test this PR using the following package version. |
The XIValuatorClassInfo is struct, so the FirstOrDefault will return the default struct when not found.
You can test this PR using the following package version. |
@@ -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)); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
Merging for 11.3 master branch. I will try to push more implementations over next months before 11.3 release. |
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); |
There was a problem hiding this comment.
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%.
* 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.
* 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.
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