diff --git a/espanso-config/src/config/mod.rs b/espanso-config/src/config/mod.rs index a564663..1985ca9 100644 --- a/espanso-config/src/config/mod.rs +++ b/espanso-config/src/config/mod.rs @@ -54,8 +54,20 @@ pub trait Config: Send { // Defines the key that disables/enables espanso when double pressed fn toggle_key(&self) -> Option; + // If true, instructs the daemon process to restart the worker (and refresh + // the configuration) after a configuration file change is detected on disk. fn auto_restart(&self) -> bool; + // If true, espanso will attempt to preserve the previous clipboard content + // after an expansion has taken place (when using the Clipboard backend). + fn preserve_clipboard(&self) -> bool; + + // The number of milliseconds to wait before restoring the previous clipboard + // content after an expansion. This is needed as without this delay, sometimes + // the target application detects the previous clipboard content instead of + // the expansion content. + fn restore_clipboard_delay(&self) -> usize; + fn is_match<'a>(&self, app: &AppProperties<'a>) -> bool; } diff --git a/espanso-config/src/config/parse/mod.rs b/espanso-config/src/config/parse/mod.rs index 4280ec8..92f4279 100644 --- a/espanso-config/src/config/parse/mod.rs +++ b/espanso-config/src/config/parse/mod.rs @@ -30,8 +30,10 @@ pub(crate) struct ParsedConfig { pub backend: Option, pub clipboard_threshold: Option, pub auto_restart: Option, + pub preserve_clipboard: Option, pub pre_paste_delay: Option, + pub restore_clipboard_delay: Option, pub toggle_key: Option, diff --git a/espanso-config/src/config/parse/yaml.rs b/espanso-config/src/config/parse/yaml.rs index 00dc3d5..5b3cdaf 100644 --- a/espanso-config/src/config/parse/yaml.rs +++ b/espanso-config/src/config/parse/yaml.rs @@ -45,6 +45,12 @@ pub(crate) struct YAMLConfig { #[serde(default)] pub auto_restart: Option, + #[serde(default)] + pub preserve_clipboard: Option, + + #[serde(default)] + pub restore_clipboard_delay: Option, + #[serde(default)] pub includes: Option>, @@ -96,8 +102,10 @@ impl TryFrom for ParsedConfig { backend: yaml_config.backend, clipboard_threshold: yaml_config.clipboard_threshold, auto_restart: yaml_config.auto_restart, + preserve_clipboard: yaml_config.preserve_clipboard, pre_paste_delay: yaml_config.pre_paste_delay, + restore_clipboard_delay: yaml_config.restore_clipboard_delay, toggle_key: yaml_config.toggle_key, @@ -130,6 +138,8 @@ mod tests { pre_paste_delay: 300 toggle_key: CTRL auto_restart: false + preserve_clipboard: false + restore_clipboard_delay: 400 use_standard_includes: true includes: ["test1"] @@ -154,6 +164,8 @@ mod tests { backend: Some("clipboard".to_string()), clipboard_threshold: Some(200), auto_restart: Some(false), + preserve_clipboard: Some(false), + restore_clipboard_delay: Some(400), pre_paste_delay: Some(300), diff --git a/espanso-config/src/config/resolve.rs b/espanso-config/src/config/resolve.rs index ea8ed82..9d47770 100644 --- a/espanso-config/src/config/resolve.rs +++ b/espanso-config/src/config/resolve.rs @@ -177,7 +177,7 @@ impl Config for ResolvedConfig { Some("right_ctrl") => Some(ToggleKey::RightCtrl), Some("right_alt") => Some(ToggleKey::RightAlt), Some("right_shift") => Some(ToggleKey::RightShift), - Some("right_meta") | Some("right_cmd")=> Some(ToggleKey::RightMeta), + Some("right_meta") | Some("right_cmd") => Some(ToggleKey::RightMeta), Some("left_ctrl") => Some(ToggleKey::LeftCtrl), Some("left_alt") => Some(ToggleKey::LeftAlt), Some("left_shift") => Some(ToggleKey::LeftShift), @@ -185,11 +185,22 @@ impl Config for ResolvedConfig { Some("off") => None, None => Some(ToggleKey::Alt), err => { - error!("invalid toggle_key specified {:?}, falling back to ALT", err); + error!( + "invalid toggle_key specified {:?}, falling back to ALT", + err + ); Some(ToggleKey::Alt) } } } + + fn preserve_clipboard(&self) -> bool { + self.parsed.preserve_clipboard.unwrap_or(true) + } + + fn restore_clipboard_delay(&self) -> usize { + self.parsed.restore_clipboard_delay.unwrap_or(300) + } } impl ResolvedConfig { @@ -250,6 +261,8 @@ impl ResolvedConfig { clipboard_threshold, auto_restart, pre_paste_delay, + preserve_clipboard, + restore_clipboard_delay, toggle_key, includes, excludes, diff --git a/espanso-config/src/legacy/mod.rs b/espanso-config/src/legacy/mod.rs index c564009..1f8c690 100644 --- a/espanso-config/src/legacy/mod.rs +++ b/espanso-config/src/legacy/mod.rs @@ -270,9 +270,9 @@ impl Config for LegacyInteropConfig { model::KeyModifier::CTRL => Some(crate::config::ToggleKey::Ctrl), model::KeyModifier::SHIFT => Some(crate::config::ToggleKey::Shift), model::KeyModifier::ALT => Some(crate::config::ToggleKey::Alt), - model::KeyModifier::META => Some(crate::config::ToggleKey::Meta), + model::KeyModifier::META => Some(crate::config::ToggleKey::Meta), model::KeyModifier::BACKSPACE => None, - model::KeyModifier::OFF => None, + model::KeyModifier::OFF => None, model::KeyModifier::LEFT_CTRL => Some(crate::config::ToggleKey::LeftCtrl), model::KeyModifier::RIGHT_CTRL => Some(crate::config::ToggleKey::RightCtrl), model::KeyModifier::LEFT_ALT => Some(crate::config::ToggleKey::LeftAlt), @@ -281,9 +281,17 @@ impl Config for LegacyInteropConfig { model::KeyModifier::RIGHT_META => Some(crate::config::ToggleKey::RightMeta), model::KeyModifier::LEFT_SHIFT => Some(crate::config::ToggleKey::LeftShift), model::KeyModifier::RIGHT_SHIFT => Some(crate::config::ToggleKey::RightShift), - model::KeyModifier::CAPS_LOCK => None + model::KeyModifier::CAPS_LOCK => None, } } + + fn preserve_clipboard(&self) -> bool { + self.config.preserve_clipboard + } + + fn restore_clipboard_delay(&self) -> usize { + self.config.restore_clipboard_delay.try_into().unwrap() + } } struct LegacyMatchGroup {