From 4a46227909820fe6f5014f72b7758a3242d67e6c Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Thu, 19 Jan 2023 11:43:46 -0800 Subject: [PATCH 1/5] Change incoming call notification to only require one click --- crates/collab_ui/src/incoming_call_notification.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/collab_ui/src/incoming_call_notification.rs b/crates/collab_ui/src/incoming_call_notification.rs index a51fb4891d20ee303d35992ef1c2dbc298dd1562..daf93ce6a213b6083915d4d390b67194309dea80 100644 --- a/crates/collab_ui/src/incoming_call_notification.rs +++ b/crates/collab_ui/src/incoming_call_notification.rs @@ -48,6 +48,7 @@ pub fn init(cx: &mut MutableAppContext) { }, |_| IncomingCallNotification::new(incoming_call.clone()), ); + cx.activate_window(window_id); notification_windows.push(window_id); } } From 4eeb1aec50f45a07ce3101bfa12eacc950235ee2 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Thu, 19 Jan 2023 14:22:12 -0800 Subject: [PATCH 2/5] Adds UI for showing the followed-by status to collaboration --- crates/collab_ui/src/collab_titlebar_item.rs | 12 ++++++++++-- crates/workspace/src/workspace.rs | 11 ++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/crates/collab_ui/src/collab_titlebar_item.rs b/crates/collab_ui/src/collab_titlebar_item.rs index 3351fb9eb9c14c7f82f0f4d27243776a5b419161..ffafa2d142c427614bc87daab65d85a947d92673 100644 --- a/crates/collab_ui/src/collab_titlebar_item.rs +++ b/crates/collab_ui/src/collab_titlebar_item.rs @@ -417,9 +417,13 @@ impl CollabTitlebarItem { theme: &Theme, cx: &mut RenderContext, ) -> ElementBox { - let is_followed = peer.map_or(false, |(peer_id, _, _)| { - workspace.read(cx).is_following(peer_id) + let (is_followed, is_following) = peer.map_or((false, false), |(peer_id, _, _)| { + ( + workspace.read(cx).is_following(peer_id), + workspace.read(cx).is_followed(peer_id), + ) }); + // my color, around their avatar. let mut avatar_style; if let Some((_, _, location)) = peer.as_ref() { @@ -442,6 +446,10 @@ impl CollabTitlebarItem { replica_color = Some(color); if is_followed { avatar_style.border = Border::all(1.0, color); + } else if is_following { + let our_id = workspace.read(cx).project().read(cx).replica_id(); + let our_color = theme.editor.replica_selection_style(our_id).cursor; + avatar_style.border = Border::all(1.0, our_color); } } diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 58517346097af8b6f79d1fe0bb60b837d037af60..6a8fdaa17b4e54d49d8868e7ebbbc3cdc8e32c21 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -1623,6 +1623,7 @@ impl Workspace { project_id, leader_id: Some(leader_id), }); + Some(cx.spawn_weak(|this, mut cx| async move { let response = request.await?; if let Some(this) = this.upgrade(&cx) { @@ -1719,6 +1720,10 @@ impl Workspace { self.follower_states_by_leader.contains_key(&peer_id) } + pub fn is_followed(&self, peer_id: PeerId) -> bool { + self.leader_state.followers.contains(&peer_id) + } + fn render_titlebar(&self, theme: &Theme, cx: &mut RenderContext) -> ElementBox { let project = &self.project.read(cx); let mut worktree_root_names = String::new(); @@ -1896,6 +1901,9 @@ impl Workspace { .to_proto(), ) }); + + cx.notify(); + Ok(proto::FollowResponse { active_view_id, views: this @@ -1928,10 +1936,11 @@ impl Workspace { _: Arc, mut cx: AsyncAppContext, ) -> Result<()> { - this.update(&mut cx, |this, _| { + this.update(&mut cx, |this, cx| { this.leader_state .followers .remove(&envelope.original_sender_id()?); + cx.notify(); Ok(()) }) } From 88170df7f0dfcb445f3c3dc3d34c3d34054ce89e Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Thu, 19 Jan 2023 15:21:26 -0800 Subject: [PATCH 3/5] Switched from active hover to NSViews acceptsFirstMouse API --- crates/collab_ui/src/collab_titlebar_item.rs | 12 ++---------- .../collab_ui/src/incoming_call_notification.rs | 4 +++- .../collab_ui/src/project_shared_notification.rs | 1 + crates/gpui/src/platform.rs | 2 ++ crates/gpui/src/platform/mac/window.rs | 15 +++++++++++++++ crates/zed/src/zed.rs | 1 + 6 files changed, 24 insertions(+), 11 deletions(-) diff --git a/crates/collab_ui/src/collab_titlebar_item.rs b/crates/collab_ui/src/collab_titlebar_item.rs index ffafa2d142c427614bc87daab65d85a947d92673..3351fb9eb9c14c7f82f0f4d27243776a5b419161 100644 --- a/crates/collab_ui/src/collab_titlebar_item.rs +++ b/crates/collab_ui/src/collab_titlebar_item.rs @@ -417,13 +417,9 @@ impl CollabTitlebarItem { theme: &Theme, cx: &mut RenderContext, ) -> ElementBox { - let (is_followed, is_following) = peer.map_or((false, false), |(peer_id, _, _)| { - ( - workspace.read(cx).is_following(peer_id), - workspace.read(cx).is_followed(peer_id), - ) + let is_followed = peer.map_or(false, |(peer_id, _, _)| { + workspace.read(cx).is_following(peer_id) }); - // my color, around their avatar. let mut avatar_style; if let Some((_, _, location)) = peer.as_ref() { @@ -446,10 +442,6 @@ impl CollabTitlebarItem { replica_color = Some(color); if is_followed { avatar_style.border = Border::all(1.0, color); - } else if is_following { - let our_id = workspace.read(cx).project().read(cx).replica_id(); - let our_color = theme.editor.replica_selection_style(our_id).cursor; - avatar_style.border = Border::all(1.0, our_color); } } diff --git a/crates/collab_ui/src/incoming_call_notification.rs b/crates/collab_ui/src/incoming_call_notification.rs index daf93ce6a213b6083915d4d390b67194309dea80..f0daa3c7e8617040d10a616b2f6353b068310ece 100644 --- a/crates/collab_ui/src/incoming_call_notification.rs +++ b/crates/collab_ui/src/incoming_call_notification.rs @@ -45,10 +45,11 @@ pub fn init(cx: &mut MutableAppContext) { kind: WindowKind::PopUp, is_movable: false, screen: Some(screen), + accepts_first_mouse: true, }, |_| IncomingCallNotification::new(incoming_call.clone()), ); - cx.activate_window(window_id); + notification_windows.push(window_id); } } @@ -226,6 +227,7 @@ impl View for IncomingCallNotification { .theme .incoming_call_notification .background; + Flex::row() .with_child(self.render_caller(cx)) .with_child(self.render_buttons(cx)) diff --git a/crates/collab_ui/src/project_shared_notification.rs b/crates/collab_ui/src/project_shared_notification.rs index 0815d9c8d8c02c6756f65c61ca0b4c5187d0b016..858886a0e3e5ba7669e476ed6202ba20f72c011f 100644 --- a/crates/collab_ui/src/project_shared_notification.rs +++ b/crates/collab_ui/src/project_shared_notification.rs @@ -44,6 +44,7 @@ pub fn init(cx: &mut MutableAppContext) { kind: WindowKind::PopUp, is_movable: false, screen: Some(screen), + accepts_first_mouse: true, }, |_| { ProjectSharedNotification::new( diff --git a/crates/gpui/src/platform.rs b/crates/gpui/src/platform.rs index d027218040909e2412248221de1371fbd22d573a..ad4d7542d300ce9c64db6fb0d2de7f628f56337e 100644 --- a/crates/gpui/src/platform.rs +++ b/crates/gpui/src/platform.rs @@ -156,6 +156,7 @@ pub struct WindowOptions<'a> { pub kind: WindowKind, pub is_movable: bool, pub screen: Option>, + pub accepts_first_mouse: bool, } #[derive(Debug)] @@ -301,6 +302,7 @@ impl<'a> Default for WindowOptions<'a> { kind: WindowKind::Normal, is_movable: true, screen: None, + accepts_first_mouse: false, } } } diff --git a/crates/gpui/src/platform/mac/window.rs b/crates/gpui/src/platform/mac/window.rs index 958ac2ebd67ea294c942dea7dfba7fc525e1f2d4..a929ba08a333458bf85f9b4b262b063506e6b704 100644 --- a/crates/gpui/src/platform/mac/window.rs +++ b/crates/gpui/src/platform/mac/window.rs @@ -252,6 +252,11 @@ unsafe fn build_classes() { do_command_by_selector as extern "C" fn(&Object, Sel, Sel), ); + decl.add_method( + sel!(acceptsFirstMouse:), + accepts_first_mouse as extern "C" fn(&Object, Sel, id) -> BOOL, + ); + decl.register() }; } @@ -338,6 +343,7 @@ struct WindowState { ime_state: ImeState, //Retains the last IME Text ime_text: Option, + accepts_first_mouse: bool, } struct InsertText { @@ -444,6 +450,7 @@ impl Window { previous_modifiers_changed_event: None, ime_state: ImeState::None, ime_text: None, + accepts_first_mouse: options.accepts_first_mouse, }))); (*native_window).set_ivar( @@ -1404,6 +1411,14 @@ extern "C" fn view_did_change_effective_appearance(this: &Object, _: Sel) { } } +extern "C" fn accepts_first_mouse(this: &Object, _: Sel, _: id) -> BOOL { + unsafe { + let state = get_window_state(this); + let state_borrow = state.as_ref().borrow(); + return state_borrow.accepts_first_mouse as BOOL; + } +} + async fn synthetic_drag( window_state: Weak>, drag_id: usize, diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index c3af91306dce4b1ba79bf46f52fdce79daa34cff..248bab5fdacb58fdf5f5f715932cf4d0598b7691 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -408,6 +408,7 @@ pub fn build_window_options() -> WindowOptions<'static> { kind: WindowKind::Normal, is_movable: true, screen: None, + accepts_first_mouse: false, } } From 95e661a78c38947c83f59f69e82ba9497924db5a Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Thu, 19 Jan 2023 15:21:26 -0800 Subject: [PATCH 4/5] Switched from active hover to NSViews acceptsFirstMouse API Co-authored-by: Nathan --- crates/gpui/src/platform/mac/window.rs | 1 + crates/gpui/src/presenter.rs | 1 + crates/workspace/src/workspace.rs | 11 ++++++++--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/gpui/src/platform/mac/window.rs b/crates/gpui/src/platform/mac/window.rs index a929ba08a333458bf85f9b4b262b063506e6b704..f5a21c46440a4b4f1e45276a181f37e3b018dfe0 100644 --- a/crates/gpui/src/platform/mac/window.rs +++ b/crates/gpui/src/platform/mac/window.rs @@ -443,6 +443,7 @@ impl Window { scene_to_render: Default::default(), renderer: Renderer::new(true, fonts), last_fresh_keydown: None, + accepts_first_mouse: matches!(options.kind, WindowKind::PopUp), traffic_light_position: options .titlebar .as_ref() diff --git a/crates/gpui/src/presenter.rs b/crates/gpui/src/presenter.rs index bbaf1ed0bbce3ec2a096e37719354ce100d00db6..4ccc319219c33c4f882d2a27ed2c0b0d43796e5f 100644 --- a/crates/gpui/src/presenter.rs +++ b/crates/gpui/src/presenter.rs @@ -156,6 +156,7 @@ impl Presenter { self.cursor_regions = scene.cursor_regions(); self.mouse_regions = scene.mouse_regions(); + // window.is_topmost for the mouse moved event's postion? if cx.window_is_active(self.window_id) { if let Some(event) = self.last_mouse_moved_event.clone() { self.dispatch_event(event, true, cx); diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 6a8fdaa17b4e54d49d8868e7ebbbc3cdc8e32c21..9665db6be60955af11c10979cad87bbc23a29ed5 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -31,14 +31,18 @@ use futures::{ }; use gpui::{ actions, + color::Color, elements::*, - geometry::vector::Vector2F, + geometry::{ + rect::RectF, + vector::{vec2f, Vector2F}, + }, impl_actions, impl_internal_actions, keymap_matcher::KeymapContext, platform::{CursorStyle, WindowOptions}, AnyModelHandle, AnyViewHandle, AppContext, AsyncAppContext, Entity, ModelContext, ModelHandle, MouseButton, MutableAppContext, PathPromptOptions, PromptLevel, RenderContext, SizeConstraint, - Task, View, ViewContext, ViewHandle, WeakViewHandle, + Task, View, ViewContext, ViewHandle, WeakViewHandle, WindowBounds, WindowKind, }; use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ProjectItem}; use language::LanguageRegistry; @@ -98,7 +102,8 @@ actions!( ToggleLeftSidebar, ToggleRightSidebar, NewTerminal, - NewSearch + NewSearch, + ShowNotif, ] ); From 97203e1e02fdf3c25d5ffd037d495947a74ac6d5 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Fri, 20 Jan 2023 09:19:58 -0800 Subject: [PATCH 5/5] Fix broken merge --- crates/collab_ui/src/incoming_call_notification.rs | 1 - crates/collab_ui/src/project_shared_notification.rs | 1 - crates/gpui/src/platform.rs | 4 +--- crates/gpui/src/platform/mac/window.rs | 3 +-- crates/workspace/src/workspace.rs | 8 ++------ crates/zed/src/zed.rs | 1 - 6 files changed, 4 insertions(+), 14 deletions(-) diff --git a/crates/collab_ui/src/incoming_call_notification.rs b/crates/collab_ui/src/incoming_call_notification.rs index f0daa3c7e8617040d10a616b2f6353b068310ece..6ad533665e7477494e221da71f85a31646671447 100644 --- a/crates/collab_ui/src/incoming_call_notification.rs +++ b/crates/collab_ui/src/incoming_call_notification.rs @@ -45,7 +45,6 @@ pub fn init(cx: &mut MutableAppContext) { kind: WindowKind::PopUp, is_movable: false, screen: Some(screen), - accepts_first_mouse: true, }, |_| IncomingCallNotification::new(incoming_call.clone()), ); diff --git a/crates/collab_ui/src/project_shared_notification.rs b/crates/collab_ui/src/project_shared_notification.rs index 858886a0e3e5ba7669e476ed6202ba20f72c011f..0815d9c8d8c02c6756f65c61ca0b4c5187d0b016 100644 --- a/crates/collab_ui/src/project_shared_notification.rs +++ b/crates/collab_ui/src/project_shared_notification.rs @@ -44,7 +44,6 @@ pub fn init(cx: &mut MutableAppContext) { kind: WindowKind::PopUp, is_movable: false, screen: Some(screen), - accepts_first_mouse: true, }, |_| { ProjectSharedNotification::new( diff --git a/crates/gpui/src/platform.rs b/crates/gpui/src/platform.rs index ad4d7542d300ce9c64db6fb0d2de7f628f56337e..99d607e4070c5eebb2039dba3754e6100a59b30a 100644 --- a/crates/gpui/src/platform.rs +++ b/crates/gpui/src/platform.rs @@ -156,7 +156,6 @@ pub struct WindowOptions<'a> { pub kind: WindowKind, pub is_movable: bool, pub screen: Option>, - pub accepts_first_mouse: bool, } #[derive(Debug)] @@ -180,7 +179,7 @@ impl Default for Appearance { } } -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] pub enum WindowKind { Normal, PopUp, @@ -302,7 +301,6 @@ impl<'a> Default for WindowOptions<'a> { kind: WindowKind::Normal, is_movable: true, screen: None, - accepts_first_mouse: false, } } } diff --git a/crates/gpui/src/platform/mac/window.rs b/crates/gpui/src/platform/mac/window.rs index f5a21c46440a4b4f1e45276a181f37e3b018dfe0..26305e86da7fe08e645b12536581934e18e15a38 100644 --- a/crates/gpui/src/platform/mac/window.rs +++ b/crates/gpui/src/platform/mac/window.rs @@ -443,7 +443,7 @@ impl Window { scene_to_render: Default::default(), renderer: Renderer::new(true, fonts), last_fresh_keydown: None, - accepts_first_mouse: matches!(options.kind, WindowKind::PopUp), + accepts_first_mouse: options.kind == WindowKind::PopUp, traffic_light_position: options .titlebar .as_ref() @@ -451,7 +451,6 @@ impl Window { previous_modifiers_changed_event: None, ime_state: ImeState::None, ime_text: None, - accepts_first_mouse: options.accepts_first_mouse, }))); (*native_window).set_ivar( diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 9665db6be60955af11c10979cad87bbc23a29ed5..8735f33fbe6cfd3197bd825e8c5abc01652eea46 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -31,18 +31,14 @@ use futures::{ }; use gpui::{ actions, - color::Color, elements::*, - geometry::{ - rect::RectF, - vector::{vec2f, Vector2F}, - }, + geometry::vector::Vector2F, impl_actions, impl_internal_actions, keymap_matcher::KeymapContext, platform::{CursorStyle, WindowOptions}, AnyModelHandle, AnyViewHandle, AppContext, AsyncAppContext, Entity, ModelContext, ModelHandle, MouseButton, MutableAppContext, PathPromptOptions, PromptLevel, RenderContext, SizeConstraint, - Task, View, ViewContext, ViewHandle, WeakViewHandle, WindowBounds, WindowKind, + Task, View, ViewContext, ViewHandle, WeakViewHandle, }; use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ProjectItem}; use language::LanguageRegistry; diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index 248bab5fdacb58fdf5f5f715932cf4d0598b7691..c3af91306dce4b1ba79bf46f52fdce79daa34cff 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -408,7 +408,6 @@ pub fn build_window_options() -> WindowOptions<'static> { kind: WindowKind::Normal, is_movable: true, screen: None, - accepts_first_mouse: false, } }