Browse Source

macOS: fall back to the current event in BeginMoveDrag when no mouse-down was recorded (#21827)

BeginMoveDrag on macOS drags from the Avalonia view's last recorded
mouse-down. A press that begins inside an embedded native view (for
example a webview hosted through NativeControlHost) is consumed by that
view and never delivered to the Avalonia view, so lastMouseDownEvent is
nil and BeginMoveDrag silently does nothing - applications embedding
native views cannot implement custom title-bar dragging through the
managed API and must reproduce performWindowDragWithEvent: through
platform interop.

When no mouse-down was recorded, fall back to the event the application
is currently tracking, guarded to left-button press or drag events that
belong to this window. Presses recorded by the Avalonia view behave
exactly as before.
pull/21852/head
Mark Zielinski 2 months ago
committed by GitHub
parent
commit
aa1ba88e79
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 15
      native/Avalonia.Native/src/OSX/WindowBaseImpl.mm

15
native/Avalonia.Native/src/OSX/WindowBaseImpl.mm

@ -347,6 +347,21 @@ HRESULT WindowBaseImpl::BeginMoveDrag() {
@autoreleasepool {
auto lastEvent = [View lastMouseDownEvent];
if (lastEvent == nullptr) {
// A press that begins inside an embedded native view (for example a webview hosted
// through NativeControlHost) is consumed by that view and never delivered to the
// Avalonia view, so no mouse-down is recorded; fall back to the event the
// application is tracking right now, provided it is a left-button press or drag
// that belongs to this window.
auto currentEvent = [NSApp currentEvent];
if (currentEvent != nullptr && [currentEvent window] == Window &&
([currentEvent type] == NSEventTypeLeftMouseDown ||
[currentEvent type] == NSEventTypeLeftMouseDragged)) {
lastEvent = currentEvent;
}
}
if (lastEvent == nullptr) {
return S_OK;
}

Loading…
Cancel
Save