Skip to content

Commit

Permalink
Merge pull request #8574 from AvaloniaUI/fixes/win32-consistent-minim…
Browse files Browse the repository at this point in the history
…ize-restore-window-size

Win32: Retain window position and size when docked and then minimized and restored.
  • Loading branch information
danwalmsley authored Aug 9, 2022
2 parents db1f157 + baac337 commit 2737c50
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Windows/Avalonia.Win32/WindowImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,12 @@ public WindowState WindowState

set
{
if (IsWindowVisible(_hwnd))
if (IsWindowVisible(_hwnd) && _lastWindowState != value)
{
ShowWindow(value, value != WindowState.Minimized); // If the window is minimized, it shouldn't be activated
}

_lastWindowState = value;
_showWindowState = value;
}
}
Expand Down
39 changes: 39 additions & 0 deletions tests/Avalonia.IntegrationTests.Appium/WindowTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using Avalonia.Controls;
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Interactions;
using Xunit;
Expand Down Expand Up @@ -55,6 +57,43 @@ public void StartupLocation(Size? size, ShowWindowMode mode, WindowStartupLocati
}
}
}

[PlatformFact(TestPlatforms.Windows)]
public void OnWindows_Docked_Windows_Retain_Size_Position_When_Restored()
{
using (OpenWindow(new Size(400, 400), ShowWindowMode.NonOwned, WindowStartupLocation.Manual))
{
var windowState = _session.FindElementByAccessibilityId("WindowState");

Assert.Equal("Normal", windowState.GetComboBoxValue());


var window = _session.FindElements(By.XPath("//Window")).First();

new Actions(_session)
.KeyDown(Keys.Meta)
.SendKeys(Keys.Left)
.KeyUp(Keys.Meta)
.Perform();

var original = GetWindowInfo();

windowState.Click();
_session.FindElementByName("Minimized").SendClick();

new Actions(_session)
.KeyDown(Keys.Alt)
.SendKeys(Keys.Tab)
.KeyUp(Keys.Alt)
.Perform();

var current = GetWindowInfo();

Assert.Equal(original.Position, current.Position);
Assert.Equal(original.FrameSize, current.FrameSize);

}
}


[Theory]
Expand Down

0 comments on commit 2737c50

Please sign in to comment.