T30: a window that shows again is read again, so a size it took just before something covered it, or it was minimized, is kept once it shows; the window opens centered at whole points, since macOS grew a window whose centered edge fell on a half point by a point
CI / platforms (ubuntu-24.04) (push) Successful in 55s
CI / platforms (windows-latest) (push) Successful in 1m26s
CI / macos (push) Canceled after 13m8s

This commit is contained in:
ZacharyZhang-NY committed 2026-10-16 04:25:58 -04:00
1 parent 2f58a0670e
commit 9729d24605
3 files changed
+20 -8

No files matched your search

+18 -6
View File
@@ -1,4 +1,4 @@
use std::{borrow::Cow, time::Duration};
use std::{borrow::Cow, cell::RefCell, rc::Rc, time::Duration};
use anyhow::Context as _;
use ely_gpui_component::theme::ActiveTheme;
@@ -89,7 +89,9 @@ pub fn start(cx: &mut App) -> anyhow::Result<()> {
/// Opens the main window running `launch`.
pub fn open(launch: Launch, cx: &mut App) -> anyhow::Result<WindowHandle<Workspace>> {
let kept = opening_size(cx);
let bounds = Bounds::centered(None, kept, cx);
// macOS grows a window by a point on a side whose edge falls on a half point.
let centered = Bounds::centered(None, kept, cx);
let bounds = Bounds::new(centered.origin.map(|at| at.round()), kept);
let background = blur::appearance(SettingsStore::get(cx));
let least = px(*settings::WINDOW.start());
let options = WindowOptions {
@@ -149,9 +151,9 @@ fn opening_size(cx: &App) -> Size<Pixels> {
/// Keeps the window's size in the settings once it settles; maximized, full screen or hidden, the size before stays.
fn keep_size(window: &mut Window, cx: &mut Context<Workspace>) {
let mut _settling: Option<Task<()>> = None;
cx.observe_window_bounds(window, move |_, window, cx| {
_settling = Some(cx.spawn_in(window, async move |_, cx| {
let settling: Rc<RefCell<Option<Task<()>>>> = Rc::default();
let settle = move |window: &mut Window, cx: &mut Context<Workspace>| {
let task = cx.spawn_in(window, async move |_, cx| {
cx.background_executor().timer(SETTLE).await;
// Read once settled: X11 marks a window maximized late, and unmaximized while hidden.
let kept = cx.update(|window, cx| {
@@ -179,7 +181,17 @@ fn keep_size(window: &mut Window, cx: &mut Context<Workspace>) {
Ok(Err(error)) => log::error!("{error:#}"),
Err(_) => log::debug!("app: the window closed before its size settled"),
}
}));
});
settling.replace(Some(task));
};
let shown = settle.clone();
cx.observe_window_bounds(window, move |_, window, cx| settle(window, cx))
.detach();
// A size skipped while the window hid is read again once it shows.
cx.observe_window_visibility(window, move |_, visibility, window, cx| {
if visibility.is_visible() {
shown(window, cx);
}
})
.detach();
}