refactor(core): change event package names

This commit is contained in:
Federico Terzi 2021-04-23 19:53:38 +02:00
parent a5fff067f7
commit 871da0aaa1
20 changed files with 106 additions and 111 deletions

1
Cargo.lock generated
View File

@ -288,6 +288,7 @@ dependencies = [
"anyhow",
"clap",
"crossbeam",
"dirs 3.0.1",
"enum-as-inner",
"espanso-clipboard",
"espanso-config",

View File

@ -32,53 +32,53 @@ impl<'a> KeyInjectorAdapter<'a> {
}
impl<'a> KeyInjector for KeyInjectorAdapter<'a> {
fn inject_sequence(&self, keys: &[crate::engine::event::keyboard::Key]) -> anyhow::Result<()> {
fn inject_sequence(&self, keys: &[crate::engine::event::input::Key]) -> anyhow::Result<()> {
let converted_keys: Vec<_> = keys.iter().map(convert_to_inject_key).collect();
self.injector.send_keys(&converted_keys, Default::default()) // TODO: handle options
}
}
fn convert_to_inject_key(key: &crate::engine::event::keyboard::Key) -> espanso_inject::keys::Key {
fn convert_to_inject_key(key: &crate::engine::event::input::Key) -> espanso_inject::keys::Key {
match key {
crate::engine::event::keyboard::Key::Alt => espanso_inject::keys::Key::Alt,
crate::engine::event::keyboard::Key::CapsLock => espanso_inject::keys::Key::CapsLock,
crate::engine::event::keyboard::Key::Control => espanso_inject::keys::Key::Control,
crate::engine::event::keyboard::Key::Meta => espanso_inject::keys::Key::Meta,
crate::engine::event::keyboard::Key::NumLock => espanso_inject::keys::Key::NumLock,
crate::engine::event::keyboard::Key::Shift => espanso_inject::keys::Key::Shift,
crate::engine::event::keyboard::Key::Enter => espanso_inject::keys::Key::Enter,
crate::engine::event::keyboard::Key::Tab => espanso_inject::keys::Key::Tab,
crate::engine::event::keyboard::Key::Space => espanso_inject::keys::Key::Space,
crate::engine::event::keyboard::Key::ArrowDown => espanso_inject::keys::Key::ArrowDown,
crate::engine::event::keyboard::Key::ArrowLeft => espanso_inject::keys::Key::ArrowLeft,
crate::engine::event::keyboard::Key::ArrowRight => espanso_inject::keys::Key::ArrowRight,
crate::engine::event::keyboard::Key::ArrowUp => espanso_inject::keys::Key::ArrowUp,
crate::engine::event::keyboard::Key::End => espanso_inject::keys::Key::End,
crate::engine::event::keyboard::Key::Home => espanso_inject::keys::Key::Home,
crate::engine::event::keyboard::Key::PageDown => espanso_inject::keys::Key::PageDown,
crate::engine::event::keyboard::Key::PageUp => espanso_inject::keys::Key::PageUp,
crate::engine::event::keyboard::Key::Escape => espanso_inject::keys::Key::Escape,
crate::engine::event::keyboard::Key::Backspace => espanso_inject::keys::Key::Backspace,
crate::engine::event::keyboard::Key::F1 => espanso_inject::keys::Key::F1,
crate::engine::event::keyboard::Key::F2 => espanso_inject::keys::Key::F2,
crate::engine::event::keyboard::Key::F3 => espanso_inject::keys::Key::F3,
crate::engine::event::keyboard::Key::F4 => espanso_inject::keys::Key::F4,
crate::engine::event::keyboard::Key::F5 => espanso_inject::keys::Key::F5,
crate::engine::event::keyboard::Key::F6 => espanso_inject::keys::Key::F6,
crate::engine::event::keyboard::Key::F7 => espanso_inject::keys::Key::F7,
crate::engine::event::keyboard::Key::F8 => espanso_inject::keys::Key::F8,
crate::engine::event::keyboard::Key::F9 => espanso_inject::keys::Key::F9,
crate::engine::event::keyboard::Key::F10 => espanso_inject::keys::Key::F10,
crate::engine::event::keyboard::Key::F11 => espanso_inject::keys::Key::F11,
crate::engine::event::keyboard::Key::F12 => espanso_inject::keys::Key::F12,
crate::engine::event::keyboard::Key::F13 => espanso_inject::keys::Key::F13,
crate::engine::event::keyboard::Key::F14 => espanso_inject::keys::Key::F14,
crate::engine::event::keyboard::Key::F15 => espanso_inject::keys::Key::F15,
crate::engine::event::keyboard::Key::F16 => espanso_inject::keys::Key::F16,
crate::engine::event::keyboard::Key::F17 => espanso_inject::keys::Key::F17,
crate::engine::event::keyboard::Key::F18 => espanso_inject::keys::Key::F18,
crate::engine::event::keyboard::Key::F19 => espanso_inject::keys::Key::F19,
crate::engine::event::keyboard::Key::F20 => espanso_inject::keys::Key::F20,
crate::engine::event::keyboard::Key::Other(raw) => espanso_inject::keys::Key::Raw(*raw),
crate::engine::event::input::Key::Alt => espanso_inject::keys::Key::Alt,
crate::engine::event::input::Key::CapsLock => espanso_inject::keys::Key::CapsLock,
crate::engine::event::input::Key::Control => espanso_inject::keys::Key::Control,
crate::engine::event::input::Key::Meta => espanso_inject::keys::Key::Meta,
crate::engine::event::input::Key::NumLock => espanso_inject::keys::Key::NumLock,
crate::engine::event::input::Key::Shift => espanso_inject::keys::Key::Shift,
crate::engine::event::input::Key::Enter => espanso_inject::keys::Key::Enter,
crate::engine::event::input::Key::Tab => espanso_inject::keys::Key::Tab,
crate::engine::event::input::Key::Space => espanso_inject::keys::Key::Space,
crate::engine::event::input::Key::ArrowDown => espanso_inject::keys::Key::ArrowDown,
crate::engine::event::input::Key::ArrowLeft => espanso_inject::keys::Key::ArrowLeft,
crate::engine::event::input::Key::ArrowRight => espanso_inject::keys::Key::ArrowRight,
crate::engine::event::input::Key::ArrowUp => espanso_inject::keys::Key::ArrowUp,
crate::engine::event::input::Key::End => espanso_inject::keys::Key::End,
crate::engine::event::input::Key::Home => espanso_inject::keys::Key::Home,
crate::engine::event::input::Key::PageDown => espanso_inject::keys::Key::PageDown,
crate::engine::event::input::Key::PageUp => espanso_inject::keys::Key::PageUp,
crate::engine::event::input::Key::Escape => espanso_inject::keys::Key::Escape,
crate::engine::event::input::Key::Backspace => espanso_inject::keys::Key::Backspace,
crate::engine::event::input::Key::F1 => espanso_inject::keys::Key::F1,
crate::engine::event::input::Key::F2 => espanso_inject::keys::Key::F2,
crate::engine::event::input::Key::F3 => espanso_inject::keys::Key::F3,
crate::engine::event::input::Key::F4 => espanso_inject::keys::Key::F4,
crate::engine::event::input::Key::F5 => espanso_inject::keys::Key::F5,
crate::engine::event::input::Key::F6 => espanso_inject::keys::Key::F6,
crate::engine::event::input::Key::F7 => espanso_inject::keys::Key::F7,
crate::engine::event::input::Key::F8 => espanso_inject::keys::Key::F8,
crate::engine::event::input::Key::F9 => espanso_inject::keys::Key::F9,
crate::engine::event::input::Key::F10 => espanso_inject::keys::Key::F10,
crate::engine::event::input::Key::F11 => espanso_inject::keys::Key::F11,
crate::engine::event::input::Key::F12 => espanso_inject::keys::Key::F12,
crate::engine::event::input::Key::F13 => espanso_inject::keys::Key::F13,
crate::engine::event::input::Key::F14 => espanso_inject::keys::Key::F14,
crate::engine::event::input::Key::F15 => espanso_inject::keys::Key::F15,
crate::engine::event::input::Key::F16 => espanso_inject::keys::Key::F16,
crate::engine::event::input::Key::F17 => espanso_inject::keys::Key::F17,
crate::engine::event::input::Key::F18 => espanso_inject::keys::Key::F18,
crate::engine::event::input::Key::F19 => espanso_inject::keys::Key::F19,
crate::engine::event::input::Key::F20 => espanso_inject::keys::Key::F20,
crate::engine::event::input::Key::Other(raw) => espanso_inject::keys::Key::Raw(*raw),
}
}

View File

@ -64,7 +64,7 @@ impl<'a> super::render::MatchProvider<'a> for MatchCache<'a> {
}
impl<'a> MatchInfoProvider for MatchCache<'a> {
fn get_force_mode(&self, match_id: i32) -> Option<crate::engine::event::text::TextInjectMode> {
fn get_force_mode(&self, match_id: i32) -> Option<crate::engine::event::effect::TextInjectMode> {
let m = self.cache.get(&match_id)?;
if let MatchEffect::Text(text_effect) = &m.effect {
// TODO: read match effect and convert it to the actual injection mode

View File

@ -23,7 +23,7 @@ use espanso_match::rolling::{
};
use crate::engine::{
event::keyboard::Key,
event::input::Key,
process::{MatchResult, Matcher, MatcherEvent},
};

View File

@ -21,7 +21,7 @@ use std::collections::HashMap;
use espanso_config::matches::{Match, MatchEffect};
use crate::engine::{event::{Event, matches::DetectedMatch, render::RenderingRequestedEvent}, process::Multiplexer};
use crate::engine::{event::{Event, internal::DetectedMatch, internal::RenderingRequestedEvent}, process::Multiplexer};
pub trait MatchProvider<'a> {
fn get(&self, match_id: i32) -> Option<&'a Match>;

View File

@ -24,7 +24,7 @@ use log::{error, trace};
use crate::engine::{
event::{
keyboard::{Key, KeyboardEvent, Status, Variant},
input::{Key, KeyboardEvent, Status, Variant},
Event,
},
funnel, process,
@ -51,7 +51,7 @@ impl<'a> funnel::Source<'a> for DetectSource {
status: keyboard_event.status.into(),
variant: keyboard_event.variant.map(|variant| variant.into()),
}),
InputEvent::Mouse(_) => todo!(), // TODO
InputEvent::Mouse(mouse_event) => todo!(), // TODO
InputEvent::HotKey(_) => todo!(), // TODO
}
}

View File

@ -19,7 +19,7 @@
use anyhow::Result;
use super::super::{Event, Executor};
use crate::engine::event::text::TextInjectMode;
use crate::engine::event::effect::TextInjectMode;
use log::{error, trace};
pub trait TextInjector {

View File

@ -19,7 +19,7 @@
use anyhow::Result;
use super::{event::keyboard::Key, Event};
use super::{event::input::Key, Event};
mod default;
mod executor;

View File

@ -17,6 +17,8 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/
use super::input::Key;
#[derive(Debug, Clone, PartialEq)]
pub struct TriggerCompensationEvent {
pub trigger: String,
@ -26,4 +28,21 @@ pub struct TriggerCompensationEvent {
#[derive(Debug, Clone, PartialEq)]
pub struct CursorHintCompensationEvent {
pub cursor_hint_back_count: usize,
}
#[derive(Debug, Clone)]
pub struct TextInjectRequest {
pub text: String,
pub force_mode: Option<TextInjectMode>,
}
#[derive(Debug, PartialEq, Clone)]
pub enum TextInjectMode {
Keys,
Clipboard,
}
#[derive(Debug, Clone)]
pub struct KeySequenceInjectRequest {
pub keys: Vec<Key>,
}

View File

@ -41,4 +41,19 @@ pub struct MatchSelectedEvent {
#[derive(Debug, Clone, PartialEq)]
pub struct CauseCompensatedMatchEvent {
pub m: DetectedMatch,
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct RenderingRequestedEvent {
pub match_id: i32,
pub trigger: Option<String>,
pub left_separator: Option<String>,
pub right_separator: Option<String>,
pub trigger_args: HashMap<String, String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct RenderedEvent {
pub match_id: i32,
pub body: String,
}

View File

@ -17,36 +17,32 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/
pub mod keyboard;
pub mod text;
pub mod matches;
pub mod render;
pub mod input;
pub mod effect;
pub mod internal;
#[derive(Debug, Clone)]
pub enum Event {
NOOP,
ProcessingError(String), // TODO: create dedicated event
ProcessingError(String),
// Inputs
// TODO: Move to the input mode
Keyboard(keyboard::KeyboardEvent),
Keyboard(input::KeyboardEvent),
// Internal
// TODO: move to the "internal" mode (maybe, change name?)
MatchesDetected(matches::MatchesDetectedEvent),
MatchSelected(matches::MatchSelectedEvent),
CauseCompensatedMatch(matches::CauseCompensatedMatchEvent),
MatchesDetected(internal::MatchesDetectedEvent),
MatchSelected(internal::MatchSelectedEvent),
CauseCompensatedMatch(internal::CauseCompensatedMatchEvent),
RenderingRequested(render::RenderingRequestedEvent),
Rendered(render::RenderedEvent),
RenderingRequested(internal::RenderingRequestedEvent),
Rendered(internal::RenderedEvent),
MatchInjected,
// Effects
TriggerCompensation(effect::TriggerCompensationEvent),
CursorHintCompensation(effect::CursorHintCompensationEvent),
// TODO: move to the "effect" mod
KeySequenceInject(keyboard::KeySequenceInjectRequest),
TextInject(text::TextInjectRequest),
KeySequenceInject(effect::KeySequenceInjectRequest),
TextInject(effect::TextInjectRequest),
}

View File

@ -1,35 +0,0 @@
/*
* This file is part of espanso.
*
* Copyright (C) 2019-2021 Federico Terzi
*
* espanso is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* espanso is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/
use std::collections::HashMap;
#[derive(Debug, Clone, PartialEq)]
pub struct RenderingRequestedEvent {
pub match_id: i32,
pub trigger: Option<String>,
pub left_separator: Option<String>,
pub right_separator: Option<String>,
pub trigger_args: HashMap<String, String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct RenderedEvent {
pub match_id: i32,
pub body: String,
}

View File

@ -19,10 +19,9 @@
use super::super::Middleware;
use crate::engine::{
dispatch::Mode,
event::{
keyboard::{Key, KeySequenceInjectRequest},
text::{TextInjectMode, TextInjectRequest},
input::{Key},
effect::{TextInjectMode, TextInjectRequest, KeySequenceInjectRequest},
Event,
},
};

View File

@ -22,8 +22,8 @@ use crate::engine::{
dispatch::Mode,
event::{
effect::TriggerCompensationEvent,
keyboard::{Key, KeySequenceInjectRequest},
matches::CauseCompensatedMatchEvent,
input::{Key, KeySequenceInjectRequest},
internal::CauseCompensatedMatchEvent,
text::{TextInjectMode, TextInjectRequest},
Event,
},

View File

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

View File

@ -22,7 +22,7 @@ use log::{debug, error};
use super::super::Middleware;
use crate::engine::{
event::{
matches::{MatchSelectedEvent},
internal::{MatchSelectedEvent},
Event,
},
process::{MatchFilter, MatchSelector},

View File

@ -23,8 +23,8 @@ use std::{cell::RefCell, collections::VecDeque};
use super::super::Middleware;
use crate::engine::{
event::{
keyboard::{Key, Status},
matches::{DetectedMatch, MatchesDetectedEvent},
input::{Key, Status},
internal::{DetectedMatch, MatchesDetectedEvent},
Event,
},
process::{Matcher, MatcherEvent},

View File

@ -23,7 +23,7 @@ use super::super::Middleware;
use crate::engine::{
event::{
effect::{CursorHintCompensationEvent, TriggerCompensationEvent},
render::RenderedEvent,
internal::RenderedEvent,
Event,
},
process::{Renderer, RendererError},

View File

@ -17,7 +17,7 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/
use super::{Event, event::{keyboard::Key, matches::DetectedMatch}};
use super::{Event, event::{input::Key, internal::DetectedMatch}};
use anyhow::Result;
use std::collections::HashMap;
use thiserror::Error;