Browse Source

Reverted code formatting

pull/6574/head
Adir 5 years ago
parent
commit
c03ff60b2d
  1. 4
      src/Windows/Avalonia.Win32/WinRT/Composition/WinUICompositedWindow.cs
  2. 47
      src/Windows/Avalonia.Win32/WinRT/Composition/WinUICompositorConnection.cs
  3. 135
      src/Windows/Avalonia.Win32/WindowImpl.cs

4
src/Windows/Avalonia.Win32/WinRT/Composition/WinUICompositedWindow.cs

@ -63,7 +63,7 @@ namespace Avalonia.Win32.WinRT.Composition
{ {
if (!_syncContext.IsCurrent) if (!_syncContext.IsCurrent)
throw new InvalidOperationException(); throw new InvalidOperationException();
var iid = IID_ID3D11Texture2D; var iid = IID_ID3D11Texture2D;
void* pTexture; void* pTexture;
var off = _surfaceInterop.BeginDraw(null, &iid, &pTexture); var off = _surfaceInterop.BeginDraw(null, &iid, &pTexture);
@ -92,7 +92,7 @@ namespace Avalonia.Win32.WinRT.Composition
Monitor.Enter(_pumpLock); Monitor.Enter(_pumpLock);
return Disposable.Create(() => Monitor.Exit(_pumpLock)); return Disposable.Create(() => Monitor.Exit(_pumpLock));
} }
public void Dispose() public void Dispose()
{ {
if (_syncContext == null) if (_syncContext == null)

47
src/Windows/Avalonia.Win32/WinRT/Composition/WinUICompositorConnection.cs

@ -44,7 +44,7 @@ namespace Avalonia.Win32.WinRT.Composition
_compositorInterop = _compositor.QueryInterface<ICompositorInterop>(); _compositorInterop = _compositor.QueryInterface<ICompositorInterop>();
_compositorDesktopInterop = _compositor.QueryInterface<ICompositorDesktopInterop>(); _compositorDesktopInterop = _compositor.QueryInterface<ICompositorDesktopInterop>();
using var device = MicroComRuntime.CreateProxyFor<IUnknown>(_angle.GetDirect3DDevice(), true); using var device = MicroComRuntime.CreateProxyFor<IUnknown>(_angle.GetDirect3DDevice(), true);
_device = _compositorInterop.CreateGraphicsDevice(device); _device = _compositorInterop.CreateGraphicsDevice(device);
_blurBrush = CreateAcrylicBlurBackdropBrush(); _blurBrush = CreateAcrylicBlurBackdropBrush();
_micaBrush = CreateMicaBackdropBrush(); _micaBrush = CreateMicaBackdropBrush();
@ -71,15 +71,18 @@ namespace Avalonia.Win32.WinRT.Composition
AvaloniaLocator.CurrentMutable.BindToSelf(connect); AvaloniaLocator.CurrentMutable.BindToSelf(connect);
AvaloniaLocator.CurrentMutable.Bind<IRenderTimer>().ToConstant(connect); AvaloniaLocator.CurrentMutable.Bind<IRenderTimer>().ToConstant(connect);
tcs.SetResult(true); tcs.SetResult(true);
} }
catch (Exception e) catch (Exception e)
{ {
tcs.SetException(e); tcs.SetException(e);
return; return;
} }
connect.RunLoop(); connect.RunLoop();
}) { IsBackground = true }; })
{
IsBackground = true
};
th.SetApartmentState(ApartmentState.STA); th.SetApartmentState(ApartmentState.STA);
th.Start(); th.Start();
return tcs.Task.Result; return tcs.Task.Result;
@ -94,9 +97,9 @@ namespace Avalonia.Win32.WinRT.Composition
{ {
_parent = parent; _parent = parent;
} }
public void Dispose() public void Dispose()
{ {
} }
public void Invoke(IAsyncAction asyncInfo, AsyncStatus asyncStatus) public void Invoke(IAsyncAction asyncInfo, AsyncStatus asyncStatus)
@ -107,7 +110,6 @@ namespace Avalonia.Win32.WinRT.Composition
} }
public MicroComShadow Shadow { get; set; } public MicroComShadow Shadow { get; set; }
public void OnReferencedFromNative() public void OnReferencedFromNative()
{ {
} }
@ -116,12 +118,12 @@ namespace Avalonia.Win32.WinRT.Composition
{ {
} }
} }
private void RunLoop() private void RunLoop()
{ {
{ {
var st = Stopwatch.StartNew(); var st = Stopwatch.StartNew();
using (var act = _compositor5.RequestCommitAsync()) using (var act = _compositor5.RequestCommitAsync())
act.SetCompleted(new RunLoopHandler(this)); act.SetCompleted(new RunLoopHandler(this));
while (true) while (true)
{ {
@ -152,6 +154,7 @@ namespace Avalonia.Win32.WinRT.Composition
{ {
Logger.TryGet(LogEventLevel.Error, "WinUIComposition") Logger.TryGet(LogEventLevel.Error, "WinUIComposition")
?.Log(null, "Unable to initialize WinUI compositor: {0}", e); ?.Log(null, "Unable to initialize WinUI compositor: {0}", e);
} }
} }
@ -168,19 +171,17 @@ namespace Avalonia.Win32.WinRT.Composition
using var sc = _syncContext.EnsureLocked(); using var sc = _syncContext.EnsureLocked();
using var desktopTarget = _compositorDesktopInterop.CreateDesktopWindowTarget(hWnd, 0); using var desktopTarget = _compositorDesktopInterop.CreateDesktopWindowTarget(hWnd, 0);
using var target = desktopTarget.QueryInterface<ICompositionTarget>(); using var target = desktopTarget.QueryInterface<ICompositionTarget>();
using var drawingSurface = _device.CreateDrawingSurface(new UnmanagedMethods.SIZE(), using var drawingSurface = _device.CreateDrawingSurface(new UnmanagedMethods.SIZE(), DirectXPixelFormat.B8G8R8A8UIntNormalized,
DirectXPixelFormat.B8G8R8A8UIntNormalized,
DirectXAlphaMode.Premultiplied); DirectXAlphaMode.Premultiplied);
using var surface = drawingSurface.QueryInterface<ICompositionSurface>(); using var surface = drawingSurface.QueryInterface<ICompositionSurface>();
using var surfaceInterop = drawingSurface.QueryInterface<ICompositionDrawingSurfaceInterop>(); using var surfaceInterop = drawingSurface.QueryInterface<ICompositionDrawingSurfaceInterop>();
using var surfaceBrush = _compositor.CreateSurfaceBrushWithSurface(surface); using var surfaceBrush = _compositor.CreateSurfaceBrushWithSurface(surface);
using var brush = surfaceBrush.QueryInterface<ICompositionBrush>(); using var brush = surfaceBrush.QueryInterface<ICompositionBrush>();
using var spriteVisual = _compositor.CreateSpriteVisual(); using var spriteVisual = _compositor.CreateSpriteVisual();
spriteVisual.SetBrush(brush); spriteVisual.SetBrush(brush);
using var visual = spriteVisual.QueryInterface<IVisual>(); using var visual = spriteVisual.QueryInterface<IVisual>();
using var visual2 = spriteVisual.QueryInterface<IVisual2>(); using var visual2 = spriteVisual.QueryInterface<IVisual2>();
using var container = _compositor.CreateContainerVisual(); using var container = _compositor.CreateContainerVisual();
@ -188,7 +189,7 @@ namespace Avalonia.Win32.WinRT.Composition
using var containerVisual2 = container.QueryInterface<IVisual2>(); using var containerVisual2 = container.QueryInterface<IVisual2>();
containerVisual2.SetRelativeSizeAdjustment(new Vector2(1, 1)); containerVisual2.SetRelativeSizeAdjustment(new Vector2(1, 1));
using var containerChildren = container.Children; using var containerChildren = container.Children;
target.SetRoot(containerVisual); target.SetRoot(containerVisual);
using var blur = CreateBlurVisual(_blurBrush); using var blur = CreateBlurVisual(_blurBrush);
@ -200,10 +201,10 @@ namespace Avalonia.Win32.WinRT.Composition
} }
var compositionRoundedRectangleGeometry = ClipVisual(blur, mica); var compositionRoundedRectangleGeometry = ClipVisual(blur, mica);
containerChildren.InsertAtTop(blur); containerChildren.InsertAtTop(blur);
containerChildren.InsertAtTop(visual); containerChildren.InsertAtTop(visual);
return new WinUICompositedWindow(_syncContext, _compositor, _pumpLock, target, surfaceInterop, visual, return new WinUICompositedWindow(_syncContext, _compositor, _pumpLock, target, surfaceInterop, visual,
blur, mica, compositionRoundedRectangleGeometry); blur, mica, compositionRoundedRectangleGeometry);
} }
@ -223,9 +224,8 @@ namespace Avalonia.Win32.WinRT.Composition
private unsafe ICompositionBrush CreateAcrylicBlurBackdropBrush() private unsafe ICompositionBrush CreateAcrylicBlurBackdropBrush()
{ {
using var backDropParameterFactory = using var backDropParameterFactory = NativeWinRTMethods.CreateActivationFactory<ICompositionEffectSourceParameterFactory>(
NativeWinRTMethods.CreateActivationFactory<ICompositionEffectSourceParameterFactory>( "Windows.UI.Composition.CompositionEffectSourceParameter");
"Windows.UI.Composition.CompositionEffectSourceParameter");
using var backdropString = new HStringInterop("backdrop"); using var backdropString = new HStringInterop("backdrop");
using var backDropParameter = using var backDropParameter =
backDropParameterFactory.Create(backdropString.Handle); backDropParameterFactory.Create(backdropString.Handle);
@ -235,7 +235,8 @@ namespace Avalonia.Win32.WinRT.Composition
using var compositionEffectBrush = blurEffectFactory.CreateBrush(); using var compositionEffectBrush = blurEffectFactory.CreateBrush();
using var backdrop = _compositor2.CreateBackdropBrush(); using var backdrop = _compositor2.CreateBackdropBrush();
using var backdropBrush = backdrop.QueryInterface<ICompositionBrush>(); using var backdropBrush = backdrop.QueryInterface<ICompositionBrush>();
var saturateEffect = new SaturationEffect(blurEffect); var saturateEffect = new SaturationEffect(blurEffect);
using var satEffectFactory = _compositor.CreateEffectFactory(saturateEffect); using var satEffectFactory = _compositor.CreateEffectFactory(saturateEffect);
using var sat = satEffectFactory.CreateBrush(); using var sat = satEffectFactory.CreateBrush();
@ -259,8 +260,8 @@ namespace Avalonia.Win32.WinRT.Composition
foreach (var visual in containerVisuals) foreach (var visual in containerVisuals)
{ {
visual?.SetClip(geometricClipWithGeometry.QueryInterface<ICompositionClip>()); visual?.SetClip(geometricClipWithGeometry.QueryInterface<ICompositionClip>());
} }
return roundedRectangleGeometry.CloneReference(); return roundedRectangleGeometry.CloneReference();
} }
@ -269,8 +270,8 @@ namespace Avalonia.Win32.WinRT.Composition
using var spriteVisual = _compositor.CreateSpriteVisual(); using var spriteVisual = _compositor.CreateSpriteVisual();
using var visual = spriteVisual.QueryInterface<IVisual>(); using var visual = spriteVisual.QueryInterface<IVisual>();
using var visual2 = spriteVisual.QueryInterface<IVisual2>(); using var visual2 = spriteVisual.QueryInterface<IVisual2>();
spriteVisual.SetBrush(compositionBrush); spriteVisual.SetBrush(compositionBrush);
visual.SetIsVisible(0); visual.SetIsVisible(0);
visual2.SetRelativeSizeAdjustment(new Vector2(1.0f, 1.0f)); visual2.SetRelativeSizeAdjustment(new Vector2(1.0f, 1.0f));

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

@ -82,7 +82,7 @@ namespace Avalonia.Win32
private Size _minSize; private Size _minSize;
private Size _maxSize; private Size _maxSize;
private POINT _maxTrackSize; private POINT _maxTrackSize;
private WindowImpl _parent; private WindowImpl _parent;
private ExtendClientAreaChromeHints _extendChromeHints = ExtendClientAreaChromeHints.Default; private ExtendClientAreaChromeHints _extendChromeHints = ExtendClientAreaChromeHints.Default;
private bool _isCloseRequested; private bool _isCloseRequested;
private bool _shown; private bool _shown;
@ -105,7 +105,9 @@ namespace Avalonia.Win32
_windowProperties = new WindowProperties _windowProperties = new WindowProperties
{ {
ShowInTaskbar = false, IsResizable = true, Decorations = SystemDecorations.Full ShowInTaskbar = false,
IsResizable = true,
Decorations = SystemDecorations.Full
}; };
_rendererLock = new ManagedDeferredRendererLock(); _rendererLock = new ManagedDeferredRendererLock();
@ -114,13 +116,13 @@ namespace Avalonia.Win32
var compositionConnector = AvaloniaLocator.Current.GetService<WinUICompositorConnection>(); var compositionConnector = AvaloniaLocator.Current.GetService<WinUICompositorConnection>();
_isUsingComposition = compositionConnector is { } && _isUsingComposition = compositionConnector is { } &&
glPlatform is EglPlatformOpenGlInterface egl && glPlatform is EglPlatformOpenGlInterface egl &&
egl.Display is AngleWin32EglDisplay angleDisplay && egl.Display is AngleWin32EglDisplay angleDisplay &&
angleDisplay.PlatformApi == AngleOptions.PlatformApi.DirectX11; angleDisplay.PlatformApi == AngleOptions.PlatformApi.DirectX11;
CreateWindow(); CreateWindow();
_framebuffer = new FramebufferManager(_hwnd); _framebuffer = new FramebufferManager(_hwnd);
if (glPlatform != null) if (glPlatform != null)
{ {
if (_isUsingComposition) if (_isUsingComposition)
@ -166,7 +168,7 @@ namespace Avalonia.Win32
public Action<PixelPoint> PositionChanged { get; set; } public Action<PixelPoint> PositionChanged { get; set; }
public Action<WindowState> WindowStateChanged { get; set; } public Action<WindowState> WindowStateChanged { get; set; }
public Action LostFocus { get; set; } public Action LostFocus { get; set; }
public Action<WindowTransparencyLevel> TransparencyLevelChanged { get; set; } public Action<WindowTransparencyLevel> TransparencyLevelChanged { get; set; }
@ -222,8 +224,7 @@ namespace Avalonia.Win32
return new Size(rcWindow.Width, rcWindow.Height) / RenderScaling; return new Size(rcWindow.Width, rcWindow.Height) / RenderScaling;
} }
DwmGetWindowAttribute(_hwnd, (int)DwmWindowAttribute.DWMWA_EXTENDED_FRAME_BOUNDS, out var rect, DwmGetWindowAttribute(_hwnd, (int)DwmWindowAttribute.DWMWA_EXTENDED_FRAME_BOUNDS, out var rect, Marshal.SizeOf(typeof(RECT)));
Marshal.SizeOf(typeof(RECT)));
return new Size(rect.Width, rect.Height) / RenderScaling; return new Size(rect.Width, rect.Height) / RenderScaling;
} }
} }
@ -232,8 +233,7 @@ namespace Avalonia.Win32
public IPlatformHandle Handle { get; private set; } public IPlatformHandle Handle { get; private set; }
public virtual Size MaxAutoSizeHint => public virtual Size MaxAutoSizeHint => new Size(_maxTrackSize.X / RenderScaling, _maxTrackSize.Y / RenderScaling);
new Size(_maxTrackSize.X / RenderScaling, _maxTrackSize.Y / RenderScaling);
public IMouseDevice MouseDevice => _mouseDevice; public IMouseDevice MouseDevice => _mouseDevice;
@ -241,7 +241,7 @@ namespace Avalonia.Win32
{ {
get get
{ {
if (_isFullScreenActive) if(_isFullScreenActive)
{ {
return WindowState.FullScreen; return WindowState.FullScreen;
} }
@ -264,7 +264,7 @@ namespace Avalonia.Win32
ShowWindow(value, true); ShowWindow(value, true);
} }
_showWindowState = value; _showWindowState = value;
} }
} }
@ -272,7 +272,7 @@ namespace Avalonia.Win32
protected IntPtr Hwnd => _hwnd; protected IntPtr Hwnd => _hwnd;
public void SetTransparencyLevelHint(WindowTransparencyLevel transparencyLevel) public void SetTransparencyLevelHint (WindowTransparencyLevel transparencyLevel)
{ {
TransparencyLevel = EnableBlur(transparencyLevel); TransparencyLevel = EnableBlur(transparencyLevel);
} }
@ -312,12 +312,12 @@ namespace Avalonia.Win32
} }
var blurInfo = new DWM_BLURBEHIND(false); var blurInfo = new DWM_BLURBEHIND(false);
if (transparencyLevel == WindowTransparencyLevel.Blur) if (transparencyLevel == WindowTransparencyLevel.Blur)
{ {
blurInfo = new DWM_BLURBEHIND(true); blurInfo = new DWM_BLURBEHIND(true);
} }
DwmEnableBlurBehindWindow(_hwnd, ref blurInfo); DwmEnableBlurBehindWindow(_hwnd, ref blurInfo);
if (transparencyLevel == WindowTransparencyLevel.Transparent) if (transparencyLevel == WindowTransparencyLevel.Transparent)
@ -385,8 +385,7 @@ namespace Avalonia.Win32
} }
else else
{ {
bool canUseAcrylic = Win32Platform.WindowsVersion.Major > 10 || bool canUseAcrylic = Win32Platform.WindowsVersion.Major > 10 || Win32Platform.WindowsVersion.Build >= 19628;
Win32Platform.WindowsVersion.Build >= 19628;
var accent = new AccentPolicy(); var accent = new AccentPolicy();
var accentStructSize = Marshal.SizeOf(accent); var accentStructSize = Marshal.SizeOf(accent);
@ -537,7 +536,7 @@ namespace Avalonia.Win32
{ {
BeforeCloseCleanup(true); BeforeCloseCleanup(true);
} }
DestroyWindow(_hwnd); DestroyWindow(_hwnd);
_hwnd = IntPtr.Zero; _hwnd = IntPtr.Zero;
} }
@ -603,7 +602,7 @@ namespace Avalonia.Win32
public void SetParent(IWindowImpl parent) public void SetParent(IWindowImpl parent)
{ {
_parent = (WindowImpl)parent; _parent = (WindowImpl)parent;
var parentHwnd = _parent?._hwnd ?? IntPtr.Zero; var parentHwnd = _parent?._hwnd ?? IntPtr.Zero;
if (parentHwnd == IntPtr.Zero && !_windowProperties.ShowInTaskbar) if (parentHwnd == IntPtr.Zero && !_windowProperties.ShowInTaskbar)
@ -714,7 +713,7 @@ namespace Avalonia.Win32
_isUsingComposition ? (int)WindowStyles.WS_EX_NOREDIRECTIONBITMAP : 0, _isUsingComposition ? (int)WindowStyles.WS_EX_NOREDIRECTIONBITMAP : 0,
atom, atom,
null, null,
(int)WindowStyles.WS_OVERLAPPEDWINDOW | (int)WindowStyles.WS_CLIPCHILDREN, (int)WindowStyles.WS_OVERLAPPEDWINDOW | (int) WindowStyles.WS_CLIPCHILDREN,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
@ -770,7 +769,7 @@ namespace Avalonia.Win32
} }
if (ShCoreAvailable && Win32Platform.WindowsVersion > PlatformConstants.Windows8) if (ShCoreAvailable && Win32Platform.WindowsVersion > PlatformConstants.Windows8)
{ {
var monitor = MonitorFromWindow( var monitor = MonitorFromWindow(
_hwnd, _hwnd,
MONITOR.MONITOR_DEFAULTTONEAREST); MONITOR.MONITOR_DEFAULTTONEAREST);
@ -816,9 +815,7 @@ namespace Avalonia.Win32
// Set new window style and size. // Set new window style and size.
SetStyle(current & ~(WindowStyles.WS_CAPTION | WindowStyles.WS_THICKFRAME), false); SetStyle(current & ~(WindowStyles.WS_CAPTION | WindowStyles.WS_THICKFRAME), false);
SetExtendedStyle( SetExtendedStyle(currentEx & ~(WindowStyles.WS_EX_DLGMODALFRAME | WindowStyles.WS_EX_WINDOWEDGE | WindowStyles.WS_EX_CLIENTEDGE | WindowStyles.WS_EX_STATICEDGE), false);
currentEx & ~(WindowStyles.WS_EX_DLGMODALFRAME | WindowStyles.WS_EX_WINDOWEDGE |
WindowStyles.WS_EX_CLIENTEDGE | WindowStyles.WS_EX_STATICEDGE), false);
// On expand, if we're given a window_rect, grow to it, otherwise do // On expand, if we're given a window_rect, grow to it, otherwise do
// not resize. // not resize.
@ -828,9 +825,8 @@ namespace Avalonia.Win32
var window_rect = monitor_info.rcMonitor.ToPixelRect(); var window_rect = monitor_info.rcMonitor.ToPixelRect();
SetWindowPos(_hwnd, IntPtr.Zero, window_rect.X, window_rect.Y, SetWindowPos(_hwnd, IntPtr.Zero, window_rect.X, window_rect.Y,
window_rect.Width, window_rect.Height, window_rect.Width, window_rect.Height,
SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_NOACTIVATE | SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_NOACTIVATE | SetWindowPosFlags.SWP_FRAMECHANGED);
SetWindowPosFlags.SWP_FRAMECHANGED);
_isFullScreenActive = true; _isFullScreenActive = true;
} }
@ -849,22 +845,21 @@ namespace Avalonia.Win32
var new_rect = _savedWindowInfo.WindowRect.ToPixelRect(); var new_rect = _savedWindowInfo.WindowRect.ToPixelRect();
SetWindowPos(_hwnd, IntPtr.Zero, new_rect.X, new_rect.Y, new_rect.Width, SetWindowPos(_hwnd, IntPtr.Zero, new_rect.X, new_rect.Y, new_rect.Width,
new_rect.Height, new_rect.Height,
SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_NOACTIVATE | SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_NOACTIVATE | SetWindowPosFlags.SWP_FRAMECHANGED);
SetWindowPosFlags.SWP_FRAMECHANGED);
UpdateWindowProperties(_windowProperties, true); UpdateWindowProperties(_windowProperties, true);
} }
TaskBarList.MarkFullscreen(_hwnd, fullscreen); TaskBarList.MarkFullscreen(_hwnd, fullscreen);
ExtendClientArea(); ExtendClientArea();
} }
private MARGINS UpdateExtendMargins() private MARGINS UpdateExtendMargins()
{ {
RECT borderThickness = new RECT(); RECT borderThickness = new RECT();
RECT borderCaptionThickness = new RECT(); RECT borderCaptionThickness = new RECT();
AdjustWindowRectEx(ref borderCaptionThickness, (uint)(GetStyle()), false, 0); AdjustWindowRectEx(ref borderCaptionThickness, (uint)(GetStyle()), false, 0);
AdjustWindowRectEx(ref borderThickness, (uint)(GetStyle() & ~WindowStyles.WS_CAPTION), false, 0); AdjustWindowRectEx(ref borderThickness, (uint)(GetStyle() & ~WindowStyles.WS_CAPTION), false, 0);
@ -873,8 +868,7 @@ namespace Avalonia.Win32
borderCaptionThickness.left *= -1; borderCaptionThickness.left *= -1;
borderCaptionThickness.top *= -1; borderCaptionThickness.top *= -1;
bool wantsTitleBar = _extendChromeHints.HasAllFlags(ExtendClientAreaChromeHints.SystemChrome) || bool wantsTitleBar = _extendChromeHints.HasAllFlags(ExtendClientAreaChromeHints.SystemChrome) || _extendTitleBarHint == -1;
_extendTitleBarHint == -1;
if (!wantsTitleBar) if (!wantsTitleBar)
{ {
@ -888,22 +882,15 @@ namespace Avalonia.Win32
if (_extendTitleBarHint != -1) if (_extendTitleBarHint != -1)
{ {
borderCaptionThickness.top = (int)(_extendTitleBarHint * RenderScaling); borderCaptionThickness.top = (int)(_extendTitleBarHint * RenderScaling);
} }
margins.cyTopHeight = margins.cyTopHeight = _extendChromeHints.HasAllFlags(ExtendClientAreaChromeHints.SystemChrome) && !_extendChromeHints.HasAllFlags(ExtendClientAreaChromeHints.PreferSystemChrome) ? borderCaptionThickness.top : 1;
_extendChromeHints.HasAllFlags(ExtendClientAreaChromeHints.SystemChrome) &&
!_extendChromeHints.HasAllFlags(ExtendClientAreaChromeHints.PreferSystemChrome) ?
borderCaptionThickness.top :
1;
if (WindowState == WindowState.Maximized) if (WindowState == WindowState.Maximized)
{ {
_extendedMargins = new Thickness(0, (borderCaptionThickness.top - borderThickness.top) / RenderScaling, _extendedMargins = new Thickness(0, (borderCaptionThickness.top - borderThickness.top) / RenderScaling, 0, 0);
0, 0); _offScreenMargin = new Thickness(borderThickness.left / RenderScaling, borderThickness.top / RenderScaling, borderThickness.right / RenderScaling, borderThickness.bottom / RenderScaling);
_offScreenMargin = new Thickness(borderThickness.left / RenderScaling,
borderThickness.top / RenderScaling, borderThickness.right / RenderScaling,
borderThickness.bottom / RenderScaling);
} }
else else
{ {
@ -920,13 +907,12 @@ namespace Avalonia.Win32
{ {
return; return;
} }
if (DwmIsCompositionEnabled(out bool compositionEnabled) < 0 || !compositionEnabled) if (DwmIsCompositionEnabled(out bool compositionEnabled) < 0 || !compositionEnabled)
{ {
_isClientAreaExtended = false; _isClientAreaExtended = false;
return; return;
} }
GetClientRect(_hwnd, out var rcClient); GetClientRect(_hwnd, out var rcClient);
GetWindowRect(_hwnd, out var rcWindow); GetWindowRect(_hwnd, out var rcWindow);
@ -949,14 +935,12 @@ namespace Avalonia.Win32
_offScreenMargin = new Thickness(); _offScreenMargin = new Thickness();
_extendedMargins = new Thickness(); _extendedMargins = new Thickness();
Resize(new Size(rcWindow.Width / RenderScaling, rcWindow.Height / RenderScaling), Resize(new Size(rcWindow.Width/ RenderScaling, rcWindow.Height / RenderScaling), PlatformResizeReason.Layout);
PlatformResizeReason.Layout);
} }
if (!_isClientAreaExtended || (_extendChromeHints.HasAllFlags(ExtendClientAreaChromeHints.SystemChrome) && if(!_isClientAreaExtended || (_extendChromeHints.HasAllFlags(ExtendClientAreaChromeHints.SystemChrome) &&
!_extendChromeHints.HasAllFlags(ExtendClientAreaChromeHints !_extendChromeHints.HasAllFlags(ExtendClientAreaChromeHints.PreferSystemChrome)))
.PreferSystemChrome)))
{ {
EnableCloseButton(_hwnd); EnableCloseButton(_hwnd);
} }
@ -971,12 +955,12 @@ namespace Avalonia.Win32
private void ShowWindow(WindowState state, bool activate) private void ShowWindow(WindowState state, bool activate)
{ {
_shown = true; _shown = true;
if (_isClientAreaExtended) if (_isClientAreaExtended)
{ {
ExtendClientArea(); ExtendClientArea();
} }
ShowWindowCommand? command; ShowWindowCommand? command;
var newWindowProperties = _windowProperties; var newWindowProperties = _windowProperties;
@ -994,7 +978,7 @@ namespace Avalonia.Win32
case WindowState.Normal: case WindowState.Normal:
newWindowProperties.IsFullScreen = false; newWindowProperties.IsFullScreen = false;
command = IsWindowVisible(_hwnd) ? ShowWindowCommand.Restore : command = IsWindowVisible(_hwnd) ? ShowWindowCommand.Restore :
activate ? ShowWindowCommand.Normal : ShowWindowCommand.ShowNoActivate; activate ? ShowWindowCommand.Normal : ShowWindowCommand.ShowNoActivate;
break; break;
@ -1024,7 +1008,7 @@ namespace Avalonia.Win32
SetFocus(_hwnd); SetFocus(_hwnd);
} }
} }
private void BeforeCloseCleanup(bool isDisposing) private void BeforeCloseCleanup(bool isDisposing)
{ {
// Based on https://github.com/dotnet/wpf/blob/master/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs#L4270-L4337 // Based on https://github.com/dotnet/wpf/blob/master/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs#L4270-L4337
@ -1042,7 +1026,7 @@ namespace Avalonia.Win32
// Our window closed callback will set enabled state to a correct value after child window gets destroyed. // Our window closed callback will set enabled state to a correct value after child window gets destroyed.
_parent.SetEnabled(true); _parent.SetEnabled(true);
} }
// We also need to activate our parent window since again OS might try to activate a window behind if it is not set. // We also need to activate our parent window since again OS might try to activate a window behind if it is not set.
if (wasActive) if (wasActive)
{ {
@ -1069,7 +1053,7 @@ namespace Avalonia.Win32
SetWindowPos(_hwnd, WindowPosZOrder.HWND_NOTOPMOST, x, y, cx, cy, SetWindowPosFlags.SWP_SHOWWINDOW); SetWindowPos(_hwnd, WindowPosZOrder.HWND_NOTOPMOST, x, y, cx, cy, SetWindowPosFlags.SWP_SHOWWINDOW);
} }
} }
} }
private WindowStyles GetWindowStateStyles() private WindowStyles GetWindowStateStyles()
{ {
@ -1222,7 +1206,10 @@ namespace Avalonia.Win32
var margins = new MARGINS var margins = new MARGINS
{ {
cyBottomHeight = margin, cxRightWidth = margin, cxLeftWidth = margin, cyTopHeight = margin cyBottomHeight = margin,
cxRightWidth = margin,
cxLeftWidth = margin,
cyTopHeight = margin
}; };
DwmExtendFrameIntoClientArea(_hwnd, ref margins); DwmExtendFrameIntoClientArea(_hwnd, ref margins);
@ -1243,7 +1230,7 @@ namespace Avalonia.Win32
SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_NOACTIVATE | SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_NOACTIVATE |
SetWindowPosFlags.SWP_FRAMECHANGED); SetWindowPosFlags.SWP_FRAMECHANGED);
} }
} }
} }
private const int MF_BYCOMMAND = 0x0; private const int MF_BYCOMMAND = 0x0;
@ -1257,13 +1244,12 @@ namespace Avalonia.Win32
void DisableCloseButton(IntPtr hwnd) void DisableCloseButton(IntPtr hwnd)
{ {
EnableMenuItem(GetSystemMenu(hwnd, false), SC_CLOSE, EnableMenuItem(GetSystemMenu(hwnd, false), SC_CLOSE,
MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
} }
void EnableCloseButton(IntPtr hwnd) void EnableCloseButton(IntPtr hwnd)
{ {
EnableMenuItem(GetSystemMenu(hwnd, false), SC_CLOSE, EnableMenuItem(GetSystemMenu(hwnd, false), SC_CLOSE,
MF_BYCOMMAND | MF_ENABLED); MF_BYCOMMAND | MF_ENABLED);
} }
#if USE_MANAGED_DRAG #if USE_MANAGED_DRAG
@ -1294,9 +1280,9 @@ namespace Avalonia.Win32
public void SetExtendClientAreaToDecorationsHint(bool hint) public void SetExtendClientAreaToDecorationsHint(bool hint)
{ {
_isClientAreaExtended = hint; _isClientAreaExtended = hint;
ExtendClientArea(); ExtendClientArea();
} }
public void SetExtendClientAreaChromeHints(ExtendClientAreaChromeHints hints) public void SetExtendClientAreaChromeHints(ExtendClientAreaChromeHints hints)
{ {
@ -1304,7 +1290,7 @@ namespace Avalonia.Win32
ExtendClientArea(); ExtendClientArea();
} }
/// <inheritdoc/> /// <inheritdoc/>
public void SetExtendClientAreaTitleBarHeightHint(double titleBarHeight) public void SetExtendClientAreaTitleBarHeightHint(double titleBarHeight)
{ {
@ -1318,11 +1304,9 @@ namespace Avalonia.Win32
/// <inheritdoc/> /// <inheritdoc/>
public Action<bool> ExtendClientAreaToDecorationsChanged { get; set; } public Action<bool> ExtendClientAreaToDecorationsChanged { get; set; }
/// <inheritdoc/> /// <inheritdoc/>
public bool NeedsManagedDecorations => _isClientAreaExtended && public bool NeedsManagedDecorations => _isClientAreaExtended && _extendChromeHints.HasAllFlags(ExtendClientAreaChromeHints.PreferSystemChrome);
_extendChromeHints.HasAllFlags(ExtendClientAreaChromeHints
.PreferSystemChrome);
/// <inheritdoc/> /// <inheritdoc/>
public Thickness ExtendedMargins => _extendedMargins; public Thickness ExtendedMargins => _extendedMargins;
@ -1331,8 +1315,7 @@ namespace Avalonia.Win32
public Thickness OffScreenMargin => _offScreenMargin; public Thickness OffScreenMargin => _offScreenMargin;
/// <inheritdoc/> /// <inheritdoc/>
public AcrylicPlatformCompensationLevels AcrylicCompensationLevels { get; } = public AcrylicPlatformCompensationLevels AcrylicCompensationLevels { get; } = new AcrylicPlatformCompensationLevels(1, 0.8, 0);
new AcrylicPlatformCompensationLevels(1, 0.8, 0);
private ResizeReasonScope SetResizeReason(PlatformResizeReason reason) private ResizeReasonScope SetResizeReason(PlatformResizeReason reason)
{ {
@ -1360,7 +1343,7 @@ namespace Avalonia.Win32
{ {
private readonly WindowImpl _owner; private readonly WindowImpl _owner;
private readonly PlatformResizeReason _restore; private readonly PlatformResizeReason _restore;
public ResizeReasonScope(WindowImpl owner, PlatformResizeReason restore) public ResizeReasonScope(WindowImpl owner, PlatformResizeReason restore)
{ {
_owner = owner; _owner = owner;

Loading…
Cancel
Save