diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 0baff67e94..c8e8efec79 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -1924,84 +1924,11 @@ impl MutableAppContext { ); root_view.update(this, |view, cx| view.on_focus_in(cx.handle().into(), cx)); - let mut window = + let window = this.cx .platform .open_window(window_id, window_options, this.foreground.clone()); - let presenter = Rc::new(RefCell::new(this.build_presenter( - window_id, - window.titlebar_height(), - window.appearance(), - ))); - - { - let mut app = this.upgrade(); - let presenter = Rc::downgrade(&presenter); - window.on_event(Box::new(move |event| { - app.update(|cx| { - if let Some(presenter) = presenter.upgrade() { - if let Event::KeyDown(KeyDownEvent { keystroke, .. }) = &event { - if cx.dispatch_keystroke(window_id, keystroke) { - return true; - } - } - - presenter.borrow_mut().dispatch_event(event, false, cx) - } else { - false - } - }) - })); - } - - { - let mut app = this.upgrade(); - window.on_active_status_change(Box::new(move |is_active| { - app.update(|cx| cx.window_changed_active_status(window_id, is_active)) - })); - } - - { - let mut app = this.upgrade(); - window.on_resize(Box::new(move || { - app.update(|cx| cx.window_was_resized(window_id)) - })); - } - - { - let mut app = this.upgrade(); - window.on_fullscreen(Box::new(move |is_fullscreen| { - app.update(|cx| cx.window_was_fullscreen_changed(window_id, is_fullscreen)) - })); - } - - { - let mut app = this.upgrade(); - window.on_close(Box::new(move || { - app.update(|cx| cx.remove_window(window_id)); - })); - } - - { - let mut app = this.upgrade(); - window - .on_appearance_changed(Box::new(move || app.update(|cx| cx.refresh_windows()))); - } - - window.set_input_handler(Box::new(WindowInputHandler { - app: this.upgrade().0, - window_id, - })); - - let scene = presenter.borrow_mut().build_scene( - window.size(), - window.scale_factor(), - false, - this, - ); - window.present_scene(scene); - this.presenters_and_platform_windows - .insert(window_id, (presenter.clone(), window)); + this.register_platform_window(window_id, window); (window_id, root_view) }) @@ -2029,47 +1956,91 @@ impl MutableAppContext { ); root_view.update(this, |view, cx| view.on_focus_in(cx.handle().into(), cx)); - let mut status_item = this.cx.platform.add_status_item(); - let presenter = Rc::new(RefCell::new(this.build_presenter( - window_id, - 0., - status_item.appearance(), - ))); - - { - let mut app = this.upgrade(); - let presenter = Rc::downgrade(&presenter); - status_item.on_event(Box::new(move |event| { - app.update(|cx| { - if let Some(presenter) = presenter.upgrade() { - presenter.borrow_mut().dispatch_event(event, false, cx) - } else { - false - } - }) - })); - } - - { - let mut app = this.upgrade(); - status_item - .on_appearance_changed(Box::new(move || app.update(|cx| cx.refresh_windows()))); - } - - let scene = presenter.borrow_mut().build_scene( - status_item.size(), - status_item.scale_factor(), - false, - this, - ); - status_item.present_scene(scene); - this.presenters_and_platform_windows - .insert(window_id, (presenter.clone(), status_item)); + let status_item = this.cx.platform.add_status_item(); + this.register_platform_window(window_id, status_item); (window_id, root_view) }) } + fn register_platform_window( + &mut self, + window_id: usize, + mut window: Box, + ) { + let presenter = Rc::new(RefCell::new(self.build_presenter( + window_id, + window.titlebar_height(), + window.appearance(), + ))); + + { + let mut app = self.upgrade(); + let presenter = Rc::downgrade(&presenter); + window.on_event(Box::new(move |event| { + app.update(|cx| { + if let Some(presenter) = presenter.upgrade() { + if let Event::KeyDown(KeyDownEvent { keystroke, .. }) = &event { + if cx.dispatch_keystroke(window_id, keystroke) { + return true; + } + } + + presenter.borrow_mut().dispatch_event(event, false, cx) + } else { + false + } + }) + })); + } + + { + let mut app = self.upgrade(); + window.on_active_status_change(Box::new(move |is_active| { + app.update(|cx| cx.window_changed_active_status(window_id, is_active)) + })); + } + + { + let mut app = self.upgrade(); + window.on_resize(Box::new(move || { + app.update(|cx| cx.window_was_resized(window_id)) + })); + } + + { + let mut app = self.upgrade(); + window.on_fullscreen(Box::new(move |is_fullscreen| { + app.update(|cx| cx.window_was_fullscreen_changed(window_id, is_fullscreen)) + })); + } + + { + let mut app = self.upgrade(); + window.on_close(Box::new(move || { + app.update(|cx| cx.remove_window(window_id)); + })); + } + + { + let mut app = self.upgrade(); + window.on_appearance_changed(Box::new(move || app.update(|cx| cx.refresh_windows()))); + } + + window.set_input_handler(Box::new(WindowInputHandler { + app: self.upgrade().0, + window_id, + })); + + let scene = + presenter + .borrow_mut() + .build_scene(window.size(), window.scale_factor(), false, self); + window.present_scene(scene); + self.presenters_and_platform_windows + .insert(window_id, (presenter.clone(), window)); + } + pub fn replace_root_view(&mut self, window_id: usize, build_root_view: F) -> ViewHandle where T: View, diff --git a/crates/gpui/src/platform/mac/status_item.rs b/crates/gpui/src/platform/mac/status_item.rs index a6570e4890..b99b707bff 100644 --- a/crates/gpui/src/platform/mac/status_item.rs +++ b/crates/gpui/src/platform/mac/status_item.rs @@ -186,29 +186,17 @@ impl platform::Window for StatusItem { self.0.borrow_mut().appearance_changed_callback = Some(callback); } - fn on_active_status_change(&mut self, _: Box) { - unimplemented!() - } + fn on_active_status_change(&mut self, _: Box) {} - fn on_resize(&mut self, _: Box) { - unimplemented!() - } + fn on_resize(&mut self, _: Box) {} - fn on_fullscreen(&mut self, _: Box) { - unimplemented!() - } + fn on_fullscreen(&mut self, _: Box) {} - fn on_should_close(&mut self, _: Box bool>) { - unimplemented!() - } + fn on_should_close(&mut self, _: Box bool>) {} - fn on_close(&mut self, _: Box) { - unimplemented!() - } + fn on_close(&mut self, _: Box) {} - fn set_input_handler(&mut self, _: Box) { - unimplemented!() - } + fn set_input_handler(&mut self, _: Box) {} fn prompt( &self,