Browse Source

feat: Support pressure and tilt on macos (#18082)

* feat: Support pressure and tilt on macos

* apply suggestions

* apply suggestion
repro/18104-drag-drop-flyout-placement
Aki Sakurai 1 year ago
committed by GitHub
parent
commit
21ecbf384b
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 36
      native/Avalonia.Native/src/OSX/AvnView.mm
  2. 2
      native/Avalonia.Native/src/OSX/AvnWindow.mm
  3. 20
      src/Avalonia.Native/TopLevelImpl.cs
  4. 13
      src/Avalonia.Native/avn.idl

36
native/Avalonia.Native/src/OSX/AvnView.mm

@ -290,6 +290,40 @@
delta.Y = [event deltaY]; delta.Y = [event deltaY];
} }
float pressure = 0.5f;
float xTilt = 0.0f;
float yTilt = 0.0f;
AvnPointerDeviceType pointerType = AvnPointerDeviceType::Mouse;
switch(event.subtype)
{
case NSEventSubtypeTabletPoint:
switch(event.type)
{
case NSEventTypeLeftMouseDown:
case NSEventTypeLeftMouseDragged:
case NSEventTypeRightMouseDown:
case NSEventTypeRightMouseDragged:
case NSEventTypeOtherMouseDown:
case NSEventTypeOtherMouseDragged:
pressure = event.pressure;
break;
default:
pressure = 0.0f;
break;
}
xTilt = event.tilt.x * 90;
yTilt = -event.tilt.y * 90;
pointerType = AvnPointerDeviceType::Pen;
break;
case NSEventSubtypeTabletProximity:
pressure = 0.0f;
pointerType = AvnPointerDeviceType::Pen;
break;
default:
break;
}
uint64_t timestamp = static_cast<uint64_t>([event timestamp] * 1000); uint64_t timestamp = static_cast<uint64_t>([event timestamp] * 1000);
auto modifiers = [self getModifiers:[event modifierFlags]]; auto modifiers = [self getModifiers:[event modifierFlags]];
@ -322,7 +356,7 @@
auto parent = _parent.tryGet(); auto parent = _parent.tryGet();
if(parent != nullptr) if(parent != nullptr)
{ {
parent->TopLevelEvents->RawMouseEvent(type, timestamp, modifiers, point, delta); parent->TopLevelEvents->RawMouseEvent(type, pointerType, timestamp, modifiers, point, delta, pressure, xTilt, yTilt);
} }
[super mouseMoved:event]; [super mouseMoved:event];

2
native/Avalonia.Native/src/OSX/AvnWindow.mm

@ -492,7 +492,7 @@
auto point = [self translateLocalPoint:avnPoint]; auto point = [self translateLocalPoint:avnPoint];
AvnVector delta = { 0, 0 }; AvnVector delta = { 0, 0 };
parent->BaseEvents->RawMouseEvent(NonClientLeftButtonDown, static_cast<uint64>([event timestamp] * 1000), AvnInputModifiersNone, point, delta); parent->BaseEvents->RawMouseEvent(NonClientLeftButtonDown, AvnPointerDeviceType::Mouse, static_cast<uint64>([event timestamp] * 1000), AvnInputModifiersNone, point, delta, .5f, .0f, .0f);
} }
if(!_isTransitioningToFullScreen) if(!_isTransitioningToFullScreen)

20
src/Avalonia.Native/TopLevelImpl.cs

@ -68,6 +68,8 @@ internal class TopLevelImpl : ITopLevelImpl, IFramebufferPlatformSurface
private PlatformBehaviorInhibition? _platformBehaviorInhibition; private PlatformBehaviorInhibition? _platformBehaviorInhibition;
private readonly MouseDevice? _mouse; private readonly MouseDevice? _mouse;
private readonly PenDevice? _pen;
private readonly IKeyboardDevice? _keyboard; private readonly IKeyboardDevice? _keyboard;
private readonly ICursorFactory? _cursorFactory; private readonly ICursorFactory? _cursorFactory;
@ -88,6 +90,7 @@ internal class TopLevelImpl : ITopLevelImpl, IFramebufferPlatformSurface
_keyboard = AvaloniaLocator.Current.GetService<IKeyboardDevice>(); _keyboard = AvaloniaLocator.Current.GetService<IKeyboardDevice>();
_mouse = new MouseDevice(); _mouse = new MouseDevice();
_pen = new PenDevice();
_cursorFactory = AvaloniaLocator.Current.GetService<ICursorFactory>(); _cursorFactory = AvaloniaLocator.Current.GetService<ICursorFactory>();
} }
@ -213,7 +216,7 @@ internal class TopLevelImpl : ITopLevelImpl, IFramebufferPlatformSurface
return args.Handled; return args.Handled;
} }
public void RawMouseEvent(AvnRawMouseEventType type, ulong timeStamp, AvnInputModifiers modifiers, AvnPoint point, AvnVector delta) public void RawMouseEvent(AvnRawMouseEventType type, AvnPointerDeviceType deviceType, ulong timeStamp, AvnInputModifiers modifiers, AvnPoint point, AvnVector delta, float pressure, float xTilt, float yTilt)
{ {
if (_inputRoot is null) if (_inputRoot is null)
return; return;
@ -248,8 +251,15 @@ internal class TopLevelImpl : ITopLevelImpl, IFramebufferPlatformSurface
break; break;
default: default:
var e = new RawPointerEventArgs(_mouse, timeStamp, _inputRoot, (RawPointerEventType)type, IInputDevice device = deviceType == AvnPointerDeviceType.Pen && _pen != null ? _pen : _mouse;
point.ToAvaloniaPoint(), (RawInputModifiers)modifiers); var e = new RawPointerEventArgs(device, timeStamp, _inputRoot, (RawPointerEventType)type,
new RawPointerPoint
{
Position = point.ToAvaloniaPoint(),
Pressure = pressure,
XTilt = xTilt,
YTilt = yTilt
}, (RawInputModifiers)modifiers);
if (!ChromeHitTest(e)) if (!ChromeHitTest(e))
{ {
@ -435,9 +445,9 @@ internal class TopLevelImpl : ITopLevelImpl, IFramebufferPlatformSurface
_parent.Resized?.Invoke(s, (WindowResizeReason)reason); _parent.Resized?.Invoke(s, (WindowResizeReason)reason);
} }
void IAvnTopLevelEvents.RawMouseEvent(AvnRawMouseEventType type, ulong timeStamp, AvnInputModifiers modifiers, AvnPoint point, AvnVector delta) void IAvnTopLevelEvents.RawMouseEvent(AvnRawMouseEventType type, AvnPointerDeviceType pointerDeviceType, ulong timeStamp, AvnInputModifiers modifiers, AvnPoint point, AvnVector delta, float pressure, float xTilt, float yTilt)
{ {
_parent.RawMouseEvent(type, timeStamp, modifiers, point, delta); _parent.RawMouseEvent(type, pointerDeviceType, timeStamp, modifiers, point, delta, pressure, xTilt, yTilt);
} }
int IAvnTopLevelEvents.RawKeyEvent(AvnRawKeyEventType type, ulong timeStamp, AvnInputModifiers modifiers, AvnKey key, AvnPhysicalKey physicalKey, string keySymbol) int IAvnTopLevelEvents.RawKeyEvent(AvnRawKeyEventType type, ulong timeStamp, AvnInputModifiers modifiers, AvnKey key, AvnPhysicalKey physicalKey, string keySymbol)

13
src/Avalonia.Native/avn.idl

@ -667,6 +667,12 @@ enum AvnPlatformThemeVariant
HighContrastDark, HighContrastDark,
} }
enum AvnPointerDeviceType
{
Mouse,
Pen,
}
[uuid(809c652e-7396-11d2-9771-00a0c9b4d50c)] [uuid(809c652e-7396-11d2-9771-00a0c9b4d50c)]
interface IAvaloniaNativeFactory : IUnknown interface IAvaloniaNativeFactory : IUnknown
{ {
@ -786,10 +792,15 @@ interface IAvnTopLevelEvents : IUnknown
HRESULT Paint(); HRESULT Paint();
void Resized([const] AvnSize& size, AvnPlatformResizeReason reason); void Resized([const] AvnSize& size, AvnPlatformResizeReason reason);
void RawMouseEvent(AvnRawMouseEventType type, void RawMouseEvent(AvnRawMouseEventType type,
AvnPointerDeviceType deviceType,
u_int64_t timeStamp, u_int64_t timeStamp,
AvnInputModifiers modifiers, AvnInputModifiers modifiers,
AvnPoint point, AvnPoint point,
AvnVector delta); AvnVector delta,
float pressure,
float xTilt,
float yTilt
);
bool RawKeyEvent(AvnRawKeyEventType type, u_int64_t timeStamp, AvnInputModifiers modifiers, bool RawKeyEvent(AvnRawKeyEventType type, u_int64_t timeStamp, AvnInputModifiers modifiers,
AvnKey key, AvnPhysicalKey physicalKey, [const] char* keySymbol); AvnKey key, AvnPhysicalKey physicalKey, [const] char* keySymbol);
bool RawTextInputEvent(u_int64_t timeStamp, [const] char* text); bool RawTextInputEvent(u_int64_t timeStamp, [const] char* text);

Loading…
Cancel
Save