feat(config): add evdev_modifier_delay option

This commit is contained in:
Federico Terzi 2021-09-06 23:11:47 +02:00
parent d20eaf1aba
commit fc96d80791
5 changed files with 23 additions and 10 deletions

View File

@ -108,6 +108,12 @@ pub trait Config: Send + Sync {
// application is missing some key events. // application is missing some key events.
fn key_delay(&self) -> Option<usize>; fn key_delay(&self) -> Option<usize>;
// Extra delay to apply when injecting modifiers under the EVDEV backend.
// This is useful on Wayland if espanso is injecting seemingly random
// cased letters, for example "Hi theRE1" instead of "Hi there!".
// Increase if necessary, decrease to speed up the injection.
fn evdev_modifier_delay(&self) -> Option<usize>;
// Chars that when pressed mark the start and end of a word. // Chars that when pressed mark the start and end of a word.
// Examples of this are . or , // Examples of this are . or ,
fn word_separators(&self) -> Vec<String>; fn word_separators(&self) -> Vec<String>;

View File

@ -52,6 +52,7 @@ pub(crate) struct ParsedConfig {
pub inject_delay: Option<usize>, pub inject_delay: Option<usize>,
pub key_delay: Option<usize>, pub key_delay: Option<usize>,
pub keyboard_layout: Option<BTreeMap<String, String>>, pub keyboard_layout: Option<BTreeMap<String, String>>,
pub evdev_modifier_delay: Option<usize>,
// Includes // Includes
pub includes: Option<Vec<String>>, pub includes: Option<Vec<String>>,

View File

@ -73,6 +73,9 @@ pub(crate) struct YAMLConfig {
#[serde(default)] #[serde(default)]
pub backspace_delay: Option<usize>, pub backspace_delay: Option<usize>,
#[serde(default)]
pub evdev_modifier_delay: Option<usize>,
#[serde(default)] #[serde(default)]
pub word_separators: Option<Vec<String>>, pub word_separators: Option<Vec<String>>,
@ -165,6 +168,7 @@ impl TryFrom<YAMLConfig> for ParsedConfig {
disable_x11_fast_inject: yaml_config.disable_x11_fast_inject, disable_x11_fast_inject: yaml_config.disable_x11_fast_inject,
inject_delay: yaml_config.inject_delay, inject_delay: yaml_config.inject_delay,
key_delay: yaml_config.key_delay.or(yaml_config.backspace_delay), key_delay: yaml_config.key_delay.or(yaml_config.backspace_delay),
evdev_modifier_delay: yaml_config.evdev_modifier_delay,
word_separators: yaml_config.word_separators, word_separators: yaml_config.word_separators,
backspace_limit: yaml_config.backspace_limit, backspace_limit: yaml_config.backspace_limit,
apply_patch: yaml_config.apply_patch, apply_patch: yaml_config.apply_patch,
@ -232,6 +236,7 @@ mod tests {
inject_delay: 10 inject_delay: 10
key_delay: 20 key_delay: 20
backspace_delay: 30 backspace_delay: 30
evdev_modifier_delay: 40
word_separators: ["'", "."] word_separators: ["'", "."]
backspace_limit: 10 backspace_limit: 10
apply_patch: false apply_patch: false
@ -301,6 +306,7 @@ mod tests {
win32_exclude_orphan_events: Some(false), win32_exclude_orphan_events: Some(false),
pre_paste_delay: Some(300), pre_paste_delay: Some(300),
evdev_modifier_delay: Some(40),
toggle_key: Some("CTRL".to_string()), toggle_key: Some("CTRL".to_string()),
word_separators: Some(vec!["'".to_owned(), ".".to_owned()]), word_separators: Some(vec!["'".to_owned(), ".".to_owned()]),

View File

@ -17,16 +17,7 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>. * along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/ */
use super::{ use super::{AppProperties, Backend, Config, RMLVOConfig, ToggleKey, default::{DEFAULT_CLIPBOARD_THRESHOLD, DEFAULT_PRE_PASTE_DELAY, DEFAULT_RESTORE_CLIPBOARD_DELAY, DEFAULT_SHORTCUT_EVENT_DELAY}, parse::ParsedConfig, path::calculate_paths, util::os_matches};
default::{
DEFAULT_CLIPBOARD_THRESHOLD, DEFAULT_PRE_PASTE_DELAY, DEFAULT_RESTORE_CLIPBOARD_DELAY,
DEFAULT_SHORTCUT_EVENT_DELAY,
},
parse::ParsedConfig,
path::calculate_paths,
util::os_matches,
AppProperties, Backend, Config, RMLVOConfig, ToggleKey,
};
use crate::{counter::next_id, merge}; use crate::{counter::next_id, merge};
use anyhow::Result; use anyhow::Result;
use log::error; use log::error;
@ -314,6 +305,10 @@ impl Config for ResolvedConfig {
fn win32_exclude_orphan_events(&self) -> bool { fn win32_exclude_orphan_events(&self) -> bool {
self.parsed.win32_exclude_orphan_events.unwrap_or(true) self.parsed.win32_exclude_orphan_events.unwrap_or(true)
} }
fn evdev_modifier_delay(&self) -> Option<usize> {
self.parsed.evdev_modifier_delay
}
} }
impl ResolvedConfig { impl ResolvedConfig {
@ -385,6 +380,7 @@ impl ResolvedConfig {
toggle_key, toggle_key,
inject_delay, inject_delay,
key_delay, key_delay,
evdev_modifier_delay,
word_separators, word_separators,
backspace_limit, backspace_limit,
keyboard_layout, keyboard_layout,

View File

@ -390,6 +390,10 @@ impl Config for LegacyInteropConfig {
fn win32_exclude_orphan_events(&self) -> bool { fn win32_exclude_orphan_events(&self) -> bool {
true true
} }
fn evdev_modifier_delay(&self) -> Option<usize> {
Some(10)
}
} }
struct LegacyMatchGroup { struct LegacyMatchGroup {