From ef37b1d5dd689e5c456dcf6f4dc94ac5da880819 Mon Sep 17 00:00:00 2001 From: aloucks Date: Sun, 16 Mar 2025 21:58:47 -0400 Subject: [PATCH] macOS: Make set_simple_fullscreen honor set_borderless_game (#4164) * Prevent panic when calling set_simple_fullscreen(false) on macos Calling `set_simple_fullscreen(false)` to restore the window after a previous call to `set_simple_fullscreen(true)` panics with `view must be installed in a window` in the call to `set_style_mask` with the old style. Moving the `set_style_mask` call after the frame has been resized fixes the issue. * Hide the doc and menubar on macos when using set_borderless_game with set_simple_fullscreen --- src/changelog/unreleased.md | 1 + src/platform/macos.rs | 4 +++- src/platform_impl/apple/appkit/window_delegate.rs | 11 ++++++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/changelog/unreleased.md b/src/changelog/unreleased.md index 26988a59..15f1ec35 100644 --- a/src/changelog/unreleased.md +++ b/src/changelog/unreleased.md @@ -237,3 +237,4 @@ changelog entry. - On macOS, fixed the scancode conversion for `IntlBackslash`. - On macOS, fixed redundant `SurfaceResized` event at window creation. - On Windows, fixed ~500 ms pause when clicking the title bar during continuous redraw. +- On macos, `WindowExtMacOS::set_simple_fullscreen` now honors `WindowExtMacOS::set_borderless_game` diff --git a/src/platform/macos.rs b/src/platform/macos.rs index 8be7afe4..a417406e 100644 --- a/src/platform/macos.rs +++ b/src/platform/macos.rs @@ -151,7 +151,9 @@ pub trait WindowExtMacOS { /// Getter for the [`WindowExtMacOS::set_option_as_alt`]. fn option_as_alt(&self) -> OptionAsAlt; - /// Disable the Menu Bar and Dock in Borderless Fullscreen mode. Useful for games. + /// Disable the Menu Bar and Dock in Simple or Borderless Fullscreen mode. Useful for games. + /// The effect is applied when [`WindowExtMacOS::set_simple_fullscreen`] or + /// [`Window::set_fullscreen`] is called. fn set_borderless_game(&self, borderless_game: bool); /// Getter for the [`WindowExtMacOS::set_borderless_game`]. diff --git a/src/platform_impl/apple/appkit/window_delegate.rs b/src/platform_impl/apple/appkit/window_delegate.rs index 86011d08..604c6834 100644 --- a/src/platform_impl/apple/appkit/window_delegate.rs +++ b/src/platform_impl/apple/appkit/window_delegate.rs @@ -1874,8 +1874,13 @@ impl WindowExtMacOS for WindowDelegate { self.ivars().is_simple_fullscreen.set(true); // Simulate pre-Lion fullscreen by hiding the dock and menu bar - let presentation_options = NSApplicationPresentationOptions::AutoHideDock - | NSApplicationPresentationOptions::AutoHideMenuBar; + let presentation_options = if self.is_borderless_game() { + NSApplicationPresentationOptions::HideDock + | NSApplicationPresentationOptions::HideMenuBar + } else { + NSApplicationPresentationOptions::AutoHideDock + | NSApplicationPresentationOptions::AutoHideMenuBar + }; app.setPresentationOptions(presentation_options); // Hide the titlebar @@ -1896,7 +1901,6 @@ impl WindowExtMacOS for WindowDelegate { self.window().setMovable(false); } else { let new_mask = self.saved_style(); - self.set_style_mask(new_mask); self.ivars().is_simple_fullscreen.set(false); let save_presentation_opts = self.ivars().save_presentation_opts.get(); @@ -1919,6 +1923,7 @@ impl WindowExtMacOS for WindowDelegate { self.window().setFrame_display(frame, true); self.window().setMovable(true); + self.set_style_mask(new_mask); } true