diff --git a/CHANGELOG.md b/CHANGELOG.md index 67b8293c25..4b154a2cb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ And please only add new entries to the top of this list, right below the `# Unre - On Wayland, fix rounding issues when doing resize. - On macOS, fix wrong focused state on startup. - On Windows, fix crash on setting taskbar when using Visual Studio debugger. +- On macOS, resize simple fullscreen windows on windowDidChangeScreen events. # 0.28.1 diff --git a/examples/fullscreen.rs b/examples/fullscreen.rs index 6f4d98e2da..a71d079f28 100644 --- a/examples/fullscreen.rs +++ b/examples/fullscreen.rs @@ -5,6 +5,9 @@ use winit::event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEve use winit::event_loop::EventLoop; use winit::window::{Fullscreen, WindowBuilder}; +#[cfg(target_os = "macos")] +use winit::platform::macos::WindowExtMacOS; + fn main() { SimpleLogger::new().init().unwrap(); let event_loop = EventLoop::new(); @@ -32,6 +35,8 @@ fn main() { println!("- Esc\tExit"); println!("- F\tToggle exclusive fullscreen mode"); println!("- B\tToggle borderless mode"); + #[cfg(target_os = "macos")] + println!("- C\tToggle simple fullscreen mode"); println!("- S\tNext screen"); println!("- M\tNext mode for this screen"); println!("- D\tToggle window decorations"); @@ -67,6 +72,10 @@ fn main() { println!("Setting mode: {fullscreen:?}"); window.set_fullscreen(fullscreen); } + #[cfg(target_os = "macos")] + VirtualKeyCode::C => { + window.set_simple_fullscreen(!window.simple_fullscreen()); + } VirtualKeyCode::S => { monitor_index += 1; if let Some(mon) = elwt.available_monitors().nth(monitor_index) { diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index ad54695567..6d3e79af96 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -150,7 +150,7 @@ pub struct SharedState { pub(crate) target_fullscreen: Option>, pub maximized: bool, pub standard_frame: Option, - is_simple_fullscreen: bool, + pub(crate) is_simple_fullscreen: bool, pub saved_style: Option, /// Presentation options saved before entering `set_simple_fullscreen`, and /// restored upon exiting it. Also used when transitioning from Borderless to @@ -1317,6 +1317,10 @@ impl WindowExtMacOS for WinitWindow { // Tell our window's state that we're in fullscreen shared_state_lock.is_simple_fullscreen = true; + // Drop shared state lock before calling app.setPresentationOptions, because + // it will call our windowDidChangeScreen listener which reacquires the lock + drop(shared_state_lock); + // Simulate pre-Lion fullscreen by hiding the dock and menu bar let presentation_options = NSApplicationPresentationOptions::NSApplicationPresentationAutoHideDock @@ -1341,11 +1345,17 @@ impl WindowExtMacOS for WinitWindow { self.set_style_mask_sync(new_mask); shared_state_lock.is_simple_fullscreen = false; - if let Some(presentation_opts) = shared_state_lock.save_presentation_opts { + let save_presentation_opts = shared_state_lock.save_presentation_opts; + let frame = shared_state_lock.saved_standard_frame(); + + // Drop shared state lock before calling app.setPresentationOptions, because + // it will call our windowDidChangeScreen listener which reacquires the lock + drop(shared_state_lock); + + if let Some(presentation_opts) = save_presentation_opts { app.setPresentationOptions(presentation_opts); } - let frame = shared_state_lock.saved_standard_frame(); self.setFrame_display(frame, true); self.setMovable(true); diff --git a/src/platform_impl/macos/window_delegate.rs b/src/platform_impl/macos/window_delegate.rs index 27f393cf6d..baa0fe80ae 100644 --- a/src/platform_impl/macos/window_delegate.rs +++ b/src/platform_impl/macos/window_delegate.rs @@ -409,6 +409,20 @@ declare_class!( self.queue_event(WindowEvent::ThemeChanged(theme)); } } + + #[sel(windowDidChangeScreen:)] + fn window_did_change_screen(&self, _: Option<&Object>) { + trace_scope!("windowDidChangeScreen:"); + let is_simple_fullscreen = self + .window + .lock_shared_state("window_did_change_screen") + .is_simple_fullscreen; + if is_simple_fullscreen { + if let Some(screen) = self.window.screen() { + self.window.setFrame_display(screen.frame(), true); + } + } + } } );