Skip to content

Commit

Permalink
Merge pull request AvaloniaUI#9716 from AvaloniaUI/fixes/macos-child-…
Browse files Browse the repository at this point in the history
…window-key-handling

macos: Fix child window key handling
  • Loading branch information
maxkatz6 authored and grokys committed Jan 17, 2023
1 parent fb67190 commit 7d09e7c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
5 changes: 4 additions & 1 deletion native/Avalonia.Native/src/OSX/AvnWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ -(void) setIsExtended:(bool)value;

-(bool) isDialog
{
return _parent->IsDialog();
return _parent->IsModal();
}

-(double) getExtendedTitleBarHeight
Expand Down Expand Up @@ -280,6 +280,9 @@ -(void)becomeKeyWindow

- (void)windowDidBecomeKey:(NSNotification *_Nonnull)notification
{
if (_parent == nullptr)
return;

_parent->BringToFront();

dispatch_async(dispatch_get_main_queue(), ^{
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 @@ -96,7 +96,7 @@ BEGIN_INTERFACE_MAP()
IAvnClipboard *clipboard, IAvnDndResultCallback *cb,
void *sourceHandle) override;

virtual bool IsDialog();
virtual bool IsModal();

id<AvnWindowProtocol> GetWindowProtocol ();

Expand Down
2 changes: 1 addition & 1 deletion native/Avalonia.Native/src/OSX/WindowBaseImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@
return S_OK;
}

bool WindowBaseImpl::IsDialog() {
bool WindowBaseImpl::IsModal() {
return false;
}

Expand Down
6 changes: 4 additions & 2 deletions native/Avalonia.Native/src/OSX/WindowImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class WindowImpl : public virtual WindowBaseImpl, public virtual IAvnWindow, pub
NSRect _preZoomSize;
bool _transitioningWindowState;
bool _isClientAreaExtended;
bool _isDialog;
bool _isModal;
WindowImpl* _parent;
std::list<WindowImpl*> _children;
AvnExtendClientAreaChromeHints _extendClientHints;
Expand Down Expand Up @@ -91,7 +91,9 @@ BEGIN_INTERFACE_MAP()

virtual HRESULT SetWindowState (AvnWindowState state) override;

virtual bool IsDialog() override;
virtual bool IsModal() override;

bool IsOwned();

virtual void BringToFront () override;

Expand Down
18 changes: 11 additions & 7 deletions native/Avalonia.Native/src/OSX/WindowImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
START_COM_CALL;

@autoreleasepool {
_isDialog = isDialog || _parent != nullptr;
_isModal = isDialog;

WindowBaseImpl::Show(activate, isDialog);

Expand Down Expand Up @@ -96,7 +96,7 @@

_parent = cparent;

_isDialog = _parent != nullptr;
_isModal = _parent != nullptr;

if(_parent != nullptr && Window != nullptr){
// If one tries to show a child window with a minimized parent window, then the parent window will be
Expand All @@ -122,7 +122,7 @@
{
if ([Window isVisible] && ![Window isMiniaturized])
{
if(IsDialog())
if(IsModal())
{
Activate();
}
Expand All @@ -149,7 +149,7 @@
{
for(auto iterator = _children.begin(); iterator != _children.end(); iterator++)
{
if((*iterator)->IsDialog())
if((*iterator)->IsModal())
{
return false;
}
Expand Down Expand Up @@ -568,8 +568,12 @@
}
}

bool WindowImpl::IsDialog() {
return _isDialog;
bool WindowImpl::IsModal() {
return _isModal;
}

bool WindowImpl::IsOwned() {
return _parent != nullptr;
}

NSWindowStyleMask WindowImpl::GetStyle() {
Expand Down Expand Up @@ -598,7 +602,7 @@
break;
}

if (!IsDialog()) {
if (!IsOwned()) {
s |= NSWindowStyleMaskMiniaturizable;
}

Expand Down

0 comments on commit 7d09e7c

Please sign in to comment.