feat(config): add config option for windows keyboard layout cache duration #745

This commit is contained in:
Federico Terzi 2021-10-25 21:31:11 +02:00
parent 92645e0987
commit 0faa838932
5 changed files with 31 additions and 0 deletions

View File

@ -156,6 +156,12 @@ pub trait Config: Send + Sync {
// Disabling this option might conflict with the undo feature. // Disabling this option might conflict with the undo feature.
fn win32_exclude_orphan_events(&self) -> bool; 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 is_match<'a>(&self, app: &AppProperties<'a>) -> bool;
fn pretty_dump(&self) -> String { fn pretty_dump(&self) -> String {
@ -187,6 +193,9 @@ pub trait Config: Send + Sync {
show_notifications: {:?} show_notifications: {:?}
secure_input_notification: {:?} secure_input_notification: {:?}
win32_exclude_orphan_events: {:?}
win32_keyboard_layout_cache_interval: {:?}
match_paths: {:#?} match_paths: {:#?}
", ",
self.label(), self.label(),
@ -215,6 +224,9 @@ pub trait Config: Send + Sync {
self.show_notifications(), self.show_notifications(),
self.secure_input_notification(), self.secure_input_notification(),
self.win32_exclude_orphan_events(),
self.win32_keyboard_layout_cache_interval(),
self.match_paths(), self.match_paths(),
} }
} }

View File

@ -45,6 +45,7 @@ pub(crate) struct ParsedConfig {
pub show_icon: Option<bool>, pub show_icon: Option<bool>,
pub secure_input_notification: Option<bool>, pub secure_input_notification: Option<bool>,
pub win32_exclude_orphan_events: Option<bool>, pub win32_exclude_orphan_events: Option<bool>,
pub win32_keyboard_layout_cache_interval: Option<i64>,
pub pre_paste_delay: Option<usize>, pub pre_paste_delay: Option<usize>,
pub restore_clipboard_delay: Option<usize>, pub restore_clipboard_delay: Option<usize>,

View File

@ -109,6 +109,9 @@ pub(crate) struct YAMLConfig {
#[serde(default)] #[serde(default)]
pub win32_exclude_orphan_events: Option<bool>, pub win32_exclude_orphan_events: Option<bool>,
#[serde(default)]
pub win32_keyboard_layout_cache_interval: Option<i64>,
// Include/Exclude // Include/Exclude
#[serde(default)] #[serde(default)]
pub includes: Option<Vec<String>>, pub includes: Option<Vec<String>>,
@ -197,6 +200,7 @@ impl TryFrom<YAMLConfig> for ParsedConfig {
paste_shortcut_event_delay: yaml_config.paste_shortcut_event_delay, paste_shortcut_event_delay: yaml_config.paste_shortcut_event_delay,
win32_exclude_orphan_events: yaml_config.win32_exclude_orphan_events, 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, use_standard_includes: yaml_config.use_standard_includes,
includes: yaml_config.includes, includes: yaml_config.includes,
@ -253,6 +257,7 @@ mod tests {
show_notifications: false show_notifications: false
secure_input_notification: false secure_input_notification: false
win32_exclude_orphan_events: false win32_exclude_orphan_events: false
win32_keyboard_layout_cache_interval: 300
use_standard_includes: true use_standard_includes: true
includes: ["test1"] includes: ["test1"]
@ -305,6 +310,7 @@ mod tests {
show_notifications: Some(false), show_notifications: Some(false),
secure_input_notification: Some(false), secure_input_notification: Some(false),
win32_exclude_orphan_events: Some(false), win32_exclude_orphan_events: Some(false),
win32_keyboard_layout_cache_interval: Some(300),
pre_paste_delay: Some(300), pre_paste_delay: Some(300),
evdev_modifier_delay: Some(40), evdev_modifier_delay: Some(40),

View File

@ -323,6 +323,13 @@ impl Config for ResolvedConfig {
fn evdev_modifier_delay(&self) -> Option<usize> { fn evdev_modifier_delay(&self) -> Option<usize> {
self.parsed.evdev_modifier_delay 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 { impl ResolvedConfig {
@ -405,6 +412,7 @@ impl ResolvedConfig {
show_notifications, show_notifications,
secure_input_notification, secure_input_notification,
win32_exclude_orphan_events, win32_exclude_orphan_events,
win32_keyboard_layout_cache_interval,
includes, includes,
excludes, excludes,
extra_includes, extra_includes,

View File

@ -394,6 +394,10 @@ impl Config for LegacyInteropConfig {
fn evdev_modifier_delay(&self) -> Option<usize> { fn evdev_modifier_delay(&self) -> Option<usize> {
Some(10) Some(10)
} }
fn win32_keyboard_layout_cache_interval(&self) -> i64 {
2000
}
} }
struct LegacyMatchGroup { struct LegacyMatchGroup {