This commit is contained in:
Anas Limem 2026-05-30 23:50:33 +01:00 committed by GitHub
commit 904be4f77a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 5 deletions

View file

@ -679,6 +679,8 @@ pub struct App {
pub(crate) text_rendering_mode: Rc<Cell<TextRenderingMode>>,
pub(crate) window_update_stack: Vec<WindowId>,
/// Tracks the last active window for cascading new windows.
pub(crate) last_active_window: Option<AnyWindowHandle>,
pub(crate) mode: GpuiMode,
pub(crate) cursor_hide_mode: CursorHideMode,
/// Whether the app was created by [`Application::new_inaccessible`]. No
@ -739,6 +741,7 @@ impl App {
new_entity_observers: SubscriberSet::new(),
windows: SlotMap::with_key(),
window_update_stack: Vec::new(),
last_active_window: None,
window_handles: FxHashMap::default(),
focus_handles: Arc::new(RwLock::new(SlotMap::with_key())),
keymap: Rc::new(RefCell::new(Keymap::default())),
@ -1140,6 +1143,9 @@ impl App {
match Window::new(handle.into(), options, cx) {
Ok(mut window) => {
cx.window_update_stack.push(id);
if cx.window_update_stack.len() == 1 {
cx.last_active_window = Some(window.handle);
}
let root_view = build_root_view(&mut window, cx);
cx.window_update_stack.pop();
window.root.replace(root_view.into());
@ -1650,6 +1656,9 @@ impl App {
let root_view = window.root.clone().unwrap();
cx.window_update_stack.push(window.handle.id);
if cx.window_update_stack.len() == 1 {
cx.last_active_window = Some(window.handle);
}
let result = update(root_view, &mut window, cx);
fn trail(id: WindowId, window: Box<Window>, cx: &mut App) -> Option<()> {
cx.window_update_stack.pop();

View file

@ -1184,14 +1184,16 @@ pub(crate) struct ElementStateBox {
}
fn default_bounds(display_id: Option<DisplayId>, cx: &mut App) -> WindowBounds {
// TODO, BUG: if you open a window with the currently active window
// on the stack, this will erroneously fallback to `None`
//
// TODO these should be the initial window bounds not considering maximized/fullscreen
let active_window_bounds = cx
.active_window()
.and_then(|w| w.update(cx, |_, window, _| window.window_bounds()).ok());
// If no platform active window, try the tracked last active window
let active_window_bounds = active_window_bounds.or_else(|| {
cx.last_active_window
.and_then(|w| w.update(cx, |_, window, _| window.window_bounds()).ok())
});
const CASCADE_OFFSET: f32 = 25.0;
let display = display_id

View file

@ -2014,10 +2014,13 @@ impl Workspace {
{
// Reopening an existing workspace - restore its saved bounds
(Some(bounds.0), Some(display))
} else if project_paths.is_empty() {
// Truly new window (empty, no paths) - let GPUI handle cascading
(None, None)
} else if let Some((display, bounds)) =
persistence::read_default_window_bounds(&kvp)
{
// New or empty workspace - use the last known window bounds
// Opening existing paths but new workspace - use persisted bounds
(Some(bounds), Some(display))
} else {
// New window - let GPUI's default_bounds() handle cascading