Browse Source

fixed bug with initial size and position calculation for X11Window (in some cases scaling is not applied until first position change event, and all calculations before it provided wrong values) (#12833)

Co-authored-by: Herman Kirshin <herman.kirshin@jetbrains.com>
pull/14856/head
Herman K 2 years ago
committed by GitHub
parent
commit
38ae473e52
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 12
      src/Avalonia.Controls/Window.cs
  2. 6
      src/Avalonia.X11/X11Window.cs

12
src/Avalonia.Controls/Window.cs

@ -714,6 +714,11 @@ namespace Avalonia.Controls
_shown = true;
IsVisible = true;
// We need to set position first because it is required for getting correct display scale. If position is not manual then it can be
// determined only by calling this method. But here it will calculate not precise location because scaling may not yet be applied (see i.e. X11Window),
// thus we ought to call it again later to center window correctly if needed, when scaling will be already applied
SetWindowStartupLocation(owner);
var initialSize = new Size(
double.IsNaN(Width) ? Math.Max(MinWidth, ClientSize.Width) : Width,
double.IsNaN(Height) ? Math.Max(MinHeight, ClientSize.Height) : Height);
@ -727,6 +732,7 @@ namespace Avalonia.Controls
Owner = owner;
// Second call will calculate correct position because both current and owner windows have correct scaling.
SetWindowStartupLocation(owner);
StartRendering();
@ -787,6 +793,11 @@ namespace Avalonia.Controls
_showingAsDialog = true;
IsVisible = true;
// We need to set position first because it is required for getting correct display scale. If position is not manual then it can be
// determined only by calling this method. But here it will calculate not precise location because scaling may not yet be applied (see i.e. X11Window),
// thus we ought to call it again later to center window correctly if needed, when scaling will be already applied
SetWindowStartupLocation(owner);
var initialSize = new Size(
double.IsNaN(Width) ? ClientSize.Width : Width,
double.IsNaN(Height) ? ClientSize.Height : Height);
@ -802,6 +813,7 @@ namespace Avalonia.Controls
Owner = owner;
// Second call will calculate correct position because both current and owner windows have correct scaling.
SetWindowStartupLocation(owner);
StartRendering();

6
src/Avalonia.X11/X11Window.cs

@ -1026,7 +1026,11 @@ namespace Avalonia.X11
public void Resize(Size clientSize, WindowResizeReason reason) => Resize(clientSize, false, reason);
public void Move(PixelPoint point) => Position = point;
public void Move(PixelPoint point)
{
Position = point;
UpdateScaling();
}
private void MoveResize(PixelPoint position, Size size, double scaling)
{
Move(position);

Loading…
Cancel
Save