Don’t foreground minimized windows when changing displays (#48902)

Jary and John Tur created

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 <john-tur@outlook.com>

Change summary

crates/gpui/src/platform/windows/display.rs |  5 ----
crates/gpui/src/platform/windows/events.rs  | 26 -----------------------
2 files changed, 31 deletions(-)

Detailed changes

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<DevicePixels> {
         self.physical_bounds
     }

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<isize> {
-        // 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;