From 3096a2d1590ec2a3172b0b79f0faa737d225f59c Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Tue, 21 Feb 2023 23:08:29 +0100 Subject: [PATCH 1/3] Add failing integration test. For the following scenario: - Open a child window of main window - Open a modal window as a child of main window - Close main window - First child window should remain in front of main window --- .../WindowTests_MacOS.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/Avalonia.IntegrationTests.Appium/WindowTests_MacOS.cs b/tests/Avalonia.IntegrationTests.Appium/WindowTests_MacOS.cs index 0839cbf1833..55812d8df79 100644 --- a/tests/Avalonia.IntegrationTests.Appium/WindowTests_MacOS.cs +++ b/tests/Avalonia.IntegrationTests.Appium/WindowTests_MacOS.cs @@ -150,6 +150,18 @@ public void WindowOrder_Owned_Dialog_Stays_InFront_Of_FullScreen_Parent() windowState = mainWindow.FindElementByAccessibilityId("MainWindowState"); Assert.Equal("Normal", windowState.Text); } + + [PlatformFact(TestPlatforms.MacOS)] + public void WindowOrder_Owned_Dialog_Stays_InFront_Of_Parent_After_Modal_Closed() + { + using (OpenWindow(new PixelSize(200, 300), ShowWindowMode.Owned, WindowStartupLocation.Manual)) + { + OpenWindow(null, ShowWindowMode.Modal, WindowStartupLocation.Manual).Dispose(); + + var secondaryWindowIndex = GetWindowOrder("SecondaryWindow"); + Assert.Equal(1, secondaryWindowIndex); + } + } [PlatformFact(TestPlatforms.MacOS)] public void Does_Not_Switch_Space_From_FullScreen_To_Main_Desktop_When_FullScreen_Window_Clicked() From e77c79b2aa4885ba3e8d4f96efd1e4ed6e48ad03 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Tue, 21 Feb 2023 23:11:10 +0100 Subject: [PATCH 2/3] Enforce window order after a delay. Sometimes, after `windowDidBecomeKey` is called and the window order is enforced via `BringToFront`, the window that became key is then moved to the front, breaking window order. Given that we're already invalidating the shadow by scheduling it on the dispatcher, use this opportunity to also enforce the window order again. --- native/Avalonia.Native/src/OSX/AvnWindow.mm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/native/Avalonia.Native/src/OSX/AvnWindow.mm b/native/Avalonia.Native/src/OSX/AvnWindow.mm index 23abf1d53f7..3a03abf211b 100644 --- a/native/Avalonia.Native/src/OSX/AvnWindow.mm +++ b/native/Avalonia.Native/src/OSX/AvnWindow.mm @@ -292,12 +292,13 @@ - (void)windowDidBecomeKey:(NSNotification *_Nonnull)notification { if (_parent == nullptr) return; - + _parent->BringToFront(); dispatch_async(dispatch_get_main_queue(), ^{ @try { - [self invalidateShadow]; + [self invalidateShadow]; + self->_parent->BringToFront(); } @finally{ } From c837c1005165413ae49f0fde2f71d5f4ed52d223 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Wed, 22 Feb 2023 22:23:17 +0100 Subject: [PATCH 3/3] Don't call BringToFront on closed window. --- native/Avalonia.Native/src/OSX/AvnWindow.mm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/native/Avalonia.Native/src/OSX/AvnWindow.mm b/native/Avalonia.Native/src/OSX/AvnWindow.mm index 80a0d3e66ff..b1fb915e04b 100644 --- a/native/Avalonia.Native/src/OSX/AvnWindow.mm +++ b/native/Avalonia.Native/src/OSX/AvnWindow.mm @@ -298,7 +298,8 @@ - (void)windowDidBecomeKey:(NSNotification *_Nonnull)notification dispatch_async(dispatch_get_main_queue(), ^{ @try { [self invalidateShadow]; - self->_parent->BringToFront(); + if (self->_parent != nullptr) + self->_parent->BringToFront(); } @finally{ }