Skip to content

Improve pen secondary button handling on list box #18766

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 11 commits into from
May 19, 2025
Merged

Conversation

maxkatz6
Copy link
Member

@maxkatz6 maxkatz6 commented May 1, 2025

What does the pull request do?

Historically, pen input in Avalonia copies touch input behavior way too much. It makes sense in some areas, like primary button press to scroll. But not so much with secondary/right button press. Touch doesn't have a secondary button at all, but pen should copy mouse behavior there.

Some operations are hard to achieve with pen, now are possible/easier with this PR: dnd with pen (at least in-process), selecting item AND showing context menu on same press+release combo.

This PR makes following changes:

  1. Scroll gesture recognizer to only accept primary button input to scroll. Secondary button pen press is ignored.
  2. ListBoxItem selects and handles input on secondary pen button pressed.

This PR behavior is closer to WPF than UWP though, as UWP doesn't select list item if there is a context menu. But majority of modern windows apps follow WPF logic from my observation (including this PR).

What is the current behavior?

left press right press left release right release holding
mouse select, start dnd* select - already selected + context menu N/A
pen scroll scroll select (in tap area) context menu (or select, if no context menu) context menu
touch scroll N/A select (in tap area) N/A context menu, start dnd*

What is the updated/expected behavior with this PR?

left press right press left release right release holding
mouse select, start dnd* select - already selected + context menu N/A
pen scroll select, start dnd* select (in tap area) already selected + context menu context menu
touch scroll N/A select (in tap area) N/A context menu, start dnd*

* DND related rules are not part of this PR, and not part of Avalonia itself. User applications and third-party controls decide themselves when to call DragDrop.Do (by filtering pointer props usually in PointerPressed event). I added these columns for the completion.

Pending: TreeDataGrid changes for the same rules.

Checklist

Breaking changes

Pen right click has different behavior now.

Obsoletions / Deprecations

Fixed issues

Fixes https://support.avaloniaui.net/agent/tickets/444

@maxkatz6 maxkatz6 added bug backport-candidate-11.2.x Consider this PR for backporting to 11.2 branch labels May 1, 2025
@avaloniaui-bot
Copy link

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

@MrJul MrJul added the backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch label May 1, 2025
@kekekeks
Copy link
Member

kekekeks commented May 3, 2025

Will test this once my pen arrives (should be next week)

@@ -64,9 +64,11 @@ protected override void OnPointerPressed(PointerPressedEventArgs e)
if (p.Properties.PointerUpdateKind is PointerUpdateKind.LeftButtonPressed or
PointerUpdateKind.RightButtonPressed)
{
if (p.Pointer.Type == PointerType.Mouse)
if (p.Pointer.Type == PointerType.Mouse
|| (p.Pointer.Type == PointerType.Pen && p.Properties.IsRightButtonPressed))
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to update the logic in PointerReleased handler here (line 108):

// As we only update selection from touch/pen on pointer release, we need to raise
// the pointer event on the owner to trigger a commit.
if (e.Pointer.Type != PointerType.Mouse)

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not going to get there, since _pointerDownPoint is unset

Copy link
Member

@kekekeks kekekeks left a comment

Choose a reason for hiding this comment

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

Tested, seems to work consistently with the rest of windows apps with my pen

@maxkatz6 maxkatz6 added this pull request to the merge queue May 17, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 17, 2025
@maxkatz6 maxkatz6 merged commit 338a5ea into master May 19, 2025
2 checks passed
@maxkatz6 maxkatz6 deleted the pen-input-rules branch May 19, 2025 04:01
MrJul pushed a commit that referenced this pull request Jun 5, 2025
* Only start ScrollGesture when left click pressed, also `GetCurrentPoint(null)` behaves the same as root visual

* Allow right-click pen to select items on press

* Add context menus to even items on ListBox page for testing

* Avoid global static in UpdateSelectionFromPointerEvent

* Revert "Avoid global static in UpdateSelectionFromPointerEvent"

This reverts commit 2562d73.

* Add comment to UpdateSelectionFromPointerEvent

* Use fully mocked rendering for list box test

* Add pen selection tests

* TouchTestHelper should use correct inputs
@MrJul MrJul added backported-11.3.x and removed backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch labels Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-candidate-11.2.x Consider this PR for backporting to 11.2 branch backported-11.3.x bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants