On macOS, fix panic in current_monitor_inner

This commit is contained in:
Xiaopeng Li 2022-11-05 10:30:39 +08:00 committed by GitHub
parent 97d4c7b303
commit 8669c2e8df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 6 deletions

View file

@ -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 `WindowBuilderExtWindows::with_theme` and `WindowBuilderExtWayland::with_wayland_csd_theme` in favour of `WindowBuilder::with_theme`.
- **Breaking:** Removed `WindowExtWindows::theme` in favour of `Window::theme`. - **Breaking:** Removed `WindowExtWindows::theme` in favour of `Window::theme`.
- Enabled `doc_auto_cfg` when generating docs on docs.rs for feature labels. - 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 # 0.27.5

View file

@ -804,7 +804,13 @@ impl WinitWindow {
if let Some(ref fullscreen) = fullscreen { if let Some(ref fullscreen) = fullscreen {
let new_screen = match fullscreen { let new_screen = match fullscreen {
Fullscreen::Borderless(Some(monitor)) => monitor.clone(), 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(), Fullscreen::Exclusive(video_mode) => video_mode.monitor(),
} }
.ns_screen() .ns_screen()
@ -1067,14 +1073,14 @@ impl WinitWindow {
#[inline] #[inline]
// Allow directly accessing the current monitor internally without unwrapping. // Allow directly accessing the current monitor internally without unwrapping.
pub(crate) fn current_monitor_inner(&self) -> MonitorHandle { pub(crate) fn current_monitor_inner(&self) -> Option<MonitorHandle> {
let display_id = self.screen().expect("expected screen").display_id(); let display_id = self.screen()?.display_id();
MonitorHandle::new(display_id) Some(MonitorHandle::new(display_id))
} }
#[inline] #[inline]
pub fn current_monitor(&self) -> Option<MonitorHandle> { pub fn current_monitor(&self) -> Option<MonitorHandle> {
Some(self.current_monitor_inner()) self.current_monitor_inner()
} }
#[inline] #[inline]

View file

@ -242,7 +242,7 @@ declare_class!(
// Otherwise, we must've reached fullscreen by the user clicking // Otherwise, we must've reached fullscreen by the user clicking
// on the green fullscreen button. Update state! // on the green fullscreen button. Update state!
None => { 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)) shared_state.fullscreen = Some(Fullscreen::Borderless(current_monitor))
} }
} }