Skip to content

Commit

Permalink
Merge pull request #8238 from AvaloniaUI/fixes/disable-parent-chrome-…
Browse files Browse the repository at this point in the history
…buttons-when-modal-is-shown

OSX: Disable parent chrome buttons when modal is shown
  • Loading branch information
danwalmsley authored Jun 1, 2022
2 parents e907c91 + e413b48 commit 30e8b17
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
11 changes: 8 additions & 3 deletions native/Avalonia.Native/src/OSX/AvnWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,10 @@ -(CLASS_NAME*_Nonnull) initWithParent: (WindowBaseImpl*_Nonnull) parent content

_isExtended = false;

#ifdef IS_NSPANEL
[self setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces|NSWindowCollectionBehaviorFullScreenAuxiliary];
#endif
if(self.isDialog)
{
[self setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces|NSWindowCollectionBehaviorFullScreenAuxiliary];
}

return self;
}
Expand Down Expand Up @@ -259,6 +260,10 @@ -(bool)shouldTryToHandleEvents
-(void) setEnabled:(bool)enable
{
_isEnabled = enable;

[[self standardWindowButton:NSWindowCloseButton] setEnabled:enable];
[[self standardWindowButton:NSWindowMiniaturizeButton] setEnabled:enable];
[[self standardWindowButton:NSWindowZoomButton] setEnabled:enable];
}

-(void)becomeKeyWindow
Expand Down
24 changes: 6 additions & 18 deletions native/Avalonia.Native/src/OSX/WindowImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,12 @@
return;
}

for (id subview in Window.contentView.superview.subviews) {
if ([subview isKindOfClass:NSClassFromString(@"NSTitlebarContainerView")]) {
NSView *titlebarView = [subview subviews][0];
for (id button in titlebarView.subviews) {
if ([button isKindOfClass:[NSButton class]]) {
if (_isClientAreaExtended) {
auto wantsChrome = (_extendClientHints & AvnSystemChrome) || (_extendClientHints & AvnPreferSystemChrome);

[button setHidden:!wantsChrome];
} else {
[button setHidden:(_decorations != SystemDecorationsFull)];
}

[button setWantsLayer:true];
}
}
}
}
bool wantsChrome = (_extendClientHints & AvnSystemChrome) || (_extendClientHints & AvnPreferSystemChrome);
bool hasTrafficLights = _isClientAreaExtended ? !wantsChrome : _decorations != SystemDecorationsFull;

[[Window standardWindowButton:NSWindowCloseButton] setHidden:hasTrafficLights];
[[Window standardWindowButton:NSWindowMiniaturizeButton] setHidden:hasTrafficLights];
[[Window standardWindowButton:NSWindowZoomButton] setHidden:hasTrafficLights];
}

void WindowImpl::OnInitialiseNSWindow(){
Expand Down
2 changes: 1 addition & 1 deletion samples/ControlCatalog/Pages/DialogsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
Text="Window dialogs" />
<Button Name="DecoratedWindow">Decorated _window</Button>
<Button Name="DecoratedWindowDialog">Decorated w_indow (dialog)</Button>
<Button Name="Dialog">_Dialog</Button>
<Button Name="Dialog" ToolTip.Tip="Shows a dialog">_Dialog</Button>
<Button Name="DialogNoTaskbar">Dialog (_No taskbar icon)</Button>
<Button Name="OwnedWindow">Own_ed window</Button>
<Button Name="OwnedWindowNoTaskbar">Owned window (No tas_kbar icon)</Button>
Expand Down
13 changes: 13 additions & 0 deletions samples/ControlCatalog/Pages/DialogsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public DialogsPage()
private Window CreateSampleWindow()
{
Button button;
Button dialogButton;

var window = new Window
{
Expand All @@ -158,13 +159,25 @@ private Window CreateSampleWindow()
HorizontalAlignment = HorizontalAlignment.Center,
Content = "Click to close",
IsDefault = true
}),
(dialogButton = new Button
{
HorizontalAlignment = HorizontalAlignment.Center,
Content = "Dialog",
IsDefault = false
})
}
},
WindowStartupLocation = WindowStartupLocation.CenterOwner
};

button.Click += (_, __) => window.Close();
dialogButton.Click += (_, __) =>
{
var dialog = CreateSampleWindow();
dialog.Height = 200;
dialog.ShowDialog(window);
};

return window;
}
Expand Down

0 comments on commit 30e8b17

Please sign in to comment.