Changed platform mouse moved handling to only fire on active or popup windows

co-authored-by: Antonio <antonio@zed.dev>
This commit is contained in:
Mikayla Maki 2023-01-20 09:37:09 -08:00
parent 5a00729fad
commit 8af1294ba5
2 changed files with 14 additions and 6 deletions

View file

@ -316,6 +316,7 @@ enum ImeState {
struct WindowState {
id: usize,
native_window: id,
kind: WindowKind,
event_callback: Option<Box<dyn FnMut(Event) -> bool>>,
activate_callback: Option<Box<dyn FnMut(bool)>>,
resize_callback: Option<Box<dyn FnMut()>>,
@ -337,7 +338,6 @@ struct WindowState {
ime_state: ImeState,
//Retains the last IME Text
ime_text: Option<String>,
accepts_first_mouse: bool,
}
struct InsertText {
@ -422,6 +422,7 @@ impl Window {
let window = Self(Rc::new(RefCell::new(WindowState {
id,
native_window,
kind: options.kind,
event_callback: None,
resize_callback: None,
should_close_callback: None,
@ -437,7 +438,6 @@ impl Window {
scene_to_render: Default::default(),
renderer: Renderer::new(true, fonts),
last_fresh_keydown: None,
accepts_first_mouse: options.kind == WindowKind::PopUp,
traffic_light_position: options
.titlebar
.as_ref()
@ -985,7 +985,11 @@ extern "C" fn handle_view_event(this: &Object, _: Sel, native_event: id) {
.detach();
}
Event::MouseMoved(_) if !is_active => return,
Event::MouseMoved(_)
if !(is_active || window_state_borrow.kind == WindowKind::PopUp) =>
{
return
}
Event::MouseUp(MouseButtonEvent {
button: MouseButton::Left,
@ -1408,7 +1412,7 @@ 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;
return state_borrow.kind == WindowKind::PopUp;
}
}

View file

@ -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;