Skip to content

Commit

Permalink
macOS: Fix returning from full screen via the button when the titleba…
Browse files Browse the repository at this point in the history
…r is hidden not hiding the buttons

Fixes #6883
  • Loading branch information
kovidgoyal committed Dec 10, 2023
1 parent e9e8894 commit 00f8f34
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ Detailed list of changes

- macOS: Fix some combining characters not being rendered (:iss:`6898`)

- macOS: Fix returning from full screen via the button when the titlebar is hidden not hiding the buttons (:iss:`6883`)


0.31.0 [2023-11-08]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
35 changes: 22 additions & 13 deletions glfw/cocoa_window.m
Original file line number Diff line number Diff line change
Expand Up @@ -1716,13 +1716,33 @@ - (BOOL)canBecomeMainWindow
return YES;
}

static void
update_titlebar_button_visibility_after_fullscreen_transition(_GLFWwindow* w, bool traditional, bool made_fullscreen) {
// Update window button visibility
if (w->ns.titlebar_hidden) {
NSWindow *window = w->ns.object;
// The hidden buttons might be automatically reset to be visible after going full screen
// to show up in the auto-hide title bar, so they need to be set back to hidden.
BOOL button_hidden = YES;
// When title bar is configured to be hidden, it should be shown with buttons (auto-hide) after going to full screen.
if (!traditional) {
button_hidden = (BOOL) !made_fullscreen;
}
[[window standardWindowButton: NSWindowCloseButton] setHidden:button_hidden];
[[window standardWindowButton: NSWindowMiniaturizeButton] setHidden:button_hidden];
[[window standardWindowButton: NSWindowZoomButton] setHidden:button_hidden];
}
}

- (void)toggleFullScreen:(nullable id)sender
{
if (glfw_window) {
if (glfw_window->ns.in_fullscreen_transition) return;
if (glfw_window->ns.toggleFullscreenCallback && glfw_window->ns.toggleFullscreenCallback((GLFWwindow*)glfw_window) == 1) return;
glfw_window->ns.in_fullscreen_transition = true;
}
NSWindowStyleMask sm = [self styleMask];
bool is_fullscreen_already = (sm & NSWindowStyleMaskFullScreen) != 0;
// When resizeIncrements is set, Cocoa cannot restore the original window size after returning from fullscreen.
const NSSize original = [self resizeIncrements];
[self setResizeIncrements:NSMakeSize(1.0, 1.0)];
Expand All @@ -1731,6 +1751,7 @@ - (void)toggleFullScreen:(nullable id)sender
// When the window decoration is hidden, toggling fullscreen causes the style mask to be changed,
// and causes the first responder to be cleared.
if (glfw_window && !glfw_window->decorated && glfw_window->ns.view) [self makeFirstResponder:glfw_window->ns.view];
update_titlebar_button_visibility_after_fullscreen_transition(glfw_window, false, !is_fullscreen_already);
}

- (void)zoom:(id)sender
Expand Down Expand Up @@ -2657,19 +2678,7 @@ bool _glfwPlatformToggleFullscreen(_GLFWwindow* w, unsigned int flags) {
if (in_fullscreen) made_fullscreen = false;
[window toggleFullScreen: nil];
}
// Update window button visibility
if (w->ns.titlebar_hidden) {
// The hidden buttons might be automatically reset to be visible after going full screen
// to show up in the auto-hide title bar, so they need to be set back to hidden.
BOOL button_hidden = YES;
// When title bar is configured to be hidden, it should be shown with buttons (auto-hide) after going to full screen.
if (!traditional) {
button_hidden = (BOOL) !made_fullscreen;
}
[[window standardWindowButton: NSWindowCloseButton] setHidden:button_hidden];
[[window standardWindowButton: NSWindowMiniaturizeButton] setHidden:button_hidden];
[[window standardWindowButton: NSWindowZoomButton] setHidden:button_hidden];
}
update_titlebar_button_visibility_after_fullscreen_transition(w, traditional, made_fullscreen);
return made_fullscreen;
}

Expand Down

0 comments on commit 00f8f34

Please sign in to comment.