feat(core): wire up mouse event

This commit is contained in:
Federico Terzi 2021-04-23 20:41:41 +02:00
parent aaa55ca063
commit 03d2aac56e
6 changed files with 48 additions and 15 deletions

View File

@ -24,7 +24,7 @@ use log::{error, trace};
use crate::engine::{ use crate::engine::{
event::{ event::{
input::{Key, KeyboardEvent, Status, Variant}, input::{Key, KeyboardEvent, MouseButton, MouseEvent, Status, Variant},
Event, Event,
}, },
funnel, process, funnel, process,
@ -51,7 +51,10 @@ impl<'a> funnel::Source<'a> for DetectSource {
status: keyboard_event.status.into(), status: keyboard_event.status.into(),
variant: keyboard_event.variant.map(|variant| variant.into()), variant: keyboard_event.variant.map(|variant| variant.into()),
}), }),
InputEvent::Mouse(mouse_event) => todo!(), // TODO InputEvent::Mouse(mouse_event) => Event::Mouse(MouseEvent {
status: mouse_event.status.into(),
button: mouse_event.button.into(),
}),
InputEvent::HotKey(_) => todo!(), // TODO InputEvent::HotKey(_) => todo!(), // TODO
} }
} }
@ -76,11 +79,13 @@ pub fn init_and_spawn() -> Result<DetectSource> {
.send(true) .send(true)
.expect("unable to send to the init_tx channel"); .expect("unable to send to the init_tx channel");
source.eventloop(Box::new(move |event| { source
sender .eventloop(Box::new(move |event| {
.send(event) sender
.expect("unable to send to the source channel"); .send(event)
})).expect("detect eventloop crashed"); .expect("unable to send to the source channel");
}))
.expect("detect eventloop crashed");
} }
} }
Err(error) => { Err(error) => {
@ -180,3 +185,18 @@ impl From<espanso_detect::event::Status> for Status {
} }
} }
} }
impl From<espanso_detect::event::MouseButton> for MouseButton {
fn from(button: espanso_detect::event::MouseButton) -> Self {
match button {
espanso_detect::event::MouseButton::Left => MouseButton::Left,
espanso_detect::event::MouseButton::Right => MouseButton::Right,
espanso_detect::event::MouseButton::Middle => MouseButton::Middle,
espanso_detect::event::MouseButton::Button1 => MouseButton::Button1,
espanso_detect::event::MouseButton::Button2 => MouseButton::Button2,
espanso_detect::event::MouseButton::Button3 => MouseButton::Button3,
espanso_detect::event::MouseButton::Button4 => MouseButton::Button4,
espanso_detect::event::MouseButton::Button5 => MouseButton::Button5,
}
}
}

View File

@ -37,9 +37,22 @@ pub struct KeyboardEvent {
pub variant: Option<Variant>, pub variant: Option<Variant>,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone, PartialEq)]
pub struct KeySequenceInjectRequest { pub enum MouseButton {
pub keys: Vec<Key>, Left,
Right,
Middle,
Button1,
Button2,
Button3,
Button4,
Button5,
}
#[derive(Debug, Clone, PartialEq)]
pub struct MouseEvent {
pub button: MouseButton,
pub status: Status,
} }
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]

View File

@ -28,6 +28,8 @@ pub enum Event {
// Inputs // Inputs
Keyboard(input::KeyboardEvent), Keyboard(input::KeyboardEvent),
Mouse(input::MouseEvent),
// TODO: hotkeys
// Internal // Internal
MatchesDetected(internal::MatchesDetectedEvent), MatchesDetected(internal::MatchesDetectedEvent),

View File

@ -19,10 +19,8 @@
use super::super::Middleware; use super::super::Middleware;
use crate::engine::{ use crate::engine::{
dispatch::Mode,
event::{ event::{
effect::TriggerCompensationEvent, effect::TriggerCompensationEvent,
input::{Key, KeySequenceInjectRequest},
internal::CauseCompensatedMatchEvent, internal::CauseCompensatedMatchEvent,
Event, Event,
}, },

View File

@ -18,7 +18,7 @@
*/ */
use super::super::Middleware; use super::super::Middleware;
use crate::engine::{dispatch::Mode, event::{Event, effect::CursorHintCompensationEvent, input::{Key}, internal::RenderedEvent}}; use crate::engine::{event::{Event, effect::CursorHintCompensationEvent, internal::RenderedEvent}};
pub struct CursorHintMiddleware {} pub struct CursorHintMiddleware {}

View File

@ -137,7 +137,7 @@ fn is_event_of_interest(event: &Event) -> bool {
} }
} }
}, },
// TODO: handle mouse Event::Mouse(mouse_event) => mouse_event.status == Status::Pressed,
Event::MatchInjected => true, Event::MatchInjected => true,
_ => false, _ => false,
} }
@ -149,8 +149,8 @@ fn convert_to_matcher_event(event: &Event) -> Option<MatcherEvent> {
key: keyboard_event.key.clone(), key: keyboard_event.key.clone(),
chars: keyboard_event.value.clone(), chars: keyboard_event.value.clone(),
}), }),
Event::Mouse(_) => Some(MatcherEvent::VirtualSeparator),
Event::MatchInjected => Some(MatcherEvent::VirtualSeparator), Event::MatchInjected => Some(MatcherEvent::VirtualSeparator),
// TODO: mouse event should act as separator
_ => None, _ => None,
} }
} }