pull event data out into individual Event structs

This commit is contained in:
Keith Simmons 2022-07-06 15:36:42 -07:00
parent bbe325930f
commit 686e57373b
13 changed files with 270 additions and 212 deletions

View File

@ -23,9 +23,10 @@ use gpui::{
json::{self, ToJson},
platform::CursorStyle,
text_layout::{self, Line, RunStyle, TextLayoutCache},
AppContext, Axis, Border, CursorRegion, Element, ElementBox, Event, EventContext,
LayoutContext, MutableAppContext, PaintContext, Quad, Scene, SizeConstraint, ViewContext,
WeakViewHandle,
AppContext, Axis, Border, CursorRegion, Element, ElementBox, Event, EventContext, KeyDownEvent,
LayoutContext, LeftMouseDownEvent, LeftMouseDraggedEvent, LeftMouseUpEvent,
ModifiersChangedEvent, MouseMovedEvent, MutableAppContext, PaintContext, Quad, Scene,
ScrollWheelEvent, SizeConstraint, ViewContext, WeakViewHandle,
};
use json::json;
use language::{Bias, DiagnosticSeverity, Selection};
@ -1463,14 +1464,14 @@ impl Element for EditorElement {
}
match event {
Event::LeftMouseDown {
Event::LeftMouseDown(LeftMouseDownEvent {
position,
cmd,
alt,
shift,
click_count,
..
} => self.mouse_down(
}) => self.mouse_down(
*position,
*cmd,
*alt,
@ -1480,18 +1481,20 @@ impl Element for EditorElement {
paint,
cx,
),
Event::LeftMouseUp { position, .. } => self.mouse_up(*position, cx),
Event::LeftMouseDragged { position, .. } => {
Event::LeftMouseUp(LeftMouseUpEvent { position, .. }) => self.mouse_up(*position, cx),
Event::LeftMouseDragged(LeftMouseDraggedEvent { position, .. }) => {
self.mouse_dragged(*position, layout, paint, cx)
}
Event::ScrollWheel {
Event::ScrollWheel(ScrollWheelEvent {
position,
delta,
precise,
} => self.scroll(*position, *delta, *precise, layout, paint, cx),
Event::KeyDown { input, .. } => self.key_down(input.as_deref(), cx),
Event::ModifiersChanged { cmd, .. } => self.modifiers_changed(*cmd, cx),
Event::MouseMoved { position, cmd, .. } => {
}) => self.scroll(*position, *delta, *precise, layout, paint, cx),
Event::KeyDown(KeyDownEvent { input, .. }) => self.key_down(input.as_deref(), cx),
Event::ModifiersChanged(ModifiersChangedEvent { cmd, .. }) => {
self.modifiers_changed(*cmd, cx)
}
Event::MouseMoved(MouseMovedEvent { position, cmd, .. }) => {
self.mouse_moved(*position, *cmd, layout, paint, cx)
}

View File

@ -4,7 +4,7 @@ use crate::{
elements::ElementBox,
executor::{self, Task},
keymap::{self, Binding, Keystroke},
platform::{self, Platform, PromptLevel, WindowOptions},
platform::{self, KeyDownEvent, Platform, PromptLevel, WindowOptions},
presenter::Presenter,
util::post_inc,
AssetCache, AssetSource, ClipboardItem, FontCache, MouseRegionId, PathPromptOptions,
@ -377,11 +377,11 @@ impl TestAppContext {
if !cx.dispatch_keystroke(window_id, dispatch_path, &keystroke) {
presenter.borrow_mut().dispatch_event(
Event::KeyDown {
Event::KeyDown(KeyDownEvent {
keystroke,
input,
is_held,
},
}),
cx,
);
}
@ -1820,7 +1820,7 @@ impl MutableAppContext {
window.on_event(Box::new(move |event| {
app.update(|cx| {
if let Some(presenter) = presenter.upgrade() {
if let Event::KeyDown { keystroke, .. } = &event {
if let Event::KeyDown(KeyDownEvent { keystroke, .. }) = &event {
if cx.dispatch_keystroke(
window_id,
presenter.borrow().dispatch_path(cx.as_ref()),
@ -5381,7 +5381,7 @@ impl RefCounts {
#[cfg(test)]
mod tests {
use super::*;
use crate::{actions, elements::*, impl_actions};
use crate::{actions, elements::*, impl_actions, LeftMouseDownEvent};
use serde::Deserialize;
use smol::future::poll_once;
use std::{
@ -5734,14 +5734,14 @@ mod tests {
let presenter = cx.presenters_and_platform_windows[&window_id].0.clone();
// Ensure window's root element is in a valid lifecycle state.
presenter.borrow_mut().dispatch_event(
Event::LeftMouseDown {
Event::LeftMouseDown(LeftMouseDownEvent {
position: Default::default(),
ctrl: false,
alt: false,
shift: false,
cmd: false,
click_count: 1,
},
}),
cx,
);
assert_eq!(mouse_down_count.load(SeqCst), 1);

View File

@ -1,6 +1,7 @@
use crate::{
geometry::vector::Vector2F, CursorRegion, DebugContext, Element, ElementBox, Event,
EventContext, LayoutContext, MouseRegion, NavigationDirection, PaintContext, SizeConstraint,
EventContext, LayoutContext, LeftMouseDownEvent, MouseRegion, NavigateMouseDownEvent,
NavigationDirection, PaintContext, RightMouseDownEvent, SizeConstraint,
};
use pathfinder_geometry::rect::RectF;
use serde_json::json;
@ -116,7 +117,7 @@ impl Element for EventHandler {
true
} else {
match event {
Event::LeftMouseDown { position, .. } => {
Event::LeftMouseDown(LeftMouseDownEvent { position, .. }) => {
if let Some(callback) = self.mouse_down.as_mut() {
if visible_bounds.contains_point(*position) {
return callback(cx);
@ -124,7 +125,7 @@ impl Element for EventHandler {
}
false
}
Event::RightMouseDown { position, .. } => {
Event::RightMouseDown(RightMouseDownEvent { position, .. }) => {
if let Some(callback) = self.right_mouse_down.as_mut() {
if visible_bounds.contains_point(*position) {
return callback(cx);
@ -132,11 +133,11 @@ impl Element for EventHandler {
}
false
}
Event::NavigateMouseDown {
Event::NavigateMouseDown(NavigateMouseDownEvent {
position,
direction,
..
} => {
}) => {
if let Some(callback) = self.navigate_mouse_down.as_mut() {
if visible_bounds.contains_point(*position) {
return callback(*direction, cx);

View File

@ -3,7 +3,8 @@ use std::{any::Any, f32::INFINITY};
use crate::{
json::{self, ToJson, Value},
Axis, DebugContext, Element, ElementBox, ElementStateHandle, Event, EventContext,
LayoutContext, PaintContext, RenderContext, SizeConstraint, Vector2FExt, View,
LayoutContext, MouseMovedEvent, PaintContext, RenderContext, ScrollWheelEvent, SizeConstraint,
Vector2FExt, View,
};
use pathfinder_geometry::{
rect::RectF,
@ -287,11 +288,11 @@ impl Element for Flex {
handled = child.dispatch_event(event, cx) || handled;
}
if !handled {
if let &Event::ScrollWheel {
if let &Event::ScrollWheel(ScrollWheelEvent {
position,
delta,
precise,
} = event
}) = event
{
if *remaining_space < 0. && bounds.contains_point(position) {
if let Some(scroll_state) = self.scroll_state.as_ref() {
@ -321,7 +322,7 @@ impl Element for Flex {
}
if !handled {
if let &Event::MouseMoved { position, .. } = event {
if let &Event::MouseMoved(MouseMovedEvent { position, .. }) = event {
// If this is a scrollable flex, and the mouse is over it, eat the scroll event to prevent
// propogating it to the element below.
if self.scroll_state.is_some() && bounds.contains_point(position) {

View File

@ -5,7 +5,7 @@ use crate::{
},
json::json,
DebugContext, Element, ElementBox, ElementRc, Event, EventContext, LayoutContext, PaintContext,
RenderContext, SizeConstraint, View, ViewContext,
RenderContext, ScrollWheelEvent, SizeConstraint, View, ViewContext,
};
use std::{cell::RefCell, collections::VecDeque, ops::Range, rc::Rc};
use sum_tree::{Bias, SumTree};
@ -311,11 +311,11 @@ impl Element for List {
state.items = new_items;
match event {
Event::ScrollWheel {
Event::ScrollWheel(ScrollWheelEvent {
position,
delta,
precise,
} => {
}) => {
if bounds.contains_point(*position) {
if state.scroll(scroll_top, bounds.height(), *delta, *precise, cx) {
handled = true;

View File

@ -5,7 +5,7 @@ use crate::{
vector::{vec2f, Vector2F},
},
json::{self, json},
ElementBox, RenderContext, View,
ElementBox, RenderContext, ScrollWheelEvent, View,
};
use json::ToJson;
use std::{cell::RefCell, cmp, ops::Range, rc::Rc};
@ -310,11 +310,11 @@ impl Element for UniformList {
}
match event {
Event::ScrollWheel {
Event::ScrollWheel(ScrollWheelEvent {
position,
delta,
precise,
} => {
}) => {
if bounds.contains_point(*position) {
if self.scroll(*position, *delta, *precise, layout.scroll_max, cx) {
handled = true;

View File

@ -28,8 +28,7 @@ pub mod json;
pub mod keymap;
pub mod platform;
pub use gpui_macros::test;
pub use platform::FontSystem;
pub use platform::{Event, NavigationDirection, PathPromptOptions, Platform, PromptLevel};
pub use platform::*;
pub use presenter::{
Axis, DebugContext, EventContext, LayoutContext, PaintContext, SizeConstraint, Vector2FExt,
};

View File

@ -20,7 +20,7 @@ use crate::{
};
use anyhow::{anyhow, Result};
use async_task::Runnable;
pub use event::{Event, NavigationDirection};
pub use event::*;
use postage::oneshot;
use serde::Deserialize;
use std::{

View File

@ -6,80 +6,116 @@ pub enum NavigationDirection {
Forward,
}
#[derive(Clone, Debug)]
pub struct KeyDownEvent {
pub keystroke: Keystroke,
pub input: Option<String>,
pub is_held: bool,
}
#[derive(Clone, Debug)]
pub struct KeyUpEvent {
pub keystroke: Keystroke,
pub input: Option<String>,
}
#[derive(Clone, Debug)]
pub struct ModifiersChangedEvent {
pub ctrl: bool,
pub alt: bool,
pub shift: bool,
pub cmd: bool,
}
#[derive(Clone, Debug)]
pub struct ScrollWheelEvent {
pub position: Vector2F,
pub delta: Vector2F,
pub precise: bool,
}
#[derive(Clone, Debug)]
pub struct LeftMouseDownEvent {
pub position: Vector2F,
pub ctrl: bool,
pub alt: bool,
pub shift: bool,
pub cmd: bool,
pub click_count: usize,
}
#[derive(Clone, Debug)]
pub struct LeftMouseUpEvent {
pub position: Vector2F,
pub click_count: usize,
}
#[derive(Clone, Debug)]
pub struct LeftMouseDraggedEvent {
pub position: Vector2F,
pub ctrl: bool,
pub alt: bool,
pub shift: bool,
pub cmd: bool,
}
#[derive(Clone, Debug)]
pub struct RightMouseDownEvent {
pub position: Vector2F,
pub ctrl: bool,
pub alt: bool,
pub shift: bool,
pub cmd: bool,
pub click_count: usize,
}
#[derive(Clone, Debug)]
pub struct RightMouseUpEvent {
pub position: Vector2F,
pub click_count: usize,
}
#[derive(Clone, Debug)]
pub struct NavigateMouseDownEvent {
pub position: Vector2F,
pub direction: NavigationDirection,
pub ctrl: bool,
pub alt: bool,
pub shift: bool,
pub cmd: bool,
pub click_count: usize,
}
#[derive(Clone, Debug)]
pub struct NavigateMouseUpEvent {
pub position: Vector2F,
pub direction: NavigationDirection,
}
#[derive(Clone, Debug)]
pub struct MouseMovedEvent {
pub position: Vector2F,
pub left_mouse_down: bool,
pub ctrl: bool,
pub cmd: bool,
pub alt: bool,
pub shift: bool,
}
#[derive(Clone, Debug)]
pub enum Event {
KeyDown {
keystroke: Keystroke,
input: Option<String>,
is_held: bool,
},
KeyUp {
keystroke: Keystroke,
input: Option<String>,
},
ModifiersChanged {
ctrl: bool,
alt: bool,
shift: bool,
cmd: bool,
},
ScrollWheel {
position: Vector2F,
delta: Vector2F,
precise: bool,
},
LeftMouseDown {
position: Vector2F,
ctrl: bool,
alt: bool,
shift: bool,
cmd: bool,
click_count: usize,
},
LeftMouseUp {
position: Vector2F,
click_count: usize,
},
LeftMouseDragged {
position: Vector2F,
ctrl: bool,
alt: bool,
shift: bool,
cmd: bool,
},
RightMouseDown {
position: Vector2F,
ctrl: bool,
alt: bool,
shift: bool,
cmd: bool,
click_count: usize,
},
RightMouseUp {
position: Vector2F,
click_count: usize,
},
NavigateMouseDown {
position: Vector2F,
direction: NavigationDirection,
ctrl: bool,
alt: bool,
shift: bool,
cmd: bool,
click_count: usize,
},
NavigateMouseUp {
position: Vector2F,
direction: NavigationDirection,
},
MouseMoved {
position: Vector2F,
left_mouse_down: bool,
ctrl: bool,
cmd: bool,
alt: bool,
shift: bool,
},
KeyDown(KeyDownEvent),
KeyUp(KeyUpEvent),
ModifiersChanged(ModifiersChangedEvent),
ScrollWheel(ScrollWheelEvent),
LeftMouseDown(LeftMouseDownEvent),
LeftMouseUp(LeftMouseUpEvent),
LeftMouseDragged(LeftMouseDraggedEvent),
RightMouseDown(RightMouseDownEvent),
RightMouseUp(RightMouseUpEvent),
NavigateMouseDown(NavigateMouseDownEvent),
NavigateMouseUp(NavigateMouseUpEvent),
MouseMoved(MouseMovedEvent),
}
impl Event {
@ -88,15 +124,15 @@ impl Event {
Event::KeyDown { .. } => None,
Event::KeyUp { .. } => None,
Event::ModifiersChanged { .. } => None,
Event::ScrollWheel { position, .. }
| Event::LeftMouseDown { position, .. }
| Event::LeftMouseUp { position, .. }
| Event::LeftMouseDragged { position, .. }
| Event::RightMouseDown { position, .. }
| Event::RightMouseUp { position, .. }
| Event::NavigateMouseDown { position, .. }
| Event::NavigateMouseUp { position, .. }
| Event::MouseMoved { position, .. } => Some(*position),
Event::ScrollWheel(ScrollWheelEvent { position, .. })
| Event::LeftMouseDown(LeftMouseDownEvent { position, .. })
| Event::LeftMouseUp(LeftMouseUpEvent { position, .. })
| Event::LeftMouseDragged(LeftMouseDraggedEvent { position, .. })
| Event::RightMouseDown(RightMouseDownEvent { position, .. })
| Event::RightMouseUp(RightMouseUpEvent { position, .. })
| Event::NavigateMouseDown(NavigateMouseDownEvent { position, .. })
| Event::NavigateMouseUp(NavigateMouseUpEvent { position, .. })
| Event::MouseMoved(MouseMovedEvent { position, .. }) => Some(*position),
}
}
}

View File

@ -2,6 +2,9 @@ use crate::{
geometry::vector::vec2f,
keymap::Keystroke,
platform::{Event, NavigationDirection},
KeyDownEvent, KeyUpEvent, LeftMouseDownEvent, LeftMouseDraggedEvent, LeftMouseUpEvent,
ModifiersChangedEvent, MouseMovedEvent, NavigateMouseDownEvent, NavigateMouseUpEvent,
RightMouseDownEvent, RightMouseUpEvent, ScrollWheelEvent,
};
use cocoa::{
appkit::{NSEvent, NSEventModifierFlags, NSEventType},
@ -59,12 +62,12 @@ impl Event {
let shift = modifiers.contains(NSEventModifierFlags::NSShiftKeyMask);
let cmd = modifiers.contains(NSEventModifierFlags::NSCommandKeyMask);
Some(Self::ModifiersChanged {
Some(Self::ModifiersChanged(ModifiersChangedEvent {
ctrl,
alt,
shift,
cmd,
})
}))
}
NSEventType::NSKeyDown => {
let modifiers = native_event.modifierFlags();
@ -76,7 +79,7 @@ impl Event {
let (unmodified_chars, input) = get_key_text(native_event, cmd, ctrl, function)?;
Some(Self::KeyDown {
Some(Self::KeyDown(KeyDownEvent {
keystroke: Keystroke {
ctrl,
alt,
@ -86,7 +89,7 @@ impl Event {
},
input,
is_held: native_event.isARepeat() == YES,
})
}))
}
NSEventType::NSKeyUp => {
let modifiers = native_event.modifierFlags();
@ -98,7 +101,7 @@ impl Event {
let (unmodified_chars, input) = get_key_text(native_event, cmd, ctrl, function)?;
Some(Self::KeyUp {
Some(Self::KeyUp(KeyUpEvent {
keystroke: Keystroke {
ctrl,
alt,
@ -107,49 +110,57 @@ impl Event {
key: unmodified_chars.into(),
},
input,
})
}))
}
NSEventType::NSLeftMouseDown => {
let modifiers = native_event.modifierFlags();
window_height.map(|window_height| Self::LeftMouseDown {
window_height.map(|window_height| {
Self::LeftMouseDown(LeftMouseDownEvent {
position: vec2f(
native_event.locationInWindow().x as f32,
window_height - native_event.locationInWindow().y as f32,
),
ctrl: modifiers.contains(NSEventModifierFlags::NSControlKeyMask),
alt: modifiers.contains(NSEventModifierFlags::NSAlternateKeyMask),
shift: modifiers.contains(NSEventModifierFlags::NSShiftKeyMask),
cmd: modifiers.contains(NSEventModifierFlags::NSCommandKeyMask),
click_count: native_event.clickCount() as usize,
})
})
}
NSEventType::NSLeftMouseUp => window_height.map(|window_height| {
Self::LeftMouseUp(LeftMouseUpEvent {
position: vec2f(
native_event.locationInWindow().x as f32,
window_height - native_event.locationInWindow().y as f32,
),
ctrl: modifiers.contains(NSEventModifierFlags::NSControlKeyMask),
alt: modifiers.contains(NSEventModifierFlags::NSAlternateKeyMask),
shift: modifiers.contains(NSEventModifierFlags::NSShiftKeyMask),
cmd: modifiers.contains(NSEventModifierFlags::NSCommandKeyMask),
click_count: native_event.clickCount() as usize,
})
}
NSEventType::NSLeftMouseUp => window_height.map(|window_height| Self::LeftMouseUp {
position: vec2f(
native_event.locationInWindow().x as f32,
window_height - native_event.locationInWindow().y as f32,
),
click_count: native_event.clickCount() as usize,
}),
NSEventType::NSRightMouseDown => {
let modifiers = native_event.modifierFlags();
window_height.map(|window_height| Self::RightMouseDown {
window_height.map(|window_height| {
Self::RightMouseDown(RightMouseDownEvent {
position: vec2f(
native_event.locationInWindow().x as f32,
window_height - native_event.locationInWindow().y as f32,
),
ctrl: modifiers.contains(NSEventModifierFlags::NSControlKeyMask),
alt: modifiers.contains(NSEventModifierFlags::NSAlternateKeyMask),
shift: modifiers.contains(NSEventModifierFlags::NSShiftKeyMask),
cmd: modifiers.contains(NSEventModifierFlags::NSCommandKeyMask),
click_count: native_event.clickCount() as usize,
})
})
}
NSEventType::NSRightMouseUp => window_height.map(|window_height| {
Self::RightMouseUp(RightMouseUpEvent {
position: vec2f(
native_event.locationInWindow().x as f32,
window_height - native_event.locationInWindow().y as f32,
),
ctrl: modifiers.contains(NSEventModifierFlags::NSControlKeyMask),
alt: modifiers.contains(NSEventModifierFlags::NSAlternateKeyMask),
shift: modifiers.contains(NSEventModifierFlags::NSShiftKeyMask),
cmd: modifiers.contains(NSEventModifierFlags::NSCommandKeyMask),
click_count: native_event.clickCount() as usize,
})
}
NSEventType::NSRightMouseUp => window_height.map(|window_height| Self::RightMouseUp {
position: vec2f(
native_event.locationInWindow().x as f32,
window_height - native_event.locationInWindow().y as f32,
),
click_count: native_event.clickCount() as usize,
}),
NSEventType::NSOtherMouseDown => {
let direction = match native_event.buttonNumber() {
@ -160,17 +171,19 @@ impl Event {
};
let modifiers = native_event.modifierFlags();
window_height.map(|window_height| Self::NavigateMouseDown {
position: vec2f(
native_event.locationInWindow().x as f32,
window_height - native_event.locationInWindow().y as f32,
),
direction,
ctrl: modifiers.contains(NSEventModifierFlags::NSControlKeyMask),
alt: modifiers.contains(NSEventModifierFlags::NSAlternateKeyMask),
shift: modifiers.contains(NSEventModifierFlags::NSShiftKeyMask),
cmd: modifiers.contains(NSEventModifierFlags::NSCommandKeyMask),
click_count: native_event.clickCount() as usize,
window_height.map(|window_height| {
Self::NavigateMouseDown(NavigateMouseDownEvent {
position: vec2f(
native_event.locationInWindow().x as f32,
window_height - native_event.locationInWindow().y as f32,
),
direction,
ctrl: modifiers.contains(NSEventModifierFlags::NSControlKeyMask),
alt: modifiers.contains(NSEventModifierFlags::NSAlternateKeyMask),
shift: modifiers.contains(NSEventModifierFlags::NSShiftKeyMask),
cmd: modifiers.contains(NSEventModifierFlags::NSCommandKeyMask),
click_count: native_event.clickCount() as usize,
})
})
}
NSEventType::NSOtherMouseUp => {
@ -181,17 +194,19 @@ impl Event {
_ => return None,
};
window_height.map(|window_height| Self::NavigateMouseUp {
position: vec2f(
native_event.locationInWindow().x as f32,
window_height - native_event.locationInWindow().y as f32,
),
direction,
window_height.map(|window_height| {
Self::NavigateMouseUp(NavigateMouseUpEvent {
position: vec2f(
native_event.locationInWindow().x as f32,
window_height - native_event.locationInWindow().y as f32,
),
direction,
})
})
}
NSEventType::NSLeftMouseDragged => window_height.map(|window_height| {
let modifiers = native_event.modifierFlags();
Self::LeftMouseDragged {
Self::LeftMouseDragged(LeftMouseDraggedEvent {
position: vec2f(
native_event.locationInWindow().x as f32,
window_height - native_event.locationInWindow().y as f32,
@ -200,22 +215,24 @@ impl Event {
alt: modifiers.contains(NSEventModifierFlags::NSAlternateKeyMask),
shift: modifiers.contains(NSEventModifierFlags::NSShiftKeyMask),
cmd: modifiers.contains(NSEventModifierFlags::NSCommandKeyMask),
}
})
}),
NSEventType::NSScrollWheel => window_height.map(|window_height| Self::ScrollWheel {
position: vec2f(
native_event.locationInWindow().x as f32,
window_height - native_event.locationInWindow().y as f32,
),
delta: vec2f(
native_event.scrollingDeltaX() as f32,
native_event.scrollingDeltaY() as f32,
),
precise: native_event.hasPreciseScrollingDeltas() == YES,
NSEventType::NSScrollWheel => window_height.map(|window_height| {
Self::ScrollWheel(ScrollWheelEvent {
position: vec2f(
native_event.locationInWindow().x as f32,
window_height - native_event.locationInWindow().y as f32,
),
delta: vec2f(
native_event.scrollingDeltaX() as f32,
native_event.scrollingDeltaY() as f32,
),
precise: native_event.hasPreciseScrollingDeltas() == YES,
})
}),
NSEventType::NSMouseMoved => window_height.map(|window_height| {
let modifiers = native_event.modifierFlags();
Self::MouseMoved {
Self::MouseMoved(MouseMovedEvent {
position: vec2f(
native_event.locationInWindow().x as f32,
window_height - native_event.locationInWindow().y as f32,
@ -225,7 +242,7 @@ impl Event {
alt: modifiers.contains(NSEventModifierFlags::NSAlternateKeyMask),
shift: modifiers.contains(NSEventModifierFlags::NSShiftKeyMask),
cmd: modifiers.contains(NSEventModifierFlags::NSCommandKeyMask),
}
})
}),
_ => None,
}

View File

@ -6,7 +6,7 @@ use crate::{
},
keymap::Keystroke,
platform::{self, Event, WindowBounds, WindowContext},
Scene,
KeyDownEvent, LeftMouseDraggedEvent, ModifiersChangedEvent, Scene,
};
use block::ConcreteBlock;
use cocoa::{
@ -562,11 +562,11 @@ extern "C" fn handle_key_equivalent(this: &Object, _: Sel, native_event: id) ->
let event = unsafe { Event::from_native(native_event, Some(window_state_borrow.size().y())) };
if let Some(event) = event {
match &event {
Event::KeyDown {
Event::KeyDown(KeyDownEvent {
keystroke,
input,
is_held,
} => {
}) => {
let keydown = (keystroke.clone(), input.clone());
// Ignore events from held-down keys after some of the initially-pressed keys
// were released.
@ -603,7 +603,7 @@ extern "C" fn handle_view_event(this: &Object, _: Sel, native_event: id) {
if let Some(event) = event {
match &event {
Event::LeftMouseDragged { position, .. } => {
Event::LeftMouseDragged(LeftMouseDraggedEvent { position, .. }) => {
window_state_borrow.synthetic_drag_counter += 1;
window_state_borrow
.executor
@ -617,19 +617,19 @@ extern "C" fn handle_view_event(this: &Object, _: Sel, native_event: id) {
Event::LeftMouseUp { .. } => {
window_state_borrow.synthetic_drag_counter += 1;
}
Event::ModifiersChanged {
Event::ModifiersChanged(ModifiersChangedEvent {
ctrl,
alt,
shift,
cmd,
} => {
}) => {
// Only raise modifiers changed event when they have actually changed
if let Some(Event::ModifiersChanged {
if let Some(Event::ModifiersChanged(ModifiersChangedEvent {
ctrl: prev_ctrl,
alt: prev_alt,
shift: prev_shift,
cmd: prev_cmd,
}) = &window_state_borrow.previous_modifiers_changed_event
})) = &window_state_borrow.previous_modifiers_changed_event
{
if prev_ctrl == ctrl
&& prev_alt == alt
@ -667,11 +667,11 @@ extern "C" fn cancel_operation(this: &Object, _sel: Sel, _sender: id) {
shift: false,
key: chars.clone(),
};
let event = Event::KeyDown {
let event = Event::KeyDown(KeyDownEvent {
keystroke: keystroke.clone(),
input: Some(chars.clone()),
is_held: false,
};
});
window_state_borrow.last_fresh_keydown = Some((keystroke, Some(chars)));
if let Some(mut callback) = window_state_borrow.event_callback.take() {
@ -844,14 +844,14 @@ async fn synthetic_drag(
if window_state_borrow.synthetic_drag_counter == drag_id {
if let Some(mut callback) = window_state_borrow.event_callback.take() {
drop(window_state_borrow);
callback(Event::LeftMouseDragged {
callback(Event::LeftMouseDragged(LeftMouseDraggedEvent {
// TODO: Make sure empty modifiers is correct for this
position,
shift: false,
ctrl: false,
alt: false,
cmd: false,
});
}));
window_state.borrow_mut().event_callback = Some(callback);
}
} else {

View File

@ -9,9 +9,10 @@ use crate::{
scene::CursorRegion,
text_layout::TextLayoutCache,
Action, AnyModelHandle, AnyViewHandle, AnyWeakModelHandle, AssetCache, ElementBox, Entity,
FontSystem, ModelHandle, MouseRegion, MouseRegionId, ReadModel, ReadView, RenderContext,
RenderParams, Scene, UpgradeModelHandle, UpgradeViewHandle, View, ViewHandle, WeakModelHandle,
WeakViewHandle,
FontSystem, LeftMouseDownEvent, LeftMouseDraggedEvent, LeftMouseUpEvent, ModelHandle,
MouseMovedEvent, MouseRegion, MouseRegionId, ReadModel, ReadView, RenderContext, RenderParams,
RightMouseDownEvent, RightMouseUpEvent, Scene, UpgradeModelHandle, UpgradeViewHandle, View,
ViewHandle, WeakModelHandle, WeakViewHandle,
};
use pathfinder_geometry::vector::{vec2f, Vector2F};
use serde_json::json;
@ -235,7 +236,7 @@ impl Presenter {
let mut dragged_region = None;
match event {
Event::LeftMouseDown { position, .. } => {
Event::LeftMouseDown(LeftMouseDownEvent { position, .. }) => {
let mut hit = false;
for (region, _) in self.mouse_regions.iter().rev() {
if region.bounds.contains_point(position) {
@ -251,11 +252,11 @@ impl Presenter {
}
}
}
Event::LeftMouseUp {
Event::LeftMouseUp(LeftMouseUpEvent {
position,
click_count,
..
} => {
}) => {
self.prev_drag_position.take();
if let Some(region) = self.clicked_region.take() {
invalidated_views.push(region.view_id);
@ -264,7 +265,7 @@ impl Presenter {
}
}
}
Event::RightMouseDown { position, .. } => {
Event::RightMouseDown(RightMouseDownEvent { position, .. }) => {
let mut hit = false;
for (region, _) in self.mouse_regions.iter().rev() {
if region.bounds.contains_point(position) {
@ -279,11 +280,11 @@ impl Presenter {
}
}
}
Event::RightMouseUp {
Event::RightMouseUp(RightMouseUpEvent {
position,
click_count,
..
} => {
}) => {
if let Some(region) = self.right_clicked_region.take() {
invalidated_views.push(region.view_id);
if region.bounds.contains_point(position) {
@ -294,13 +295,13 @@ impl Presenter {
Event::MouseMoved { .. } => {
self.last_mouse_moved_event = Some(event.clone());
}
Event::LeftMouseDragged {
Event::LeftMouseDragged(LeftMouseDraggedEvent {
position,
shift,
ctrl,
alt,
cmd,
} => {
}) => {
if let Some((clicked_region, prev_drag_position)) = self
.clicked_region
.as_ref()
@ -311,14 +312,14 @@ impl Presenter {
*prev_drag_position = position;
}
self.last_mouse_moved_event = Some(Event::MouseMoved {
self.last_mouse_moved_event = Some(Event::MouseMoved(MouseMovedEvent {
position,
left_mouse_down: true,
shift,
ctrl,
alt,
cmd,
});
}));
}
_ => {}
}
@ -410,11 +411,11 @@ impl Presenter {
let mut unhovered_regions = Vec::new();
let mut hovered_regions = Vec::new();
if let Event::MouseMoved {
if let Event::MouseMoved(MouseMovedEvent {
position,
left_mouse_down,
..
} = event
}) = event
{
if !left_mouse_down {
let mut style_to_assign = CursorStyle::Arrow;

View File

@ -18,8 +18,8 @@ use gpui::{
},
json::json,
text_layout::{Line, RunStyle},
Event, FontCache, MouseRegion, PaintContext, Quad, SizeConstraint, TextLayoutCache,
WeakViewHandle,
Event, FontCache, KeyDownEvent, MouseRegion, PaintContext, Quad, ScrollWheelEvent,
SizeConstraint, TextLayoutCache, WeakViewHandle,
};
use itertools::Itertools;
use ordered_float::OrderedFloat;
@ -276,9 +276,9 @@ impl Element for TerminalEl {
cx: &mut gpui::EventContext,
) -> bool {
match event {
Event::ScrollWheel {
Event::ScrollWheel(ScrollWheelEvent {
delta, position, ..
} => visible_bounds
}) => visible_bounds
.contains_point(*position)
.then(|| {
let vertical_scroll =
@ -286,9 +286,9 @@ impl Element for TerminalEl {
cx.dispatch_action(ScrollTerminal(vertical_scroll.round() as i32));
})
.is_some(),
Event::KeyDown {
Event::KeyDown(KeyDownEvent {
input: Some(input), ..
} => cx
}) => cx
.is_parent_view_focused()
.then(|| {
cx.dispatch_action(Input(input.to_string()));