Skip to content

Commit 29fbaaa

Browse files
authored
Fixed unnecessary window displacement on resize (#18004)
* Added new test: changing window size should not change position * Removed unnecessary window placement assignment to fix window position shifting due to incorrect workspace coordinate usage * Fixed test because buttons went off the window on tiny screen resolutions * Make test Windows specific * Use `Bounds` instead of `Width` and `Height` properties as they are "requested" size rather than actual size (see #18060)
1 parent 9441362 commit 29fbaaa

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

samples/IntegrationTestApp/ShowWindowTest.axaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@
5353
<Label Grid.Row="11" Content="MeasuredWith:" />
5454
<TextBlock Grid.Column="1" Grid.Row="11" Name="CurrentMeasuredWithText" Text="{Binding #MyBorder.MeasuredWith}" />
5555

56-
<Button Name="HideButton" Grid.Row="12" Command="{Binding $parent[Window].Hide}">Hide</Button>
56+
<StackPanel Orientation="Horizontal" Grid.Row="12">
57+
<Button Name="HideButton" Command="{Binding $parent[Window].Hide}">Hide</Button>
58+
<Button Name="AddToWidth" Click="AddToWidth_Click">Add to Width</Button>
59+
<Button Name="AddToHeight" Click="AddToHeight_Click">Add to Height</Button>
60+
</StackPanel>
5761

5862
</Grid>
5963
</integrationTestApp:MeasureBorder>

samples/IntegrationTestApp/ShowWindowTest.axaml.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Runtime.InteropServices;
33
using Avalonia;
44
using Avalonia.Controls;
5+
using Avalonia.Interactivity;
56
using Avalonia.Threading;
67

78
namespace IntegrationTestApp
@@ -70,5 +71,8 @@ private void TimerOnTick(object? sender, EventArgs e)
7071
{
7172
_orderTextBox!.Text = MacOSIntegration.GetOrderedIndex(this).ToString();
7273
}
74+
75+
private void AddToWidth_Click(object? sender, RoutedEventArgs e) => Width = Bounds.Width + 10;
76+
private void AddToHeight_Click(object? sender, RoutedEventArgs e) => Height = Bounds.Height + 10;
7377
}
7478
}

src/Windows/Avalonia.Win32/WindowImpl.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -608,12 +608,6 @@ public void Resize(Size value, WindowResizeReason reason)
608608
return;
609609
}
610610
}
611-
else
612-
{
613-
var position = Position;
614-
windowPlacement.NormalPosition.left = position.X;
615-
windowPlacement.NormalPosition.top = position.Y;
616-
}
617611

618612
windowPlacement.NormalPosition.right = windowPlacement.NormalPosition.left + windowWidth;
619613
windowPlacement.NormalPosition.bottom = windowPlacement.NormalPosition.top + windowHeight;

tests/Avalonia.IntegrationTests.Appium/WindowTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,24 @@ public void Changing_WindowState_Should_Not_Change_Frame_Size_And_Position()
349349
}
350350
}
351351

352+
[PlatformFact(TestPlatforms.Windows)]
353+
public void Changing_Size_Should_Not_Change_Position()
354+
{
355+
using (OpenWindow())
356+
{
357+
var info = GetWindowInfo();
358+
359+
Session.FindElementByAccessibilityId("AddToWidth").SendClick();
360+
Session.FindElementByAccessibilityId("AddToHeight").SendClick();
361+
362+
var updatedInfo = GetWindowInfo();
363+
Assert.Equal(info.Position, updatedInfo.Position);
364+
Assert.Equal(info.FrameSize
365+
.WithWidth(info.FrameSize.Width + 10)
366+
.WithHeight(info.FrameSize.Height + 10), updatedInfo.FrameSize);
367+
}
368+
}
369+
352370
public static TheoryData<Size?, ShowWindowMode, WindowStartupLocation, bool> StartupLocationData()
353371
{
354372
var sizes = new Size?[] { null, new Size(400, 300) };

0 commit comments

Comments
 (0)