diff --git a/espanso-config/src/config/mod.rs b/espanso-config/src/config/mod.rs index d3d12da..dd88929 100644 --- a/espanso-config/src/config/mod.rs +++ b/espanso-config/src/config/mod.rs @@ -156,6 +156,12 @@ pub trait Config: Send + Sync { // Disabling this option might conflict with the undo feature. fn win32_exclude_orphan_events(&self) -> bool; + // The maximum interval (in milliseconds) for which a keyboard layout + // can be cached. If switching often between different layouts, you + // could lower this amount to avoid the "lost detection" effect described + // in this issue: https://github.com/federico-terzi/espanso/issues/745 + fn win32_keyboard_layout_cache_interval(&self) -> i64; + fn is_match<'a>(&self, app: &AppProperties<'a>) -> bool; fn pretty_dump(&self) -> String { @@ -187,6 +193,9 @@ pub trait Config: Send + Sync { show_notifications: {:?} secure_input_notification: {:?} + win32_exclude_orphan_events: {:?} + win32_keyboard_layout_cache_interval: {:?} + match_paths: {:#?} ", self.label(), @@ -215,6 +224,9 @@ pub trait Config: Send + Sync { self.show_notifications(), self.secure_input_notification(), + self.win32_exclude_orphan_events(), + self.win32_keyboard_layout_cache_interval(), + self.match_paths(), } } diff --git a/espanso-config/src/config/parse/mod.rs b/espanso-config/src/config/parse/mod.rs index 134afc0..bd39ad4 100644 --- a/espanso-config/src/config/parse/mod.rs +++ b/espanso-config/src/config/parse/mod.rs @@ -45,6 +45,7 @@ pub(crate) struct ParsedConfig { pub show_icon: Option, pub secure_input_notification: Option, pub win32_exclude_orphan_events: Option, + pub win32_keyboard_layout_cache_interval: Option, pub pre_paste_delay: Option, pub restore_clipboard_delay: Option, diff --git a/espanso-config/src/config/parse/yaml.rs b/espanso-config/src/config/parse/yaml.rs index 81e884d..824429c 100644 --- a/espanso-config/src/config/parse/yaml.rs +++ b/espanso-config/src/config/parse/yaml.rs @@ -109,6 +109,9 @@ pub(crate) struct YAMLConfig { #[serde(default)] pub win32_exclude_orphan_events: Option, + #[serde(default)] + pub win32_keyboard_layout_cache_interval: Option, + // Include/Exclude #[serde(default)] pub includes: Option>, @@ -197,6 +200,7 @@ impl TryFrom for ParsedConfig { paste_shortcut_event_delay: yaml_config.paste_shortcut_event_delay, win32_exclude_orphan_events: yaml_config.win32_exclude_orphan_events, + win32_keyboard_layout_cache_interval: yaml_config.win32_keyboard_layout_cache_interval, use_standard_includes: yaml_config.use_standard_includes, includes: yaml_config.includes, @@ -253,6 +257,7 @@ mod tests { show_notifications: false secure_input_notification: false win32_exclude_orphan_events: false + win32_keyboard_layout_cache_interval: 300 use_standard_includes: true includes: ["test1"] @@ -305,6 +310,7 @@ mod tests { show_notifications: Some(false), secure_input_notification: Some(false), win32_exclude_orphan_events: Some(false), + win32_keyboard_layout_cache_interval: Some(300), pre_paste_delay: Some(300), evdev_modifier_delay: Some(40), diff --git a/espanso-config/src/config/resolve.rs b/espanso-config/src/config/resolve.rs index ea74240..afcad9b 100644 --- a/espanso-config/src/config/resolve.rs +++ b/espanso-config/src/config/resolve.rs @@ -323,6 +323,13 @@ impl Config for ResolvedConfig { fn evdev_modifier_delay(&self) -> Option { self.parsed.evdev_modifier_delay } + + fn win32_keyboard_layout_cache_interval(&self) -> i64 { + self + .parsed + .win32_keyboard_layout_cache_interval + .unwrap_or(2000) + } } impl ResolvedConfig { @@ -405,6 +412,7 @@ impl ResolvedConfig { show_notifications, secure_input_notification, win32_exclude_orphan_events, + win32_keyboard_layout_cache_interval, includes, excludes, extra_includes, diff --git a/espanso-config/src/legacy/mod.rs b/espanso-config/src/legacy/mod.rs index 4efbb56..674b08a 100644 --- a/espanso-config/src/legacy/mod.rs +++ b/espanso-config/src/legacy/mod.rs @@ -394,6 +394,10 @@ impl Config for LegacyInteropConfig { fn evdev_modifier_delay(&self) -> Option { Some(10) } + + fn win32_keyboard_layout_cache_interval(&self) -> i64 { + 2000 + } } struct LegacyMatchGroup {