Browse Source

Fix issue when WindowTransparencyLevel is set to AcrylicBlur (#22144)

1. Background fully white in inactive state
2. Unusable when dark theme and white content behind window
pull/22200/head
Lin 3 weeks ago
committed by GitHub
parent
commit
099c373195
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 11
      native/Avalonia.Native/src/OSX/AutoFitContentView.mm
  2. 28
      native/Avalonia.Native/src/OSX/WindowBaseImpl.mm
  3. 14
      native/Avalonia.Native/src/OSX/WindowImpl.h

11
native/Avalonia.Native/src/OSX/AutoFitContentView.mm

@ -43,9 +43,16 @@
_blurBehind = [NSVisualEffectView new]; _blurBehind = [NSVisualEffectView new];
[_blurBehind setBlendingMode:NSVisualEffectBlendingModeBehindWindow]; [_blurBehind setBlendingMode:NSVisualEffectBlendingModeBehindWindow];
[_blurBehind setMaterial:NSVisualEffectMaterialLight];
[_blurBehind setWantsLayer:true]; [_blurBehind setWantsLayer:true];
_blurBehind.hidden = true; _blurBehind.hidden = true;
if (@available(macOS 10.14, *))
{
[_blurBehind setMaterial:NSVisualEffectMaterialHUDWindow];
}
else
{
[_blurBehind setMaterial:NSVisualEffectMaterialSidebar];
}
[_blurBehind setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; [_blurBehind setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[_content setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; [_content setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
@ -103,4 +110,4 @@
_settingSize = false; _settingSize = false;
} }
@end @end

28
native/Avalonia.Native/src/OSX/WindowBaseImpl.mm

@ -56,11 +56,11 @@ WindowBaseImpl::WindowBaseImpl(IAvnWindowBaseEvents *events, bool usePanel) : To
lastMaxSize = NSSize { CGFLOAT_MAX, CGFLOAT_MAX}; lastMaxSize = NSSize { CGFLOAT_MAX, CGFLOAT_MAX};
lastMinSize = NSSize { 0, 0 }; lastMinSize = NSSize { 0, 0 };
lastMenu = nullptr; lastMenu = nullptr;
CreateNSWindow(usePanel); CreateNSWindow(usePanel);
StandardContainer = [[AutoFitContentView new] initWithContent:View]; StandardContainer = [[AutoFitContentView new] initWithContent:View];
[Window setContentView:StandardContainer]; [Window setContentView:StandardContainer];
[Window setBackingType:NSBackingStoreBuffered]; [Window setBackingType:NSBackingStoreBuffered];
[Window setContentMinSize:lastMinSize]; [Window setContentMinSize:lastMinSize];
@ -89,7 +89,7 @@ HRESULT WindowBaseImpl::Show(bool activate, bool isDialog) {
@autoreleasepool { @autoreleasepool {
[Window setContentSize:lastSize]; [Window setContentSize:lastSize];
if(hasPosition) if(hasPosition)
{ {
SetPosition(lastPositionSet); SetPosition(lastPositionSet);
@ -110,7 +110,7 @@ HRESULT WindowBaseImpl::Show(bool activate, bool isDialog) {
[Window setCollectionBehavior:collectionBehavior & ~NSWindowCollectionBehaviorFullScreenPrimary]; [Window setCollectionBehavior:collectionBehavior & ~NSWindowCollectionBehaviorFullScreenPrimary];
UpdateAppearance(); UpdateAppearance();
[Window invalidateShadow]; [Window invalidateShadow];
if (ShouldTakeFocusOnShow() && activate) { if (ShouldTakeFocusOnShow() && activate) {
@ -124,13 +124,13 @@ HRESULT WindowBaseImpl::Show(bool activate, bool isDialog) {
_shown = true; _shown = true;
[Window setCollectionBehavior:collectionBehavior]; [Window setCollectionBehavior:collectionBehavior];
// Ensure that we call needsDisplay = YES so that AvnView.updateLayer is called after the // Ensure that we call needsDisplay = YES so that AvnView.updateLayer is called after the
// window is shown: if the client is pumping messages during the window creation/show // window is shown: if the client is pumping messages during the window creation/show
// process, it's possible that updateLayer gets called after the window is created but // process, it's possible that updateLayer gets called after the window is created but
// before it's is shown. // before it's is shown.
[View.layer setNeedsDisplay]; [View.layer setNeedsDisplay];
return S_OK; return S_OK;
} }
} }
@ -161,7 +161,7 @@ HRESULT WindowBaseImpl::Hide() {
@autoreleasepool { @autoreleasepool {
if (Window != nullptr) { if (Window != nullptr) {
// If window is hidden without ending attached sheet first, it will stuck in "order out" state, // If window is hidden without ending attached sheet first, it will stuck in "order out" state,
// and block any new sheets from being attached. // and block any new sheets from being attached.
// Additionaly, we don't know if user would define any custom panels, so we only end/close file dialog sheets. // Additionaly, we don't know if user would define any custom panels, so we only end/close file dialog sheets.
@ -501,18 +501,18 @@ HRESULT WindowBaseImpl::SetParent(IAvnWindowBase *parent) {
START_COM_CALL; START_COM_CALL;
@autoreleasepool { @autoreleasepool {
auto oldParent = Parent.tryGet(); auto oldParent = Parent.tryGet();
if(oldParent != nullptr) if(oldParent != nullptr)
{ {
oldParent->_children.remove(this); oldParent->_children.remove(this);
} }
auto cparent = dynamic_cast<WindowImpl *>(parent); auto cparent = dynamic_cast<WindowImpl *>(parent);
Parent = cparent; Parent = cparent;
if(cparent != nullptr && Window != nullptr){ if(cparent != nullptr && Window != nullptr){
// If one tries to show a child window with a minimized parent window, then the parent window will be // If one tries to show a child window with a minimized parent window, then the parent window will be
// restored but macOS isn't kind enough to *tell* us that, so the window will be left in a non-interactive // restored but macOS isn't kind enough to *tell* us that, so the window will be left in a non-interactive
@ -521,9 +521,9 @@ HRESULT WindowBaseImpl::SetParent(IAvnWindowBase *parent) {
cparent->SetWindowState(Normal); cparent->SetWindowState(Normal);
[Window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenAuxiliary]; [Window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenAuxiliary];
cparent->_children.push_back(this); cparent->_children.push_back(this);
UpdateAppearance(); UpdateAppearance();
} }

14
native/Avalonia.Native/src/OSX/WindowImpl.h

@ -45,9 +45,9 @@ BEGIN_INTERFACE_MAP()
void DoZoom(); void DoZoom();
virtual HRESULT SetCanResize(bool value) override; virtual HRESULT SetCanResize(bool value) override;
virtual HRESULT SetCanMinimize(bool value) override; virtual HRESULT SetCanMinimize(bool value) override;
virtual HRESULT SetCanMaximize(bool value) override; virtual HRESULT SetCanMaximize(bool value) override;
virtual HRESULT SetDecorations(SystemDecorations value) override; virtual HRESULT SetDecorations(SystemDecorations value) override;
@ -65,7 +65,7 @@ BEGIN_INTERFACE_MAP()
virtual HRESULT GetExtendTitleBarHeight (double*ret) override; virtual HRESULT GetExtendTitleBarHeight (double*ret) override;
virtual HRESULT SetExtendTitleBarHeight (double value) override; virtual HRESULT SetExtendTitleBarHeight (double value) override;
virtual HRESULT GetWindowZOrder (long* zOrder) override; virtual HRESULT GetWindowZOrder (long* zOrder) override;
void EnterFullScreenMode (); void EnterFullScreenMode ();
@ -73,15 +73,15 @@ BEGIN_INTERFACE_MAP()
void ExitFullScreenMode (); void ExitFullScreenMode ();
virtual HRESULT SetWindowState (AvnWindowState state) override; virtual HRESULT SetWindowState (AvnWindowState state) override;
virtual HRESULT SetWindowState (AvnWindowState state, bool shouldResize); virtual HRESULT SetWindowState (AvnWindowState state, bool shouldResize);
virtual bool IsModal() override; virtual bool IsModal() override;
bool IsOwned(); bool IsOwned();
virtual void BringToFront () override; virtual void BringToFront () override;
bool CanBecomeKeyWindow (); bool CanBecomeKeyWindow ();
bool CanZoom() override { return _isEnabled && _canMaximize; } bool CanZoom() override { return _isEnabled && _canMaximize; }

Loading…
Cancel
Save