diff --git a/espanso-config/src/config/mod.rs b/espanso-config/src/config/mod.rs index 205adbd..b3841b9 100644 --- a/espanso-config/src/config/mod.rs +++ b/espanso-config/src/config/mod.rs @@ -83,6 +83,14 @@ pub trait Config: Send { // the expansion content. fn restore_clipboard_delay(&self) -> usize; + // Number of milliseconds between text injection events. Increase if the target + // application is missing some characters. + fn inject_delay(&self) -> Option; + + // Number of milliseconds between key injection events. Increase if the target + // application is missing some key events. + fn key_delay(&self) -> Option; + 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 47a5304..1e30991 100644 --- a/espanso-config/src/config/parse/mod.rs +++ b/espanso-config/src/config/parse/mod.rs @@ -38,6 +38,8 @@ pub(crate) struct ParsedConfig { pub pre_paste_delay: Option, pub restore_clipboard_delay: Option, pub paste_shortcut_event_delay: Option, + pub inject_delay: Option, + pub key_delay: Option, // Includes diff --git a/espanso-config/src/config/parse/yaml.rs b/espanso-config/src/config/parse/yaml.rs index d78a2dd..b1deee3 100644 --- a/espanso-config/src/config/parse/yaml.rs +++ b/espanso-config/src/config/parse/yaml.rs @@ -60,6 +60,15 @@ pub(crate) struct YAMLConfig { #[serde(default)] pub disable_x11_fast_inject: Option, + #[serde(default)] + pub inject_delay: Option, + + #[serde(default)] + pub key_delay: Option, + + #[serde(default)] + pub backspace_delay: Option, + // Include/Exclude #[serde(default)] pub includes: Option>, @@ -116,6 +125,8 @@ impl TryFrom for ParsedConfig { preserve_clipboard: yaml_config.preserve_clipboard, paste_shortcut: yaml_config.paste_shortcut, disable_x11_fast_inject: yaml_config.disable_x11_fast_inject, + inject_delay: yaml_config.inject_delay, + key_delay: yaml_config.key_delay.or(yaml_config.backspace_delay), pre_paste_delay: yaml_config.pre_paste_delay, restore_clipboard_delay: yaml_config.restore_clipboard_delay, @@ -155,6 +166,9 @@ mod tests { paste_shortcut: CTRL+ALT+V paste_shortcut_event_delay: 10 disable_x11_fast_inject: true + inject_delay: 10 + key_delay: 20 + backspace_delay: 30 use_standard_includes: true includes: ["test1"] @@ -184,6 +198,8 @@ mod tests { paste_shortcut: Some("CTRL+ALT+V".to_string()), paste_shortcut_event_delay: Some(10), disable_x11_fast_inject: Some(true), + inject_delay: Some(10), + key_delay: Some(20), pre_paste_delay: Some(300), diff --git a/espanso-config/src/config/resolve.rs b/espanso-config/src/config/resolve.rs index f82a036..b3de63b 100644 --- a/espanso-config/src/config/resolve.rs +++ b/espanso-config/src/config/resolve.rs @@ -207,6 +207,14 @@ impl Config for ResolvedConfig { fn disable_x11_fast_inject(&self) -> bool { self.parsed.disable_x11_fast_inject.unwrap_or(false) } + + fn inject_delay(&self) -> Option { + self.parsed.inject_delay + } + + fn key_delay(&self) -> Option { + self.parsed.key_delay + } } impl ResolvedConfig { @@ -273,6 +281,8 @@ impl ResolvedConfig { paste_shortcut_event_delay, disable_x11_fast_inject, toggle_key, + inject_delay, + key_delay, includes, excludes, extra_includes, diff --git a/espanso-config/src/legacy/mod.rs b/espanso-config/src/legacy/mod.rs index 6d01bd8..94c3465 100644 --- a/espanso-config/src/legacy/mod.rs +++ b/espanso-config/src/legacy/mod.rs @@ -301,16 +301,32 @@ impl Config for LegacyInteropConfig { match self.config.paste_shortcut { model::PasteShortcut::Default => None, model::PasteShortcut::CtrlV => Some("CTRL+V".to_string()), - model::PasteShortcut::CtrlShiftV => Some("CTRL+SHIFT+V".to_string()), - model::PasteShortcut::ShiftInsert => Some("SHIFT+INSERT".to_string()), - model::PasteShortcut::CtrlAltV => Some("CTRL+ALT+V".to_string()), - model::PasteShortcut::MetaV => Some("META+V".to_string()), + model::PasteShortcut::CtrlShiftV => Some("CTRL+SHIFT+V".to_string()), + model::PasteShortcut::ShiftInsert => Some("SHIFT+INSERT".to_string()), + model::PasteShortcut::CtrlAltV => Some("CTRL+ALT+V".to_string()), + model::PasteShortcut::MetaV => Some("META+V".to_string()), } } fn disable_x11_fast_inject(&self) -> bool { self.config.fast_inject } + + fn inject_delay(&self) -> Option { + if self.config.inject_delay == 0 { + None + } else { + Some(self.config.inject_delay.try_into().unwrap()) + } + } + + fn key_delay(&self) -> Option { + if self.config.backspace_delay == 0 { + None + } else { + Some(self.config.backspace_delay.try_into().unwrap()) + } + } } struct LegacyMatchGroup {