feat(core): pass necessary modifier state provider to engine

This commit is contained in:
Federico Terzi 2021-10-16 13:23:50 +02:00
parent 6f94ee3f38
commit 789acc3d76
2 changed files with 42 additions and 0 deletions
espanso/src/cli/worker/engine

View File

@ -149,3 +149,44 @@ impl ModifierStatusProvider for ModifierStateStore {
self.is_any_conflicting_modifier_pressed()
}
}
impl espanso_engine::process::ModifierStateProvider for ModifierStateStore {
fn get_modifier_state(&self) -> espanso_engine::process::ModifierState {
let mut state = self.state.lock().expect("unable to obtain modifier state");
let mut is_ctrl_down = false;
let mut is_alt_down = false;
let mut is_meta_down = false;
for (modifier, status) in &mut state.modifiers {
if status.is_outdated() {
warn!(
"detected outdated modifier records for {:?}, releasing the state",
modifier
);
status.release();
}
if status.is_pressed() {
match modifier {
Modifier::Ctrl => {
is_ctrl_down = true;
}
Modifier::Alt => {
is_alt_down = true;
}
Modifier::Meta => {
is_meta_down = true;
}
_ => {}
}
}
}
espanso_engine::process::ModifierState {
is_ctrl_down,
is_alt_down,
is_meta_down,
}
}
}

View File

@ -223,6 +223,7 @@ pub fn initialize_and_spawn(
&combined_match_cache,
&config_manager,
&config_manager,
&modifier_state_store,
);
let event_injector = EventInjectorAdapter::new(&*injector, &config_manager);