windows: Avoid recording minimized position to database (#9407)

Minimizing window records strange position to DB. When Zed is restarted,
the window goes far away.
<img width="975" alt="image"
src="https://github.com/zed-industries/zed/assets/6465609/98dbab71-fdbb-4911-b41a-9c3e498e5478">

So I fixed.

Release Notes:

- N/A
This commit is contained in:
白山風露 2024-03-22 01:15:16 +09:00 committed by GitHub
parent f88f1bce20
commit f179158913
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 40 additions and 11 deletions

View File

@ -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;

View File

@ -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 {

View File

@ -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()
}

View File

@ -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()
}

View File

@ -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()
}

View File

@ -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

View File

@ -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();

View File

@ -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);