Browse Source

Merge pull request #7450 from ngarside/windows-position

Fix offset window position
pull/8404/head
Max Katz 4 years ago
committed by GitHub
parent
commit
2bc89e79be
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      src/Windows/Avalonia.Win32/WindowImpl.cs

24
src/Windows/Avalonia.Win32/WindowImpl.cs

@ -469,10 +469,14 @@ namespace Avalonia.Win32
{
GetWindowRect(_hwnd, out var rc);
return new PixelPoint(rc.left, rc.top);
var border = HiddenBorderSize;
return new PixelPoint(rc.left + border.Width, rc.top + border.Height);
}
set
{
var border = HiddenBorderSize;
value = new PixelPoint(value.X - border.Width, value.Y - border.Height);
SetWindowPos(
Handle.Handle,
IntPtr.Zero,
@ -486,6 +490,24 @@ namespace Avalonia.Win32
private bool HasFullDecorations => _windowProperties.Decorations == SystemDecorations.Full;
private PixelSize HiddenBorderSize
{
get
{
// Windows 10 and 11 add a 7 pixel invisible border on the left/right/bottom of windows for resizing
if (Win32Platform.WindowsVersion.Major < 10 || !HasFullDecorations)
{
return PixelSize.Empty;
}
DwmGetWindowAttribute(_hwnd, (int)DwmWindowAttribute.DWMWA_EXTENDED_FRAME_BOUNDS, out var clientRect, Marshal.SizeOf(typeof(RECT)));
GetWindowRect(_hwnd, out var frameRect);
var borderWidth = GetSystemMetrics(SystemMetric.SM_CXBORDER);
return new PixelSize(clientRect.left - frameRect.left - borderWidth, 0);
}
}
public void Move(PixelPoint point) => Position = point;
public void SetMinMaxSize(Size minSize, Size maxSize)

Loading…
Cancel
Save