Skip to content

Commit 7331167

Browse files
authored
fix: schedule DWM frame extension to next render frame on Windows 10 (#1087)
The DwmExtendFrameIntoClientArea call needs to be posted to the next render frame to ensure the window handle is fully initialized and avoid potential race conditions.
1 parent f07832c commit 7331167

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/Native/Windows.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
using Avalonia;
1010
using Avalonia.Controls;
11+
using Avalonia.Threading;
1112

1213
namespace SourceGit.Native
1314
{
@@ -214,12 +215,17 @@ public void OpenWithDefaultEditor(string file)
214215

215216
private void FixWindowFrameOnWin10(Window w)
216217
{
217-
var platformHandle = w.TryGetPlatformHandle();
218-
if (platformHandle == null)
219-
return;
218+
// Schedule the DWM frame extension to run in the next render frame
219+
// to ensure proper timing with the window initialization sequence
220+
Dispatcher.UIThread.InvokeAsync(() =>
221+
{
222+
var platformHandle = w.TryGetPlatformHandle();
223+
if (platformHandle == null)
224+
return;
220225

221-
var margins = new MARGINS { cxLeftWidth = 1, cxRightWidth = 1, cyTopHeight = 1, cyBottomHeight = 1 };
222-
DwmExtendFrameIntoClientArea(platformHandle.Handle, ref margins);
226+
var margins = new MARGINS { cxLeftWidth = 1, cxRightWidth = 1, cyTopHeight = 1, cyBottomHeight = 1 };
227+
DwmExtendFrameIntoClientArea(platformHandle.Handle, ref margins);
228+
}, DispatcherPriority.Render);
223229
}
224230

225231
#region EXTERNAL_EDITOR_FINDER

0 commit comments

Comments
 (0)