zed/crates/gpui/src
tims ca9cee85e1
linux: Fix non-maximized Zed windows growing larger across sessions (#22301)
Closes #17870

Context:

On Linux, when creating a new window, bounds are either pulled from
existing workspace data (serialized in an SQLite DB) or fall back to
some default constants if no data exists.

These bounds include the full dimensions of the window (width and
height), which already account for insets. However, properties like
`inset` (Wayland) or `last_insets` (X11) exist only at the platform
level and are not part of the window bounds themselves.

During rendering, we call `set_client_inset`, which updates the inset
values and also adjusts the window bounds, increasing their dimensions.
In Zed's case, the inset is 10px, which adds 20px to both the width and
height (10px from each side).

Problem:

When quitting, the full window bounds (which already account for inset)
are saved to the DB. On reopening, these saved bounds are used to create
the window. `set_client_inset` runs again and inflates the dimensions
even more.

Solution:

Store window bounds *without* the inset-inflated dimensions. On the next
session, `set_client_inset` will take care of applying the inset,
resulting window dimensions matching the previous session. This fix is
in the PR.

Alternative Solution:

Another option is to save the inset explicitly in the DB and apply it
during window creation. But this means storing more data, and the inset
would need to be platform-agnostic, which adds complexity. Doesn’t seem
worth it for no real gain.

X11 Before:
```sh
saving window bounds with width: 1136, height: 784
tims@lemon ~/w/zed (fix-window-growing-larger)> cargo run
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.37s
     Running `target/debug/zed`
saving window bounds with width: 1156, height: 804   <---- +20px
tims@lemon ~/w/zed (fix-window-growing-larger)> cargo run
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.35s
     Running `target/debug/zed`
saving window bounds with width: 1176, height: 824  <---- +20px
tims@lemon ~/w/zed (fix-window-growing-larger)> cargo run
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.36s
     Running `target/debug/zed`
saving window bounds with width: 1196, height: 844  <---- +20px
```

X11 After:
```sh
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.35s
     Running `target/debug/zed`
saving window bounds with width: 1116, height: 764
tims@lemon ~/w/zed (fix-window-growing-larger)> cargo run
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.35s
     Running `target/debug/zed`
saving window bounds with width: 1116, height: 764     <---- same
tims@lemon ~/w/zed (fix-window-growing-larger)> cargo run
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.35s
     Running `target/debug/zed`
saving window bounds with width: 1116, height: 764   <---- same
```

On Wayland, saving occurs only when you actually resize the window (on
X11, saving happens both on init and while dragging the window). To
trigger saving, I manually resized the window by ~1px to make it print.

Wayland Before:
```sh
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 1m 36s
     Running `target/debug/zed`
saving window bounds with width: 945, height: 577
tims@orange ~/zed (fix-window-growing-larger)> cargo run
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.77s
     Running `target/debug/zed`
saving window bounds with width: 966, height: 597    <--- +20px on both  (1px increase in width is me resizing)
tims@orange ~/zed (fix-window-growing-larger)> cargo run
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.87s
     Running `target/debug/zed`
saving window bounds with width: 987, height: 618    <--- +20px on both  (1px increase in width and height is me resizing)
tims@orange ~/zed (fix-window-growing-larger)> cargo run
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.89s
     Running `target/debug/zed`
saving window bounds with width: 1006, height: 638   <--- +20px on both  (1px decrease in width is me resizing)
```

Wayland After:
```sh
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.82s
     Running `target/debug/zed`
saving window bounds with width: 925, height: 558
tims@orange ~/zed (fix-window-growing-larger)> cargo run
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.84s
     Running `target/debug/zed`
saving window bounds with width: 925, height: 557     <--- same (1px decrease in height is me resizing)
saving window bounds with width: 925, height: 558
```

Release Notes:

- Fix non-maximized zed windows growing larger across sessions on Linux

---------

Co-authored-by: mgsloan@gmail.com <michael@zed.dev>
2024-12-20 22:23:25 +00:00
..
app Use LiveKit's Rust SDK on Linux while continue using Swift SDK on Mac (#21550) 2024-12-05 15:06:17 -08:00
elements Add Corner to geometry and make names of corner methods consistent (#22119) 2024-12-16 22:57:15 -07:00
keymap
platform linux: Fix non-maximized Zed windows growing larger across sessions (#22301) 2024-12-20 22:23:25 +00:00
text_system Allow splitting the terminal panel (#21238) 2024-11-27 20:22:39 +02:00
window
action.rs
app.rs Store focus handles in AppContext instead of Window (#22158) 2024-12-17 14:41:00 -07:00
arena.rs
asset_cache.rs
assets.rs
bounds_tree.rs
color.rs gpui: Add linear gradient support to fill background (#20812) 2024-12-11 21:52:52 +02:00
element.rs Store focus handles in AppContext instead of Window (#22158) 2024-12-17 14:41:00 -07:00
executor.rs Remove Task::get_ready method I added, which is unusable in practice (#22012) 2024-12-14 03:21:41 -07:00
geometry.rs Fix docs for Bounds::from_corner_and_size (#22265) 2024-12-19 21:50:52 +00:00
global.rs
gpui.rs gpui: Rename GPUSpecs to GpuSpecs (#22166) 2024-12-17 17:22:53 -05:00
input.rs
interactive.rs
key_dispatch.rs
keymap.rs
platform.rs linux: Fix non-maximized Zed windows growing larger across sessions (#22301) 2024-12-20 22:23:25 +00:00
prelude.rs gpui: Don't export named Context from prelude (#21869) 2024-12-11 13:21:40 -05:00
scene.rs gpui: Add linear gradient support to fill background (#20812) 2024-12-11 21:52:52 +02:00
shared_string.rs
shared_uri.rs
style.rs Add Corner to geometry and make names of corner methods consistent (#22119) 2024-12-16 22:57:15 -07:00
styled.rs
subscription.rs
svg_renderer.rs
taffy.rs
test.rs
text_system.rs
util.rs
view.rs Do not reuse render cache for nested items whose parents are re-rendered (#21165) 2024-11-25 15:58:45 +02:00
window.rs linux: Fix non-maximized Zed windows growing larger across sessions (#22301) 2024-12-20 22:23:25 +00:00