feat: Add BrowserWindow.setWindowButtonVisibility()
Fixes #12701 and supersedes #13131. Ideally we would have added `setTitleBarStyle()`, but that is a significantly more involved change. For example, consider the case where we switch from `hidden` to `normal`. We would not only have to show the traffic light buttons, we would also have to switch the window from a frameless to a framed window and deal with various other window state. Lets instead implement a simple solution for #12701.
This commit is contained in:
parent
00c0c180ab
commit
a42ca9eecc
8 changed files with 82 additions and 7 deletions
|
@ -884,8 +884,9 @@ void NativeWindowMac::SetSimpleFullScreen(bool simple_fullscreen) {
|
|||
// Resize the window to accomodate the _entire_ screen size
|
||||
fullscreenFrame.size.height -=
|
||||
[[[NSApplication sharedApplication] mainMenu] menuBarHeight];
|
||||
} else {
|
||||
// No need to hide the title, but we should still hide the window buttons
|
||||
} else if (!window_button_visibility_.has_value()) {
|
||||
// Lets keep previous behaviour - hide window controls in titled
|
||||
// fullscreen mode when not specified otherwise.
|
||||
[[window standardWindowButton:NSWindowZoomButton] setHidden:YES];
|
||||
[[window standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES];
|
||||
[[window standardWindowButton:NSWindowCloseButton] setHidden:YES];
|
||||
|
@ -904,13 +905,17 @@ void NativeWindowMac::SetSimpleFullScreen(bool simple_fullscreen) {
|
|||
if (!fullscreen_window_title()) {
|
||||
// Restore the titlebar
|
||||
SetStyleMask(true, NSTitledWindowMask);
|
||||
} else {
|
||||
// Show the window buttons
|
||||
[[window standardWindowButton:NSWindowZoomButton] setHidden:NO];
|
||||
[[window standardWindowButton:NSWindowMiniaturizeButton] setHidden:NO];
|
||||
[[window standardWindowButton:NSWindowCloseButton] setHidden:NO];
|
||||
}
|
||||
|
||||
// Restore window controls visibility state
|
||||
const bool window_button_hidden = !window_button_visibility_.value_or(true);
|
||||
[[window standardWindowButton:NSWindowZoomButton]
|
||||
setHidden:window_button_hidden];
|
||||
[[window standardWindowButton:NSWindowMiniaturizeButton]
|
||||
setHidden:window_button_hidden];
|
||||
[[window standardWindowButton:NSWindowCloseButton]
|
||||
setHidden:window_button_hidden];
|
||||
|
||||
[window setFrame:original_frame_ display:YES animate:YES];
|
||||
|
||||
[NSApp setPresentationOptions:simple_fullscreen_options_];
|
||||
|
@ -1148,6 +1153,19 @@ bool NativeWindowMac::AddTabbedWindow(NativeWindow* window) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool NativeWindowMac::SetWindowButtonVisibility(bool visible) {
|
||||
if (title_bar_style_ == CUSTOM_BUTTONS_ON_HOVER) {
|
||||
return false;
|
||||
}
|
||||
|
||||
window_button_visibility_ = visible;
|
||||
|
||||
[[window_ standardWindowButton:NSWindowCloseButton] setHidden:!visible];
|
||||
[[window_ standardWindowButton:NSWindowMiniaturizeButton] setHidden:!visible];
|
||||
[[window_ standardWindowButton:NSWindowZoomButton] setHidden:!visible];
|
||||
return true;
|
||||
}
|
||||
|
||||
void NativeWindowMac::SetVibrancy(const std::string& type) {
|
||||
if (@available(macOS 10.10, *)) {
|
||||
NSView* vibrant_view = [window_ vibrantView];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue