Skip to content

Conversation

@flabbet
Copy link
Contributor

@flabbet flabbet commented Oct 24, 2025

What does the pull request do?

This PR adds support for Pressure TwistX and TwistY for X11 platform inside Move, Press and Release events.

What is the current behavior?

Avalonia on Linux never reports Pen as pointer type and does not set Pressure and Twist properties in mentioned pointer events.

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

Pressure and Twist events are simple atomics, I only added a few fields and read from evaluators. Pointer Type is determined based on presence of these evaluators.

I couldn't find information about Twist anywhere, my tablet (Huion H950P) doesn't seem to report it, or at least not without any additional drivers (no evaluator with relevant data is present).

While this PR does not provide full API (back eraser detection, twist), it's already better than having nothing on Linux. I'd be more than happy to implement missing elements.

  • Twist: I'd need an information about Twist evaluator name and value range provided by their tablet.

  • Back Eraser: I'd need a small hint where should I implement it, it's not part of RawPointerEvent, but processed PointerEventProperties, not sure where it is handled. I can then try implementing detection based on device name as mentioned in [X11] Some WACOM tablets are not supported #18873. My hardware doesn't support it, but the principle is simple enough to implement dry, then someone could confirm if it works properly.

  • Barrel buttons: Also, I'd use a hint where it is implemented too.

Checklist

Breaking changes

Obsoletions / Deprecations

Fixed issues

#18873

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0059559-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. 12.0.999-cibuild0059576-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul MrJul added feature area-x11 backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch labels Oct 28, 2025
@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0059676-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. 12.0.999-cibuild0059820-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. 12.0.999-cibuild0059968-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. 12.0.999-cibuild0060030-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. 12.0.999-cibuild0060445-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. 12.0.999-cibuild0060495-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

Copy link
Member

@MrJul MrJul left a comment

Choose a reason for hiding this comment

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

A couple nit but the logic looks good, thank you!
However, I have no pen to currently test this.

UpdateKnownValuator();
}

public bool HasPenEvaluators()
Copy link
Member

Choose a reason for hiding this comment

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

Nit: this also works for touch. I understand that it's used only to distinguish between mouse and pen but this isn't obvious at first glance. Rename to something like HasPressureValuator (or remove completely and check for PressureXIValuatorClassInfo directly since it's public).

{
if (xiValuatorClassInfo.Label == pressureAtom)
if (xiValuatorClassInfo.Label == pressureAtom ||
xiValuatorClassInfo.Label == pressureAtomPen)
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible for a device to have both Abs Pressure and Abs MT Pressure? I don't think so, but if that's the case we should probably prefer the second one.

Copy link
Member

Choose a reason for hiding this comment

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

I think Abs MT Pressure is specifically for multitouch. The master device can't have both at the same time, it will issue a DeviceChange event when switching between touch and pen.

i. e. this is the event sequence for my pen-aware touchscreen (press finger, press with pen without releasing finger, release pen without releasing finger):

Slave switch: Wacom Pen and multitouch sensor Finger touch
TouchBegin
TouchEnd
Slave switch: Wacom Pen and multitouch sensor Pen stylus
LeftButtonDown
LeftButtonUp
Slave switch: Wacom Pen and multitouch sensor Finger touch
TouchBegin
TouchEnd

Copy link
Member

Choose a reason for hiding this comment

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

Probably need somebody to test with a separate tablet device, since TouchEnd is actually issued by the device driver.

Copy link
Member

Choose a reason for hiding this comment

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

But in general it still should do a slave switch like it does with touchpad/trackpoint/mouse

XiEventType.XI_ButtonPress,
XiEventType.XI_ButtonRelease,
XiEventType.XI_Leave,
XiEventType.XI_Motion, XiEventType.XI_ButtonPress, XiEventType.XI_ButtonRelease, XiEventType.XI_Leave,
Copy link
Member

Choose a reason for hiding this comment

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

Please revert the formatting changes here and on the field below.

@kekekeks
Copy link
Member

kekekeks commented Dec 5, 2025

Tested the PR, eraser detection doesn't seem to be implemented. I think you need to monitor the source field from the last DeviceChange event with SlaveSwitch reason and check for "Eraser" string being present in the source device name.

@kekekeks
Copy link
Member

kekekeks commented Dec 5, 2025

abe0f9b - this seems to work for eraser detection.

@flabbet
Copy link
Contributor Author

flabbet commented Dec 8, 2025

I merged your eraser commit @kekekeks, I don't have eraser pen so I can't really test it, if it works, then great.

I also did not implement Twist, as this is something my tablet also doesn't provide, so if yours do, I'd appreciate if you check the valuator name and values it provide.

@flabbet flabbet requested review from MrJul and kekekeks December 8, 2025 12:36
@avaloniaui-bot
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-x11 backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants