diff --git a/CHANGELOG.md b/CHANGELOG.md index 36046736..1d538d3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ And please only add new entries to the top of this list, right below the `# Unre - **Breaking:** Removed `WindowBuilderExtWindows::with_theme` and `WindowBuilderExtWayland::with_wayland_csd_theme` in favour of `WindowBuilder::with_theme`. - **Breaking:** Removed `WindowExtWindows::theme` in favour of `Window::theme`. - Enabled `doc_auto_cfg` when generating docs on docs.rs for feature labels. +- On macOS, fix panic when getting current monitor without any monitor attached. # 0.27.5 diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index 368be89a..5e96fbac 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -804,7 +804,13 @@ impl WinitWindow { if let Some(ref fullscreen) = fullscreen { let new_screen = match fullscreen { Fullscreen::Borderless(Some(monitor)) => monitor.clone(), - Fullscreen::Borderless(None) => self.current_monitor_inner(), + Fullscreen::Borderless(None) => { + if let Some(monitor) = self.current_monitor_inner() { + monitor + } else { + return; + } + } Fullscreen::Exclusive(video_mode) => video_mode.monitor(), } .ns_screen() @@ -1067,14 +1073,14 @@ impl WinitWindow { #[inline] // Allow directly accessing the current monitor internally without unwrapping. - pub(crate) fn current_monitor_inner(&self) -> MonitorHandle { - let display_id = self.screen().expect("expected screen").display_id(); - MonitorHandle::new(display_id) + pub(crate) fn current_monitor_inner(&self) -> Option { + let display_id = self.screen()?.display_id(); + Some(MonitorHandle::new(display_id)) } #[inline] pub fn current_monitor(&self) -> Option { - Some(self.current_monitor_inner()) + self.current_monitor_inner() } #[inline] diff --git a/src/platform_impl/macos/window_delegate.rs b/src/platform_impl/macos/window_delegate.rs index e328e59c..92f8ecd3 100644 --- a/src/platform_impl/macos/window_delegate.rs +++ b/src/platform_impl/macos/window_delegate.rs @@ -242,7 +242,7 @@ declare_class!( // Otherwise, we must've reached fullscreen by the user clicking // on the green fullscreen button. Update state! None => { - let current_monitor = Some(self.window.current_monitor_inner()); + let current_monitor = self.window.current_monitor_inner(); shared_state.fullscreen = Some(Fullscreen::Borderless(current_monitor)) } }