Skip to content

Commit

Permalink
Merge pull request AvaloniaUI#9469 from AvaloniaUI/fixes/window-borde…
Browse files Browse the repository at this point in the history
…r-for-opaque-windows

[OSX] Use non-opaque window background for non-transparent windows
# Conflicts:
#	src/Avalonia.Native/avn.idl
  • Loading branch information
Dan Walmsley authored and danwalmsley committed Dec 6, 2022
1 parent 1dacc90 commit fdb32b7
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 15 deletions.
2 changes: 0 additions & 2 deletions native/Avalonia.Native/src/OSX/AvnWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,7 @@ -(CLASS_NAME*_Nonnull) initWithParent: (WindowBaseImpl*_Nonnull) parent content
_closed = false;
_isEnabled = true;

[self backingScaleFactor];
[self setOpaque:NO];
[self setBackgroundColor: [NSColor clearColor]];

_isExtended = false;
_isTransitioningToFullScreen = false;
Expand Down
2 changes: 1 addition & 1 deletion native/Avalonia.Native/src/OSX/WindowBaseImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions native/Avalonia.Native/src/OSX/WindowBaseImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -488,10 +488,11 @@
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;
}
Expand Down
16 changes: 7 additions & 9 deletions src/Avalonia.Native/WindowImplBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -474,19 +474,17 @@ public void SetTransparencyLevelHint(WindowTransparencyLevel transparencyLevel)
{
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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Avalonia.Native/avn.idl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit fdb32b7

Please sign in to comment.