From 871da0aaa173c79df1ecd4a43b241cf237381f2c Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Fri, 23 Apr 2021 19:53:38 +0200 Subject: [PATCH] refactor(core): change event package names --- Cargo.lock | 1 + .../worker/engine/executor/key_injector.rs | 84 +++++++++---------- espanso/src/cli/worker/engine/match_cache.rs | 2 +- .../src/cli/worker/engine/matcher/rolling.rs | 2 +- espanso/src/cli/worker/engine/multiplex.rs | 2 +- .../src/cli/worker/engine/source/detect.rs | 4 +- .../engine/dispatch/executor/text_inject.rs | 2 +- espanso/src/engine/dispatch/mod.rs | 2 +- espanso/src/engine/event/effect.rs | 19 +++++ .../engine/event/{keyboard.rs => input.rs} | 0 .../engine/event/{matches.rs => internal.rs} | 17 +++- espanso/src/engine/event/mod.rs | 26 +++--- espanso/src/engine/event/render.rs | 35 -------- .../src/engine/process/middleware/action.rs | 5 +- .../src/engine/process/middleware/cause.rs | 4 +- .../engine/process/middleware/cursor_hint.rs | 2 +- .../engine/process/middleware/match_select.rs | 2 +- .../src/engine/process/middleware/matcher.rs | 4 +- .../src/engine/process/middleware/render.rs | 2 +- espanso/src/engine/process/mod.rs | 2 +- 20 files changed, 106 insertions(+), 111 deletions(-) rename espanso/src/engine/event/{keyboard.rs => input.rs} (100%) rename espanso/src/engine/event/{matches.rs => internal.rs} (78%) delete mode 100644 espanso/src/engine/event/render.rs diff --git a/Cargo.lock b/Cargo.lock index f98aeff..175f9b1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -288,6 +288,7 @@ dependencies = [ "anyhow", "clap", "crossbeam", + "dirs 3.0.1", "enum-as-inner", "espanso-clipboard", "espanso-config", diff --git a/espanso/src/cli/worker/engine/executor/key_injector.rs b/espanso/src/cli/worker/engine/executor/key_injector.rs index ba160af..8fa907e 100644 --- a/espanso/src/cli/worker/engine/executor/key_injector.rs +++ b/espanso/src/cli/worker/engine/executor/key_injector.rs @@ -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), } } diff --git a/espanso/src/cli/worker/engine/match_cache.rs b/espanso/src/cli/worker/engine/match_cache.rs index f7a0e66..d4f1346 100644 --- a/espanso/src/cli/worker/engine/match_cache.rs +++ b/espanso/src/cli/worker/engine/match_cache.rs @@ -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 { + fn get_force_mode(&self, match_id: i32) -> Option { 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 diff --git a/espanso/src/cli/worker/engine/matcher/rolling.rs b/espanso/src/cli/worker/engine/matcher/rolling.rs index b0e6b90..3dca1b2 100644 --- a/espanso/src/cli/worker/engine/matcher/rolling.rs +++ b/espanso/src/cli/worker/engine/matcher/rolling.rs @@ -23,7 +23,7 @@ use espanso_match::rolling::{ }; use crate::engine::{ - event::keyboard::Key, + event::input::Key, process::{MatchResult, Matcher, MatcherEvent}, }; diff --git a/espanso/src/cli/worker/engine/multiplex.rs b/espanso/src/cli/worker/engine/multiplex.rs index 41a4d8d..574f8e3 100644 --- a/espanso/src/cli/worker/engine/multiplex.rs +++ b/espanso/src/cli/worker/engine/multiplex.rs @@ -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>; diff --git a/espanso/src/cli/worker/engine/source/detect.rs b/espanso/src/cli/worker/engine/source/detect.rs index e544585..60c8e57 100644 --- a/espanso/src/cli/worker/engine/source/detect.rs +++ b/espanso/src/cli/worker/engine/source/detect.rs @@ -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 } } diff --git a/espanso/src/engine/dispatch/executor/text_inject.rs b/espanso/src/engine/dispatch/executor/text_inject.rs index d0a5c6d..f0f8ac8 100644 --- a/espanso/src/engine/dispatch/executor/text_inject.rs +++ b/espanso/src/engine/dispatch/executor/text_inject.rs @@ -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 { diff --git a/espanso/src/engine/dispatch/mod.rs b/espanso/src/engine/dispatch/mod.rs index ada9fc0..3bb7c8e 100644 --- a/espanso/src/engine/dispatch/mod.rs +++ b/espanso/src/engine/dispatch/mod.rs @@ -19,7 +19,7 @@ use anyhow::Result; -use super::{event::keyboard::Key, Event}; +use super::{event::input::Key, Event}; mod default; mod executor; diff --git a/espanso/src/engine/event/effect.rs b/espanso/src/engine/event/effect.rs index 501ebc8..f3f103a 100644 --- a/espanso/src/engine/event/effect.rs +++ b/espanso/src/engine/event/effect.rs @@ -17,6 +17,8 @@ * along with espanso. If not, see . */ +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, +} + +#[derive(Debug, PartialEq, Clone)] +pub enum TextInjectMode { + Keys, + Clipboard, +} + +#[derive(Debug, Clone)] +pub struct KeySequenceInjectRequest { + pub keys: Vec, } \ No newline at end of file diff --git a/espanso/src/engine/event/keyboard.rs b/espanso/src/engine/event/input.rs similarity index 100% rename from espanso/src/engine/event/keyboard.rs rename to espanso/src/engine/event/input.rs diff --git a/espanso/src/engine/event/matches.rs b/espanso/src/engine/event/internal.rs similarity index 78% rename from espanso/src/engine/event/matches.rs rename to espanso/src/engine/event/internal.rs index af1976c..fd3e273 100644 --- a/espanso/src/engine/event/matches.rs +++ b/espanso/src/engine/event/internal.rs @@ -41,4 +41,19 @@ pub struct MatchSelectedEvent { #[derive(Debug, Clone, PartialEq)] pub struct CauseCompensatedMatchEvent { pub m: DetectedMatch, -} \ No newline at end of file +} + +#[derive(Debug, Clone, PartialEq)] +pub struct RenderingRequestedEvent { + pub match_id: i32, + pub trigger: Option, + pub left_separator: Option, + pub right_separator: Option, + pub trigger_args: HashMap, +} + +#[derive(Debug, Clone, PartialEq)] +pub struct RenderedEvent { + pub match_id: i32, + pub body: String, +} diff --git a/espanso/src/engine/event/mod.rs b/espanso/src/engine/event/mod.rs index f8df790..7af62dc 100644 --- a/espanso/src/engine/event/mod.rs +++ b/espanso/src/engine/event/mod.rs @@ -17,36 +17,32 @@ * along with espanso. If not, see . */ -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), } \ No newline at end of file diff --git a/espanso/src/engine/event/render.rs b/espanso/src/engine/event/render.rs deleted file mode 100644 index 09a6a22..0000000 --- a/espanso/src/engine/event/render.rs +++ /dev/null @@ -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 . - */ - -use std::collections::HashMap; - -#[derive(Debug, Clone, PartialEq)] -pub struct RenderingRequestedEvent { - pub match_id: i32, - pub trigger: Option, - pub left_separator: Option, - pub right_separator: Option, - pub trigger_args: HashMap, -} - -#[derive(Debug, Clone, PartialEq)] -pub struct RenderedEvent { - pub match_id: i32, - pub body: String, -} diff --git a/espanso/src/engine/process/middleware/action.rs b/espanso/src/engine/process/middleware/action.rs index 23b5ae9..df10916 100644 --- a/espanso/src/engine/process/middleware/action.rs +++ b/espanso/src/engine/process/middleware/action.rs @@ -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, }, }; diff --git a/espanso/src/engine/process/middleware/cause.rs b/espanso/src/engine/process/middleware/cause.rs index f4ff571..17adc94 100644 --- a/espanso/src/engine/process/middleware/cause.rs +++ b/espanso/src/engine/process/middleware/cause.rs @@ -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, }, diff --git a/espanso/src/engine/process/middleware/cursor_hint.rs b/espanso/src/engine/process/middleware/cursor_hint.rs index f1f1758..f177941 100644 --- a/espanso/src/engine/process/middleware/cursor_hint.rs +++ b/espanso/src/engine/process/middleware/cursor_hint.rs @@ -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 {} diff --git a/espanso/src/engine/process/middleware/match_select.rs b/espanso/src/engine/process/middleware/match_select.rs index 82c46a8..5bdfcd1 100644 --- a/espanso/src/engine/process/middleware/match_select.rs +++ b/espanso/src/engine/process/middleware/match_select.rs @@ -22,7 +22,7 @@ use log::{debug, error}; use super::super::Middleware; use crate::engine::{ event::{ - matches::{MatchSelectedEvent}, + internal::{MatchSelectedEvent}, Event, }, process::{MatchFilter, MatchSelector}, diff --git a/espanso/src/engine/process/middleware/matcher.rs b/espanso/src/engine/process/middleware/matcher.rs index 3c02020..02efcb3 100644 --- a/espanso/src/engine/process/middleware/matcher.rs +++ b/espanso/src/engine/process/middleware/matcher.rs @@ -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}, diff --git a/espanso/src/engine/process/middleware/render.rs b/espanso/src/engine/process/middleware/render.rs index c57d7e9..38211b7 100644 --- a/espanso/src/engine/process/middleware/render.rs +++ b/espanso/src/engine/process/middleware/render.rs @@ -23,7 +23,7 @@ use super::super::Middleware; use crate::engine::{ event::{ effect::{CursorHintCompensationEvent, TriggerCompensationEvent}, - render::RenderedEvent, + internal::RenderedEvent, Event, }, process::{Renderer, RendererError}, diff --git a/espanso/src/engine/process/mod.rs b/espanso/src/engine/process/mod.rs index 9da7e7b..51b4370 100644 --- a/espanso/src/engine/process/mod.rs +++ b/espanso/src/engine/process/mod.rs @@ -17,7 +17,7 @@ * along with espanso. If not, see . */ -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;