Skip to content

Commit 30e8b17

Browse files
authored
Merge pull request AvaloniaUI#8238 from AvaloniaUI/fixes/disable-parent-chrome-buttons-when-modal-is-shown
OSX: Disable parent chrome buttons when modal is shown
2 parents e907c91 + e413b48 commit 30e8b17

File tree

4 files changed

+28
-22
lines changed

4 files changed

+28
-22
lines changed

native/Avalonia.Native/src/OSX/AvnWindow.mm

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,10 @@ -(CLASS_NAME*_Nonnull) initWithParent: (WindowBaseImpl*_Nonnull) parent content
175175

176176
_isExtended = false;
177177

178-
#ifdef IS_NSPANEL
179-
[self setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces|NSWindowCollectionBehaviorFullScreenAuxiliary];
180-
#endif
178+
if(self.isDialog)
179+
{
180+
[self setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces|NSWindowCollectionBehaviorFullScreenAuxiliary];
181+
}
181182

182183
return self;
183184
}
@@ -259,6 +260,10 @@ -(bool)shouldTryToHandleEvents
259260
-(void) setEnabled:(bool)enable
260261
{
261262
_isEnabled = enable;
263+
264+
[[self standardWindowButton:NSWindowCloseButton] setEnabled:enable];
265+
[[self standardWindowButton:NSWindowMiniaturizeButton] setEnabled:enable];
266+
[[self standardWindowButton:NSWindowZoomButton] setEnabled:enable];
262267
}
263268

264269
-(void)becomeKeyWindow

native/Avalonia.Native/src/OSX/WindowImpl.mm

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,12 @@
2929
return;
3030
}
3131

32-
for (id subview in Window.contentView.superview.subviews) {
33-
if ([subview isKindOfClass:NSClassFromString(@"NSTitlebarContainerView")]) {
34-
NSView *titlebarView = [subview subviews][0];
35-
for (id button in titlebarView.subviews) {
36-
if ([button isKindOfClass:[NSButton class]]) {
37-
if (_isClientAreaExtended) {
38-
auto wantsChrome = (_extendClientHints & AvnSystemChrome) || (_extendClientHints & AvnPreferSystemChrome);
39-
40-
[button setHidden:!wantsChrome];
41-
} else {
42-
[button setHidden:(_decorations != SystemDecorationsFull)];
43-
}
44-
45-
[button setWantsLayer:true];
46-
}
47-
}
48-
}
49-
}
32+
bool wantsChrome = (_extendClientHints & AvnSystemChrome) || (_extendClientHints & AvnPreferSystemChrome);
33+
bool hasTrafficLights = _isClientAreaExtended ? !wantsChrome : _decorations != SystemDecorationsFull;
34+
35+
[[Window standardWindowButton:NSWindowCloseButton] setHidden:hasTrafficLights];
36+
[[Window standardWindowButton:NSWindowMiniaturizeButton] setHidden:hasTrafficLights];
37+
[[Window standardWindowButton:NSWindowZoomButton] setHidden:hasTrafficLights];
5038
}
5139

5240
void WindowImpl::OnInitialiseNSWindow(){

samples/ControlCatalog/Pages/DialogsPage.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
Text="Window dialogs" />
2121
<Button Name="DecoratedWindow">Decorated _window</Button>
2222
<Button Name="DecoratedWindowDialog">Decorated w_indow (dialog)</Button>
23-
<Button Name="Dialog">_Dialog</Button>
23+
<Button Name="Dialog" ToolTip.Tip="Shows a dialog">_Dialog</Button>
2424
<Button Name="DialogNoTaskbar">Dialog (_No taskbar icon)</Button>
2525
<Button Name="OwnedWindow">Own_ed window</Button>
2626
<Button Name="OwnedWindowNoTaskbar">Owned window (No tas_kbar icon)</Button>

samples/ControlCatalog/Pages/DialogsPage.xaml.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public DialogsPage()
142142
private Window CreateSampleWindow()
143143
{
144144
Button button;
145+
Button dialogButton;
145146

146147
var window = new Window
147148
{
@@ -158,13 +159,25 @@ private Window CreateSampleWindow()
158159
HorizontalAlignment = HorizontalAlignment.Center,
159160
Content = "Click to close",
160161
IsDefault = true
162+
}),
163+
(dialogButton = new Button
164+
{
165+
HorizontalAlignment = HorizontalAlignment.Center,
166+
Content = "Dialog",
167+
IsDefault = false
161168
})
162169
}
163170
},
164171
WindowStartupLocation = WindowStartupLocation.CenterOwner
165172
};
166173

167174
button.Click += (_, __) => window.Close();
175+
dialogButton.Click += (_, __) =>
176+
{
177+
var dialog = CreateSampleWindow();
178+
dialog.Height = 200;
179+
dialog.ShowDialog(window);
180+
};
168181

169182
return window;
170183
}

0 commit comments

Comments
 (0)