From 36e7ab50043a871d725f72be5366950d93737801 Mon Sep 17 00:00:00 2001 From: Jumar Macato <16554748+jmacato@users.noreply.github.com> Date: Sat, 13 Jan 2024 22:12:07 +0800 Subject: [PATCH] Post native win32 dragmove on next dispatcher call (#14190) --- src/Windows/Avalonia.Win32/WindowImpl.cs | 28 +++++++++++++----------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/Windows/Avalonia.Win32/WindowImpl.cs b/src/Windows/Avalonia.Win32/WindowImpl.cs index ba4a828f1c..92d009b530 100644 --- a/src/Windows/Avalonia.Win32/WindowImpl.cs +++ b/src/Windows/Avalonia.Win32/WindowImpl.cs @@ -26,6 +26,7 @@ using Avalonia.Win32.WinRT; using static Avalonia.Win32.Interop.UnmanagedMethods; using Avalonia.Input.Platform; using System.Diagnostics; +using Avalonia.Threading; using static Avalonia.Controls.Platform.IWin32OptionsTopLevelImpl; using static Avalonia.Controls.Platform.Win32SpecificOptions; @@ -668,21 +669,22 @@ namespace Avalonia.Win32 { e.Pointer.Capture(null); - // Mouse.LeftButton actually reflects the primary button user is using. - // So we don't need to check whether the button has been swapped here. - if (e.Pointer.IsPrimary) + Dispatcher.UIThread.Post(() => { - // SendMessage's return value is dependent on the message send. WM_SYSCOMMAND - // and WM_LBUTTONUP return value just signify whether the WndProc handled the - // message or not, so they are not interesting + if (e.Pointer.IsPrimary) + { + // SendMessage's return value is dependent on the message send. WM_SYSCOMMAND + // and WM_LBUTTONUP return value just signify whether the WndProc handled the + // message or not, so they are not interesting - SendMessage(_hwnd, (int)WindowsMessage.WM_SYSCOMMAND, (IntPtr)SC_MOUSEMOVE, IntPtr.Zero); - SendMessage(_hwnd, (int)WindowsMessage.WM_LBUTTONUP, IntPtr.Zero, IntPtr.Zero); - } - else - { - throw new InvalidOperationException("BeginMoveDrag Failed"); - } + SendMessage(_hwnd, (int)WindowsMessage.WM_SYSCOMMAND, (IntPtr)SC_MOUSEMOVE, IntPtr.Zero); + SendMessage(_hwnd, (int)WindowsMessage.WM_LBUTTONUP, IntPtr.Zero, IntPtr.Zero); + } + else + { + throw new InvalidOperationException("BeginMoveDrag Failed"); + } + }, DispatcherPriority.Send); } public void BeginResizeDrag(WindowEdge edge, PointerPressedEventArgs e)