From 6db4a25b37905972cc7f45f60ad984d2f19f0b14 Mon Sep 17 00:00:00 2001 From: Jary Date: Sat, 14 Feb 2026 05:56:31 +0800 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20foreground=20minimized=20window?= =?UTF-8?q?s=20when=20changing=20displays=20(#48902)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit on windows 10, When a laptop is plugged into or unplugged from a monitor, Zed and my using GPUI app will restore from minimized state to the foreground. Closes #ISSUE - [ ] Tests or screenshots needed? - [ ] Code Reviewed - [ ] Manual QA Release Notes: - N/A *or* Added/Fixed/Improved ... --------- Co-authored-by: John Tur --- crates/gpui/src/platform/windows/display.rs | 5 ---- crates/gpui/src/platform/windows/events.rs | 26 --------------------- 2 files changed, 31 deletions(-) diff --git a/crates/gpui/src/platform/windows/display.rs b/crates/gpui/src/platform/windows/display.rs index 720d459c1ce3b0251d8009dc2b77864727ed5441..f26ba835908ff1d14e76ddc5430cd8498f4b7a00 100644 --- a/crates/gpui/src/platform/windows/display.rs +++ b/crates/gpui/src/platform/windows/display.rs @@ -199,11 +199,6 @@ impl WindowsDisplay { .collect() } - /// Check if this monitor is still online - pub fn is_connected(hmonitor: HMONITOR) -> bool { - available_monitors().iter().contains(&hmonitor) - } - pub fn physical_bounds(&self) -> Bounds { self.physical_bounds } diff --git a/crates/gpui/src/platform/windows/events.rs b/crates/gpui/src/platform/windows/events.rs index 45bd3320c069f68fcf173b57662f9b843dd95cf9..d0504c9cf384352cc14db4b5d8c4daad53fbebb1 100644 --- a/crates/gpui/src/platform/windows/events.rs +++ b/crates/gpui/src/platform/windows/events.rs @@ -812,34 +812,8 @@ impl WindowsWindowInner { Some(0) } - /// The following conditions will trigger this event: - /// 1. The monitor on which the window is located goes offline or changes resolution. - /// 2. Another monitor goes offline, is plugged in, or changes resolution. - /// - /// In either case, the window will only receive information from the monitor on which - /// it is located. - /// - /// For example, in the case of condition 2, where the monitor on which the window is - /// located has actually changed nothing, it will still receive this event. fn handle_display_change_msg(&self, handle: HWND) -> Option { - // NOTE: - // Even the `lParam` holds the resolution of the screen, we just ignore it. - // Because WM_DPICHANGED, WM_MOVE, WM_SIZE will come first, window reposition and resize - // are handled there. - // So we only care about if monitor is disconnected. - let previous_monitor = self.state.display.get(); - if WindowsDisplay::is_connected(previous_monitor.handle) { - // we are fine, other display changed - return None; - } - // display disconnected - // in this case, the OS will move our window to another monitor, and minimize it. - // we deminimize the window and query the monitor after moving - unsafe { - let _ = ShowWindow(handle, SW_SHOWNORMAL); - }; let new_monitor = unsafe { MonitorFromWindow(handle, MONITOR_DEFAULTTONULL) }; - // all monitors disconnected if new_monitor.is_invalid() { log::error!("No monitor detected!"); return None;