From 645cd78573a1e126ed79d4f7fdeb888077d83a9d Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Tue, 8 Jun 2021 20:48:33 +0200 Subject: [PATCH] feat(core): wire up parameters in clipboard injector --- .../dispatch/executor/clipboard_injector.rs | 40 ++++++++++++------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/espanso/src/cli/worker/engine/dispatch/executor/clipboard_injector.rs b/espanso/src/cli/worker/engine/dispatch/executor/clipboard_injector.rs index 6b88271..3237d13 100644 --- a/espanso/src/cli/worker/engine/dispatch/executor/clipboard_injector.rs +++ b/espanso/src/cli/worker/engine/dispatch/executor/clipboard_injector.rs @@ -67,26 +67,28 @@ impl<'a> ClipboardInjectorAdapter<'a> { params.pre_paste_delay.try_into().unwrap(), )); - // TODO: handle case of custom combination - let combination = if cfg!(target_os = "macos") { - &[Key::Meta, Key::V] + let mut custom_combination = None; + if let Some(custom_shortcut) = params.paste_shortcut { + if let Some(combination) = parse_combination(&custom_shortcut) { + custom_combination = Some(combination); + } else { + error!("'{}' is not a valid paste shortcut", custom_shortcut); + } + } + + let combination = if let Some(custom_combination) = custom_combination { + custom_combination + } else if cfg!(target_os = "macos") { + vec![Key::Meta, Key::V] } else { - &[Key::Control, Key::V] + vec![Key::Control, Key::V] }; - // TODO: handle user-specified delays - // let paste_combination_delay = if cfg!(target_os = "macos") { - // 5 - // } else { - // InjectionOptions::default().delay - // }; - - // TODO: handle options self.injector.send_key_combination( - combination, + &combination, InjectionOptions { delay: params.paste_shortcut_event_delay as i32, - ..Default::default() + disable_fast_inject: params.disable_x11_fast_inject, }, )?; @@ -192,3 +194,13 @@ impl<'a> Drop for ClipboardRestoreGuard<'a> { } } } + +fn parse_combination(combination: &str) -> Option> { + let tokens = combination.split("+"); + let mut keys: Vec = Vec::new(); + for token in tokens { + keys.push(Key::parse(token)?); + } + + Some(keys) +}