Add fn modifier to modifier keys in gpui and refactor platform events to use a single modifiers struct
This commit is contained in:
parent
c295f943ba
commit
a725ded95e
8 changed files with 110 additions and 98 deletions
39
Cargo.lock
generated
39
Cargo.lock
generated
|
@ -1160,6 +1160,12 @@ dependencies = [
|
||||||
"theme",
|
"theme",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "convert_case"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "core-foundation"
|
name = "core-foundation"
|
||||||
version = "0.9.3"
|
version = "0.9.3"
|
||||||
|
@ -1572,6 +1578,19 @@ dependencies = [
|
||||||
"byteorder",
|
"byteorder",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "derive_more"
|
||||||
|
version = "0.99.17"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321"
|
||||||
|
dependencies = [
|
||||||
|
"convert_case",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"rustc_version 0.4.0",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dhat"
|
name = "dhat"
|
||||||
version = "0.3.1"
|
version = "0.3.1"
|
||||||
|
@ -2388,6 +2407,7 @@ dependencies = [
|
||||||
"core-graphics",
|
"core-graphics",
|
||||||
"core-text",
|
"core-text",
|
||||||
"ctor",
|
"ctor",
|
||||||
|
"derive_more",
|
||||||
"dhat",
|
"dhat",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"etagere",
|
"etagere",
|
||||||
|
@ -3945,7 +3965,7 @@ version = "0.5.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "39fe46acc5503595e5949c17b818714d26fdf9b4920eacf3b2947f0199f4a6ff"
|
checksum = "39fe46acc5503595e5949c17b818714d26fdf9b4920eacf3b2947f0199f4a6ff"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"rustc_version",
|
"rustc_version 0.3.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -4897,7 +4917,16 @@ version = "0.3.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee"
|
checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"semver",
|
"semver 0.11.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustc_version"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366"
|
||||||
|
dependencies = [
|
||||||
|
"semver 1.0.14",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -5152,6 +5181,12 @@ dependencies = [
|
||||||
"semver-parser",
|
"semver-parser",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "semver"
|
||||||
|
version = "1.0.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "semver-parser"
|
name = "semver-parser"
|
||||||
version = "0.10.2"
|
version = "0.10.2"
|
||||||
|
|
|
@ -30,8 +30,8 @@ use gpui::{
|
||||||
platform::CursorStyle,
|
platform::CursorStyle,
|
||||||
text_layout::{self, Line, RunStyle, TextLayoutCache},
|
text_layout::{self, Line, RunStyle, TextLayoutCache},
|
||||||
AppContext, Axis, Border, CursorRegion, Element, ElementBox, EventContext, LayoutContext,
|
AppContext, Axis, Border, CursorRegion, Element, ElementBox, EventContext, LayoutContext,
|
||||||
MouseButton, MouseButtonEvent, MouseMovedEvent, MouseRegion, MutableAppContext, PaintContext,
|
Modifiers, MouseButton, MouseButtonEvent, MouseMovedEvent, MouseRegion, MutableAppContext,
|
||||||
Quad, Scene, SizeConstraint, ViewContext, WeakViewHandle,
|
PaintContext, Quad, Scene, SizeConstraint, ViewContext, WeakViewHandle,
|
||||||
};
|
};
|
||||||
use json::json;
|
use json::json;
|
||||||
use language::{Bias, CursorShape, DiagnosticSeverity, OffsetUtf16, Point, Selection};
|
use language::{Bias, CursorShape, DiagnosticSeverity, OffsetUtf16, Point, Selection};
|
||||||
|
@ -209,10 +209,14 @@ impl EditorElement {
|
||||||
fn mouse_down(
|
fn mouse_down(
|
||||||
MouseButtonEvent {
|
MouseButtonEvent {
|
||||||
position,
|
position,
|
||||||
|
modifiers:
|
||||||
|
Modifiers {
|
||||||
|
shift,
|
||||||
ctrl,
|
ctrl,
|
||||||
alt,
|
alt,
|
||||||
shift,
|
|
||||||
cmd,
|
cmd,
|
||||||
|
..
|
||||||
|
},
|
||||||
mut click_count,
|
mut click_count,
|
||||||
..
|
..
|
||||||
}: MouseButtonEvent,
|
}: MouseButtonEvent,
|
||||||
|
@ -303,8 +307,7 @@ impl EditorElement {
|
||||||
fn mouse_dragged(
|
fn mouse_dragged(
|
||||||
view: WeakViewHandle<Editor>,
|
view: WeakViewHandle<Editor>,
|
||||||
MouseMovedEvent {
|
MouseMovedEvent {
|
||||||
cmd,
|
modifiers: Modifiers { cmd, shift, .. },
|
||||||
shift,
|
|
||||||
position,
|
position,
|
||||||
..
|
..
|
||||||
}: MouseMovedEvent,
|
}: MouseMovedEvent,
|
||||||
|
@ -379,8 +382,7 @@ impl EditorElement {
|
||||||
|
|
||||||
fn mouse_moved(
|
fn mouse_moved(
|
||||||
MouseMovedEvent {
|
MouseMovedEvent {
|
||||||
cmd,
|
modifiers: Modifiers { shift, cmd, .. },
|
||||||
shift,
|
|
||||||
position,
|
position,
|
||||||
..
|
..
|
||||||
}: MouseMovedEvent,
|
}: MouseMovedEvent,
|
||||||
|
|
|
@ -358,7 +358,7 @@ fn go_to_fetched_definition_of_kind(
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use gpui::{ModifiersChangedEvent, View};
|
use gpui::{Modifiers, ModifiersChangedEvent, View};
|
||||||
use indoc::indoc;
|
use indoc::indoc;
|
||||||
use lsp::request::{GotoDefinition, GotoTypeDefinition};
|
use lsp::request::{GotoDefinition, GotoTypeDefinition};
|
||||||
|
|
||||||
|
@ -431,9 +431,12 @@ mod tests {
|
||||||
cx.update_editor(|editor, cx| {
|
cx.update_editor(|editor, cx| {
|
||||||
editor.modifiers_changed(
|
editor.modifiers_changed(
|
||||||
&gpui::ModifiersChangedEvent {
|
&gpui::ModifiersChangedEvent {
|
||||||
|
modifiers: Modifiers {
|
||||||
cmd: true,
|
cmd: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -660,9 +663,11 @@ mod tests {
|
||||||
cx.update_editor(|editor, cx| {
|
cx.update_editor(|editor, cx| {
|
||||||
editor.modifiers_changed(
|
editor.modifiers_changed(
|
||||||
&ModifiersChangedEvent {
|
&ModifiersChangedEvent {
|
||||||
|
modifiers: Modifiers {
|
||||||
cmd: true,
|
cmd: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|
},
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -20,6 +20,7 @@ sum_tree = { path = "../sum_tree" }
|
||||||
async-task = "4.0.3"
|
async-task = "4.0.3"
|
||||||
backtrace = { version = "0.3", optional = true }
|
backtrace = { version = "0.3", optional = true }
|
||||||
ctor = "0.1"
|
ctor = "0.1"
|
||||||
|
derive_more = "0.99.17"
|
||||||
dhat = { version = "0.3", optional = true }
|
dhat = { version = "0.3", optional = true }
|
||||||
env_logger = { version = "0.9", optional = true }
|
env_logger = { version = "0.9", optional = true }
|
||||||
etagere = "0.2"
|
etagere = "0.2"
|
||||||
|
|
|
@ -5777,10 +5777,7 @@ mod tests {
|
||||||
Event::MouseDown(MouseButtonEvent {
|
Event::MouseDown(MouseButtonEvent {
|
||||||
position: Default::default(),
|
position: Default::default(),
|
||||||
button: MouseButton::Left,
|
button: MouseButton::Left,
|
||||||
ctrl: false,
|
modifiers: Default::default(),
|
||||||
alt: false,
|
|
||||||
shift: false,
|
|
||||||
cmd: false,
|
|
||||||
click_count: 1,
|
click_count: 1,
|
||||||
}),
|
}),
|
||||||
false,
|
false,
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use derive_more::Deref;
|
||||||
|
|
||||||
use crate::{geometry::vector::Vector2F, keymap::Keystroke};
|
use crate::{geometry::vector::Vector2F, keymap::Keystroke};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
@ -11,12 +13,19 @@ pub struct KeyUpEvent {
|
||||||
pub keystroke: Keystroke,
|
pub keystroke: Keystroke,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default)]
|
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
||||||
pub struct ModifiersChangedEvent {
|
pub struct Modifiers {
|
||||||
pub ctrl: bool,
|
pub ctrl: bool,
|
||||||
pub alt: bool,
|
pub alt: bool,
|
||||||
pub shift: bool,
|
pub shift: bool,
|
||||||
pub cmd: bool,
|
pub cmd: bool,
|
||||||
|
pub fun: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, Default, Deref)]
|
||||||
|
pub struct ModifiersChangedEvent {
|
||||||
|
#[deref]
|
||||||
|
pub modifiers: Modifiers,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The phase of a touch motion event.
|
/// The phase of a touch motion event.
|
||||||
|
@ -28,15 +37,13 @@ pub enum TouchPhase {
|
||||||
Ended,
|
Ended,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default)]
|
#[derive(Clone, Copy, Debug, Default, Deref)]
|
||||||
pub struct ScrollWheelEvent {
|
pub struct ScrollWheelEvent {
|
||||||
pub position: Vector2F,
|
pub position: Vector2F,
|
||||||
pub delta: Vector2F,
|
pub delta: Vector2F,
|
||||||
pub precise: bool,
|
pub precise: bool,
|
||||||
pub ctrl: bool,
|
#[deref]
|
||||||
pub alt: bool,
|
pub modifiers: Modifiers,
|
||||||
pub shift: bool,
|
|
||||||
pub cmd: bool,
|
|
||||||
/// If the platform supports returning the phase of a scroll wheel event, it will be stored here
|
/// If the platform supports returning the phase of a scroll wheel event, it will be stored here
|
||||||
pub phase: Option<TouchPhase>,
|
pub phase: Option<TouchPhase>,
|
||||||
}
|
}
|
||||||
|
@ -79,25 +86,21 @@ impl Default for MouseButton {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default)]
|
#[derive(Clone, Copy, Debug, Default, Deref)]
|
||||||
pub struct MouseButtonEvent {
|
pub struct MouseButtonEvent {
|
||||||
pub button: MouseButton,
|
pub button: MouseButton,
|
||||||
pub position: Vector2F,
|
pub position: Vector2F,
|
||||||
pub ctrl: bool,
|
#[deref]
|
||||||
pub alt: bool,
|
pub modifiers: Modifiers,
|
||||||
pub shift: bool,
|
|
||||||
pub cmd: bool,
|
|
||||||
pub click_count: usize,
|
pub click_count: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default)]
|
#[derive(Clone, Copy, Debug, Default, Deref)]
|
||||||
pub struct MouseMovedEvent {
|
pub struct MouseMovedEvent {
|
||||||
pub position: Vector2F,
|
pub position: Vector2F,
|
||||||
pub pressed_button: Option<MouseButton>,
|
pub pressed_button: Option<MouseButton>,
|
||||||
pub ctrl: bool,
|
#[deref]
|
||||||
pub cmd: bool,
|
pub modifiers: Modifiers,
|
||||||
pub alt: bool,
|
|
||||||
pub shift: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MouseMovedEvent {
|
impl MouseMovedEvent {
|
||||||
|
@ -105,10 +108,7 @@ impl MouseMovedEvent {
|
||||||
MouseButtonEvent {
|
MouseButtonEvent {
|
||||||
position: self.position,
|
position: self.position,
|
||||||
button: self.pressed_button.unwrap_or(button),
|
button: self.pressed_button.unwrap_or(button),
|
||||||
ctrl: self.ctrl,
|
modifiers: self.modifiers,
|
||||||
alt: self.alt,
|
|
||||||
shift: self.shift,
|
|
||||||
cmd: self.cmd,
|
|
||||||
click_count: 0,
|
click_count: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::{
|
||||||
geometry::vector::vec2f,
|
geometry::vector::vec2f,
|
||||||
keymap::Keystroke,
|
keymap::Keystroke,
|
||||||
platform::{Event, NavigationDirection},
|
platform::{Event, NavigationDirection},
|
||||||
KeyDownEvent, KeyUpEvent, ModifiersChangedEvent, MouseButton, MouseButtonEvent,
|
KeyDownEvent, KeyUpEvent, Modifiers, ModifiersChangedEvent, MouseButton, MouseButtonEvent,
|
||||||
MouseMovedEvent, ScrollWheelEvent, TouchPhase,
|
MouseMovedEvent, ScrollWheelEvent, TouchPhase,
|
||||||
};
|
};
|
||||||
use cocoa::{
|
use cocoa::{
|
||||||
|
@ -65,6 +65,23 @@ pub fn key_to_native(key: &str) -> Cow<str> {
|
||||||
Cow::Owned(String::from_utf16(&[code]).unwrap())
|
Cow::Owned(String::from_utf16(&[code]).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsafe fn read_modifiers(native_event: id) -> Modifiers {
|
||||||
|
let modifiers = native_event.modifierFlags();
|
||||||
|
let ctrl = modifiers.contains(NSEventModifierFlags::NSControlKeyMask);
|
||||||
|
let alt = modifiers.contains(NSEventModifierFlags::NSAlternateKeyMask);
|
||||||
|
let shift = modifiers.contains(NSEventModifierFlags::NSShiftKeyMask);
|
||||||
|
let cmd = modifiers.contains(NSEventModifierFlags::NSCommandKeyMask);
|
||||||
|
let fun = modifiers.contains(NSEventModifierFlags::NSFunctionKeyMask);
|
||||||
|
|
||||||
|
Modifiers {
|
||||||
|
ctrl,
|
||||||
|
alt,
|
||||||
|
shift,
|
||||||
|
cmd,
|
||||||
|
fun,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Event {
|
impl Event {
|
||||||
pub unsafe fn from_native(native_event: id, window_height: Option<f32>) -> Option<Self> {
|
pub unsafe fn from_native(native_event: id, window_height: Option<f32>) -> Option<Self> {
|
||||||
let event_type = native_event.eventType();
|
let event_type = native_event.eventType();
|
||||||
|
@ -79,20 +96,9 @@ impl Event {
|
||||||
}
|
}
|
||||||
|
|
||||||
match event_type {
|
match event_type {
|
||||||
NSEventType::NSFlagsChanged => {
|
NSEventType::NSFlagsChanged => Some(Self::ModifiersChanged(ModifiersChangedEvent {
|
||||||
let modifiers = native_event.modifierFlags();
|
modifiers: read_modifiers(native_event),
|
||||||
let ctrl = modifiers.contains(NSEventModifierFlags::NSControlKeyMask);
|
})),
|
||||||
let alt = modifiers.contains(NSEventModifierFlags::NSAlternateKeyMask);
|
|
||||||
let shift = modifiers.contains(NSEventModifierFlags::NSShiftKeyMask);
|
|
||||||
let cmd = modifiers.contains(NSEventModifierFlags::NSCommandKeyMask);
|
|
||||||
|
|
||||||
Some(Self::ModifiersChanged(ModifiersChangedEvent {
|
|
||||||
ctrl,
|
|
||||||
alt,
|
|
||||||
shift,
|
|
||||||
cmd,
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
NSEventType::NSKeyDown => Some(Self::KeyDown(KeyDownEvent {
|
NSEventType::NSKeyDown => Some(Self::KeyDown(KeyDownEvent {
|
||||||
keystroke: parse_keystroke(native_event),
|
keystroke: parse_keystroke(native_event),
|
||||||
is_held: native_event.isARepeat() == YES,
|
is_held: native_event.isARepeat() == YES,
|
||||||
|
@ -112,8 +118,6 @@ impl Event {
|
||||||
// Other mouse buttons aren't tracked currently
|
// Other mouse buttons aren't tracked currently
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
let modifiers = native_event.modifierFlags();
|
|
||||||
|
|
||||||
window_height.map(|window_height| {
|
window_height.map(|window_height| {
|
||||||
Self::MouseDown(MouseButtonEvent {
|
Self::MouseDown(MouseButtonEvent {
|
||||||
button,
|
button,
|
||||||
|
@ -121,10 +125,7 @@ impl Event {
|
||||||
native_event.locationInWindow().x as f32,
|
native_event.locationInWindow().x as f32,
|
||||||
window_height - native_event.locationInWindow().y as f32,
|
window_height - native_event.locationInWindow().y as f32,
|
||||||
),
|
),
|
||||||
ctrl: modifiers.contains(NSEventModifierFlags::NSControlKeyMask),
|
modifiers: read_modifiers(native_event),
|
||||||
alt: modifiers.contains(NSEventModifierFlags::NSAlternateKeyMask),
|
|
||||||
shift: modifiers.contains(NSEventModifierFlags::NSShiftKeyMask),
|
|
||||||
cmd: modifiers.contains(NSEventModifierFlags::NSCommandKeyMask),
|
|
||||||
click_count: native_event.clickCount() as usize,
|
click_count: native_event.clickCount() as usize,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -143,24 +144,18 @@ impl Event {
|
||||||
};
|
};
|
||||||
|
|
||||||
window_height.map(|window_height| {
|
window_height.map(|window_height| {
|
||||||
let modifiers = native_event.modifierFlags();
|
|
||||||
Self::MouseUp(MouseButtonEvent {
|
Self::MouseUp(MouseButtonEvent {
|
||||||
button,
|
button,
|
||||||
position: vec2f(
|
position: vec2f(
|
||||||
native_event.locationInWindow().x as f32,
|
native_event.locationInWindow().x as f32,
|
||||||
window_height - native_event.locationInWindow().y as f32,
|
window_height - native_event.locationInWindow().y as f32,
|
||||||
),
|
),
|
||||||
ctrl: modifiers.contains(NSEventModifierFlags::NSControlKeyMask),
|
modifiers: read_modifiers(native_event),
|
||||||
alt: modifiers.contains(NSEventModifierFlags::NSAlternateKeyMask),
|
|
||||||
shift: modifiers.contains(NSEventModifierFlags::NSShiftKeyMask),
|
|
||||||
cmd: modifiers.contains(NSEventModifierFlags::NSCommandKeyMask),
|
|
||||||
click_count: native_event.clickCount() as usize,
|
click_count: native_event.clickCount() as usize,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
NSEventType::NSScrollWheel => window_height.map(|window_height| {
|
NSEventType::NSScrollWheel => window_height.map(|window_height| {
|
||||||
let modifiers = native_event.modifierFlags();
|
|
||||||
|
|
||||||
let phase = match native_event.phase() {
|
let phase = match native_event.phase() {
|
||||||
NSEventPhase::NSEventPhaseMayBegin | NSEventPhase::NSEventPhaseBegan => {
|
NSEventPhase::NSEventPhaseMayBegin | NSEventPhase::NSEventPhaseBegan => {
|
||||||
Some(TouchPhase::Started)
|
Some(TouchPhase::Started)
|
||||||
|
@ -180,10 +175,7 @@ impl Event {
|
||||||
),
|
),
|
||||||
phase,
|
phase,
|
||||||
precise: native_event.hasPreciseScrollingDeltas() == YES,
|
precise: native_event.hasPreciseScrollingDeltas() == YES,
|
||||||
ctrl: modifiers.contains(NSEventModifierFlags::NSControlKeyMask),
|
modifiers: read_modifiers(native_event),
|
||||||
alt: modifiers.contains(NSEventModifierFlags::NSAlternateKeyMask),
|
|
||||||
shift: modifiers.contains(NSEventModifierFlags::NSShiftKeyMask),
|
|
||||||
cmd: modifiers.contains(NSEventModifierFlags::NSCommandKeyMask),
|
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
NSEventType::NSLeftMouseDragged
|
NSEventType::NSLeftMouseDragged
|
||||||
|
@ -200,32 +192,24 @@ impl Event {
|
||||||
};
|
};
|
||||||
|
|
||||||
window_height.map(|window_height| {
|
window_height.map(|window_height| {
|
||||||
let modifiers = native_event.modifierFlags();
|
|
||||||
Self::MouseMoved(MouseMovedEvent {
|
Self::MouseMoved(MouseMovedEvent {
|
||||||
pressed_button: Some(pressed_button),
|
pressed_button: Some(pressed_button),
|
||||||
position: vec2f(
|
position: vec2f(
|
||||||
native_event.locationInWindow().x as f32,
|
native_event.locationInWindow().x as f32,
|
||||||
window_height - native_event.locationInWindow().y as f32,
|
window_height - native_event.locationInWindow().y as f32,
|
||||||
),
|
),
|
||||||
ctrl: modifiers.contains(NSEventModifierFlags::NSControlKeyMask),
|
modifiers: read_modifiers(native_event),
|
||||||
alt: modifiers.contains(NSEventModifierFlags::NSAlternateKeyMask),
|
|
||||||
shift: modifiers.contains(NSEventModifierFlags::NSShiftKeyMask),
|
|
||||||
cmd: modifiers.contains(NSEventModifierFlags::NSCommandKeyMask),
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
NSEventType::NSMouseMoved => window_height.map(|window_height| {
|
NSEventType::NSMouseMoved => window_height.map(|window_height| {
|
||||||
let modifiers = native_event.modifierFlags();
|
|
||||||
Self::MouseMoved(MouseMovedEvent {
|
Self::MouseMoved(MouseMovedEvent {
|
||||||
position: vec2f(
|
position: vec2f(
|
||||||
native_event.locationInWindow().x as f32,
|
native_event.locationInWindow().x as f32,
|
||||||
window_height - native_event.locationInWindow().y as f32,
|
window_height - native_event.locationInWindow().y as f32,
|
||||||
),
|
),
|
||||||
pressed_button: None,
|
pressed_button: None,
|
||||||
ctrl: modifiers.contains(NSEventModifierFlags::NSControlKeyMask),
|
modifiers: read_modifiers(native_event),
|
||||||
alt: modifiers.contains(NSEventModifierFlags::NSAlternateKeyMask),
|
|
||||||
shift: modifiers.contains(NSEventModifierFlags::NSShiftKeyMask),
|
|
||||||
cmd: modifiers.contains(NSEventModifierFlags::NSCommandKeyMask),
|
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
|
|
@ -981,25 +981,13 @@ extern "C" fn handle_view_event(this: &Object, _: Sel, native_event: id) {
|
||||||
}) => {
|
}) => {
|
||||||
window_state_borrow.synthetic_drag_counter += 1;
|
window_state_borrow.synthetic_drag_counter += 1;
|
||||||
}
|
}
|
||||||
Event::ModifiersChanged(ModifiersChangedEvent {
|
Event::ModifiersChanged(ModifiersChangedEvent { modifiers }) => {
|
||||||
ctrl,
|
|
||||||
alt,
|
|
||||||
shift,
|
|
||||||
cmd,
|
|
||||||
}) => {
|
|
||||||
// Only raise modifiers changed event when they have actually changed
|
// Only raise modifiers changed event when they have actually changed
|
||||||
if let Some(Event::ModifiersChanged(ModifiersChangedEvent {
|
if let Some(Event::ModifiersChanged(ModifiersChangedEvent {
|
||||||
ctrl: prev_ctrl,
|
modifiers: prev_modifiers,
|
||||||
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
|
if prev_modifiers == modifiers {
|
||||||
&& prev_alt == alt
|
|
||||||
&& prev_shift == shift
|
|
||||||
&& prev_cmd == cmd
|
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue