Detailed changes
@@ -170,6 +170,7 @@ unsafe impl Send for DisplayId {}
pub(crate) trait PlatformWindow: HasWindowHandle + HasDisplayHandle {
fn bounds(&self) -> Bounds<GlobalPixels>;
fn is_maximized(&self) -> bool;
+ fn is_minimized(&self) -> bool;
fn content_size(&self) -> Size<Pixels>;
fn scale_factor(&self) -> f32;
fn appearance(&self) -> WindowAppearance;
@@ -283,6 +283,11 @@ impl PlatformWindow for WaylandWindow {
false
}
+ // todo(linux)
+ fn is_minimized(&self) -> bool {
+ false
+ }
+
fn content_size(&self) -> Size<Pixels> {
let inner = self.0.inner.borrow();
Size {
@@ -338,6 +338,11 @@ impl PlatformWindow for X11Window {
false
}
+ // todo(linux)
+ fn is_minimized(&self) -> bool {
+ false
+ }
+
fn content_size(&self) -> Size<Pixels> {
self.0.inner.borrow_mut().content_size()
}
@@ -419,6 +419,11 @@ impl MacWindowState {
}
}
+ // todo(macos)
+ fn is_minimized(&self) -> bool {
+ false
+ }
+
fn is_fullscreen(&self) -> bool {
unsafe {
let style_mask = self.native_window.styleMask();
@@ -728,6 +733,10 @@ impl PlatformWindow for MacWindow {
self.0.as_ref().lock().is_maximized()
}
+ fn is_minimized(&self) -> bool {
+ self.0.as_ref().lock().is_minimized()
+ }
+
fn content_size(&self) -> Size<Pixels> {
self.0.as_ref().lock().content_size()
}
@@ -115,6 +115,10 @@ impl PlatformWindow for TestWindow {
false
}
+ fn is_minimized(&self) -> bool {
+ false
+ }
+
fn content_size(&self) -> Size<Pixels> {
self.bounds().size.into()
}
@@ -126,12 +126,11 @@ impl WindowsWindowInner {
}
fn is_maximized(&self) -> bool {
- let mut placement = WINDOWPLACEMENT::default();
- placement.length = std::mem::size_of::<WINDOWPLACEMENT>() as u32;
- if unsafe { GetWindowPlacement(self.hwnd, &mut placement) }.is_ok() {
- return placement.showCmd == SW_SHOWMAXIMIZED.0 as u32;
- }
- return false;
+ unsafe { IsZoomed(self.hwnd) }.as_bool()
+ }
+
+ fn is_minimized(&self) -> bool {
+ unsafe { IsIconic(self.hwnd) }.as_bool()
}
pub(crate) fn title_bar_padding(&self) -> Pixels {
@@ -1168,10 +1167,6 @@ impl WindowsWindow {
unsafe { ShowWindow(wnd.inner.hwnd, SW_SHOW) };
wnd
}
-
- fn maximize(&self) {
- unsafe { ShowWindowAsync(self.inner.hwnd, SW_MAXIMIZE) };
- }
}
impl HasWindowHandle for WindowsWindow {
@@ -1215,6 +1210,10 @@ impl PlatformWindow for WindowsWindow {
self.inner.is_maximized()
}
+ fn is_minimized(&self) -> bool {
+ self.inner.is_minimized()
+ }
+
/// get the logical size of the app's drawable area.
///
/// Currently, GPUI uses logical size of the app to handle mouse interactions (such as
@@ -722,6 +722,12 @@ impl<'a> WindowContext<'a> {
self.window.platform_window.is_maximized()
}
+ /// Check if the platform window is minimized
+ /// On some platforms (namely Windows) the position is incorrect when minimized
+ pub fn is_minimized(&self) -> bool {
+ self.window.platform_window.is_minimized()
+ }
+
/// Dispatch the given action on the currently focused element.
pub fn dispatch_action(&mut self, action: Box<dyn Action>) {
let focus_handle = self.focused();
@@ -754,7 +754,7 @@ impl Workspace {
cx.background_executor()
.spawn(DB.set_fullscreen(workspace_id, true))
.detach_and_log_err(cx);
- } else {
+ } else if !cx.is_minimized() {
cx.background_executor()
.spawn(DB.set_fullscreen(workspace_id, false))
.detach_and_log_err(cx);