From 6483b5edc778e8fbeb1a0c29d55c150f9d60965e Mon Sep 17 00:00:00 2001 From: Luis von der Eltz Date: Thu, 7 Jul 2022 10:46:06 +0200 Subject: [PATCH 01/13] Add Has method to IPseudoClasses --- src/Avalonia.Base/Controls/IPseudoClasses.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Avalonia.Base/Controls/IPseudoClasses.cs b/src/Avalonia.Base/Controls/IPseudoClasses.cs index eda521727f..45013ee069 100644 --- a/src/Avalonia.Base/Controls/IPseudoClasses.cs +++ b/src/Avalonia.Base/Controls/IPseudoClasses.cs @@ -19,5 +19,12 @@ namespace Avalonia.Controls /// /// The pseudoclass name. bool Remove(string name); + + /// + /// Returns whether a pseudoclass is present in the collection. + /// + /// The pseudoclass name. + /// Whether the pseudoclass is present. + bool Has(string name); } } From 0553c7ceabf01199a0c45cf21c3e6126fde1e660 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Fri, 8 Jul 2022 15:32:09 +0100 Subject: [PATCH 02/13] add a failing unit test --- .../WindowTests.cs | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tests/Avalonia.Controls.UnitTests/WindowTests.cs b/tests/Avalonia.Controls.UnitTests/WindowTests.cs index a8c9b68d12..ab4fd566c8 100644 --- a/tests/Avalonia.Controls.UnitTests/WindowTests.cs +++ b/tests/Avalonia.Controls.UnitTests/WindowTests.cs @@ -540,6 +540,51 @@ namespace Avalonia.Controls.UnitTests Assert.Equal(window.Position, expectedPosition); } } + + [Fact] + public void Window_Should_Be_Centered_When_WindowStartupLocation_Is_CenterScreen_1080_175() + { + var screen1 = new Mock(1.75, new PixelRect(new PixelSize(1920, 1080)), new PixelRect(new PixelSize(1920, 966)), true); + + var screens = new Mock(); + screens.Setup(x => x.AllScreens).Returns(new Screen[] { screen1.Object }); + screens.Setup(x => x.ScreenFromPoint(It.IsAny())).Returns(screen1.Object); + + + var windowImpl = MockWindowingPlatform.CreateWindowMock(); + windowImpl.Setup(x => x.DesktopScaling).Returns(1.75); + windowImpl.Setup(x => x.RenderScaling).Returns(1.75); + windowImpl.Setup(x => x.Screen).Returns(screens.Object); + + var clientSize = new Size(801.142, 366); + + windowImpl.Setup(x => x.ClientSize).Returns(() => clientSize); + + windowImpl.Setup(x => x.Resize(It.IsAny(), It.IsAny())) + .Callback((x, y) => + { + clientSize = x;//.Constrain(screen1.Object.Bounds.Size.ToSize(1.75)); + windowImpl.Object.Resized?.Invoke(clientSize, y); + }); + + windowImpl.Setup(x => x.FrameSize).Returns(() => clientSize.Inflate(new Thickness(5, 25, 5, 5))); + + using (UnitTestApplication.Start(TestServices.StyledWindow)) + { + var window = new Window(windowImpl.Object); + window.WindowStartupLocation = WindowStartupLocation.CenterScreen; + window.MinWidth = 720; + window.MinHeight = 480; + //window.Width = 720; + //window.Height = 480; + + window.Show(); + + var expectedPosition = new PixelPoint(321, 36); + + Assert.Equal(window.Position, expectedPosition); + } + } [Fact] public void Window_Should_Be_Centered_Relative_To_Owner_When_WindowStartupLocation_Is_CenterOwner() From b9aa49bc05d039b01a52e0a10d0494be6bdb92d9 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Fri, 8 Jul 2022 18:31:49 +0100 Subject: [PATCH 03/13] Add failing unit test. --- .../Avalonia.Controls.UnitTests/WindowTests.cs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/tests/Avalonia.Controls.UnitTests/WindowTests.cs b/tests/Avalonia.Controls.UnitTests/WindowTests.cs index ab4fd566c8..3677d62050 100644 --- a/tests/Avalonia.Controls.UnitTests/WindowTests.cs +++ b/tests/Avalonia.Controls.UnitTests/WindowTests.cs @@ -542,28 +542,25 @@ namespace Avalonia.Controls.UnitTests } [Fact] - public void Window_Should_Be_Centered_When_WindowStartupLocation_Is_CenterScreen_1080_175() + public void Window_Should_Be_Sized_To_MinSize_If_InitialSize_Less_Than_MinSize() { var screen1 = new Mock(1.75, new PixelRect(new PixelSize(1920, 1080)), new PixelRect(new PixelSize(1920, 966)), true); - var screens = new Mock(); screens.Setup(x => x.AllScreens).Returns(new Screen[] { screen1.Object }); screens.Setup(x => x.ScreenFromPoint(It.IsAny())).Returns(screen1.Object); - var windowImpl = MockWindowingPlatform.CreateWindowMock(); windowImpl.Setup(x => x.DesktopScaling).Returns(1.75); windowImpl.Setup(x => x.RenderScaling).Returns(1.75); windowImpl.Setup(x => x.Screen).Returns(screens.Object); - var clientSize = new Size(801.142, 366); + var clientSize = new Size(400.142, 366); windowImpl.Setup(x => x.ClientSize).Returns(() => clientSize); - windowImpl.Setup(x => x.Resize(It.IsAny(), It.IsAny())) .Callback((x, y) => { - clientSize = x;//.Constrain(screen1.Object.Bounds.Size.ToSize(1.75)); + clientSize = x; windowImpl.Object.Resized?.Invoke(clientSize, y); }); @@ -575,14 +572,10 @@ namespace Avalonia.Controls.UnitTests window.WindowStartupLocation = WindowStartupLocation.CenterScreen; window.MinWidth = 720; window.MinHeight = 480; - //window.Width = 720; - //window.Height = 480; window.Show(); - - var expectedPosition = new PixelPoint(321, 36); - - Assert.Equal(window.Position, expectedPosition); + + Assert.Equal(new Size(720, 480), window.Bounds.Size); } } From 9be71040c8fa3a0beeda709cbcc49e5d924f2d49 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Mon, 11 Jul 2022 12:45:17 +0100 Subject: [PATCH 04/13] failing unit test. --- .../WindowTests.cs | 24 ++++++++++++++----- .../MockWindowingPlatform.cs | 4 ++-- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/tests/Avalonia.Controls.UnitTests/WindowTests.cs b/tests/Avalonia.Controls.UnitTests/WindowTests.cs index 3677d62050..436f52ef65 100644 --- a/tests/Avalonia.Controls.UnitTests/WindowTests.cs +++ b/tests/Avalonia.Controls.UnitTests/WindowTests.cs @@ -549,22 +549,33 @@ namespace Avalonia.Controls.UnitTests screens.Setup(x => x.AllScreens).Returns(new Screen[] { screen1.Object }); screens.Setup(x => x.ScreenFromPoint(It.IsAny())).Returns(screen1.Object); - var windowImpl = MockWindowingPlatform.CreateWindowMock(); + var windowImpl = MockWindowingPlatform.CreateWindowMock(400, 300); windowImpl.Setup(x => x.DesktopScaling).Returns(1.75); windowImpl.Setup(x => x.RenderScaling).Returns(1.75); windowImpl.Setup(x => x.Screen).Returns(screens.Object); - var clientSize = new Size(400.142, 366); + var clientSize = new Size(400, 300); + bool isShown = false; - windowImpl.Setup(x => x.ClientSize).Returns(() => clientSize); windowImpl.Setup(x => x.Resize(It.IsAny(), It.IsAny())) .Callback((x, y) => { - clientSize = x; - windowImpl.Object.Resized?.Invoke(clientSize, y); + if (x != clientSize) + { + clientSize = x; + + windowImpl.Object.Resized?.Invoke(clientSize, y); + } }); - windowImpl.Setup(x => x.FrameSize).Returns(() => clientSize.Inflate(new Thickness(5, 25, 5, 5))); + windowImpl.Setup(x => x.Show(It.IsAny(), It.IsAny())) + .Callback((activate, isDialog) => + { + isShown = true; + windowImpl.Object.Resized?.Invoke(clientSize, PlatformResizeReason.Unspecified); + }); + + windowImpl.Setup(x => x.FrameSize).Returns(() => windowImpl.Object.ClientSize.Inflate(new Thickness(5, 25, 5, 5))); using (UnitTestApplication.Start(TestServices.StyledWindow)) { @@ -575,6 +586,7 @@ namespace Avalonia.Controls.UnitTests window.Show(); + Assert.Equal(new PixelPoint(601, 194), window.Position); Assert.Equal(new Size(720, 480), window.Bounds.Size); } } diff --git a/tests/Avalonia.UnitTests/MockWindowingPlatform.cs b/tests/Avalonia.UnitTests/MockWindowingPlatform.cs index 461e0f4392..ffa71d5226 100644 --- a/tests/Avalonia.UnitTests/MockWindowingPlatform.cs +++ b/tests/Avalonia.UnitTests/MockWindowingPlatform.cs @@ -21,11 +21,11 @@ namespace Avalonia.UnitTests _popupImpl = popupImpl; } - public static Mock CreateWindowMock() + public static Mock CreateWindowMock(double initialWidth = 800, double initialHeight = 600) { var windowImpl = new Mock(); var position = new PixelPoint(); - var clientSize = new Size(800, 600); + var clientSize = new Size(initialWidth, initialHeight); windowImpl.SetupAllProperties(); windowImpl.Setup(x => x.ClientSize).Returns(() => clientSize); From d4ec5474d34c5f8e1fa153d25c9ced04719bdaa6 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Mon, 11 Jul 2022 12:45:57 +0100 Subject: [PATCH 05/13] Ensure Window MinHeight/Width is obeyed. --- src/Avalonia.Controls/Window.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Controls/Window.cs b/src/Avalonia.Controls/Window.cs index 2dd391945b..9b4bb51aca 100644 --- a/src/Avalonia.Controls/Window.cs +++ b/src/Avalonia.Controls/Window.cs @@ -681,8 +681,8 @@ namespace Avalonia.Controls IsVisible = true; var initialSize = new Size( - double.IsNaN(Width) ? ClientSize.Width : Width, - double.IsNaN(Height) ? ClientSize.Height : Height); + double.IsNaN(Width) ? Math.Max(MinWidth, ClientSize.Width) : Width, + double.IsNaN(Height) ? Math.Max(MinHeight, ClientSize.Height) : Height); if (initialSize != ClientSize) { From 0aacec3fae881ca74515b814d880bbe7259ba43a Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Mon, 11 Jul 2022 13:29:59 +0100 Subject: [PATCH 06/13] fix mockwindowplatform and test. --- .../WindowTests.cs | 25 +------------------ .../MockWindowingPlatform.cs | 10 ++++++-- 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/tests/Avalonia.Controls.UnitTests/WindowTests.cs b/tests/Avalonia.Controls.UnitTests/WindowTests.cs index 436f52ef65..0cdde445d5 100644 --- a/tests/Avalonia.Controls.UnitTests/WindowTests.cs +++ b/tests/Avalonia.Controls.UnitTests/WindowTests.cs @@ -553,29 +553,6 @@ namespace Avalonia.Controls.UnitTests windowImpl.Setup(x => x.DesktopScaling).Returns(1.75); windowImpl.Setup(x => x.RenderScaling).Returns(1.75); windowImpl.Setup(x => x.Screen).Returns(screens.Object); - - var clientSize = new Size(400, 300); - bool isShown = false; - - windowImpl.Setup(x => x.Resize(It.IsAny(), It.IsAny())) - .Callback((x, y) => - { - if (x != clientSize) - { - clientSize = x; - - windowImpl.Object.Resized?.Invoke(clientSize, y); - } - }); - - windowImpl.Setup(x => x.Show(It.IsAny(), It.IsAny())) - .Callback((activate, isDialog) => - { - isShown = true; - windowImpl.Object.Resized?.Invoke(clientSize, PlatformResizeReason.Unspecified); - }); - - windowImpl.Setup(x => x.FrameSize).Returns(() => windowImpl.Object.ClientSize.Inflate(new Thickness(5, 25, 5, 5))); using (UnitTestApplication.Start(TestServices.StyledWindow)) { @@ -586,7 +563,7 @@ namespace Avalonia.Controls.UnitTests window.Show(); - Assert.Equal(new PixelPoint(601, 194), window.Position); + Assert.Equal(new PixelPoint(330, 63), window.Position); Assert.Equal(new Size(720, 480), window.Bounds.Size); } } diff --git a/tests/Avalonia.UnitTests/MockWindowingPlatform.cs b/tests/Avalonia.UnitTests/MockWindowingPlatform.cs index ffa71d5226..339b87cf88 100644 --- a/tests/Avalonia.UnitTests/MockWindowingPlatform.cs +++ b/tests/Avalonia.UnitTests/MockWindowingPlatform.cs @@ -55,12 +55,18 @@ namespace Avalonia.UnitTests windowImpl.Setup(x => x.Resize(It.IsAny(), It.IsAny())) .Callback((x, y) => { - clientSize = x.Constrain(s_screenSize); - windowImpl.Object.Resized?.Invoke(clientSize, y); + var constrainedSize = x.Constrain(s_screenSize); + + if (constrainedSize != clientSize) + { + clientSize = constrainedSize; + windowImpl.Object.Resized?.Invoke(clientSize, y); + } }); windowImpl.Setup(x => x.Show(true, It.IsAny())).Callback(() => { + windowImpl.Object.Resized?.Invoke(windowImpl.Object.ClientSize, PlatformResizeReason.Unspecified); windowImpl.Object.Activated?.Invoke(); }); From efcca77ddb194a5395cc4d2287319873f1851d36 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Mon, 11 Jul 2022 15:00:57 +0100 Subject: [PATCH 07/13] only trigger resized event if the window is shown. --- native/Avalonia.Native/src/OSX/AvnView.mm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/native/Avalonia.Native/src/OSX/AvnView.mm b/native/Avalonia.Native/src/OSX/AvnView.mm index 01725ace03..4ae6ad5a00 100644 --- a/native/Avalonia.Native/src/OSX/AvnView.mm +++ b/native/Avalonia.Native/src/OSX/AvnView.mm @@ -127,7 +127,11 @@ [self updateRenderTarget]; auto reason = [self inLiveResize] ? ResizeUser : _resizeReason; - _parent->BaseEvents->Resized(AvnSize{newSize.width, newSize.height}, reason); + + if(_parent->IsShown()) + { + _parent->BaseEvents->Resized(AvnSize{newSize.width, newSize.height}, reason); + } } } From 926b3656527199a53a866a02c4f134bcaa5e73a4 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 12 Jul 2022 15:21:03 +0200 Subject: [PATCH 08/13] Fix: DataGrid Grouping symbol wrong in Fluent Theme - Expanded icon was vertically flipped. - ToggleButton :checked means open, :unchecked means closed. The icon reference was corrected here to match this. --- src/Avalonia.Controls.DataGrid/Themes/Fluent.xaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Avalonia.Controls.DataGrid/Themes/Fluent.xaml b/src/Avalonia.Controls.DataGrid/Themes/Fluent.xaml index 2baa8c88c9..fb032fec3e 100644 --- a/src/Avalonia.Controls.DataGrid/Themes/Fluent.xaml +++ b/src/Avalonia.Controls.DataGrid/Themes/Fluent.xaml @@ -7,7 +7,7 @@ M1875 1011l-787 787v-1798h-128v1798l-787 -787l-90 90l941 941l941 -941z M1965 947l-941 -941l-941 941l90 90l787 -787v1798h128v-1798l787 787z M515 93l930 931l-930 931l90 90l1022 -1021l-1022 -1021z - M1939 1581l90 -90l-1005 -1005l-1005 1005l90 90l915 -915z + M109 486 19 576 1024 1581 2029 576 1939 486 1024 1401z @@ -499,12 +499,12 @@ From 4ca4986b4f6e6bf31e7e53a5de531895a33b8ee7 Mon Sep 17 00:00:00 2001 From: Luis von der Eltz Date: Tue, 12 Jul 2022 15:58:58 +0200 Subject: [PATCH 09/13] rename --- src/Avalonia.Base/Controls/IPseudoClasses.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Base/Controls/IPseudoClasses.cs b/src/Avalonia.Base/Controls/IPseudoClasses.cs index 45013ee069..438b05a8cf 100644 --- a/src/Avalonia.Base/Controls/IPseudoClasses.cs +++ b/src/Avalonia.Base/Controls/IPseudoClasses.cs @@ -25,6 +25,6 @@ namespace Avalonia.Controls /// /// The pseudoclass name. /// Whether the pseudoclass is present. - bool Has(string name); + bool Contains(string name); } } From d1f3c4d691c3e8336b3f98dc7f524b3fc30f515b Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Tue, 12 Jul 2022 17:04:03 +0300 Subject: [PATCH 10/13] [mac] Don't update layer if IOSurface doesn't have any valid content yet --- native/Avalonia.Native/src/OSX/rendertarget.mm | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/native/Avalonia.Native/src/OSX/rendertarget.mm b/native/Avalonia.Native/src/OSX/rendertarget.mm index 266d0345d1..2075cc85ab 100644 --- a/native/Avalonia.Native/src/OSX/rendertarget.mm +++ b/native/Avalonia.Native/src/OSX/rendertarget.mm @@ -13,6 +13,7 @@ { @public IOSurfaceRef surface; @public AvnPixelSize size; + @public bool hasContent; @public float scale; ComPtr _context; GLuint _framebuffer, _texture, _renderbuffer; @@ -41,6 +42,7 @@ self->scale = scale; self->size = size; self->_context = context; + self->hasContent = false; return self; } @@ -92,6 +94,7 @@ _context->MakeCurrent(release.getPPV()); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); glFlush(); + self->hasContent = true; } -(void) dealloc @@ -170,6 +173,8 @@ static IAvnGlSurfaceRenderTarget* CreateGlRenderTarget(IOSurfaceRenderTarget* ta @synchronized (lock) { if(_layer == nil) return; + if(!surface->hasContent) + return; [CATransaction begin]; [_layer setContents: nil]; if(surface != nil) @@ -213,6 +218,7 @@ static IAvnGlSurfaceRenderTarget* CreateGlRenderTarget(IOSurfaceRenderTarget* ta memcpy(pSurface + y*sstride, pFb + y*fstride, wbytes); } IOSurfaceUnlock(surf, 0, nil); + surface->hasContent = true; [self updateLayer]; return S_OK; } From 7746b79fb5d21a17d055cb2b7dbdbd1c1577a5bc Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Wed, 13 Jul 2022 10:46:31 +0100 Subject: [PATCH 11/13] close app after running --- tests/Avalonia.IntegrationTests.Appium/TestAppFixture.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Avalonia.IntegrationTests.Appium/TestAppFixture.cs b/tests/Avalonia.IntegrationTests.Appium/TestAppFixture.cs index b3385d8ee7..70052b672c 100644 --- a/tests/Avalonia.IntegrationTests.Appium/TestAppFixture.cs +++ b/tests/Avalonia.IntegrationTests.Appium/TestAppFixture.cs @@ -57,6 +57,7 @@ namespace Avalonia.IntegrationTests.Appium { try { + Session.CloseApp(); Session.Close(); } catch From e0c1bae8422d052d55085bb24507e04480cc0fe5 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Wed, 13 Jul 2022 10:56:15 +0100 Subject: [PATCH 12/13] use pkill to close app. --- tests/Avalonia.IntegrationTests.Appium/TestAppFixture.cs | 1 - .../Avalonia.IntegrationTests.Appium/macos-clean-build-test.sh | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Avalonia.IntegrationTests.Appium/TestAppFixture.cs b/tests/Avalonia.IntegrationTests.Appium/TestAppFixture.cs index 70052b672c..b3385d8ee7 100644 --- a/tests/Avalonia.IntegrationTests.Appium/TestAppFixture.cs +++ b/tests/Avalonia.IntegrationTests.Appium/TestAppFixture.cs @@ -57,7 +57,6 @@ namespace Avalonia.IntegrationTests.Appium { try { - Session.CloseApp(); Session.Close(); } catch diff --git a/tests/Avalonia.IntegrationTests.Appium/macos-clean-build-test.sh b/tests/Avalonia.IntegrationTests.Appium/macos-clean-build-test.sh index 635c593f37..b3cba2c5ea 100755 --- a/tests/Avalonia.IntegrationTests.Appium/macos-clean-build-test.sh +++ b/tests/Avalonia.IntegrationTests.Appium/macos-clean-build-test.sh @@ -6,4 +6,6 @@ git clean -xdf ./build.sh CompileNative ./samples/IntegrationTestApp/bundle.sh open -n ./samples/IntegrationTestApp/bin/Debug/net6.0/osx-arm64/publish/IntegrationTestApp.app +pkill IntegrationTestApp dotnet test tests/Avalonia.IntegrationTests.Appium/ -l "console;verbosity=detailed" +pkill IntegrationTestApp From d59c9feac9a0d70494fef36a5718af37b1a7f075 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Wed, 13 Jul 2022 11:11:58 +0100 Subject: [PATCH 13/13] make sure any existing instances are closed. --- tests/Avalonia.IntegrationTests.Appium/macos-clean-build-test.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Avalonia.IntegrationTests.Appium/macos-clean-build-test.sh b/tests/Avalonia.IntegrationTests.Appium/macos-clean-build-test.sh index b3cba2c5ea..5018e78d68 100755 --- a/tests/Avalonia.IntegrationTests.Appium/macos-clean-build-test.sh +++ b/tests/Avalonia.IntegrationTests.Appium/macos-clean-build-test.sh @@ -3,6 +3,7 @@ SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd) cd "$SCRIPT_DIR"/../.. || exit git clean -xdf +pkill IntegrationTestApp ./build.sh CompileNative ./samples/IntegrationTestApp/bundle.sh open -n ./samples/IntegrationTestApp/bin/Debug/net6.0/osx-arm64/publish/IntegrationTestApp.app