diff --git a/src/Windows/Avalonia.Win32/WindowImpl.WndProc.cs b/src/Windows/Avalonia.Win32/WindowImpl.WndProc.cs index 3ce34250fa..e9664d234f 100644 --- a/src/Windows/Avalonia.Win32/WindowImpl.WndProc.cs +++ b/src/Windows/Avalonia.Win32/WindowImpl.WndProc.cs @@ -80,50 +80,20 @@ namespace Avalonia.Win32 { IntPtr lRet = IntPtr.Zero; - callDwp = !DwmDefWindowProc(hWnd, msg, wParam, lParam, ref lRet); - - MARGINS margins = new MARGINS { cxLeftWidth = 0, cxRightWidth = 0, cyBottomHeight = 0, cyTopHeight = 100 }; - RECT border_thickness = new RECT(); - + callDwp = !DwmDefWindowProc(hWnd, msg, wParam, lParam, ref lRet); + switch ((WindowsMessage)msg) { - case WindowsMessage.WM_ACTIVATE: - { - if (!_isClientAreaExtended) - { - if (GetStyle().HasFlag(WindowStyles.WS_THICKFRAME)) - { - AdjustWindowRectEx(ref border_thickness, (uint)(GetStyle()), false, 0); - border_thickness.left *= -1; - border_thickness.top *= -1; - } - else if (GetStyle().HasFlag(WindowStyles.WS_BORDER)) - { - border_thickness = new RECT { bottom = 1, left = 1, right = 1, top = 1 }; - } - - // Extend the frame into the client area. - margins.cxLeftWidth = border_thickness.left; - margins.cxRightWidth = border_thickness.right; - margins.cyBottomHeight = border_thickness.bottom; - margins.cyTopHeight = border_thickness.top; - - var hr = DwmExtendFrameIntoClientArea(hWnd, ref margins); - - //if (hr < 0) - { - // Handle the error. - } - - _isClientAreaExtended = true; - _extendedMargins = new Thickness(margins.cxLeftWidth / Scaling, margins.cyTopHeight / Scaling, margins.cxRightWidth / Scaling, margins.cyBottomHeight / Scaling); - ExtendClientAreaToDecorationsChanged?.Invoke(true); - - } - lRet = IntPtr.Zero; - callDwp = true; - break; - } + //case WindowsMessage.WM_ACTIVATE: + // { + // if (!_isClientAreaExtended) + // { + // ExtendClientArea(); + // } + // lRet = IntPtr.Zero; + // callDwp = true; + // break; + // } case WindowsMessage.WM_NCCALCSIZE: { diff --git a/src/Windows/Avalonia.Win32/WindowImpl.cs b/src/Windows/Avalonia.Win32/WindowImpl.cs index 6024dc01da..6cacd0b6cc 100644 --- a/src/Windows/Avalonia.Win32/WindowImpl.cs +++ b/src/Windows/Avalonia.Win32/WindowImpl.cs @@ -40,6 +40,7 @@ namespace Avalonia.Win32 private SavedWindowInfo _savedWindowInfo; private bool _isFullScreenActive; + private bool _isClientAreaExtended; #if USE_MANAGED_DRAG private readonly ManagedWindowResizeDragHelper _managedDrag; @@ -68,6 +69,7 @@ namespace Avalonia.Win32 private Size _maxSize; private POINT _maxTrackSize; private WindowImpl _parent; + private bool _extendClientAreaToDecorationsHint; public WindowImpl() { @@ -664,6 +666,43 @@ namespace Avalonia.Win32 TaskBarList.MarkFullscreen(_hwnd, fullscreen); } + private void ExtendClientArea () + { + if (!_isClientAreaExtended) + { + RECT border_thickness = new RECT(); + MARGINS margins = new MARGINS(); + + if (GetStyle().HasFlag(WindowStyles.WS_THICKFRAME)) + { + AdjustWindowRectEx(ref border_thickness, (uint)(GetStyle()), false, 0); + border_thickness.left *= -1; + border_thickness.top *= -1; + } + else if (GetStyle().HasFlag(WindowStyles.WS_BORDER)) + { + border_thickness = new RECT { bottom = 1, left = 1, right = 1, top = 1 }; + } + + // Extend the frame into the client area. + margins.cxLeftWidth = border_thickness.left; + margins.cxRightWidth = border_thickness.right; + margins.cyBottomHeight = border_thickness.bottom; + margins.cyTopHeight = border_thickness.top; + + var hr = DwmExtendFrameIntoClientArea(_hwnd, ref margins); + + //if (hr < 0) + { + // Handle the error. + } + + _isClientAreaExtended = true; + _extendedMargins = new Thickness(margins.cxLeftWidth / Scaling, margins.cyTopHeight / Scaling, margins.cxRightWidth / Scaling, margins.cyBottomHeight / Scaling); + ExtendClientAreaToDecorationsChanged?.Invoke(true); + } + } + private void ShowWindow(WindowState state) { ShowWindowCommand command; @@ -904,7 +943,25 @@ namespace Avalonia.Win32 } } - IntPtr EglGlPlatformSurface.IEglWindowGlPlatformSurfaceInfo.Handle => Handle.Handle; + IntPtr EglGlPlatformSurface.IEglWindowGlPlatformSurfaceInfo.Handle => Handle.Handle; + + public bool ExtendClientAreaToDecorationsHint + { + get => _extendClientAreaToDecorationsHint; + set + { + _extendClientAreaToDecorationsHint = true; + + ExtendClientArea(); + // TODO Trigger transition. + } + } + + public Action ExtendClientAreaToDecorationsChanged { get; set; } + + private Thickness _extendedMargins; + + public Thickness ExtendedMargins => _extendedMargins; private struct SavedWindowInfo {