From 7eb95255cb1055c7d981b6ff20b86a014c9dc570 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Thu, 15 Dec 2022 14:16:04 +0100 Subject: [PATCH 1/3] Don't mark all owned windows as dialogs. This was preventing owner windows of non-modal dialogs from receiving key window status, meaning that input was broken in combination with embedding (Avalonia controls did work however because the routing was carried out internal to Avalonia). --- native/Avalonia.Native/src/OSX/WindowImpl.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/Avalonia.Native/src/OSX/WindowImpl.mm b/native/Avalonia.Native/src/OSX/WindowImpl.mm index b6dacb6ce44..bbf419bccd4 100644 --- a/native/Avalonia.Native/src/OSX/WindowImpl.mm +++ b/native/Avalonia.Native/src/OSX/WindowImpl.mm @@ -63,7 +63,7 @@ START_COM_CALL; @autoreleasepool { - _isDialog = isDialog || _parent != nullptr; + _isDialog = isDialog; WindowBaseImpl::Show(activate, isDialog); From 102b1b351bce7a75be28c51ac70e19d50f786126 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Thu, 15 Dec 2022 14:17:19 +0100 Subject: [PATCH 2/3] Add null check, Customer was seeing a crash in this method, don't have a repro but other uses of `_parent` are surrounded by a null check so this makes sense I think. --- native/Avalonia.Native/src/OSX/AvnWindow.mm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/native/Avalonia.Native/src/OSX/AvnWindow.mm b/native/Avalonia.Native/src/OSX/AvnWindow.mm index 6611dcc73fc..42c500716cb 100644 --- a/native/Avalonia.Native/src/OSX/AvnWindow.mm +++ b/native/Avalonia.Native/src/OSX/AvnWindow.mm @@ -281,6 +281,9 @@ -(void)becomeKeyWindow - (void)windowDidBecomeKey:(NSNotification *_Nonnull)notification { + if (_parent == nullptr) + return; + _parent->BringToFront(); dispatch_async(dispatch_get_main_queue(), ^{ From 872eca05b2df322077c273be1922201381520e12 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Fri, 16 Dec 2022 09:01:15 +0100 Subject: [PATCH 3/3] Disable minimize button on owned windows again. 7eb95255c regressed disabling the minimize button on owned windows. Split what was previously `IsDialog` into two flags: `IsModal` and `IsOwned` and use `IsOwned` to control the disabled state of the minimize button. --- native/Avalonia.Native/src/OSX/AvnWindow.mm | 2 +- .../Avalonia.Native/src/OSX/WindowBaseImpl.h | 2 +- .../Avalonia.Native/src/OSX/WindowBaseImpl.mm | 2 +- native/Avalonia.Native/src/OSX/WindowImpl.h | 6 ++++-- native/Avalonia.Native/src/OSX/WindowImpl.mm | 18 +++++++++++------- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/native/Avalonia.Native/src/OSX/AvnWindow.mm b/native/Avalonia.Native/src/OSX/AvnWindow.mm index 42c500716cb..d3b7b4ede60 100644 --- a/native/Avalonia.Native/src/OSX/AvnWindow.mm +++ b/native/Avalonia.Native/src/OSX/AvnWindow.mm @@ -44,7 +44,7 @@ -(void) setIsExtended:(bool)value; -(bool) isDialog { - return _parent->IsDialog(); + return _parent->IsModal(); } -(double) getExtendedTitleBarHeight diff --git a/native/Avalonia.Native/src/OSX/WindowBaseImpl.h b/native/Avalonia.Native/src/OSX/WindowBaseImpl.h index 7fb002e54f3..bb8d5fae753 100644 --- a/native/Avalonia.Native/src/OSX/WindowBaseImpl.h +++ b/native/Avalonia.Native/src/OSX/WindowBaseImpl.h @@ -96,7 +96,7 @@ BEGIN_INTERFACE_MAP() IAvnClipboard *clipboard, IAvnDndResultCallback *cb, void *sourceHandle) override; - virtual bool IsDialog(); + virtual bool IsModal(); id GetWindowProtocol (); diff --git a/native/Avalonia.Native/src/OSX/WindowBaseImpl.mm b/native/Avalonia.Native/src/OSX/WindowBaseImpl.mm index 9946ad9b10f..9650290fbb2 100644 --- a/native/Avalonia.Native/src/OSX/WindowBaseImpl.mm +++ b/native/Avalonia.Native/src/OSX/WindowBaseImpl.mm @@ -542,7 +542,7 @@ return S_OK; } -bool WindowBaseImpl::IsDialog() { +bool WindowBaseImpl::IsModal() { return false; } diff --git a/native/Avalonia.Native/src/OSX/WindowImpl.h b/native/Avalonia.Native/src/OSX/WindowImpl.h index b4b1d4e70b8..3861aaf1707 100644 --- a/native/Avalonia.Native/src/OSX/WindowImpl.h +++ b/native/Avalonia.Native/src/OSX/WindowImpl.h @@ -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 _children; AvnExtendClientAreaChromeHints _extendClientHints; @@ -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; diff --git a/native/Avalonia.Native/src/OSX/WindowImpl.mm b/native/Avalonia.Native/src/OSX/WindowImpl.mm index bbf419bccd4..f345043f617 100644 --- a/native/Avalonia.Native/src/OSX/WindowImpl.mm +++ b/native/Avalonia.Native/src/OSX/WindowImpl.mm @@ -63,7 +63,7 @@ START_COM_CALL; @autoreleasepool { - _isDialog = isDialog; + _isModal = isDialog; WindowBaseImpl::Show(activate, isDialog); @@ -97,7 +97,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 @@ -123,7 +123,7 @@ { if ([Window isVisible] && ![Window isMiniaturized]) { - if(IsDialog()) + if(IsModal()) { Activate(); } @@ -150,7 +150,7 @@ { for(auto iterator = _children.begin(); iterator != _children.end(); iterator++) { - if((*iterator)->IsDialog()) + if((*iterator)->IsModal()) { return false; } @@ -569,8 +569,12 @@ } } -bool WindowImpl::IsDialog() { - return _isDialog; +bool WindowImpl::IsModal() { + return _isModal; +} + +bool WindowImpl::IsOwned() { + return _parent != nullptr; } NSWindowStyleMask WindowImpl::GetStyle() { @@ -599,7 +603,7 @@ break; } - if (!IsDialog()) { + if (!IsOwned()) { s |= NSWindowStyleMaskMiniaturizable; }