Merge 7eafc4573e
into bd4e943597
This commit is contained in:
commit
7e166bb993
3 changed files with 61 additions and 30 deletions
|
@ -534,6 +534,23 @@ impl InputEvent for FileDropEvent {
|
||||||
}
|
}
|
||||||
impl MouseEvent for FileDropEvent {}
|
impl MouseEvent for FileDropEvent {}
|
||||||
|
|
||||||
|
/// A swipe direction on macOS.
|
||||||
|
#[derive(Hash, PartialEq, Eq, Copy, Clone, Debug)]
|
||||||
|
#[allow(missing_docs)]
|
||||||
|
pub enum SwipeDirection {
|
||||||
|
Left,
|
||||||
|
Right,
|
||||||
|
Up,
|
||||||
|
Down,
|
||||||
|
}
|
||||||
|
/// Recognizing touch pad gesture, such as swipe.
|
||||||
|
/// For now only swipe is supported.
|
||||||
|
#[derive(Clone, Copy, Eq, PartialEq, Debug)]
|
||||||
|
pub enum TouchPadGestureEvent {
|
||||||
|
/// A swipe gesture was performed.
|
||||||
|
Swipe(SwipeDirection),
|
||||||
|
}
|
||||||
|
|
||||||
/// An enum corresponding to all kinds of platform input events.
|
/// An enum corresponding to all kinds of platform input events.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum PlatformInput {
|
pub enum PlatformInput {
|
||||||
|
@ -555,6 +572,8 @@ pub enum PlatformInput {
|
||||||
ScrollWheel(ScrollWheelEvent),
|
ScrollWheel(ScrollWheelEvent),
|
||||||
/// Files were dragged and dropped onto the window.
|
/// Files were dragged and dropped onto the window.
|
||||||
FileDrop(FileDropEvent),
|
FileDrop(FileDropEvent),
|
||||||
|
/// Touch pad gesture was performed.
|
||||||
|
TouchPad(TouchPadGestureEvent),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PlatformInput {
|
impl PlatformInput {
|
||||||
|
@ -569,6 +588,7 @@ impl PlatformInput {
|
||||||
PlatformInput::MouseExited(event) => Some(event),
|
PlatformInput::MouseExited(event) => Some(event),
|
||||||
PlatformInput::ScrollWheel(event) => Some(event),
|
PlatformInput::ScrollWheel(event) => Some(event),
|
||||||
PlatformInput::FileDrop(event) => Some(event),
|
PlatformInput::FileDrop(event) => Some(event),
|
||||||
|
PlatformInput::TouchPad(_) => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -583,6 +603,13 @@ impl PlatformInput {
|
||||||
PlatformInput::MouseExited(_) => None,
|
PlatformInput::MouseExited(_) => None,
|
||||||
PlatformInput::ScrollWheel(_) => None,
|
PlatformInput::ScrollWheel(_) => None,
|
||||||
PlatformInput::FileDrop(_) => None,
|
PlatformInput::FileDrop(_) => None,
|
||||||
|
PlatformInput::TouchPad(_) => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub(crate) fn touchpad_event(&self) -> Option<&TouchPadGestureEvent> {
|
||||||
|
match self {
|
||||||
|
PlatformInput::TouchPad(event) => Some(event),
|
||||||
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
Capslock, KeyDownEvent, KeyUpEvent, Keystroke, Modifiers, ModifiersChangedEvent, MouseButton,
|
Capslock, KeyDownEvent, KeyUpEvent, Keystroke, Modifiers, ModifiersChangedEvent, MouseButton,
|
||||||
MouseDownEvent, MouseExitEvent, MouseMoveEvent, MouseUpEvent, NavigationDirection, Pixels,
|
MouseDownEvent, MouseExitEvent, MouseMoveEvent, MouseUpEvent, NavigationDirection,
|
||||||
PlatformInput, ScrollDelta, ScrollWheelEvent, TouchPhase,
|
Pixels, PlatformInput, ScrollDelta, ScrollWheelEvent, SwipeDirection, TouchPadGestureEvent, TouchPhase,
|
||||||
platform::mac::{
|
platform::mac::{
|
||||||
LMGetKbdType, NSStringExt, TISCopyCurrentKeyboardLayoutInputSource,
|
LMGetKbdType, NSStringExt, TISCopyCurrentKeyboardLayoutInputSource,
|
||||||
TISGetInputSourceProperty, UCKeyTranslate, kTISPropertyUnicodeKeyLayoutData,
|
TISGetInputSourceProperty, UCKeyTranslate, kTISPropertyUnicodeKeyLayoutData,
|
||||||
|
@ -186,33 +186,14 @@ impl PlatformInput {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// Some mice (like Logitech MX Master) send navigation buttons as swipe events
|
NSEventType::NSEventTypeSwipe => match (native_event.deltaX() as i32, native_event.deltaY() as i32) {
|
||||||
NSEventType::NSEventTypeSwipe => {
|
(1, 0) => Some(SwipeDirection::Left),
|
||||||
let navigation_direction = match native_event.phase() {
|
(-1, 0) => Some(SwipeDirection::Right),
|
||||||
NSEventPhase::NSEventPhaseEnded => match native_event.deltaX() {
|
(0, 1) => Some(SwipeDirection::Up),
|
||||||
x if x > 0.0 => Some(NavigationDirection::Back),
|
(0, -1) => Some(SwipeDirection::Down),
|
||||||
x if x < 0.0 => Some(NavigationDirection::Forward),
|
_ => None,
|
||||||
_ => return None,
|
|
||||||
},
|
|
||||||
_ => return None,
|
|
||||||
};
|
|
||||||
|
|
||||||
match navigation_direction {
|
|
||||||
Some(direction) => window_height.map(|window_height| {
|
|
||||||
Self::MouseDown(MouseDownEvent {
|
|
||||||
button: MouseButton::Navigate(direction),
|
|
||||||
position: point(
|
|
||||||
px(native_event.locationInWindow().x as f32),
|
|
||||||
window_height - px(native_event.locationInWindow().y as f32),
|
|
||||||
),
|
|
||||||
modifiers: read_modifiers(native_event),
|
|
||||||
click_count: 1,
|
|
||||||
first_mouse: false,
|
|
||||||
})
|
|
||||||
}),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
.map(|direction| Self::TouchPad(TouchPadGestureEvent::Swipe(direction))),
|
||||||
NSEventType::NSScrollWheel => window_height.map(|window_height| {
|
NSEventType::NSScrollWheel => window_height.map(|window_height| {
|
||||||
let phase = match native_event.phase() {
|
let phase = match native_event.phase() {
|
||||||
NSEventPhase::NSEventPhaseMayBegin | NSEventPhase::NSEventPhaseBegan => {
|
NSEventPhase::NSEventPhaseMayBegin | NSEventPhase::NSEventPhaseBegan => {
|
||||||
|
|
|
@ -12,8 +12,8 @@ use crate::{
|
||||||
PlatformInputHandler, PlatformWindow, Point, PolychromeSprite, PromptButton, PromptLevel, Quad,
|
PlatformInputHandler, PlatformWindow, Point, PolychromeSprite, PromptButton, PromptLevel, Quad,
|
||||||
Render, RenderGlyphParams, RenderImage, RenderImageParams, RenderSvgParams, Replay, ResizeEdge,
|
Render, RenderGlyphParams, RenderImage, RenderImageParams, RenderSvgParams, Replay, ResizeEdge,
|
||||||
SMOOTH_SVG_SCALE_FACTOR, SUBPIXEL_VARIANTS, ScaledPixels, Scene, Shadow, SharedString, Size,
|
SMOOTH_SVG_SCALE_FACTOR, SUBPIXEL_VARIANTS, ScaledPixels, Scene, Shadow, SharedString, Size,
|
||||||
StrikethroughStyle, Style, SubscriberSet, Subscription, TabHandles, TaffyLayoutEngine, Task,
|
StrikethroughStyle, Style, SubscriberSet, Subscription, SwipeDirection, TabHandles, TaffyLayoutEngine, Task, TextStyle,
|
||||||
TextStyle, TextStyleRefinement, TransformationMatrix, Underline, UnderlineStyle,
|
TextStyleRefinement, TouchPadGestureEvent, TransformationMatrix, Underline, UnderlineStyle,
|
||||||
WindowAppearance, WindowBackgroundAppearance, WindowBounds, WindowControls, WindowDecorations,
|
WindowAppearance, WindowBackgroundAppearance, WindowBounds, WindowControls, WindowDecorations,
|
||||||
WindowOptions, WindowParams, WindowTextSystem, point, prelude::*, px, rems, size,
|
WindowOptions, WindowParams, WindowTextSystem, point, prelude::*, px, rems, size,
|
||||||
transparent_black,
|
transparent_black,
|
||||||
|
@ -3554,12 +3554,15 @@ impl Window {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
PlatformInput::KeyDown(_) | PlatformInput::KeyUp(_) => event,
|
PlatformInput::KeyDown(_) | PlatformInput::KeyUp(_) => event,
|
||||||
|
PlatformInput::TouchPad(TouchPadGestureEvent::Swipe(_)) => event,
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(any_mouse_event) = event.mouse_event() {
|
if let Some(any_mouse_event) = event.mouse_event() {
|
||||||
self.dispatch_mouse_event(any_mouse_event, cx);
|
self.dispatch_mouse_event(any_mouse_event, cx);
|
||||||
} else if let Some(any_key_event) = event.keyboard_event() {
|
} else if let Some(any_key_event) = event.keyboard_event() {
|
||||||
self.dispatch_key_event(any_key_event, cx);
|
self.dispatch_key_event(any_key_event, cx);
|
||||||
|
} else if let Some(TouchPadGestureEvent::Swipe(direction)) = event.touchpad_event() {
|
||||||
|
self.dispatch_swipe_event(direction, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
DispatchEventResult {
|
DispatchEventResult {
|
||||||
|
@ -3621,6 +3624,26 @@ impl Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn dispatch_swipe_event(&mut self, direction: &SwipeDirection, cx: &mut App) {
|
||||||
|
// Eventually we want to read from a config what to do, while forward/back is default.
|
||||||
|
let action_name = match direction {
|
||||||
|
SwipeDirection::Right => Some("pane::GoForward"),
|
||||||
|
SwipeDirection::Left => Some("pane::GoBack"),
|
||||||
|
_ => None,
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Ok(_) = action_name
|
||||||
|
.ok_or_else(|| crate::ActionBuildError::NotFound {
|
||||||
|
name: format!("swipe::{:?}", action_name),
|
||||||
|
})
|
||||||
|
.and_then(|action_name| cx.build_action(action_name, None))
|
||||||
|
.map(|action| {
|
||||||
|
self.dispatch_action(action, cx);
|
||||||
|
direction
|
||||||
|
})
|
||||||
|
{}
|
||||||
|
}
|
||||||
|
|
||||||
fn dispatch_key_event(&mut self, event: &dyn Any, cx: &mut App) {
|
fn dispatch_key_event(&mut self, event: &dyn Any, cx: &mut App) {
|
||||||
if self.invalidator.is_dirty() {
|
if self.invalidator.is_dirty() {
|
||||||
self.draw(cx).clear();
|
self.draw(cx).clear();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue