Switched from active hover to NSViews acceptsFirstMouse API

Mikayla Maki created

Change summary

crates/collab_ui/src/collab_titlebar_item.rs        | 12 ++----------
crates/collab_ui/src/incoming_call_notification.rs  |  4 +++-
crates/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(-)

Detailed changes

crates/collab_ui/src/collab_titlebar_item.rs 🔗

@@ -417,13 +417,9 @@ impl CollabTitlebarItem {
         theme: &Theme,
         cx: &mut RenderContext<Self>,
     ) -> 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);
             }
         }
 

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))

crates/gpui/src/platform.rs 🔗

@@ -156,6 +156,7 @@ pub struct WindowOptions<'a> {
     pub kind: WindowKind,
     pub is_movable: bool,
     pub screen: Option<Rc<dyn Screen>>,
+    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,
         }
     }
 }

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<String>,
+    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<RefCell<WindowState>>,
     drag_id: usize,

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,
     }
 }