From 691541adf65ebc80ae023121d47382ded3cc4a4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Korczy=C5=84ski?= Date: Mon, 11 Mar 2024 04:39:30 +0000 Subject: [PATCH] Addressed PR comments --- native/Avalonia.Native/src/OSX/WindowImpl.mm | 4 ++- .../IntegrationTestApp/MacOSIntegration.cs | 27 ------------------- .../ShowWindowTest.axaml.cs | 2 +- src/Avalonia.Native/WindowImpl.cs | 9 +------ .../WindowTests_MacOS.cs | 16 +++++------ 5 files changed, 13 insertions(+), 45 deletions(-) delete mode 100644 samples/IntegrationTestApp/MacOSIntegration.cs diff --git a/native/Avalonia.Native/src/OSX/WindowImpl.mm b/native/Avalonia.Native/src/OSX/WindowImpl.mm index 33ddaf3795..1cdf81e2fb 100644 --- a/native/Avalonia.Native/src/OSX/WindowImpl.mm +++ b/native/Avalonia.Native/src/OSX/WindowImpl.mm @@ -373,7 +373,9 @@ HRESULT WindowImpl::GetWindowZOrder(long* zOrder) { return E_POINTER; } - *zOrder = [Window orderedIndex]; + // negate the value to match expected z-order in Avalonia + // (top-most window should have the highest z-order value) + *zOrder = -[Window orderedIndex]; return S_OK; } } diff --git a/samples/IntegrationTestApp/MacOSIntegration.cs b/samples/IntegrationTestApp/MacOSIntegration.cs deleted file mode 100644 index f700a5b4e2..0000000000 --- a/samples/IntegrationTestApp/MacOSIntegration.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using Avalonia.Controls; - -namespace IntegrationTestApp -{ - public static class MacOSIntegration - { - [DllImport("/usr/lib/libobjc.dylib", EntryPoint = "sel_registerName")] - private static extern IntPtr GetHandle(string name); - - [DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")] - private static extern long Int64_objc_msgSend(IntPtr receiver, IntPtr selector); - - private static readonly IntPtr s_orderedIndexSelector; - - static MacOSIntegration() - { - s_orderedIndexSelector = GetHandle("orderedIndex");; - } - - public static long GetOrderedIndex(Window window) - { - return Int64_objc_msgSend(window.PlatformImpl!.Handle.Handle, s_orderedIndexSelector); - } - } -} diff --git a/samples/IntegrationTestApp/ShowWindowTest.axaml.cs b/samples/IntegrationTestApp/ShowWindowTest.axaml.cs index f0be34fdaa..5764a90a1f 100644 --- a/samples/IntegrationTestApp/ShowWindowTest.axaml.cs +++ b/samples/IntegrationTestApp/ShowWindowTest.axaml.cs @@ -75,7 +75,7 @@ namespace IntegrationTestApp private void TimerOnTick(object? sender, EventArgs e) { - _orderTextBox!.Text = MacOSIntegration.GetOrderedIndex(this).ToString(); + _orderTextBox!.Text = WindowZOrder.ToString(); } } } diff --git a/src/Avalonia.Native/WindowImpl.cs b/src/Avalonia.Native/WindowImpl.cs index 62f6bee91a..aa3d869a3a 100644 --- a/src/Avalonia.Native/WindowImpl.cs +++ b/src/Avalonia.Native/WindowImpl.cs @@ -103,14 +103,7 @@ namespace Avalonia.Native public Thickness OffScreenMargin { get; } = new Thickness(); - public IntPtr? ZOrder - { - get - { - // macOS returns z-order in reverse order - the topmost window has the lowest z-order - return new IntPtr(-_native.WindowZOrder.ToInt64()); - } - } + public IntPtr? ZOrder => _native.WindowZOrder; private bool _isExtended; public bool IsClientAreaExtendedToDecorations => _isExtended; diff --git a/tests/Avalonia.IntegrationTests.Appium/WindowTests_MacOS.cs b/tests/Avalonia.IntegrationTests.Appium/WindowTests_MacOS.cs index 247198b254..4a2ce4c89b 100644 --- a/tests/Avalonia.IntegrationTests.Appium/WindowTests_MacOS.cs +++ b/tests/Avalonia.IntegrationTests.Appium/WindowTests_MacOS.cs @@ -52,7 +52,7 @@ namespace Avalonia.IntegrationTests.Appium var secondaryWindowIndex = GetWindowOrder("SecondaryWindow"); - Assert.Equal(1, secondaryWindowIndex); + Assert.Equal(-1, secondaryWindowIndex); } } @@ -75,7 +75,7 @@ namespace Avalonia.IntegrationTests.Appium .Release() .Perform(); - Assert.Equal(1, secondaryWindowIndex); + Assert.Equal(-1, secondaryWindowIndex); } } @@ -94,7 +94,7 @@ namespace Avalonia.IntegrationTests.Appium using (OpenWindow(new PixelSize(200, 100), ShowWindowMode.Modal, WindowStartupLocation.Manual)) { var secondaryWindowIndex = GetWindowOrder("SecondaryWindow"); - Assert.Equal(1, secondaryWindowIndex); + Assert.Equal(-1, secondaryWindowIndex); } } finally @@ -112,7 +112,7 @@ namespace Avalonia.IntegrationTests.Appium { mainWindow.SendClick(); var secondaryWindowIndex = GetWindowOrder("SecondaryWindow"); - Assert.Equal(1, secondaryWindowIndex); + Assert.Equal(-1, secondaryWindowIndex); } } @@ -136,7 +136,7 @@ namespace Avalonia.IntegrationTests.Appium { mainWindow.SendClick(); var secondaryWindowIndex = GetWindowOrder("SecondaryWindow"); - Assert.Equal(1, secondaryWindowIndex); + Assert.Equal(-1, secondaryWindowIndex); } // Exit fullscreen by menu shortcut Command+R @@ -159,7 +159,7 @@ namespace Avalonia.IntegrationTests.Appium OpenWindow(null, ShowWindowMode.Modal, WindowStartupLocation.Manual).Dispose(); var secondaryWindowIndex = GetWindowOrder("SecondaryWindow"); - Assert.Equal(1, secondaryWindowIndex); + Assert.Equal(-1, secondaryWindowIndex); } } @@ -212,7 +212,7 @@ namespace Avalonia.IntegrationTests.Appium var secondaryWindowIndex = GetWindowOrder("SecondaryWindow"); - Assert.Equal(2, secondaryWindowIndex); + Assert.Equal(-2, secondaryWindowIndex); var sendToBack = _session.FindElementByAccessibilityId("SendToBack"); sendToBack.Click(); @@ -231,7 +231,7 @@ namespace Avalonia.IntegrationTests.Appium var secondaryWindowIndex = GetWindowOrder("SecondaryWindow"); - Assert.Equal(1, secondaryWindowIndex); + Assert.Equal(-1, secondaryWindowIndex); } }