From 426aeb7c5e919801360eb46ccd6354f34e12da65 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Fri, 20 Jan 2023 18:10:24 -0800 Subject: [PATCH 1/5] WIP - adds platform APIs for checking the top most window --- crates/gpui/src/app.rs | 7 +++ crates/gpui/src/platform.rs | 3 +- crates/gpui/src/platform/mac/platform.rs | 15 ++++- crates/gpui/src/platform/mac/status_item.rs | 4 ++ crates/gpui/src/platform/mac/window.rs | 30 ++++++++++ crates/gpui/src/platform/test.rs | 6 +- crates/gpui/src/presenter.rs | 9 ++- crates/gpui/src/presenter/event_dispatcher.rs | 1 + crates/workspace/src/workspace.rs | 56 ++++++++++++++++++- 9 files changed, 126 insertions(+), 5 deletions(-) diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index ad1fad85b1..0e5697c30b 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -21,6 +21,7 @@ use std::{ use anyhow::{anyhow, Context, Result}; use lazy_static::lazy_static; use parking_lot::Mutex; +use pathfinder_geometry::vector::Vector2F; use postage::oneshot; use smallvec::SmallVec; use smol::prelude::*; @@ -865,6 +866,12 @@ impl MutableAppContext { } } + pub fn screen_position(&self, window_id: usize, view_position: &Vector2F) -> Option { + self.presenters_and_platform_windows + .get(&window_id) + .map(|(_, window)| window.screen_position(view_position)) + } + pub fn window_ids(&self) -> impl Iterator + '_ { self.cx.windows.keys().cloned() } diff --git a/crates/gpui/src/platform.rs b/crates/gpui/src/platform.rs index 99d607e407..0601fd9764 100644 --- a/crates/gpui/src/platform.rs +++ b/crates/gpui/src/platform.rs @@ -64,7 +64,7 @@ pub trait Platform: Send + Sync { fn read_credentials(&self, url: &str) -> Result)>>; fn delete_credentials(&self, url: &str) -> Result<()>; - fn set_cursor_style(&self, style: CursorStyle); + fn set_cursor_style(&self, style: CursorStyle, window_id: usize, screen_position: &Vector2F); fn should_auto_hide_scrollbars(&self) -> bool; fn local_timezone(&self) -> UtcOffset; @@ -145,6 +145,7 @@ pub trait Window { fn present_scene(&mut self, scene: Scene); fn appearance(&self) -> Appearance; fn on_appearance_changed(&mut self, callback: Box); + fn screen_position(&self, view_position: &Vector2F) -> Vector2F; } #[derive(Debug)] diff --git a/crates/gpui/src/platform/mac/platform.rs b/crates/gpui/src/platform/mac/platform.rs index 37406858ec..f1b7f75c03 100644 --- a/crates/gpui/src/platform/mac/platform.rs +++ b/crates/gpui/src/platform/mac/platform.rs @@ -37,6 +37,7 @@ use objc::{ runtime::{Class, Object, Sel}, sel, sel_impl, }; +use pathfinder_geometry::vector::Vector2F; use postage::oneshot; use ptr::null_mut; use std::{ @@ -695,7 +696,19 @@ impl platform::Platform for MacPlatform { Ok(()) } - fn set_cursor_style(&self, style: CursorStyle) { + fn set_cursor_style(&self, style: CursorStyle, window_id: usize, screen_position: &Vector2F) { + let top_most = Window::window_id_under(screen_position); + if top_most.is_none() { + return; + } + if top_most.unwrap() != window_id { + return; + } + + dbg!(top_most.unwrap(), window_id); + + dbg!(style); + unsafe { let cursor: id = match style { CursorStyle::Arrow => msg_send![class!(NSCursor), arrowCursor], diff --git a/crates/gpui/src/platform/mac/status_item.rs b/crates/gpui/src/platform/mac/status_item.rs index 33feb4808f..d05c559772 100644 --- a/crates/gpui/src/platform/mac/status_item.rs +++ b/crates/gpui/src/platform/mac/status_item.rs @@ -258,6 +258,10 @@ impl platform::Window for StatusItem { crate::Appearance::from_native(appearance) } } + + fn screen_position(&self, _view_position: &Vector2F) -> Vector2F { + unimplemented!() + } } impl StatusItemState { diff --git a/crates/gpui/src/platform/mac/window.rs b/crates/gpui/src/platform/mac/window.rs index 6126533644..032b88507b 100644 --- a/crates/gpui/src/platform/mac/window.rs +++ b/crates/gpui/src/platform/mac/window.rs @@ -559,6 +559,26 @@ impl Window { } } } + + pub fn window_id_under(screen_position: &Vector2F) -> Option { + unsafe { + let app = NSApplication::sharedApplication(nil); + + let point = NSPoint::new(screen_position.x() as f64, screen_position.y() as f64); + let window_number: NSInteger = msg_send![class!(NSWindow), windowNumberAtPoint:point belowWindowWithWindowNumber:0 as NSInteger]; + // For some reason this API doesn't work when our two windows are on top of each other + let top_most_window: id = msg_send![app, windowWithWindowNumber: window_number]; + dbg!(top_most_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 | is_window { + let id = get_window_state(&*top_most_window).borrow().id; + Some(id) + } else { + None + } + } + } } impl Drop for Window { @@ -755,6 +775,16 @@ impl platform::Window for Window { fn on_appearance_changed(&mut self, callback: Box) { self.0.borrow_mut().appearance_changed_callback = Some(callback); } + + fn screen_position(&self, view_position: &Vector2F) -> Vector2F { + let self_borrow = self.0.borrow_mut(); + unsafe { + let point = NSPoint::new(view_position.x() as f64, view_position.y() as f64); + let screen_point: NSPoint = + msg_send![self_borrow.native_window, convertPointToScreen: point]; + vec2f(screen_point.x as f32, screen_point.y as f32) + } + } } impl WindowState { diff --git a/crates/gpui/src/platform/test.rs b/crates/gpui/src/platform/test.rs index 00cd524c1d..7295bf525b 100644 --- a/crates/gpui/src/platform/test.rs +++ b/crates/gpui/src/platform/test.rs @@ -178,7 +178,7 @@ impl super::Platform for Platform { Ok(()) } - fn set_cursor_style(&self, style: CursorStyle) { + fn set_cursor_style(&self, style: CursorStyle, _window_id: usize, _position: &Vector2F) { *self.cursor.lock() = style; } @@ -332,6 +332,10 @@ impl super::Window for Window { } fn on_appearance_changed(&mut self, _: Box) {} + + fn screen_position(&self, view_position: &Vector2F) -> Vector2F { + view_position.clone() + } } pub fn platform() -> Platform { diff --git a/crates/gpui/src/presenter.rs b/crates/gpui/src/presenter.rs index 0909d95fd0..f74eef463a 100644 --- a/crates/gpui/src/presenter.rs +++ b/crates/gpui/src/presenter.rs @@ -316,7 +316,14 @@ impl Presenter { break; } } - cx.platform().set_cursor_style(style_to_assign); + + if let Some(screen_position) = cx.screen_position(self.window_id, position) { + cx.platform().set_cursor_style( + style_to_assign, + self.window_id, + &screen_position, + ); + } if !event_reused { if pressed_button.is_some() { diff --git a/crates/gpui/src/presenter/event_dispatcher.rs b/crates/gpui/src/presenter/event_dispatcher.rs index 4c72334910..960c565bd4 100644 --- a/crates/gpui/src/presenter/event_dispatcher.rs +++ b/crates/gpui/src/presenter/event_dispatcher.rs @@ -209,6 +209,7 @@ impl EventDispatcher { break; } } + cx.platform().set_cursor_style(style_to_assign); if !event_reused { diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index ec7ba8fae0..71c5ef97a2 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -31,8 +31,9 @@ use futures::{ }; use gpui::{ actions, + color::Color, elements::*, - geometry::vector::Vector2F, + geometry::vector::{vec2f, Vector2F}, impl_actions, impl_internal_actions, keymap_matcher::KeymapContext, platform::{CursorStyle, WindowOptions}, @@ -263,6 +264,59 @@ pub fn init(app_state: Arc, cx: &mut MutableAppContext) { client.add_view_request_handler(Workspace::handle_follow); client.add_view_message_handler(Workspace::handle_unfollow); client.add_view_message_handler(Workspace::handle_update_followers); + + // REMEMBER TO DELETE THE SHOW NOTIF + cx.add_action( + |_workspace: &mut Workspace, _: &ShowNotif, cx: &mut ViewContext| { + struct DummyView; + + impl Entity for DummyView { + type Event = (); + } + + impl View for DummyView { + fn ui_name() -> &'static str { + "DummyView" + } + fn render(&mut self, cx: &mut RenderContext<'_, Self>) -> ElementBox { + MouseEventHandler::::new(0, cx, |state, _cx| { + Empty::new() + .contained() + .with_background_color(if state.hovered() { + Color::red() + } else { + Color::blue() + }) + .constrained() + .with_width(200.) + .with_height(200.) + .boxed() + }) + .on_click(MouseButton::Left, |_, _| { + println!("click"); + }) + .with_cursor_style(CursorStyle::ResizeUpDown) + .boxed() + } + } + + cx.add_window( + WindowOptions { + bounds: gpui::WindowBounds::Fixed(gpui::geometry::rect::RectF::new( + vec2f(400., 200.), + vec2f(300., 200.), + )), + titlebar: None, + center: false, + focus: false, + kind: gpui::WindowKind::PopUp, + is_movable: true, + screen: None, + }, + |_cx| DummyView, + ) + }, + ) } type ProjectItemBuilders = HashMap< From 27a80a1c94c56b2c9f23cd26acf83982e1d40c41 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Mon, 23 Jan 2023 10:45:31 -0800 Subject: [PATCH 2/5] WIP --- crates/gpui/src/platform/mac/event.rs | 2 ++ crates/gpui/src/platform/mac/platform.rs | 35 ++++++++++-------------- crates/gpui/src/platform/mac/window.rs | 12 +++++--- crates/gpui/src/presenter.rs | 3 ++ 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/crates/gpui/src/platform/mac/event.rs b/crates/gpui/src/platform/mac/event.rs index 2f29898c26..6882721372 100644 --- a/crates/gpui/src/platform/mac/event.rs +++ b/crates/gpui/src/platform/mac/event.rs @@ -125,6 +125,7 @@ impl Event { button, position: vec2f( native_event.locationInWindow().x as f32, + // MacOS screen coordinates are relative to bottom left window_height - native_event.locationInWindow().y as f32, ), modifiers: read_modifiers(native_event), @@ -150,6 +151,7 @@ impl Event { button, position: vec2f( native_event.locationInWindow().x as f32, + // MacOS view coordinates are relative to bottom left window_height - native_event.locationInWindow().y as f32, ), modifiers: read_modifiers(native_event), diff --git a/crates/gpui/src/platform/mac/platform.rs b/crates/gpui/src/platform/mac/platform.rs index f1b7f75c03..ae9db6a396 100644 --- a/crates/gpui/src/platform/mac/platform.rs +++ b/crates/gpui/src/platform/mac/platform.rs @@ -697,27 +697,20 @@ impl platform::Platform for MacPlatform { } fn set_cursor_style(&self, style: CursorStyle, window_id: usize, screen_position: &Vector2F) { - let top_most = Window::window_id_under(screen_position); - if top_most.is_none() { - return; - } - if top_most.unwrap() != window_id { - return; - } - - dbg!(top_most.unwrap(), window_id); - - dbg!(style); - - unsafe { - let cursor: id = match style { - CursorStyle::Arrow => msg_send![class!(NSCursor), arrowCursor], - CursorStyle::ResizeLeftRight => msg_send![class!(NSCursor), resizeLeftRightCursor], - CursorStyle::ResizeUpDown => msg_send![class!(NSCursor), resizeUpDownCursor], - CursorStyle::PointingHand => msg_send![class!(NSCursor), pointingHandCursor], - CursorStyle::IBeam => msg_send![class!(NSCursor), IBeamCursor], - }; - let _: () = msg_send![cursor, set]; + if Some(window_id) == Window::window_id_under(screen_position) { + dbg!(screen_position, style); + unsafe { + let cursor: id = match style { + CursorStyle::Arrow => msg_send![class!(NSCursor), arrowCursor], + CursorStyle::ResizeLeftRight => { + msg_send![class!(NSCursor), resizeLeftRightCursor] + } + CursorStyle::ResizeUpDown => msg_send![class!(NSCursor), resizeUpDownCursor], + CursorStyle::PointingHand => msg_send![class!(NSCursor), pointingHandCursor], + CursorStyle::IBeam => msg_send![class!(NSCursor), IBeamCursor], + }; + let _: () = msg_send![cursor, set]; + } } } diff --git a/crates/gpui/src/platform/mac/window.rs b/crates/gpui/src/platform/mac/window.rs index 032b88507b..067dd69115 100644 --- a/crates/gpui/src/platform/mac/window.rs +++ b/crates/gpui/src/platform/mac/window.rs @@ -52,6 +52,8 @@ use std::{ time::Duration, }; +use super::geometry::Vector2FExt; + const WINDOW_STATE_IVAR: &str = "windowState"; static mut WINDOW_CLASS: *const Class = ptr::null(); @@ -564,11 +566,13 @@ impl Window { unsafe { let app = NSApplication::sharedApplication(nil); - let point = NSPoint::new(screen_position.x() as f64, screen_position.y() as f64); - let window_number: NSInteger = msg_send![class!(NSWindow), windowNumberAtPoint:point belowWindowWithWindowNumber:0 as NSInteger]; + let point = screen_position.to_ns_point(); + let window_number: NSInteger = msg_send![class!(NSWindow), windowNumberAtPoint:point belowWindowWithWindowNumber:0]; + // For some reason this API doesn't work when our two windows are on top of each other let top_most_window: id = msg_send![app, windowWithWindowNumber: window_number]; - dbg!(top_most_window); + + // dbg!(top_most_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 | is_window { @@ -779,7 +783,7 @@ impl platform::Window for Window { fn screen_position(&self, view_position: &Vector2F) -> Vector2F { let self_borrow = self.0.borrow_mut(); unsafe { - let point = NSPoint::new(view_position.x() as f64, view_position.y() as f64); + let point = view_position.to_ns_point(); let screen_point: NSPoint = msg_send![self_borrow.native_window, convertPointToScreen: point]; vec2f(screen_point.x as f32, screen_point.y as f32) diff --git a/crates/gpui/src/presenter.rs b/crates/gpui/src/presenter.rs index f74eef463a..1b16574cb8 100644 --- a/crates/gpui/src/presenter.rs +++ b/crates/gpui/src/presenter.rs @@ -317,6 +317,9 @@ impl Presenter { } } + dbg!("*******"); + dbg!(position); + dbg!(event_reused); if let Some(screen_position) = cx.screen_position(self.window_id, position) { cx.platform().set_cursor_style( style_to_assign, From 45e4e3354e4729578d935bbd65da98b48f9f8e0f Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Wed, 25 Jan 2023 08:58:41 -0800 Subject: [PATCH 3/5] Changed the presenter to only send 'set_cursor_style' on the topmost window co-authored-by: Antonio --- crates/gpui/src/app.rs | 6 ++- crates/gpui/src/platform.rs | 4 +- crates/gpui/src/platform/mac/platform.rs | 28 +++++----- crates/gpui/src/platform/mac/status_item.rs | 4 +- crates/gpui/src/platform/mac/window.rs | 59 ++++++++++----------- crates/gpui/src/platform/test.rs | 6 +-- crates/gpui/src/presenter.rs | 12 ++--- 7 files changed, 54 insertions(+), 65 deletions(-) diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 0e5697c30b..2e7378fc16 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -866,10 +866,12 @@ impl MutableAppContext { } } - pub fn screen_position(&self, window_id: usize, view_position: &Vector2F) -> Option { + pub fn is_topmost_window_for_position(&self, window_id: usize, position: Vector2F) -> bool { self.presenters_and_platform_windows .get(&window_id) - .map(|(_, window)| window.screen_position(view_position)) + .map_or(false, |(_, window)| { + window.is_topmost_for_position(position) + }) } pub fn window_ids(&self) -> impl Iterator + '_ { diff --git a/crates/gpui/src/platform.rs b/crates/gpui/src/platform.rs index 0601fd9764..05ba61a9ad 100644 --- a/crates/gpui/src/platform.rs +++ b/crates/gpui/src/platform.rs @@ -64,7 +64,7 @@ pub trait Platform: Send + Sync { fn read_credentials(&self, url: &str) -> Result)>>; fn delete_credentials(&self, url: &str) -> Result<()>; - fn set_cursor_style(&self, style: CursorStyle, window_id: usize, screen_position: &Vector2F); + fn set_cursor_style(&self, style: CursorStyle); fn should_auto_hide_scrollbars(&self) -> bool; fn local_timezone(&self) -> UtcOffset; @@ -145,7 +145,7 @@ pub trait Window { fn present_scene(&mut self, scene: Scene); fn appearance(&self) -> Appearance; fn on_appearance_changed(&mut self, callback: Box); - fn screen_position(&self, view_position: &Vector2F) -> Vector2F; + fn is_topmost_for_position(&self, position: Vector2F) -> bool; } #[derive(Debug)] diff --git a/crates/gpui/src/platform/mac/platform.rs b/crates/gpui/src/platform/mac/platform.rs index ae9db6a396..dbb1a01f31 100644 --- a/crates/gpui/src/platform/mac/platform.rs +++ b/crates/gpui/src/platform/mac/platform.rs @@ -37,7 +37,6 @@ use objc::{ runtime::{Class, Object, Sel}, sel, sel_impl, }; -use pathfinder_geometry::vector::Vector2F; use postage::oneshot; use ptr::null_mut; use std::{ @@ -696,21 +695,18 @@ impl platform::Platform for MacPlatform { Ok(()) } - fn set_cursor_style(&self, style: CursorStyle, window_id: usize, screen_position: &Vector2F) { - if Some(window_id) == Window::window_id_under(screen_position) { - dbg!(screen_position, style); - unsafe { - let cursor: id = match style { - CursorStyle::Arrow => msg_send![class!(NSCursor), arrowCursor], - CursorStyle::ResizeLeftRight => { - msg_send![class!(NSCursor), resizeLeftRightCursor] - } - CursorStyle::ResizeUpDown => msg_send![class!(NSCursor), resizeUpDownCursor], - CursorStyle::PointingHand => msg_send![class!(NSCursor), pointingHandCursor], - CursorStyle::IBeam => msg_send![class!(NSCursor), IBeamCursor], - }; - let _: () = msg_send![cursor, set]; - } + fn set_cursor_style(&self, style: CursorStyle) { + unsafe { + let cursor: id = match style { + CursorStyle::Arrow => msg_send![class!(NSCursor), arrowCursor], + CursorStyle::ResizeLeftRight => { + msg_send![class!(NSCursor), resizeLeftRightCursor] + } + CursorStyle::ResizeUpDown => msg_send![class!(NSCursor), resizeUpDownCursor], + CursorStyle::PointingHand => msg_send![class!(NSCursor), pointingHandCursor], + CursorStyle::IBeam => msg_send![class!(NSCursor), IBeamCursor], + }; + let _: () = msg_send![cursor, set]; } } diff --git a/crates/gpui/src/platform/mac/status_item.rs b/crates/gpui/src/platform/mac/status_item.rs index d05c559772..2da7caab7e 100644 --- a/crates/gpui/src/platform/mac/status_item.rs +++ b/crates/gpui/src/platform/mac/status_item.rs @@ -259,8 +259,8 @@ impl platform::Window for StatusItem { } } - fn screen_position(&self, _view_position: &Vector2F) -> Vector2F { - unimplemented!() + fn is_topmost_for_position(&self, _: Vector2F) -> bool { + true } } diff --git a/crates/gpui/src/platform/mac/window.rs b/crates/gpui/src/platform/mac/window.rs index 067dd69115..191ab77058 100644 --- a/crates/gpui/src/platform/mac/window.rs +++ b/crates/gpui/src/platform/mac/window.rs @@ -17,9 +17,9 @@ use crate::{ use block::ConcreteBlock; use cocoa::{ appkit::{ - CGPoint, NSApplication, NSBackingStoreBuffered, NSScreen, NSView, NSViewHeightSizable, - NSViewWidthSizable, NSWindow, NSWindowButton, NSWindowCollectionBehavior, - NSWindowStyleMask, + CGFloat, CGPoint, NSApplication, NSBackingStoreBuffered, NSScreen, NSView, + NSViewHeightSizable, NSViewWidthSizable, NSWindow, NSWindowButton, + NSWindowCollectionBehavior, NSWindowStyleMask, }, base::{id, nil}, foundation::{ @@ -52,8 +52,6 @@ use std::{ time::Duration, }; -use super::geometry::Vector2FExt; - const WINDOW_STATE_IVAR: &str = "windowState"; static mut WINDOW_CLASS: *const Class = ptr::null(); @@ -561,28 +559,6 @@ impl Window { } } } - - pub fn window_id_under(screen_position: &Vector2F) -> Option { - unsafe { - let app = NSApplication::sharedApplication(nil); - - let point = screen_position.to_ns_point(); - let window_number: NSInteger = msg_send![class!(NSWindow), windowNumberAtPoint:point belowWindowWithWindowNumber:0]; - - // For some reason this API doesn't work when our two windows are on top of each other - let top_most_window: id = msg_send![app, windowWithWindowNumber: window_number]; - - // dbg!(top_most_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 | is_window { - let id = get_window_state(&*top_most_window).borrow().id; - Some(id) - } else { - None - } - } - } } impl Drop for Window { @@ -780,13 +756,34 @@ impl platform::Window for Window { self.0.borrow_mut().appearance_changed_callback = Some(callback); } - fn screen_position(&self, view_position: &Vector2F) -> Vector2F { - let self_borrow = self.0.borrow_mut(); + fn is_topmost_for_position(&self, position: Vector2F) -> bool { + let window_bounds = self.bounds(); + let self_borrow = self.0.borrow(); + let self_id = self_borrow.id; + unsafe { - let point = view_position.to_ns_point(); + let app = NSApplication::sharedApplication(nil); + + // Convert back to bottom-left coordinates + let point = NSPoint::new( + position.x() as CGFloat, + (window_bounds.height() - position.y()) as CGFloat, + ); + let screen_point: NSPoint = msg_send![self_borrow.native_window, convertPointToScreen: point]; - vec2f(screen_point.x as f32, screen_point.y as f32) + let window_number: NSInteger = msg_send![class!(NSWindow), windowNumberAtPoint:screen_point belowWindowWithWindowNumber:0]; + let top_most_window: id = msg_send![app, windowWithWindowNumber: window_number]; + + 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 | is_window { + let topmost_window_id = get_window_state(&*top_most_window).borrow().id; + topmost_window_id == self_id + } else { + // Someone else's window is on top + false + } } } } diff --git a/crates/gpui/src/platform/test.rs b/crates/gpui/src/platform/test.rs index 7295bf525b..d33e3e2fca 100644 --- a/crates/gpui/src/platform/test.rs +++ b/crates/gpui/src/platform/test.rs @@ -178,7 +178,7 @@ impl super::Platform for Platform { Ok(()) } - fn set_cursor_style(&self, style: CursorStyle, _window_id: usize, _position: &Vector2F) { + fn set_cursor_style(&self, style: CursorStyle) { *self.cursor.lock() = style; } @@ -333,8 +333,8 @@ impl super::Window for Window { fn on_appearance_changed(&mut self, _: Box) {} - fn screen_position(&self, view_position: &Vector2F) -> Vector2F { - view_position.clone() + fn is_topmost_for_position(&self, _position: Vector2F) -> bool { + true } } diff --git a/crates/gpui/src/presenter.rs b/crates/gpui/src/presenter.rs index 1b16574cb8..5bff7e7bb1 100644 --- a/crates/gpui/src/presenter.rs +++ b/crates/gpui/src/presenter.rs @@ -31,6 +31,7 @@ use std::{ ops::{Deref, DerefMut, Range}, sync::Arc, }; +use time::Instant; pub struct Presenter { window_id: usize, @@ -317,15 +318,8 @@ impl Presenter { } } - dbg!("*******"); - dbg!(position); - dbg!(event_reused); - if let Some(screen_position) = cx.screen_position(self.window_id, position) { - cx.platform().set_cursor_style( - style_to_assign, - self.window_id, - &screen_position, - ); + if cx.is_topmost_window_for_position(self.window_id, *position) { + cx.platform().set_cursor_style(style_to_assign); } if !event_reused { From 1fc6276eaba51b1544f130cfa4c0f5537e129fea Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Wed, 25 Jan 2023 09:09:59 -0800 Subject: [PATCH 4/5] Remove debug wiring --- crates/gpui/src/presenter.rs | 9 +++-- crates/workspace/src/workspace.rs | 57 +------------------------------ 2 files changed, 8 insertions(+), 58 deletions(-) diff --git a/crates/gpui/src/presenter.rs b/crates/gpui/src/presenter.rs index 5bff7e7bb1..1fff5c50b5 100644 --- a/crates/gpui/src/presenter.rs +++ b/crates/gpui/src/presenter.rs @@ -31,7 +31,6 @@ use std::{ ops::{Deref, DerefMut, Range}, sync::Arc, }; -use time::Instant; pub struct Presenter { window_id: usize, @@ -318,8 +317,14 @@ impl Presenter { } } - if cx.is_topmost_window_for_position(self.window_id, *position) { + let t0 = std::time::Instant::now(); + let is_topmost_window = + cx.is_topmost_window_for_position(self.window_id, *position); + println!("is_topmost_window => {:?}", t0.elapsed()); + if is_topmost_window { + let t1 = std::time::Instant::now(); cx.platform().set_cursor_style(style_to_assign); + println!("set_cursor_style => {:?}", t1.elapsed()); } if !event_reused { diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 71c5ef97a2..b0abe09070 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -31,9 +31,8 @@ use futures::{ }; use gpui::{ actions, - color::Color, elements::*, - geometry::vector::{vec2f, Vector2F}, + geometry::vector::Vector2F, impl_actions, impl_internal_actions, keymap_matcher::KeymapContext, platform::{CursorStyle, WindowOptions}, @@ -101,7 +100,6 @@ actions!( NewTerminal, NewSearch, Feedback, - ShowNotif, ] ); @@ -264,59 +262,6 @@ pub fn init(app_state: Arc, cx: &mut MutableAppContext) { client.add_view_request_handler(Workspace::handle_follow); client.add_view_message_handler(Workspace::handle_unfollow); client.add_view_message_handler(Workspace::handle_update_followers); - - // REMEMBER TO DELETE THE SHOW NOTIF - cx.add_action( - |_workspace: &mut Workspace, _: &ShowNotif, cx: &mut ViewContext| { - struct DummyView; - - impl Entity for DummyView { - type Event = (); - } - - impl View for DummyView { - fn ui_name() -> &'static str { - "DummyView" - } - fn render(&mut self, cx: &mut RenderContext<'_, Self>) -> ElementBox { - MouseEventHandler::::new(0, cx, |state, _cx| { - Empty::new() - .contained() - .with_background_color(if state.hovered() { - Color::red() - } else { - Color::blue() - }) - .constrained() - .with_width(200.) - .with_height(200.) - .boxed() - }) - .on_click(MouseButton::Left, |_, _| { - println!("click"); - }) - .with_cursor_style(CursorStyle::ResizeUpDown) - .boxed() - } - } - - cx.add_window( - WindowOptions { - bounds: gpui::WindowBounds::Fixed(gpui::geometry::rect::RectF::new( - vec2f(400., 200.), - vec2f(300., 200.), - )), - titlebar: None, - center: false, - focus: false, - kind: gpui::WindowKind::PopUp, - is_movable: true, - screen: None, - }, - |_cx| DummyView, - ) - }, - ) } type ProjectItemBuilders = HashMap< From ecb7d1072ffd21a2de5bbd7d2d65170375c87277 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Wed, 25 Jan 2023 09:33:07 -0800 Subject: [PATCH 5/5] Fixes a broken conditional that is only caught on darwin systems --- crates/gpui/src/platform/mac/window.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/gpui/src/platform/mac/window.rs b/crates/gpui/src/platform/mac/window.rs index 191ab77058..bef6f65e42 100644 --- a/crates/gpui/src/platform/mac/window.rs +++ b/crates/gpui/src/platform/mac/window.rs @@ -777,7 +777,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 | is_window { + if is_panel == YES || is_window == YES { let topmost_window_id = get_window_state(&*top_most_window).borrow().id; topmost_window_id == self_id } else {