From 44052a093e1ec97f875453b440883a46ff79aab2 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Sat, 16 Dec 2023 18:34:18 +0200 Subject: [PATCH] On Windows, fix `set_fullscreen` early return for `Fullscreen::Borderless(None)` --- CHANGELOG.md | 1 + src/platform_impl/windows/window.rs | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f4c6936f6..eb6ae10450 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ Unreleased` header. - On macOS, fix `refresh_rate_millihertz`. - On Wayland, disable Client Side Decorations when `wl_subcompositor` is not supported. - On X11, fix `Xft.dpi` detection from Xresources. +- On Windows, fix consecutive calls to `window.set_fullscreen(Some(Fullscreen::Borderless(None)))` resulting in losing previous window state when eventually exiting fullscreen using `window.set_fullscreen(None)`. # 0.29.4 diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index 7d5bc6d746..f19272aba1 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -686,9 +686,19 @@ impl Window { let mut window_state_lock = window_state.lock().unwrap(); let old_fullscreen = window_state_lock.fullscreen.clone(); - if window_state_lock.fullscreen == fullscreen { - return; + + match (&old_fullscreen, &fullscreen) { + // Return if we already are in the same fullscreen mode + _ if old_fullscreen == fullscreen => return, + // Return if saved Borderless(monitor) is the same as current monitor when requested fullscreen is Borderless(None) + (Some(Fullscreen::Borderless(Some(monitor))), Some(Fullscreen::Borderless(None))) + if *monitor == monitor::current_monitor(window.0) => + { + return + } + _ => {} } + window_state_lock.fullscreen = fullscreen.clone(); drop(window_state_lock);