diff --git a/espanso/src/cli/worker/config.rs b/espanso/src/cli/worker/config.rs
index d888a06..ad67507 100644
--- a/espanso/src/cli/worker/config.rs
+++ b/espanso/src/cli/worker/config.rs
@@ -61,6 +61,10 @@ impl<'a> ConfigManager<'a> {
let match_paths = config.match_paths();
(config, self.match_store.query(&match_paths))
}
+
+ pub fn default(&self) -> &'a dyn Config {
+ self.config_store.default()
+ }
}
// TODO: test
diff --git a/espanso/src/cli/worker/engine/executor/icon.rs b/espanso/src/cli/worker/engine/executor/icon.rs
new file mode 100644
index 0000000..aae1562
--- /dev/null
+++ b/espanso/src/cli/worker/engine/executor/icon.rs
@@ -0,0 +1,46 @@
+/*
+ * 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 espanso_ui::{UIRemote, icons::TrayIcon};
+
+use crate::engine::{dispatch::IconHandler, event::ui::IconStatus};
+
+pub struct IconHandlerAdapter<'a> {
+ remote: &'a dyn UIRemote,
+}
+
+impl<'a> IconHandlerAdapter<'a> {
+ pub fn new(remote: &'a dyn UIRemote) -> Self {
+ Self { remote }
+ }
+}
+
+impl<'a> IconHandler for IconHandlerAdapter<'a> {
+ fn update_icon(&self, status: &IconStatus) -> anyhow::Result<()> {
+ let icon = match status {
+ IconStatus::Enabled => TrayIcon::Normal,
+ IconStatus::Disabled => TrayIcon::Disabled,
+ IconStatus::SecureInputDisabled => TrayIcon::SystemDisabled,
+ };
+
+ self.remote.update_tray_icon(icon);
+
+ Ok(())
+ }
+}
\ No newline at end of file
diff --git a/espanso/src/cli/worker/engine/executor/mod.rs b/espanso/src/cli/worker/engine/executor/mod.rs
index ad18615..425f595 100644
--- a/espanso/src/cli/worker/engine/executor/mod.rs
+++ b/espanso/src/cli/worker/engine/executor/mod.rs
@@ -20,4 +20,5 @@
pub mod clipboard_injector;
pub mod context_menu;
pub mod event_injector;
+pub mod icon;
pub mod key_injector;
\ No newline at end of file
diff --git a/espanso/src/cli/worker/engine/mod.rs b/espanso/src/cli/worker/engine/mod.rs
index 49eb9ec..87fcf44 100644
--- a/espanso/src/cli/worker/engine/mod.rs
+++ b/espanso/src/cli/worker/engine/mod.rs
@@ -34,6 +34,7 @@ pub mod match_cache;
pub mod matcher;
pub mod multiplex;
pub mod path;
+pub mod process;
pub mod render;
pub mod source;
pub mod ui;
@@ -118,6 +119,8 @@ pub fn initialize_and_spawn(
super::engine::render::RendererAdapter::new(&match_cache, &config_manager, &renderer);
let path_provider = PathProviderAdapter::new(&paths);
+ let disable_options = process::middleware::disable::extract_disable_options(config_manager.default());
+
let mut processor = crate::engine::process::default(
&matchers,
&config_manager,
@@ -128,6 +131,7 @@ pub fn initialize_and_spawn(
&modifier_state_store,
&sequencer,
&path_provider,
+ disable_options,
);
let event_injector =
@@ -140,6 +144,7 @@ pub fn initialize_and_spawn(
);
let key_injector = super::engine::executor::key_injector::KeyInjectorAdapter::new(&*injector);
let context_menu_adapter = super::engine::executor::context_menu::ContextMenuHandlerAdapter::new(&*ui_remote);
+ let icon_adapter = super::engine::executor::icon::IconHandlerAdapter::new(&*ui_remote);
let dispatcher = crate::engine::dispatch::default(
&event_injector,
&clipboard_injector,
@@ -148,6 +153,7 @@ pub fn initialize_and_spawn(
&clipboard_injector,
&clipboard_injector,
&context_menu_adapter,
+ &icon_adapter,
);
let mut engine = crate::engine::Engine::new(&funnel, &mut processor, &dispatcher);
diff --git a/espanso/src/cli/worker/engine/process/middleware/disable.rs b/espanso/src/cli/worker/engine/process/middleware/disable.rs
new file mode 100644
index 0000000..f5ca7f8
--- /dev/null
+++ b/espanso/src/cli/worker/engine/process/middleware/disable.rs
@@ -0,0 +1,49 @@
+/*
+ * 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::time::Duration;
+
+use crate::engine::{event::input::{Key, Variant}, process::DisableOptions};
+use espanso_config::config::Config;
+
+pub fn extract_disable_options(config: &dyn Config) -> DisableOptions {
+ let (toggle_key, variant) = match config.toggle_key() {
+ Some(key) => match key {
+ espanso_config::config::ToggleKey::Ctrl => (Some(Key::Control), None),
+ espanso_config::config::ToggleKey::Meta => (Some(Key::Meta), None),
+ espanso_config::config::ToggleKey::Alt => (Some(Key::Alt), None),
+ espanso_config::config::ToggleKey::Shift => (Some(Key::Shift), None),
+ espanso_config::config::ToggleKey::RightCtrl => (Some(Key::Control), Some(Variant::Right)),
+ espanso_config::config::ToggleKey::RightAlt => (Some(Key::Alt), Some(Variant::Right)),
+ espanso_config::config::ToggleKey::RightShift => (Some(Key::Shift), Some(Variant::Right)),
+ espanso_config::config::ToggleKey::RightMeta => (Some(Key::Meta), Some(Variant::Right)),
+ espanso_config::config::ToggleKey::LeftCtrl => (Some(Key::Control), Some(Variant::Left)),
+ espanso_config::config::ToggleKey::LeftAlt => (Some(Key::Alt), Some(Variant::Left)),
+ espanso_config::config::ToggleKey::LeftShift => (Some(Key::Shift), Some(Variant::Left)),
+ espanso_config::config::ToggleKey::LeftMeta => (Some(Key::Meta), Some(Variant::Left)),
+ },
+ None => (None, None),
+ };
+
+ DisableOptions {
+ toggle_key,
+ toggle_key_variant: variant,
+ toggle_key_maximum_window: Duration::from_millis(1000),
+ }
+}
diff --git a/espanso/src/cli/worker/engine/process/middleware/mod.rs b/espanso/src/cli/worker/engine/process/middleware/mod.rs
new file mode 100644
index 0000000..1b892d6
--- /dev/null
+++ b/espanso/src/cli/worker/engine/process/middleware/mod.rs
@@ -0,0 +1,20 @@
+/*
+ * 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 .
+ */
+
+pub mod disable;
\ No newline at end of file
diff --git a/espanso/src/cli/worker/engine/process/mod.rs b/espanso/src/cli/worker/engine/process/mod.rs
new file mode 100644
index 0000000..f83f234
--- /dev/null
+++ b/espanso/src/cli/worker/engine/process/mod.rs
@@ -0,0 +1,20 @@
+/*
+ * 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 .
+ */
+
+pub mod middleware;
\ No newline at end of file
diff --git a/espanso/src/engine/dispatch/default.rs b/espanso/src/engine/dispatch/default.rs
index af91f5a..4615643 100644
--- a/espanso/src/engine/dispatch/default.rs
+++ b/espanso/src/engine/dispatch/default.rs
@@ -17,7 +17,7 @@
* along with espanso. If not, see .
*/
-use super::{ContextMenuHandler, Event, ImageInjector};
+use super::{ContextMenuHandler, Event, IconHandler, ImageInjector};
use super::{ModeProvider, Dispatcher, Executor, KeyInjector, TextInjector, HtmlInjector};
pub struct DefaultDispatcher<'a> {
@@ -33,6 +33,7 @@ impl<'a> DefaultDispatcher<'a> {
html_injector: &'a dyn HtmlInjector,
image_injector: &'a dyn ImageInjector,
context_menu_handler: &'a dyn ContextMenuHandler,
+ icon_handler: &'a dyn IconHandler,
) -> Self {
Self {
executors: vec![
@@ -52,6 +53,9 @@ impl<'a> DefaultDispatcher<'a> {
)),
Box::new(super::executor::context_menu::ContextMenuExecutor::new(
context_menu_handler,
+ )),
+ Box::new(super::executor::icon_update::IconUpdateExecutor::new(
+ icon_handler,
))
],
}
diff --git a/espanso/src/engine/dispatch/executor/icon_update.rs b/espanso/src/engine/dispatch/executor/icon_update.rs
new file mode 100644
index 0000000..95395a3
--- /dev/null
+++ b/espanso/src/engine/dispatch/executor/icon_update.rs
@@ -0,0 +1,53 @@
+/*
+ * 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 super::super::{Event, Executor};
+use crate::engine::event::{EventType, ui::{IconStatus}};
+use anyhow::Result;
+use log::error;
+
+pub trait IconHandler {
+ fn update_icon(&self, status: &IconStatus) -> Result<()>;
+}
+
+pub struct IconUpdateExecutor<'a> {
+ handler: &'a dyn IconHandler,
+}
+
+impl<'a> IconUpdateExecutor<'a> {
+ pub fn new(handler: &'a dyn IconHandler) -> Self {
+ Self { handler }
+ }
+}
+
+impl<'a> Executor for IconUpdateExecutor<'a> {
+ fn execute(&self, event: &Event) -> bool {
+ if let EventType::IconStatusChange(m_event) = &event.etype {
+ if let Err(error) = self.handler.update_icon(&m_event.status) {
+ error!("icon handler reported an error: {:?}", error);
+ }
+
+ return true;
+ }
+
+ false
+ }
+}
+
+// TODO: test
diff --git a/espanso/src/engine/dispatch/executor/mod.rs b/espanso/src/engine/dispatch/executor/mod.rs
index 158d6d8..54d7865 100644
--- a/espanso/src/engine/dispatch/executor/mod.rs
+++ b/espanso/src/engine/dispatch/executor/mod.rs
@@ -18,6 +18,7 @@
*/
pub mod context_menu;
+pub mod icon_update;
pub mod image_inject;
pub mod html_inject;
pub mod key_inject;
diff --git a/espanso/src/engine/dispatch/mod.rs b/espanso/src/engine/dispatch/mod.rs
index fc710c0..edf606e 100644
--- a/espanso/src/engine/dispatch/mod.rs
+++ b/espanso/src/engine/dispatch/mod.rs
@@ -37,6 +37,7 @@ pub use executor::html_inject::HtmlInjector;
pub use executor::text_inject::{Mode, ModeProvider, TextInjector};
pub use executor::image_inject::{ImageInjector};
pub use executor::context_menu::{ContextMenuHandler};
+pub use executor::icon_update::IconHandler;
// TODO: move into module
pub trait KeyInjector {
@@ -51,6 +52,7 @@ pub fn default<'a>(
html_injector: &'a dyn HtmlInjector,
image_injector: &'a dyn ImageInjector,
context_menu_handler: &'a dyn ContextMenuHandler,
+ icon_handler: &'a dyn IconHandler,
) -> impl Dispatcher + 'a {
default::DefaultDispatcher::new(
event_injector,
@@ -60,5 +62,6 @@ pub fn default<'a>(
html_injector,
image_injector,
context_menu_handler,
+ icon_handler,
)
}
diff --git a/espanso/src/engine/event/mod.rs b/espanso/src/engine/event/mod.rs
index 2f52c43..e5fedaa 100644
--- a/espanso/src/engine/event/mod.rs
+++ b/espanso/src/engine/event/mod.rs
@@ -70,6 +70,11 @@ pub enum EventType {
MatchInjected,
DiscardPrevious(internal::DiscardPreviousEvent),
+ Disabled,
+ Enabled,
+ SecureInputEnabled,
+ SecureInputDisabled,
+
// Effects
TriggerCompensation(effect::TriggerCompensationEvent),
CursorHintCompensation(effect::CursorHintCompensationEvent),
@@ -82,6 +87,7 @@ pub enum EventType {
// UI
ShowContextMenu(ui::ShowContextMenuEvent),
+ IconStatusChange(ui::IconStatusChangeEvent),
}
#[derive(Debug, Clone)]
diff --git a/espanso/src/engine/event/ui.rs b/espanso/src/engine/event/ui.rs
index 1412264..76e4ad0 100644
--- a/espanso/src/engine/event/ui.rs
+++ b/espanso/src/engine/event/ui.rs
@@ -39,4 +39,16 @@ pub struct SimpleMenuItem {
pub struct SubMenuItem {
pub label: String,
pub items: Vec