Skip to content

Commit

Permalink
Merge pull request #6250 from AvaloniaUI/fixes/osx-red-flicker
Browse files Browse the repository at this point in the history
Fixes/osx flicker
  • Loading branch information
kekekeks authored and Dan Walmsley committed Jul 15, 2021
1 parent d77143f commit b53db52
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions native/Avalonia.Native/src/OSX/window.mm
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@
IAvnMenu* _mainMenu;

bool _shown;
bool _inResize;

WindowBaseImpl(IAvnWindowBaseEvents* events, IAvnGlContext* gl)
{
_shown = false;
_inResize = false;
_mainMenu = nullptr;
BaseEvents = events;
_glContext = gl;
Expand Down Expand Up @@ -262,6 +264,13 @@ virtual HRESULT SetMinMaxSize (AvnSize minSize, AvnSize maxSize) override

virtual HRESULT Resize(double x, double y) override
{
if(_inResize)
{
return S_OK;
}

_inResize = true;

START_COM_CALL;

@autoreleasepool
Expand Down Expand Up @@ -289,13 +298,19 @@ virtual HRESULT Resize(double x, double y) override
y = maxSize.height;
}

if(!_shown)
@try
{
BaseEvents->Resized(AvnSize{x,y});
if(!_shown)
{
BaseEvents->Resized(AvnSize{x,y});
}

[Window setContentSize:NSSize{x, y}];
}
@finally
{
_inResize = false;
}

[StandardContainer setFrameSize:NSSize{x,y}];
[Window setContentSize:NSSize{x, y}];

return S_OK;
}
Expand Down Expand Up @@ -1274,6 +1289,9 @@ -(AutoFitContentView* _Nonnull) initWithContent:(NSView *)content
[_blurBehind setWantsLayer:true];
_blurBehind.hidden = true;

[_blurBehind setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[_content setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];

[self addSubview:_blurBehind];
[self addSubview:_content];

Expand Down Expand Up @@ -1309,9 +1327,6 @@ -(void)setFrameSize:(NSSize)newSize
_settingSize = true;
[super setFrameSize:newSize];

[_blurBehind setFrameSize:newSize];
[_content setFrameSize:newSize];

auto window = objc_cast<AvnWindow>([self window]);

// TODO get actual titlebar size
Expand All @@ -1327,6 +1342,7 @@ -(void)setFrameSize:(NSSize)newSize
[_titleBarMaterial setFrame:tbar];
tbar.size.height = height < 1 ? 0 : 1;
[_titleBarUnderline setFrame:tbar];

_settingSize = false;
}

Expand Down Expand Up @@ -2353,11 +2369,12 @@ virtual NSWindowStyleMask GetStyle() override

virtual HRESULT Resize(double x, double y) override
{
START_COM_CALL;

@autoreleasepool
{
if (Window != nullptr)
{
[StandardContainer setFrameSize:NSSize{x,y}];
[Window setContentSize:NSSize{x, y}];

[Window setFrameTopLeftPoint:ToNSPoint(ConvertPointY(lastPositionSet))];
Expand Down

0 comments on commit b53db52

Please sign in to comment.