Browse Source

Calculate border size

pull/7450/head
Nathan Garside 5 years ago
parent
commit
1ae26b326e
  1. 34
      src/Windows/Avalonia.Win32/WindowImpl.cs

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

@ -448,20 +448,14 @@ namespace Avalonia.Win32
{ {
GetWindowRect(_hwnd, out var rc); GetWindowRect(_hwnd, out var rc);
// Windows 10 and 11 add a 7 pixel invisible border on the left/right/bottom of windows for resizing var border = HiddenBorderSize;
if (Win32Platform.WindowsVersion.Major >= 10 && HasFullDecorations) return new PixelPoint(rc.left + border.Width, rc.top + border.Height);
{
return new PixelPoint(rc.left + (int)(7 * _scaling), rc.top);
}
return new PixelPoint(rc.left, rc.top);
} }
set set
{ {
if (Win32Platform.WindowsVersion.Major >= 10 && HasFullDecorations) var border = HiddenBorderSize;
{ value = new PixelPoint(value.X - border.Width, value.Y - border.Height);
value = new PixelPoint(value.X - (int)(7 * _scaling), value.Y);
}
SetWindowPos( SetWindowPos(
Handle.Handle, Handle.Handle,
IntPtr.Zero, IntPtr.Zero,
@ -475,6 +469,24 @@ namespace Avalonia.Win32
private bool HasFullDecorations => _windowProperties.Decorations == SystemDecorations.Full; 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 Move(PixelPoint point) => Position = point;
public void SetMinMaxSize(Size minSize, Size maxSize) public void SetMinMaxSize(Size minSize, Size maxSize)

Loading…
Cancel
Save