Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
linux: Fix non-maximized Zed windows growing larger across sessions (#22301)
timsca9cee85e195
diff --git a/crates/gpui/src/platform.rs b/crates/gpui/src/platform.rsindex 18c6199c768..e01d3e61f02 100644--- a/crates/gpui/src/platform.rs+++ b/crates/gpui/src/platform.rs@@ -420,6 +420,9 @@ pub(crate) trait PlatformWindow: HasWindowHandle + HasDisplayHandle {fn get_raw_handle(&self) -> windows::HWND;// Linux specific methods+ fn inner_window_bounds(&self) -> WindowBounds {+ self.window_bounds()+ }fn request_decorations(&self, _decorations: WindowDecorations) {}fn show_window_menu(&self, _position: Point<Pixels>) {}fn start_window_move(&self) {}diff --git a/crates/gpui/src/platform/linux/wayland/window.rs b/crates/gpui/src/platform/linux/wayland/window.rsindex bb1a687c32e..4cdc8929a5f 100644--- a/crates/gpui/src/platform/linux/wayland/window.rs+++ b/crates/gpui/src/platform/linux/wayland/window.rs@@ -781,6 +781,19 @@ impl PlatformWindow for WaylandWindow {}}+ fn inner_window_bounds(&self) -> WindowBounds {+ let state = self.borrow();+ if state.fullscreen {+ WindowBounds::Fullscreen(state.window_bounds)+ } else if state.maximized {+ WindowBounds::Maximized(state.window_bounds)+ } else {+ let inset = state.inset.unwrap_or(px(0.));+ drop(state);+ WindowBounds::Windowed(self.bounds().inset(inset))+ }+ }+fn content_size(&self) -> Size<Pixels> {self.borrow().bounds.size}diff --git a/crates/gpui/src/platform/linux/x11/window.rs b/crates/gpui/src/platform/linux/x11/window.rsindex 9a685773a2c..ed6467a5e16 100644--- a/crates/gpui/src/platform/linux/x11/window.rs+++ b/crates/gpui/src/platform/linux/x11/window.rs@@ -1100,6 +1100,30 @@ impl PlatformWindow for X11Window {}}+ fn inner_window_bounds(&self) -> WindowBounds {+ let state = self.0.state.borrow();+ if self.is_maximized() {+ WindowBounds::Maximized(state.bounds)+ } else {+ let mut bounds = state.bounds;+ let [left, right, top, bottom] = state.last_insets;++ let [left, right, top, bottom] = [+ Pixels((left as f32) / state.scale_factor),+ Pixels((right as f32) / state.scale_factor),+ Pixels((top as f32) / state.scale_factor),+ Pixels((bottom as f32) / state.scale_factor),+ ];++ bounds.origin.x += left;+ bounds.origin.y += top;+ bounds.size.width -= left + right;+ bounds.size.height -= top + bottom;++ WindowBounds::Windowed(bounds)+ }+ }+fn content_size(&self) -> Size<Pixels> {// We divide by the scale factor here because this value is queried to determine how much to draw,// but it will be multiplied later by the scale to adjust for scaling.diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rsindex 437de7dcb31..3bc8eda9a19 100644--- a/crates/gpui/src/window.rs+++ b/crates/gpui/src/window.rs@@ -999,6 +999,11 @@ impl<'a> WindowContext<'a> {self.window.platform_window.window_bounds()}+ /// Return the `WindowBounds` excluding insets (Wayland and X11)+ pub fn inner_window_bounds(&self) -> WindowBounds {+ self.window.platform_window.inner_window_bounds()+ }+/// Dispatch the given action on the currently focused element.pub fn dispatch_action(&mut self, action: Box<dyn Action>) {let focus_handle = self.focused();diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rsindex be7c13d5931..8c724351b4a 100644--- a/crates/workspace/src/workspace.rs+++ b/crates/workspace/src/workspace.rs@@ -995,7 +995,7 @@ impl Workspace {this.update(&mut cx, |this, cx| {if let Some(display) = cx.display() {if let Ok(display_uuid) = display.uuid() {- let window_bounds = cx.window_bounds();+ let window_bounds = cx.inner_window_bounds();if let Some(database_id) = workspace_id {cx.background_executor().spawn(DB.set_window_open_status(