diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 2e9ac0f267..3e311aa50c 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -1315,7 +1315,7 @@ impl AppContext { { self.update(|this| { let window_id = post_inc(&mut this.next_window_id); - let platform_window = this.platform.add_status_item(); + let platform_window = this.platform.add_status_item(window_id); let window = this.build_window(window_id, platform_window, build_root_view); let root_view = window.root_view().clone().downcast::().unwrap(); diff --git a/crates/gpui/src/platform.rs b/crates/gpui/src/platform.rs index 4c0c319745..ec301939f7 100644 --- a/crates/gpui/src/platform.rs +++ b/crates/gpui/src/platform.rs @@ -63,7 +63,7 @@ pub trait Platform: Send + Sync { ) -> Box; fn main_window_id(&self) -> Option; - fn add_status_item(&self) -> Box; + fn add_status_item(&self, id: usize) -> Box; fn write_to_clipboard(&self, item: ClipboardItem); fn read_from_clipboard(&self) -> Option; diff --git a/crates/gpui/src/platform/mac/platform.rs b/crates/gpui/src/platform/mac/platform.rs index 41c196acc1..8b5b801ada 100644 --- a/crates/gpui/src/platform/mac/platform.rs +++ b/crates/gpui/src/platform/mac/platform.rs @@ -601,7 +601,7 @@ impl platform::Platform for MacPlatform { Window::main_window_id() } - fn add_status_item(&self) -> Box { + fn add_status_item(&self, _id: usize) -> Box { Box::new(StatusItem::add(self.fonts())) } diff --git a/crates/gpui/src/platform/test.rs b/crates/gpui/src/platform/test.rs index fa711c3eea..f949a6cd78 100644 --- a/crates/gpui/src/platform/test.rs +++ b/crates/gpui/src/platform/test.rs @@ -102,6 +102,7 @@ pub struct Platform { fonts: Arc, current_clipboard_item: Mutex>, cursor: Mutex, + active_window_id: Arc>>, } impl Platform { @@ -111,6 +112,7 @@ impl Platform { fonts: Arc::new(super::current::FontSystem::new()), current_clipboard_item: Default::default(), cursor: Mutex::new(CursorStyle::Arrow), + active_window_id: Default::default(), } } } @@ -144,22 +146,31 @@ impl super::Platform for Platform { fn open_window( &self, - _: usize, + id: usize, options: super::WindowOptions, _executor: Rc, ) -> Box { - Box::new(Window::new(match options.bounds { - WindowBounds::Maximized | WindowBounds::Fullscreen => vec2f(1024., 768.), - WindowBounds::Fixed(rect) => rect.size(), - })) + *self.active_window_id.lock() = Some(id); + Box::new(Window::new( + id, + match options.bounds { + WindowBounds::Maximized | WindowBounds::Fullscreen => vec2f(1024., 768.), + WindowBounds::Fixed(rect) => rect.size(), + }, + self.active_window_id.clone(), + )) } fn main_window_id(&self) -> Option { - None + self.active_window_id.lock().clone() } - fn add_status_item(&self) -> Box { - Box::new(Window::new(vec2f(24., 24.))) + fn add_status_item(&self, id: usize) -> Box { + Box::new(Window::new( + id, + vec2f(24., 24.), + self.active_window_id.clone(), + )) } fn write_to_clipboard(&self, item: ClipboardItem) { @@ -245,6 +256,7 @@ impl super::Screen for Screen { } pub struct Window { + id: usize, pub(crate) size: Vector2F, scale_factor: f32, current_scene: Option, @@ -258,11 +270,13 @@ pub struct Window { pub(crate) title: Option, pub(crate) edited: bool, pub(crate) pending_prompts: RefCell>>, + active_window_id: Arc>>, } impl Window { - pub fn new(size: Vector2F) -> Self { + pub fn new(id: usize, size: Vector2F, active_window_id: Arc>>) -> Self { Self { + id, size, event_handlers: Default::default(), resize_handlers: Default::default(), @@ -276,6 +290,7 @@ impl Window { title: None, edited: false, pending_prompts: Default::default(), + active_window_id, } } @@ -326,7 +341,9 @@ impl super::Window for Window { done_rx } - fn activate(&self) {} + fn activate(&self) { + *self.active_window_id.lock() = Some(self.id); + } fn set_title(&mut self, title: &str) { self.title = Some(title.to_string())