From 3abe84f8b027e7bc1ebadc8175810a661eb586d7 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Sat, 5 Mar 2022 20:27:49 +0100 Subject: [PATCH] feat(config): create options to delay injection after form/search gui --- espanso-config/src/config/default.rs | 2 ++ espanso-config/src/config/mod.rs | 16 ++++++++++++++++ espanso-config/src/config/parse/mod.rs | 2 ++ espanso-config/src/config/parse/yaml.rs | 12 ++++++++++++ espanso-config/src/config/resolve.rs | 20 ++++++++++++++++++-- espanso-config/src/legacy/mod.rs | 8 ++++++++ 6 files changed, 58 insertions(+), 2 deletions(-) diff --git a/espanso-config/src/config/default.rs b/espanso-config/src/config/default.rs index 09decba..7966ba7 100644 --- a/espanso-config/src/config/default.rs +++ b/espanso-config/src/config/default.rs @@ -21,3 +21,5 @@ pub(crate) const DEFAULT_CLIPBOARD_THRESHOLD: usize = 100; pub(crate) const DEFAULT_PRE_PASTE_DELAY: usize = 100; pub(crate) const DEFAULT_SHORTCUT_EVENT_DELAY: usize = 10; pub(crate) const DEFAULT_RESTORE_CLIPBOARD_DELAY: usize = 300; +pub(crate) const DEFAULT_POST_FORM_DELAY: usize = 200; +pub(crate) const DEFAULT_POST_SEARCH_DELAY: usize = 200; diff --git a/espanso-config/src/config/mod.rs b/espanso-config/src/config/mod.rs index 0992372..945841e 100644 --- a/espanso-config/src/config/mod.rs +++ b/espanso-config/src/config/mod.rs @@ -150,6 +150,18 @@ pub trait Config: Send + Sync { // If false, avoid showing the SecureInput notification on macOS fn secure_input_notification(&self) -> bool; + // The number of milliseconds to wait after a form has been closed. + // This is useful to let the target application regain focus + // after a form has been closed, otherwise the injection might + // not be targeted to the right application. + fn post_form_delay(&self) -> usize; + + // The number of milliseconds to wait after the search bar has been closed. + // This is useful to let the target application regain focus + // after the search bar has been closed, otherwise the injection might + // not be targeted to the right application. + fn post_search_delay(&self) -> usize; + // If true, use the `xclip` command to implement the clipboard instead of // the built-in native module on X11. fn x11_use_xclip_backend(&self) -> bool; @@ -188,6 +200,8 @@ pub trait Config: Send + Sync { toggle_key: {:?} auto_restart: {:?} restore_clipboard_delay: {:?} + post_form_delay: {:?} + post_search_delay: {:?} backspace_limit: {} search_trigger: {:?} search_shortcut: {:?} @@ -220,6 +234,8 @@ pub trait Config: Send + Sync { self.toggle_key(), self.auto_restart(), self.restore_clipboard_delay(), + self.post_form_delay(), + self.post_search_delay(), self.backspace_limit(), self.search_trigger(), self.search_shortcut(), diff --git a/espanso-config/src/config/parse/mod.rs b/espanso-config/src/config/parse/mod.rs index 94f174d..644b068 100644 --- a/espanso-config/src/config/parse/mod.rs +++ b/espanso-config/src/config/parse/mod.rs @@ -44,6 +44,8 @@ pub(crate) struct ParsedConfig { pub show_notifications: Option, pub show_icon: Option, pub secure_input_notification: Option, + pub post_form_delay: Option, + pub post_search_delay: Option, pub win32_exclude_orphan_events: Option, pub win32_keyboard_layout_cache_interval: Option, pub x11_use_xclip_backend: Option, diff --git a/espanso-config/src/config/parse/yaml.rs b/espanso-config/src/config/parse/yaml.rs index d666662..64558db 100644 --- a/espanso-config/src/config/parse/yaml.rs +++ b/espanso-config/src/config/parse/yaml.rs @@ -103,6 +103,12 @@ pub(crate) struct YAMLConfig { #[serde(default)] pub show_icon: Option, + #[serde(default)] + pub post_form_delay: Option, + + #[serde(default)] + pub post_search_delay: Option, + #[serde(default)] pub secure_input_notification: Option, @@ -201,6 +207,8 @@ impl TryFrom for ParsedConfig { pre_paste_delay: yaml_config.pre_paste_delay, restore_clipboard_delay: yaml_config.restore_clipboard_delay, paste_shortcut_event_delay: yaml_config.paste_shortcut_event_delay, + post_form_delay: yaml_config.post_form_delay, + post_search_delay: yaml_config.post_search_delay, win32_exclude_orphan_events: yaml_config.win32_exclude_orphan_events, win32_keyboard_layout_cache_interval: yaml_config.win32_keyboard_layout_cache_interval, @@ -260,6 +268,8 @@ mod tests { show_icon: false show_notifications: false secure_input_notification: false + post_form_delay: 300 + post_search_delay: 400 win32_exclude_orphan_events: false win32_keyboard_layout_cache_interval: 300 x11_use_xclip_backend: true @@ -314,6 +324,8 @@ mod tests { show_icon: Some(false), show_notifications: Some(false), secure_input_notification: Some(false), + post_form_delay: Some(300), + post_search_delay: Some(400), win32_exclude_orphan_events: Some(false), win32_keyboard_layout_cache_interval: Some(300), x11_use_xclip_backend: Some(true), diff --git a/espanso-config/src/config/resolve.rs b/espanso-config/src/config/resolve.rs index 518c1ff..7b7dcc3 100644 --- a/espanso-config/src/config/resolve.rs +++ b/espanso-config/src/config/resolve.rs @@ -19,8 +19,8 @@ use super::{ default::{ - DEFAULT_CLIPBOARD_THRESHOLD, DEFAULT_PRE_PASTE_DELAY, DEFAULT_RESTORE_CLIPBOARD_DELAY, - DEFAULT_SHORTCUT_EVENT_DELAY, + DEFAULT_CLIPBOARD_THRESHOLD, DEFAULT_POST_FORM_DELAY, DEFAULT_POST_SEARCH_DELAY, + DEFAULT_PRE_PASTE_DELAY, DEFAULT_RESTORE_CLIPBOARD_DELAY, DEFAULT_SHORTCUT_EVENT_DELAY, }, parse::ParsedConfig, path::calculate_paths, @@ -299,6 +299,20 @@ impl Config for ResolvedConfig { self.parsed.secure_input_notification.unwrap_or(true) } + fn post_form_delay(&self) -> usize { + self + .parsed + .post_form_delay + .unwrap_or(DEFAULT_POST_FORM_DELAY) + } + + fn post_search_delay(&self) -> usize { + self + .parsed + .post_search_delay + .unwrap_or(DEFAULT_POST_SEARCH_DELAY) + } + fn win32_exclude_orphan_events(&self) -> bool { self.parsed.win32_exclude_orphan_events.unwrap_or(true) } @@ -398,6 +412,8 @@ impl ResolvedConfig { show_icon, show_notifications, secure_input_notification, + post_form_delay, + post_search_delay, win32_exclude_orphan_events, win32_keyboard_layout_cache_interval, x11_use_xclip_backend, diff --git a/espanso-config/src/legacy/mod.rs b/espanso-config/src/legacy/mod.rs index b67e0f7..24a94aa 100644 --- a/espanso-config/src/legacy/mod.rs +++ b/espanso-config/src/legacy/mod.rs @@ -387,6 +387,14 @@ impl Config for LegacyInteropConfig { self.config.enable_active } + fn post_form_delay(&self) -> usize { + crate::config::default::DEFAULT_POST_FORM_DELAY + } + + fn post_search_delay(&self) -> usize { + crate::config::default::DEFAULT_POST_SEARCH_DELAY + } + fn win32_exclude_orphan_events(&self) -> bool { true }