From 95911aaa1450b6e613139298b676e15cdb928ec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=B0=8F=E7=99=BD?= <364772080@qq.com> Date: Wed, 25 Dec 2024 17:52:19 +0800 Subject: [PATCH] windows: Fix crashing when minimizing a window on Windows 11 (#22414) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #22366 This PR fixes the issue of crashing when minimizing a window on Windows 11. And this PR supersedes #22366. The main change in this PR is to stop rendering the window when it is minimized. Additionally, I’ve made some modifications to the code in #21756 to improve clarity (I think...). cc @mgsloan Release Notes: - N/A --- crates/gpui/src/platform/windows/events.rs | 7 +++---- crates/gpui/src/platform/windows/window.rs | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/crates/gpui/src/platform/windows/events.rs b/crates/gpui/src/platform/windows/events.rs index 49c338c7c3a20..f5313a39b07fd 100644 --- a/crates/gpui/src/platform/windows/events.rs +++ b/crates/gpui/src/platform/windows/events.rs @@ -146,19 +146,18 @@ fn handle_size_msg( // Don't resize the renderer when the window is minimized, but record that it was minimized so // that on restore the swap chain can be recreated via `update_drawable_size_even_if_unchanged`. if wparam.0 == SIZE_MINIMIZED as usize { - lock.is_minimized = Some(true); + lock.restore_from_minimized = lock.callbacks.request_frame.take(); return Some(0); } - let may_have_been_minimized = lock.is_minimized.unwrap_or(true); - lock.is_minimized = Some(false); let width = lparam.loword().max(1) as i32; let height = lparam.hiword().max(1) as i32; let new_size = size(DevicePixels(width), DevicePixels(height)); let scale_factor = lock.scale_factor; - if may_have_been_minimized { + if lock.restore_from_minimized.is_some() { lock.renderer .update_drawable_size_even_if_unchanged(new_size); + lock.callbacks.request_frame = lock.restore_from_minimized.take(); } else { lock.renderer.update_drawable_size(new_size); } diff --git a/crates/gpui/src/platform/windows/window.rs b/crates/gpui/src/platform/windows/window.rs index cb8bde647d594..e2389f0dba443 100644 --- a/crates/gpui/src/platform/windows/window.rs +++ b/crates/gpui/src/platform/windows/window.rs @@ -38,7 +38,7 @@ pub struct WindowsWindowState { pub fullscreen_restore_bounds: Bounds, pub border_offset: WindowBorderOffset, pub scale_factor: f32, - pub is_minimized: Option, + pub restore_from_minimized: Option>, pub callbacks: Callbacks, pub input_handler: Option, @@ -94,7 +94,7 @@ impl WindowsWindowState { size: logical_size, }; let border_offset = WindowBorderOffset::default(); - let is_minimized = None; + let restore_from_minimized = None; let renderer = windows_renderer::init(gpu_context, hwnd, transparent)?; let callbacks = Callbacks::default(); let input_handler = None; @@ -112,7 +112,7 @@ impl WindowsWindowState { fullscreen_restore_bounds, border_offset, scale_factor, - is_minimized, + restore_from_minimized, callbacks, input_handler, system_key_handled,