Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Store AnyWindowHandles instead of usizes
Nathan Soboafd89b256abb
diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rsindex e6e11ca321b..507cbffad27 100644--- a/crates/gpui/src/app.rs+++ b/crates/gpui/src/app.rs@@ -444,9 +444,9 @@ type WindowShouldCloseSubscriptionCallback = Box<dyn FnMut(&mut AppContext) -> bpub struct AppContext {models: HashMap<usize, Box<dyn AnyModel>>,- views: HashMap<(usize, usize), Box<dyn AnyView>>,- views_metadata: HashMap<(usize, usize), ViewMetadata>,- windows: HashMap<usize, Window>,+ views: HashMap<(AnyWindowHandle, usize), Box<dyn AnyView>>,+ views_metadata: HashMap<(AnyWindowHandle, usize), ViewMetadata>,+ windows: HashMap<AnyWindowHandle, Window>,globals: HashMap<TypeId, Box<dyn Any>>,element_states: HashMap<ElementStateId, Box<dyn Any>>,background: Arc<executor::Background>,@@ -727,12 +727,12 @@ impl AppContext {}pub fn view_ui_name(&self, window: AnyWindowHandle, view_id: usize) -> Option<&'static str> {- Some(self.views.get(&(window.id(), view_id))?.ui_name())+ Some(self.views.get(&(window, view_id))?.ui_name())}pub fn view_type_id(&self, window: AnyWindowHandle, view_id: usize) -> Option<TypeId> {self.views_metadata- .get(&(window.id(), view_id))+ .get(&(window, view_id)).map(|metadata| metadata.type_id)}@@ -758,7 +758,7 @@ impl AppContext {handle: AnyWindowHandle,callback: F,) -> Option<T> {- let window = self.windows.get(&handle.id())?;+ let window = self.windows.get(&handle)?;let window_context = WindowContext::immutable(self, &window, handle);Some(callback(&window_context))}@@ -1033,7 +1033,7 @@ impl AppContext {if let Some(focused_view_id) = cx.focused_view_id() {for view_id in cx.ancestors(focused_view_id) {if let Some(view_metadata) =- cx.views_metadata.get(&(cx.window_handle.id(), view_id))+ cx.views_metadata.get(&(cx.window_handle, view_id)){if let Some(actions) = cx.actions.get(&view_metadata.type_id) {if actions.contains_key(&action_id) {@@ -1259,13 +1259,12 @@ impl AppContext {F: FnOnce(&mut ViewContext<V>) -> V,{self.update(|this| {- let window_id = post_inc(&mut this.next_id);+ let handle = WindowHandle::<V>::new(post_inc(&mut this.next_id));let platform_window =this.platform- .open_window(window_id, window_options, this.foreground.clone());- let handle = WindowHandle::<V>::new(window_id);- let window = this.build_window(handle, platform_window, build_root_view);- this.windows.insert(window_id, window);+ .open_window(handle.into(), window_options, this.foreground.clone());+ let window = this.build_window(handle.into(), platform_window, build_root_view);+ this.windows.insert(handle.into(), window);handle})}@@ -1276,29 +1275,25 @@ impl AppContext {F: FnOnce(&mut ViewContext<V>) -> V,{self.update(|this| {- let window_id = post_inc(&mut this.next_id);- let platform_window = this.platform.add_status_item(window_id);- let handle = WindowHandle::<V>::new(window_id);- let window = this.build_window(handle, platform_window, build_root_view);- this.windows.insert(window_id, window);+ let handle = WindowHandle::<V>::new(post_inc(&mut this.next_id));+ let platform_window = this.platform.add_status_item(handle.into());+ let window = this.build_window(handle.into(), platform_window, build_root_view);+ this.windows.insert(handle.into(), window);handle.update_root(this, |view, cx| view.focus_in(cx.handle().into_any(), cx));handle})}- pub fn build_window<H, V, F>(+ pub fn build_window<V, F>(&mut self,- handle: H,+ handle: AnyWindowHandle,mut platform_window: Box<dyn platform::Window>,build_root_view: F,) -> Windowwhere- H: Into<AnyWindowHandle>,V: View,F: FnOnce(&mut ViewContext<V>) -> V,{- let handle: AnyWindowHandle = handle.into();-{let mut app = self.upgrade();@@ -1371,21 +1366,15 @@ impl AppContext {}pub fn active_window(&self) -> Option<AnyWindowHandle> {- self.platform.main_window_id().and_then(|main_window_id| {- self.windows- .get(&main_window_id)- .map(|window| AnyWindowHandle::new(main_window_id, window.root_view().type_id()))- })+ self.platform.main_window()}pub fn windows(&self) -> impl '_ + Iterator<Item = AnyWindowHandle> {- self.windows.iter().map(|(window_id, window)| {- AnyWindowHandle::new(*window_id, window.root_view().type_id())- })+ self.windows.keys().copied()}pub fn read_view<T: View>(&self, handle: &ViewHandle<T>) -> &T {- if let Some(view) = self.views.get(&(handle.window.id(), handle.view_id)) {+ if let Some(view) = self.views.get(&(handle.window, handle.view_id)) {view.as_any().downcast_ref().expect("downcast is type safe")} else {panic!("circular view reference for type {}", type_name::<T>());@@ -1437,13 +1426,13 @@ impl AppContext {.push_back(Effect::ModelRelease { model_id, model });}- for (window_id, view_id) in dropped_views {+ for (window, view_id) in dropped_views {self.subscriptions.remove(view_id);self.observations.remove(view_id);- self.views_metadata.remove(&(window_id, view_id));- let mut view = self.views.remove(&(window_id, view_id)).unwrap();+ self.views_metadata.remove(&(window, view_id));+ let mut view = self.views.remove(&(window, view_id)).unwrap();view.release(self);- if let Some(window) = self.windows.get_mut(&window_id) {+ if let Some(window) = self.windows.get_mut(&window) {window.parents.remove(&view_id);window.invalidation@@ -1571,7 +1560,7 @@ impl AppContext {}Effect::ResizeWindow { window } => {- if let Some(window) = self.windows.get_mut(&window.id()) {+ if let Some(window) = self.windows.get_mut(&window) {window.invalidation.get_or_insert(WindowInvalidation::default());@@ -1696,15 +1685,14 @@ impl AppContext {for old_ancestor in old_ancestors.iter().copied() {if !new_ancestors.contains(&old_ancestor) {if let Some(mut view) =- cx.views.remove(&(window.id(), old_ancestor))+ cx.views.remove(&(window, old_ancestor)){view.focus_out(focused_view_id,cx,old_ancestor,);- cx.views- .insert((window.id(), old_ancestor), view);+ cx.views.insert((window, old_ancestor), view);}}}@@ -1713,15 +1701,14 @@ impl AppContext {for new_ancestor in new_ancestors.iter().copied() {if !old_ancestors.contains(&new_ancestor) {if let Some(mut view) =- cx.views.remove(&(window.id(), new_ancestor))+ cx.views.remove(&(window, new_ancestor)){view.focus_in(focused_view_id,cx,new_ancestor,);- cx.views- .insert((window.id(), new_ancestor), view);+ cx.views.insert((window, new_ancestor), view);}}}@@ -1730,9 +1717,7 @@ impl AppContext {// there isn't any pending focus, focus the root view.let root_view_id = cx.window.root_view().id();if focused_view_id != root_view_id- && !cx- .views- .contains_key(&(window.id(), focused_view_id))+ && !cx.views.contains_key(&(window, focused_view_id))&& !focus_effects.contains_key(&window.id()){focus_effects.insert(@@ -1837,13 +1822,13 @@ impl AppContext {observed_window: AnyWindowHandle,observed_view_id: usize,) {- let view_key = (observed_window.id(), observed_view_id);+ let view_key = (observed_window, observed_view_id);if let Some((view, mut view_metadata)) = self.views.remove(&view_key).zip(self.views_metadata.remove(&view_key)){- if let Some(window) = self.windows.get_mut(&observed_window.id()) {+ if let Some(window) = self.windows.get_mut(&observed_window) {window.invalidation.get_or_insert_with(Default::default)@@ -1924,7 +1909,7 @@ impl AppContext {let focused_id = match effect {FocusEffect::View { view_id, .. } => {if let Some(view_id) = view_id {- if cx.views.contains_key(&(window.id(), view_id)) {+ if cx.views.contains_key(&(window, view_id)) {Some(view_id)} else {Some(cx.root_view().id())@@ -1949,9 +1934,9 @@ impl AppContext {if focus_changed {if let Some(blurred_id) = blurred_id {for view_id in cx.ancestors(blurred_id).collect::<Vec<_>>() {- if let Some(mut view) = cx.views.remove(&(window.id(), view_id)) {+ if let Some(mut view) = cx.views.remove(&(window, view_id)) {view.focus_out(blurred_id, cx, view_id);- cx.views.insert((window.id(), view_id), view);+ cx.views.insert((window, view_id), view);}}@@ -1963,9 +1948,9 @@ impl AppContext {if focus_changed || effect.is_forced() {if let Some(focused_id) = focused_id {for view_id in cx.ancestors(focused_id).collect::<Vec<_>>() {- if let Some(mut view) = cx.views.remove(&(window.id(), view_id)) {+ if let Some(mut view) = cx.views.remove(&(window, view_id)) {view.focus_in(focused_id, cx, view_id);- cx.views.insert((window.id(), view_id), view);+ cx.views.insert((window, view_id), view);}}@@ -1991,7 +1976,7 @@ impl AppContext {mut callback: WindowShouldCloseSubscriptionCallback,) {let mut app = self.upgrade();- if let Some(window) = self.windows.get_mut(&window.id()) {+ if let Some(window) = self.windows.get_mut(&window) {window.platform_window.on_should_close(Box::new(move || app.update(|cx| callback(cx))))@@ -2127,15 +2112,13 @@ impl BorrowWindowContext for AppContext {whereF: FnOnce(&mut WindowContext) -> T,{- self.update(|app_context| {- let mut window = app_context.windows.remove(&handle.id())?;- let mut window_context = WindowContext::mutable(app_context, &mut window, handle);- let result = f(&mut window_context);- if !window_context.removed {- app_context.windows.insert(handle.id(), window);- }- Some(result)- })+ let mut window = self.windows.remove(&handle)?;+ let mut window_context = WindowContext::mutable(self, &mut window, handle);+ let result = f(&mut window_context);+ if !window_context.removed {+ self.windows.insert(handle, window);+ }+ Some(result)}fn update_window_optional<T, F>(&mut self, handle: AnyWindowHandle, f: F) -> Option<T>@@ -2590,7 +2573,7 @@ where} else {let focused_type = cx.views_metadata- .get(&(cx.window_handle.id(), focused_id))+ .get(&(cx.window_handle, focused_id)).unwrap().type_id;AnyViewHandle::new(@@ -2610,7 +2593,7 @@ where} else {let blurred_type = cx.views_metadata- .get(&(cx.window_handle.id(), blurred_id))+ .get(&(cx.window_handle, blurred_id)).unwrap().type_id;AnyViewHandle::new(@@ -3413,7 +3396,7 @@ impl<'a, 'b, 'c, V: View> LayoutContext<'a, 'b, 'c, V> {let mut contexts = Vec::new();let mut handler_depth = None;for (i, view_id) in self.ancestors(view_id).enumerate() {- if let Some(view_metadata) = self.views_metadata.get(&(window.id(), view_id)) {+ if let Some(view_metadata) = self.views_metadata.get(&(window, view_id)) {if let Some(actions) = self.actions.get(&view_metadata.type_id) {if actions.contains_key(&action.id()) {handler_depth = Some(i);@@ -3873,10 +3856,7 @@ impl<V> Copy for WindowHandle<V> {}impl<V: View> WindowHandle<V> {fn new(window_id: usize) -> Self {WindowHandle {- any_handle: AnyWindowHandle {- window_id,- root_view_type: TypeId::of::<V>(),- },+ any_handle: AnyWindowHandle::new(window_id, TypeId::of::<V>()),root_view_type: PhantomData,}}@@ -4240,7 +4220,7 @@ impl AnyViewHandle {view_type: TypeId,ref_counts: Arc<Mutex<RefCounts>>,) -> Self {- ref_counts.lock().inc_view(window.id(), view_id);+ ref_counts.lock().inc_view(window, view_id);#[cfg(any(test, feature = "test-support"))]let handle_id = ref_counts@@ -4308,7 +4288,7 @@ impl AnyViewHandle {pub fn debug_json<'a, 'b>(&self, cx: &'b WindowContext<'a>) -> serde_json::Value {cx.views- .get(&(self.window.id(), self.view_id))+ .get(&(self.window, self.view_id)).map_or_else(|| serde_json::Value::Null, |view| view.debug_json(cx))}}@@ -4338,9 +4318,7 @@ impl<T> PartialEq<ViewHandle<T>> for AnyViewHandle {impl Drop for AnyViewHandle {fn drop(&mut self) {- self.ref_counts- .lock()- .dec_view(self.window.id(), self.view_id);+ self.ref_counts.lock().dec_view(self.window, self.view_id);#[cfg(any(test, feature = "test-support"))]self.ref_counts.lock()diff --git a/crates/gpui/src/app/ref_counts.rs b/crates/gpui/src/app/ref_counts.rsindex f0c1699f165..63905326fe2 100644--- a/crates/gpui/src/app/ref_counts.rs+++ b/crates/gpui/src/app/ref_counts.rs@@ -9,7 +9,7 @@ use collections::{hash_map::Entry, HashMap, HashSet};#[cfg(any(test, feature = "test-support"))]use crate::util::post_inc;-use crate::ElementStateId;+use crate::{AnyWindowHandle, ElementStateId};lazy_static! {static ref LEAK_BACKTRACE: bool =@@ -26,7 +26,7 @@ pub struct RefCounts {entity_counts: HashMap<usize, usize>,element_state_counts: HashMap<ElementStateId, ElementStateRefCount>,dropped_models: HashSet<usize>,- dropped_views: HashSet<(usize, usize)>,+ dropped_views: HashSet<(AnyWindowHandle, usize)>,dropped_element_states: HashSet<ElementStateId>,#[cfg(any(test, feature = "test-support"))]@@ -55,12 +55,12 @@ impl RefCounts {}}- pub fn inc_view(&mut self, window_id: usize, view_id: usize) {+ pub fn inc_view(&mut self, window: AnyWindowHandle, view_id: usize) {match self.entity_counts.entry(view_id) {Entry::Occupied(mut entry) => *entry.get_mut() += 1,Entry::Vacant(entry) => {entry.insert(1);- self.dropped_views.remove(&(window_id, view_id));+ self.dropped_views.remove(&(window, view_id));}}}@@ -94,12 +94,12 @@ impl RefCounts {}}- pub fn dec_view(&mut self, window_id: usize, view_id: usize) {+ pub fn dec_view(&mut self, window: AnyWindowHandle, view_id: usize) {let count = self.entity_counts.get_mut(&view_id).unwrap();*count -= 1;if *count == 0 {self.entity_counts.remove(&view_id);- self.dropped_views.insert((window_id, view_id));+ self.dropped_views.insert((window, view_id));}}@@ -120,7 +120,7 @@ impl RefCounts {&mut self,) -> (HashSet<usize>,- HashSet<(usize, usize)>,+ HashSet<(AnyWindowHandle, usize)>,HashSet<ElementStateId>,) {(diff --git a/crates/gpui/src/app/test_app_context.rs b/crates/gpui/src/app/test_app_context.rsindex b1729d89b85..6d593c2e724 100644--- a/crates/gpui/src/app/test_app_context.rs+++ b/crates/gpui/src/app/test_app_context.rs@@ -159,7 +159,7 @@ impl TestAppContext {.borrow_mut().add_window(Default::default(), build_root_view);window.simulate_activation(self);- WindowHandle::new(window.id())+ window}pub fn observe_global<E, F>(&mut self, callback: F) -> Subscription@@ -516,7 +516,7 @@ impl AnyWindowHandle {cx: &'a mut TestAppContext,) -> std::cell::RefMut<'a, platform::test::Window> {std::cell::RefMut::map(cx.cx.borrow_mut(), |state| {- let window = state.windows.get_mut(&self.window_id).unwrap();+ let window = state.windows.get_mut(&self).unwrap();let test_window = window.platform_window.as_any_mut()diff --git a/crates/gpui/src/app/window.rs b/crates/gpui/src/app/window.rsindex df3f8207556..d39219e65d4 100644--- a/crates/gpui/src/app/window.rs+++ b/crates/gpui/src/app/window.rs@@ -235,9 +235,9 @@ impl<'a> WindowContext<'a> {F: FnOnce(&mut dyn AnyView, &mut Self) -> T,{let handle = self.window_handle;- let mut view = self.views.remove(&(handle.id(), view_id))?;+ let mut view = self.views.remove(&(handle, view_id))?;let result = f(view.as_mut(), self);- self.views.insert((handle.id(), view_id), view);+ self.views.insert((handle, view_id), view);Some(result)}@@ -389,7 +389,7 @@ impl<'a> WindowContext<'a> {let mut contexts = Vec::new();let mut handler_depths_by_action_id = HashMap::<TypeId, usize>::default();for (depth, view_id) in self.ancestors(view_id).enumerate() {- if let Some(view_metadata) = self.views_metadata.get(&(handle.id(), view_id)) {+ if let Some(view_metadata) = self.views_metadata.get(&(handle, view_id)) {contexts.push(view_metadata.keymap_context.clone());if let Some(actions) = self.actions.get(&view_metadata.type_id) {handler_depths_by_action_id@@ -440,7 +440,7 @@ impl<'a> WindowContext<'a> {.ancestors(focused_view_id).filter_map(|view_id| {self.views_metadata- .get(&(handle.id(), view_id))+ .get(&(handle, view_id)).map(|view| (view_id, view.keymap_context.clone()))}).collect();@@ -850,9 +850,9 @@ impl<'a> WindowContext<'a> {let handle = self.window_handle;if let Some(focused_view_id) = self.window.focused_view_id {for view_id in self.ancestors(focused_view_id).collect::<Vec<_>>() {- if let Some(mut view) = self.views.remove(&(handle.id(), view_id)) {+ if let Some(mut view) = self.views.remove(&(handle, view_id)) {let handled = view.key_down(event, self, view_id);- self.views.insert((handle.id(), view_id), view);+ self.views.insert((handle, view_id), view);if handled {return true;}@@ -869,9 +869,9 @@ impl<'a> WindowContext<'a> {let handle = self.window_handle;if let Some(focused_view_id) = self.window.focused_view_id {for view_id in self.ancestors(focused_view_id).collect::<Vec<_>>() {- if let Some(mut view) = self.views.remove(&(handle.id(), view_id)) {+ if let Some(mut view) = self.views.remove(&(handle, view_id)) {let handled = view.key_up(event, self, view_id);- self.views.insert((handle.id(), view_id), view);+ self.views.insert((handle, view_id), view);if handled {return true;}@@ -888,9 +888,9 @@ impl<'a> WindowContext<'a> {let handle = self.window_handle;if let Some(focused_view_id) = self.window.focused_view_id {for view_id in self.ancestors(focused_view_id).collect::<Vec<_>>() {- if let Some(mut view) = self.views.remove(&(handle.id(), view_id)) {+ if let Some(mut view) = self.views.remove(&(handle, view_id)) {let handled = view.modifiers_changed(event, self, view_id);- self.views.insert((handle.id(), view_id), view);+ self.views.insert((handle, view_id), view);if handled {return true;}@@ -929,10 +929,10 @@ impl<'a> WindowContext<'a> {let view_id = params.view_id;let mut view = self.views- .remove(&(handle.id(), view_id))+ .remove(&(handle, view_id)).ok_or_else(|| anyhow!("view not found"))?;let element = view.render(self, view_id);- self.views.insert((handle.id(), view_id), view);+ self.views.insert((handle, view_id), view);Ok(element)}@@ -1190,13 +1190,13 @@ impl<'a> WindowContext<'a> {let mut keymap_context = KeymapContext::default();view.update_keymap_context(&mut keymap_context, cx.app_context());self.views_metadata.insert(- (handle.id(), view_id),+ (handle, view_id),ViewMetadata {type_id: TypeId::of::<T>(),keymap_context,},);- self.views.insert((handle.id(), view_id), Box::new(view));+ self.views.insert((handle, view_id), Box::new(view));self.window.invalidation.get_or_insert_with(Default::default)diff --git a/crates/gpui/src/app/window_input_handler.rs b/crates/gpui/src/app/window_input_handler.rsindex d7c65b11fae..bdc871a8027 100644--- a/crates/gpui/src/app/window_input_handler.rs+++ b/crates/gpui/src/app/window_input_handler.rs@@ -23,7 +23,7 @@ impl WindowInputHandler {let mut app = self.app.try_borrow_mut().ok()?;self.window.update_optional(&mut *app, |cx| {let view_id = cx.window.focused_view_id?;- let view = cx.views.get(&(self.window.id(), view_id))?;+ let view = cx.views.get(&(self.window, view_id))?;let result = f(view.as_ref(), &cx);Some(result)})diff --git a/crates/gpui/src/platform.rs b/crates/gpui/src/platform.rsindex 67f8e52c04f..1d93a45fc7b 100644--- a/crates/gpui/src/platform.rs+++ b/crates/gpui/src/platform.rs@@ -19,7 +19,7 @@ use crate::{},keymap_matcher::KeymapMatcher,text_layout::{LineLayout, RunStyle},- Action, ClipboardItem, Menu, Scene,+ Action, AnyWindowHandle, ClipboardItem, Menu, Scene,};use anyhow::{anyhow, bail, Result};use async_task::Runnable;@@ -58,13 +58,13 @@ pub trait Platform: Send + Sync {fn open_window(&self,- id: usize,+ handle: AnyWindowHandle,options: WindowOptions,executor: Rc<executor::Foreground>,) -> Box<dyn Window>;- fn main_window_id(&self) -> Option<usize>;+ fn main_window(&self) -> Option<AnyWindowHandle>;- fn add_status_item(&self, id: usize) -> Box<dyn Window>;+ fn add_status_item(&self, handle: AnyWindowHandle) -> Box<dyn Window>;fn write_to_clipboard(&self, item: ClipboardItem);fn read_from_clipboard(&self) -> Option<ClipboardItem>;diff --git a/crates/gpui/src/platform/mac/platform.rs b/crates/gpui/src/platform/mac/platform.rsindex 509c979b853..277ff8403f8 100644--- a/crates/gpui/src/platform/mac/platform.rs+++ b/crates/gpui/src/platform/mac/platform.rs@@ -6,7 +6,7 @@ use crate::{executor,keymap_matcher::KeymapMatcher,platform::{self, AppVersion, CursorStyle, Event},- Action, ClipboardItem, Menu, MenuItem,+ Action, AnyWindowHandle, ClipboardItem, Menu, MenuItem,};use anyhow::{anyhow, Result};use block::ConcreteBlock;@@ -590,18 +590,18 @@ impl platform::Platform for MacPlatform {fn open_window(&self,- id: usize,+ handle: AnyWindowHandle,options: platform::WindowOptions,executor: Rc<executor::Foreground>,) -> Box<dyn platform::Window> {- Box::new(Window::open(id, options, executor, self.fonts()))+ Box::new(Window::open(handle, options, executor, self.fonts()))}- fn main_window_id(&self) -> Option<usize> {- Window::main_window_id()+ fn main_window(&self) -> Option<AnyWindowHandle> {+ Window::main_window()}- fn add_status_item(&self, _id: usize) -> Box<dyn platform::Window> {+ fn add_status_item(&self, _handle: AnyWindowHandle) -> Box<dyn platform::Window> {Box::new(StatusItem::add(self.fonts()))}diff --git a/crates/gpui/src/platform/mac/window.rs b/crates/gpui/src/platform/mac/window.rsindex c0f0ade7b92..59324f473a9 100644--- a/crates/gpui/src/platform/mac/window.rs+++ b/crates/gpui/src/platform/mac/window.rs@@ -13,6 +13,7 @@ use crate::{Event, InputHandler, KeyDownEvent, Modifiers, ModifiersChangedEvent, MouseButton,MouseButtonEvent, MouseMovedEvent, Scene, WindowBounds, WindowKind,},+ AnyWindowHandle,};use block::ConcreteBlock;use cocoa::{@@ -282,7 +283,7 @@ struct InsertText {}struct WindowState {- id: usize,+ handle: AnyWindowHandle,native_window: id,kind: WindowKind,event_callback: Option<Box<dyn FnMut(Event) -> bool>>,@@ -426,7 +427,7 @@ pub struct Window(Rc<RefCell<WindowState>>);impl Window {pub fn open(- id: usize,+ handle: AnyWindowHandle,options: platform::WindowOptions,executor: Rc<executor::Foreground>,fonts: Arc<dyn platform::FontSystem>,@@ -504,7 +505,7 @@ impl Window {assert!(!native_view.is_null());let window = Self(Rc::new(RefCell::new(WindowState {- id,+ handle,native_window,kind: options.kind,event_callback: None,@@ -621,13 +622,13 @@ impl Window {}}- pub fn main_window_id() -> Option<usize> {+ pub fn main_window() -> Option<AnyWindowHandle> {unsafe {let app = NSApplication::sharedApplication(nil);let main_window: id = msg_send![app, mainWindow];if msg_send![main_window, isKindOfClass: WINDOW_CLASS] {- let id = get_window_state(&*main_window).borrow().id;- Some(id)+ let handle = get_window_state(&*main_window).borrow().handle;+ Some(handle)} else {None}@@ -881,7 +882,7 @@ impl platform::Window for Window {fn is_topmost_for_position(&self, position: Vector2F) -> bool {let self_borrow = self.0.borrow();- let self_id = self_borrow.id;+ let self_id = self_borrow.handle;unsafe {let app = NSApplication::sharedApplication(nil);@@ -898,7 +899,7 @@ impl platform::Window for Window {let is_panel: BOOL = msg_send![top_most_window, isKindOfClass: PANEL_CLASS];let is_window: BOOL = msg_send![top_most_window, isKindOfClass: WINDOW_CLASS];if is_panel == YES || is_window == YES {- let topmost_window_id = get_window_state(&*top_most_window).borrow().id;+ let topmost_window_id = get_window_state(&*top_most_window).borrow().handle;topmost_window_id == self_id} else {// Someone else's window is on topdiff --git a/crates/gpui/src/platform/test.rs b/crates/gpui/src/platform/test.rsindex f949a6cd78e..6c11817b5c1 100644--- a/crates/gpui/src/platform/test.rs+++ b/crates/gpui/src/platform/test.rs@@ -5,7 +5,7 @@ use crate::{vector::{vec2f, Vector2F},},keymap_matcher::KeymapMatcher,- Action, ClipboardItem, Menu,+ Action, AnyWindowHandle, ClipboardItem, Menu,};use anyhow::{anyhow, Result};use collections::VecDeque;@@ -102,7 +102,7 @@ pub struct Platform {fonts: Arc<dyn super::FontSystem>,current_clipboard_item: Mutex<Option<ClipboardItem>>,cursor: Mutex<CursorStyle>,- active_window_id: Arc<Mutex<Option<usize>>>,+ active_window: Arc<Mutex<Option<AnyWindowHandle>>>,}impl Platform {@@ -112,7 +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(),+ active_window: Default::default(),}}}@@ -146,30 +146,30 @@ impl super::Platform for Platform {fn open_window(&self,- id: usize,+ handle: AnyWindowHandle,options: super::WindowOptions,_executor: Rc<super::executor::Foreground>,) -> Box<dyn super::Window> {- *self.active_window_id.lock() = Some(id);+ *self.active_window.lock() = Some(handle);Box::new(Window::new(- id,+ handle,match options.bounds {WindowBounds::Maximized | WindowBounds::Fullscreen => vec2f(1024., 768.),WindowBounds::Fixed(rect) => rect.size(),},- self.active_window_id.clone(),+ self.active_window.clone(),))}- fn main_window_id(&self) -> Option<usize> {- self.active_window_id.lock().clone()+ fn main_window(&self) -> Option<AnyWindowHandle> {+ self.active_window.lock().clone()}- fn add_status_item(&self, id: usize) -> Box<dyn crate::platform::Window> {+ fn add_status_item(&self, handle: AnyWindowHandle) -> Box<dyn crate::platform::Window> {Box::new(Window::new(- id,+ handle,vec2f(24., 24.),- self.active_window_id.clone(),+ self.active_window.clone(),))}@@ -256,7 +256,7 @@ impl super::Screen for Screen {}pub struct Window {- id: usize,+ handle: AnyWindowHandle,pub(crate) size: Vector2F,scale_factor: f32,current_scene: Option<crate::Scene>,@@ -270,13 +270,17 @@ pub struct Window {pub(crate) title: Option<String>,pub(crate) edited: bool,pub(crate) pending_prompts: RefCell<VecDeque<oneshot::Sender<usize>>>,- active_window_id: Arc<Mutex<Option<usize>>>,+ active_window: Arc<Mutex<Option<AnyWindowHandle>>>,}impl Window {- pub fn new(id: usize, size: Vector2F, active_window_id: Arc<Mutex<Option<usize>>>) -> Self {+ pub fn new(+ handle: AnyWindowHandle,+ size: Vector2F,+ active_window: Arc<Mutex<Option<AnyWindowHandle>>>,+ ) -> Self {Self {- id,+ handle,size,event_handlers: Default::default(),resize_handlers: Default::default(),@@ -290,7 +294,7 @@ impl Window {title: None,edited: false,pending_prompts: Default::default(),- active_window_id,+ active_window,}}@@ -342,7 +346,7 @@ impl super::Window for Window {}fn activate(&self) {- *self.active_window_id.lock() = Some(self.id);+ *self.active_window.lock() = Some(self.handle);}fn set_title(&mut self, title: &str) {