From fddb2711e435e1618210e5a4801212bcd0272d7a Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Wed, 5 May 2021 21:19:32 +0200 Subject: [PATCH] feat(config): introduce clipboard threshold option --- espanso-config/src/config/mod.rs | 1 + 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/config/store.rs | 4 ++++ espanso-config/src/legacy/config.rs | 25 ------------------------- espanso-config/src/legacy/mod.rs | 4 ++++ 7 files changed, 21 insertions(+), 25 deletions(-) diff --git a/espanso-config/src/config/mod.rs b/espanso-config/src/config/mod.rs index 13e957d..4968f48 100644 --- a/espanso-config/src/config/mod.rs +++ b/espanso-config/src/config/mod.rs @@ -32,6 +32,7 @@ pub trait Config: Send { fn label(&self) -> &str; fn match_paths(&self) -> &[String]; fn backend(&self) -> Backend; + fn clipboard_threshold(&self) -> usize; fn is_match(&self, app: &AppProperties) -> bool; } diff --git a/espanso-config/src/config/parse/mod.rs b/espanso-config/src/config/parse/mod.rs index c68602a..38bd6f9 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 clipboard_threshold: Option, // Includes pub includes: Option>, diff --git a/espanso-config/src/config/parse/yaml.rs b/espanso-config/src/config/parse/yaml.rs index 73be307..6021b9a 100644 --- a/espanso-config/src/config/parse/yaml.rs +++ b/espanso-config/src/config/parse/yaml.rs @@ -33,6 +33,9 @@ pub(crate) struct YAMLConfig { #[serde(default)] pub backend: Option, + #[serde(default)] + pub clipboard_threshold: Option, + #[serde(default)] pub includes: Option>, @@ -82,6 +85,7 @@ impl TryFrom for ParsedConfig { Ok(Self { label: yaml_config.label, backend: yaml_config.backend, + clipboard_threshold: yaml_config.clipboard_threshold, use_standard_includes: yaml_config.use_standard_includes, includes: yaml_config.includes, extra_includes: yaml_config.extra_includes, @@ -107,6 +111,7 @@ mod tests { r#" label: "test" backend: clipboard + clipboard_threshold: 200 use_standard_includes: true includes: ["test1"] @@ -129,6 +134,7 @@ mod tests { label: Some("test".to_string()), backend: Some("clipboard".to_string()), + clipboard_threshold: Some(200), use_standard_includes: Some(true), includes: Some(vec!["test1".to_string()]), diff --git a/espanso-config/src/config/resolve.rs b/espanso-config/src/config/resolve.rs index 6f79f83..e4df76b 100644 --- a/espanso-config/src/config/resolve.rs +++ b/espanso-config/src/config/resolve.rs @@ -128,6 +128,10 @@ impl Config for ResolvedConfig { } } } + + fn clipboard_threshold(&self) -> usize { + self.parsed.clipboard_threshold.unwrap_or(100) + } } impl ResolvedConfig { @@ -185,6 +189,7 @@ impl ResolvedConfig { // Fields label, backend, + clipboard_threshold, includes, excludes, extra_includes, diff --git a/espanso-config/src/config/store.rs b/espanso-config/src/config/store.rs index 76016d1..57b9885 100644 --- a/espanso-config/src/config/store.rs +++ b/espanso-config/src/config/store.rs @@ -161,6 +161,10 @@ mod tests { fn backend(&self) -> crate::config::Backend { unimplemented!() } + + fn clipboard_threshold(&self) -> usize { + unimplemented!() + } } #[test] diff --git a/espanso-config/src/legacy/config.rs b/espanso-config/src/legacy/config.rs index 782852f..efa0246 100644 --- a/espanso-config/src/legacy/config.rs +++ b/espanso-config/src/legacy/config.rs @@ -378,34 +378,9 @@ impl LegacyConfig { pub enum BackendType { Inject, Clipboard, - - // On Linux systems there is a long standing issue with text injection (which - // in general is better than Clipboard copy/pasting) that prevents certain - // apps from correctly handling special characters (such as emojis or accented letters) - // when injected. For this reason, espanso initially defaulted on the Clipboard - // backend on Linux, as it was the most reliable (working in 99% of cases), - // even though it was less efficient and with a few inconveniences (for example, the - // previous clipboard content being overwritten). - // The Auto backend tries to take it a step further, by automatically determining - // when an injection is possible (only ascii characters in the replacement), and falling - // back to the Clipboard backend otherwise. - // Should only be used on Linux systems. Auto, } impl Default for BackendType { - // The default backend varies based on the operating system. - // On Windows and macOS, the Inject backend is working great and should - // be preferred as it doesn't override the clipboard. - // On the other hand, on linux it has many problems due to the bugs - // of the libxdo used. For this reason, Clipboard will be the default - // backend on Linux from version v0.3.0 - - #[cfg(not(target_os = "linux"))] - fn default() -> Self { - BackendType::Inject - } - - #[cfg(target_os = "linux")] fn default() -> Self { BackendType::Auto } diff --git a/espanso-config/src/legacy/mod.rs b/espanso-config/src/legacy/mod.rs index e0470a8..bea0251 100644 --- a/espanso-config/src/legacy/mod.rs +++ b/espanso-config/src/legacy/mod.rs @@ -252,6 +252,10 @@ impl Config for LegacyInteropConfig { // All the filters that have been specified must be true to define a match is_exec_match && is_title_match && is_class_match } + + fn clipboard_threshold(&self) -> usize { + 100 + } } struct LegacyMatchGroup {