From eb727abeeca3120791fe645268afaad01e6fc42e Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Sat, 21 Aug 2021 09:21:59 +0200 Subject: [PATCH] feat(config): add enable option --- espanso-config/src/config/mod.rs | 13 +++++++++++++ espanso-config/src/config/parse/mod.rs | 1 + espanso-config/src/config/parse/yaml.rs | 6 ++++++ espanso-config/src/config/resolve.rs | 5 +++++ espanso-config/src/legacy/mod.rs | 4 ++++ 5 files changed, 29 insertions(+) diff --git a/espanso-config/src/config/mod.rs b/espanso-config/src/config/mod.rs index c1cd266..f6e20ed 100644 --- a/espanso-config/src/config/mod.rs +++ b/espanso-config/src/config/mod.rs @@ -39,8 +39,21 @@ pub trait Config: Send + Sync { fn id(&self) -> i32; fn label(&self) -> &str; fn match_paths(&self) -> &[String]; + + // The mechanism used to perform the injection. Espanso can either + // inject text by simulating keypresses (Inject backend) or + // by using the clipboard (Clipboard backend). Both of them have pros + // and cons, so the "Auto" backend is used by default to automatically + // choose the most appropriate one based on the situation. + // If for whatever reason the Auto backend is not appropriate, you + // can change this option to override it. fn backend(&self) -> Backend; + // If false, espanso will be disabled for the current configuration. + // This option can be used to selectively disable espanso when + // using a specific application (by creating an app-specific config). + fn enable(&self) -> bool; + // Number of chars after which a match is injected with the clipboard // backend instead of the default one. This is done for efficiency // reasons, as injecting a long match through separate events becomes diff --git a/espanso-config/src/config/parse/mod.rs b/espanso-config/src/config/parse/mod.rs index 25dbbc9..d8f49fb 100644 --- a/espanso-config/src/config/parse/mod.rs +++ b/espanso-config/src/config/parse/mod.rs @@ -28,6 +28,7 @@ pub(crate) struct ParsedConfig { pub label: Option, pub backend: Option, + pub enable: Option, pub clipboard_threshold: Option, pub auto_restart: Option, pub preserve_clipboard: Option, diff --git a/espanso-config/src/config/parse/yaml.rs b/espanso-config/src/config/parse/yaml.rs index 6e19955..18fcdd9 100644 --- a/espanso-config/src/config/parse/yaml.rs +++ b/espanso-config/src/config/parse/yaml.rs @@ -34,6 +34,9 @@ pub(crate) struct YAMLConfig { #[serde(default)] pub backend: Option, + #[serde(default)] + pub enable: Option, + #[serde(default)] pub clipboard_threshold: Option, @@ -150,6 +153,7 @@ impl TryFrom for ParsedConfig { Ok(Self { label: yaml_config.label, backend: yaml_config.backend, + enable: yaml_config.enable, clipboard_threshold: yaml_config.clipboard_threshold, auto_restart: yaml_config.auto_restart, toggle_key: yaml_config.toggle_key, @@ -210,6 +214,7 @@ mod tests { r#" label: "test" backend: clipboard + enable: false clipboard_threshold: 200 pre_paste_delay: 300 toggle_key: CTRL @@ -268,6 +273,7 @@ mod tests { label: Some("test".to_string()), backend: Some("clipboard".to_string()), + enable: Some(false), clipboard_threshold: Some(200), auto_restart: Some(false), preserve_clipboard: Some(false), diff --git a/espanso-config/src/config/resolve.rs b/espanso-config/src/config/resolve.rs index d49a5aa..3db8eb4 100644 --- a/espanso-config/src/config/resolve.rs +++ b/espanso-config/src/config/resolve.rs @@ -158,6 +158,10 @@ impl Config for ResolvedConfig { } } } + + fn enable(&self) -> bool { + self.parsed.enable.unwrap_or(true) + } fn clipboard_threshold(&self) -> usize { self @@ -364,6 +368,7 @@ impl ResolvedConfig { // Fields label, backend, + enable, clipboard_threshold, auto_restart, pre_paste_delay, diff --git a/espanso-config/src/legacy/mod.rs b/espanso-config/src/legacy/mod.rs index e81a3f8..d059358 100644 --- a/espanso-config/src/legacy/mod.rs +++ b/espanso-config/src/legacy/mod.rs @@ -382,6 +382,10 @@ impl Config for LegacyInteropConfig { fn secure_input_notification(&self) -> bool { self.config.secure_input_notification } + + fn enable(&self) -> bool { + self.config.enable_active + } } struct LegacyMatchGroup {