Browse Source

iOS some pointer/keyboard fixes (#15061)

* Fix stylus input state mapping on iOS

* Fix UIKeyboardHidUsage.KeyboardDeleteOrBackspace mapping on iOS, should be mapped to Backspace

* Release iOS pen pointer on PenUp event, fixing IsPrimary state

* Don't limit scroll gestures to single primary input - user should be able to scroll two different scrolls
pull/15079/head
Max Katz 2 years ago
committed by GitHub
parent
commit
bad2e8dbdc
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 3
      src/Avalonia.Base/Input/GestureRecognizers/ScrollGestureRecognizer.cs
  2. 51
      src/Avalonia.Base/Input/PenDevice.cs
  3. 14
      src/iOS/Avalonia.iOS/InputHandler.cs

3
src/Avalonia.Base/Input/GestureRecognizers/ScrollGestureRecognizer.cs

@ -94,8 +94,7 @@ namespace Avalonia.Input.GestureRecognizers
protected override void PointerPressed(PointerPressedEventArgs e) protected override void PointerPressed(PointerPressedEventArgs e)
{ {
if (e.Pointer.IsPrimary && if (e.Pointer.Type == PointerType.Touch || e.Pointer.Type == PointerType.Pen)
(e.Pointer.Type == PointerType.Touch || e.Pointer.Type == PointerType.Pen))
{ {
EndGesture(); EndGesture();
_tracking = e.Pointer; _tracking = e.Pointer;

51
src/Avalonia.Base/Input/PenDevice.cs

@ -1,12 +1,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection;
using Avalonia.Input.GestureRecognizers; using Avalonia.Input.GestureRecognizers;
using Avalonia.Input.Raw; using Avalonia.Input.Raw;
using Avalonia.Interactivity; using Avalonia.Interactivity;
using Avalonia.Metadata; using Avalonia.Metadata;
using Avalonia.Platform;
using Avalonia.VisualTree; using Avalonia.VisualTree;
#pragma warning disable CS0618 #pragma warning disable CS0618
@ -20,6 +18,7 @@ namespace Avalonia.Input
public class PenDevice : IPenDevice, IDisposable public class PenDevice : IPenDevice, IDisposable
{ {
private readonly Dictionary<long, Pointer> _pointers = new(); private readonly Dictionary<long, Pointer> _pointers = new();
private readonly bool _releasePointerOnPenUp;
private int _clickCount; private int _clickCount;
private Rect _lastClickRect; private Rect _lastClickRect;
private ulong _lastClickTime; private ulong _lastClickTime;
@ -27,6 +26,11 @@ namespace Avalonia.Input
private bool _disposed; private bool _disposed;
public PenDevice(bool releasePointerOnPenUp = false)
{
_releasePointerOnPenUp = releasePointerOnPenUp;
}
public void ProcessRawEvent(RawInputEventArgs e) public void ProcessRawEvent(RawInputEventArgs e)
{ {
if (!e.Handled && e is RawPointerEventArgs margs) if (!e.Handled && e is RawPointerEventArgs margs)
@ -52,26 +56,35 @@ namespace Avalonia.Input
var keyModifiers = e.InputModifiers.ToKeyModifiers(); var keyModifiers = e.InputModifiers.ToKeyModifiers();
bool shouldReleasePointer = false; bool shouldReleasePointer = false;
switch (e.Type) try
{ {
case RawPointerEventType.LeaveWindow: switch (e.Type)
shouldReleasePointer = true; {
break; case RawPointerEventType.LeaveWindow:
case RawPointerEventType.LeftButtonDown: shouldReleasePointer = true;
e.Handled = PenDown(pointer, e.Timestamp, e.Root, e.Position, props, keyModifiers, e.InputHitTestResult); break;
break; case RawPointerEventType.LeftButtonDown:
case RawPointerEventType.LeftButtonUp: e.Handled = PenDown(pointer, e.Timestamp, e.Root, e.Position, props, keyModifiers, e.InputHitTestResult);
e.Handled = PenUp(pointer, e.Timestamp, e.Root, e.Position, props, keyModifiers, e.InputHitTestResult); break;
break; case RawPointerEventType.LeftButtonUp:
case RawPointerEventType.Move: if (_releasePointerOnPenUp)
e.Handled = PenMove(pointer, e.Timestamp, e.Root, e.Position, props, keyModifiers, e.InputHitTestResult, e.IntermediatePoints); {
break; shouldReleasePointer = true;
}
e.Handled = PenUp(pointer, e.Timestamp, e.Root, e.Position, props, keyModifiers, e.InputHitTestResult);
break;
case RawPointerEventType.Move:
e.Handled = PenMove(pointer, e.Timestamp, e.Root, e.Position, props, keyModifiers, e.InputHitTestResult, e.IntermediatePoints);
break;
}
} }
finally
if (shouldReleasePointer)
{ {
pointer.Dispose(); if (shouldReleasePointer)
_pointers.Remove(e.RawPointerId); {
pointer.Dispose();
_pointers.Remove(e.RawPointerId);
}
} }
} }

14
src/iOS/Avalonia.iOS/InputHandler.cs

@ -17,7 +17,7 @@ internal sealed class InputHandler
private readonly ITopLevelImpl _tl; private readonly ITopLevelImpl _tl;
private readonly TouchDevice _touchDevice = new(); private readonly TouchDevice _touchDevice = new();
private readonly MouseDevice _mouseDevice = new(); private readonly MouseDevice _mouseDevice = new();
private readonly PenDevice _penDevice = new(); private readonly PenDevice _penDevice = new(releasePointerOnPenUp: true);
private static long _nextTouchPointId = 1; private static long _nextTouchPointId = 1;
private readonly Dictionary<UITouch, long> _knownTouches = new(); private readonly Dictionary<UITouch, long> _knownTouches = new();
@ -68,8 +68,13 @@ internal sealed class InputHandler
(TouchDevice, UITouchPhase.Cancelled) => RawPointerEventType.TouchCancel, (TouchDevice, UITouchPhase.Cancelled) => RawPointerEventType.TouchCancel,
(TouchDevice, _) => RawPointerEventType.TouchUpdate, (TouchDevice, _) => RawPointerEventType.TouchUpdate,
(_, UITouchPhase.Began) => IsRightClick() ? RawPointerEventType.RightButtonDown : RawPointerEventType.LeftButtonDown, (_, UITouchPhase.Began) => IsRightClick()
(_, UITouchPhase.Ended or UITouchPhase.Cancelled) => IsRightClick() ? RawPointerEventType.RightButtonUp : RawPointerEventType.RightButtonDown, ? RawPointerEventType.RightButtonDown
: RawPointerEventType.LeftButtonDown,
(_, UITouchPhase.Ended) => IsRightClick()
? RawPointerEventType.RightButtonUp
: RawPointerEventType.LeftButtonUp,
(_, UITouchPhase.Cancelled) => RawPointerEventType.LeaveWindow,
(_, _) => RawPointerEventType.Move, (_, _) => RawPointerEventType.Move,
}, ToPointerPoint(t), modifiers, id) }, ToPointerPoint(t), modifiers, id)
{ {
@ -288,7 +293,8 @@ internal sealed class InputHandler
[UIKeyboardHidUsage.Keyboard0] = PhysicalKey.Digit0, [UIKeyboardHidUsage.Keyboard0] = PhysicalKey.Digit0,
[UIKeyboardHidUsage.KeyboardReturnOrEnter] = PhysicalKey.Enter, [UIKeyboardHidUsage.KeyboardReturnOrEnter] = PhysicalKey.Enter,
[UIKeyboardHidUsage.KeyboardEscape] = PhysicalKey.Escape, [UIKeyboardHidUsage.KeyboardEscape] = PhysicalKey.Escape,
[UIKeyboardHidUsage.KeyboardDeleteOrBackspace] = PhysicalKey.Delete, // See KeyboardDeleteForward for an actual Delete.
[UIKeyboardHidUsage.KeyboardDeleteOrBackspace] = PhysicalKey.Backspace,
[UIKeyboardHidUsage.KeyboardTab] = PhysicalKey.Tab, [UIKeyboardHidUsage.KeyboardTab] = PhysicalKey.Tab,
[UIKeyboardHidUsage.KeyboardSpacebar] = PhysicalKey.Space, [UIKeyboardHidUsage.KeyboardSpacebar] = PhysicalKey.Space,
[UIKeyboardHidUsage.KeyboardHyphen] = PhysicalKey.NumPadSubtract, [UIKeyboardHidUsage.KeyboardHyphen] = PhysicalKey.NumPadSubtract,

Loading…
Cancel
Save