From fdb32b7fde67a153134802e2fdb9dfe3ff09f019 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Sat, 19 Nov 2022 14:47:02 +0000 Subject: [PATCH] Merge pull request #9469 from AvaloniaUI/fixes/window-border-for-opaque-windows [OSX] Use non-opaque window background for non-transparent windows # Conflicts: # src/Avalonia.Native/avn.idl --- native/Avalonia.Native/src/OSX/AvnWindow.mm | 2 -- native/Avalonia.Native/src/OSX/WindowBaseImpl.h | 2 +- native/Avalonia.Native/src/OSX/WindowBaseImpl.mm | 5 +++-- src/Avalonia.Native/WindowImplBase.cs | 16 +++++++--------- src/Avalonia.Native/avn.idl | 2 +- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/native/Avalonia.Native/src/OSX/AvnWindow.mm b/native/Avalonia.Native/src/OSX/AvnWindow.mm index 054b5333db..bcb15eca18 100644 --- a/native/Avalonia.Native/src/OSX/AvnWindow.mm +++ b/native/Avalonia.Native/src/OSX/AvnWindow.mm @@ -170,9 +170,7 @@ _closed = false; _isEnabled = true; - [self backingScaleFactor]; [self setOpaque:NO]; - [self setBackgroundColor: [NSColor clearColor]]; _isExtended = false; _isTransitioningToFullScreen = false; diff --git a/native/Avalonia.Native/src/OSX/WindowBaseImpl.h b/native/Avalonia.Native/src/OSX/WindowBaseImpl.h index 2baf3b09b5..7fb002e54f 100644 --- a/native/Avalonia.Native/src/OSX/WindowBaseImpl.h +++ b/native/Avalonia.Native/src/OSX/WindowBaseImpl.h @@ -90,7 +90,7 @@ BEGIN_INTERFACE_MAP() virtual HRESULT CreateNativeControlHost(IAvnNativeControlHost **retOut) override; - virtual HRESULT SetBlurEnabled(bool enable) override; + virtual HRESULT SetTransparencyMode(AvnWindowTransparencyMode mode) override; virtual HRESULT BeginDragAndDropOperation(AvnDragDropEffects effects, AvnPoint point, IAvnClipboard *clipboard, IAvnDndResultCallback *cb, diff --git a/native/Avalonia.Native/src/OSX/WindowBaseImpl.mm b/native/Avalonia.Native/src/OSX/WindowBaseImpl.mm index 7ce8a3b4b5..dcec8bafc9 100644 --- a/native/Avalonia.Native/src/OSX/WindowBaseImpl.mm +++ b/native/Avalonia.Native/src/OSX/WindowBaseImpl.mm @@ -488,10 +488,11 @@ HRESULT WindowBaseImpl::CreateNativeControlHost(IAvnNativeControlHost **retOut) return S_OK; } -HRESULT WindowBaseImpl::SetBlurEnabled(bool enable) { +HRESULT WindowBaseImpl::SetTransparencyMode(AvnWindowTransparencyMode mode) { START_COM_CALL; - [StandardContainer ShowBlur:enable]; + [Window setBackgroundColor: (mode != Transparent ? [NSColor windowBackgroundColor] : [NSColor clearColor])]; + [StandardContainer ShowBlur: mode == Blur]; return S_OK; } diff --git a/src/Avalonia.Native/WindowImplBase.cs b/src/Avalonia.Native/WindowImplBase.cs index 700f1f2c20..fe7d15cf32 100644 --- a/src/Avalonia.Native/WindowImplBase.cs +++ b/src/Avalonia.Native/WindowImplBase.cs @@ -474,19 +474,17 @@ namespace Avalonia.Native { if (TransparencyLevel != transparencyLevel) { - if (transparencyLevel >= WindowTransparencyLevel.Blur) - { + if (transparencyLevel > WindowTransparencyLevel.Transparent) transparencyLevel = WindowTransparencyLevel.AcrylicBlur; - } - - if(transparencyLevel == WindowTransparencyLevel.None) - { - transparencyLevel = WindowTransparencyLevel.Transparent; - } TransparencyLevel = transparencyLevel; - _native?.SetBlurEnabled((TransparencyLevel >= WindowTransparencyLevel.Blur).AsComBool()); + _native.SetTransparencyMode(transparencyLevel == WindowTransparencyLevel.None + ? AvnWindowTransparencyMode.Opaque + : transparencyLevel == WindowTransparencyLevel.Transparent + ? AvnWindowTransparencyMode.Transparent + : AvnWindowTransparencyMode.Blur); + TransparencyLevelChanged?.Invoke(TransparencyLevel); } } diff --git a/src/Avalonia.Native/avn.idl b/src/Avalonia.Native/avn.idl index e02b244db6..8f884fc162 100644 --- a/src/Avalonia.Native/avn.idl +++ b/src/Avalonia.Native/avn.idl @@ -471,7 +471,7 @@ interface IAvnWindowBase : IUnknown HRESULT CreateNativeControlHost(IAvnNativeControlHost** retOut); HRESULT BeginDragAndDropOperation(AvnDragDropEffects effects, AvnPoint point, IAvnClipboard* clipboard, IAvnDndResultCallback* cb, [intptr]void* sourceHandle); - HRESULT SetBlurEnabled(bool enable); + HRESULT SetTransparencyMode(AvnWindowTransparencyMode mode); } [uuid(83e588f3-6981-4e48-9ea0-e1e569f79a91), cpp-virtual-inherits]