From aa1ba88e792bfe375b259cde3bfbdcdd2c48802d Mon Sep 17 00:00:00 2001 From: Mark Zielinski Date: Fri, 24 Jul 2026 09:44:47 -0500 Subject: [PATCH] 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. --- native/Avalonia.Native/src/OSX/WindowBaseImpl.mm | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/native/Avalonia.Native/src/OSX/WindowBaseImpl.mm b/native/Avalonia.Native/src/OSX/WindowBaseImpl.mm index 976e26148e..33ab1529fc 100644 --- a/native/Avalonia.Native/src/OSX/WindowBaseImpl.mm +++ b/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; }