diff --git a/Cargo.lock b/Cargo.lock index c1ab2f7a7..3b422d539 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -320,7 +320,7 @@ dependencies = [ [[package]] name = "kanata" -version = "0.1.3" +version = "0.1.4" dependencies = [ "anyhow", "clap", diff --git a/Cargo.toml b/Cargo.toml index f874edda6..84640a515 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,13 +1,12 @@ [package] name = "kanata" -version = "0.1.3" +version = "0.1.4" authors = ["jtroo "] -description = "Multi-layout keyboard customization" +description = "Multi-layer keyboard customization" keywords = ["cli", "linux", "windows", "keyboard", "layout"] categories = ["command-line-utilities"] homepage = "https://github.com/jtroo/kanata" repository = "https://github.com/jtroo/kanata" -documentation = "https://github.com/jtroo/kanata" readme = "README.md" license = "LGPL-3.0" edition = "2021" @@ -18,7 +17,6 @@ clap = { version = "3", features = [ "derive" ] } log = "0.4.8" simplelog = "0.8.0" anyhow = "1" -once_cell = "1" parking_lot = "0.12" crossbeam-channel = "0.5" @@ -30,6 +28,7 @@ evdev-rs = "0.4.0" uinput-sys = "0.1.7" [target.'cfg(target_os = "windows")'.dependencies] +once_cell = "1" encode_unicode = "0.3.6" winapi = { version = "0.3.9", features = ["consoleapi", "wincon"] } native-windows-gui = { version = "1.0.12", features = [ diff --git a/src/kanata.rs b/src/kanata.rs index 57dba31b9..ef9146304 100644 --- a/src/kanata.rs +++ b/src/kanata.rs @@ -242,15 +242,11 @@ impl Kanata { pub fn event_loop(kanata: Arc>, tx: Sender) -> Result<()> { info!("Kanata: entering the event loop"); - let (kbd_in, mapped_keys) = { - let kanata = kanata.lock(); - let kbd_in = match KbdIn::new(&kanata.kbd_in_path) { - Ok(kbd_in) => kbd_in, - Err(e) => { - bail!("failed to open keyboard device: {}", e) - } - }; - (kbd_in, kanata.mapped_keys) + let kbd_in = match KbdIn::new(&kanata.lock().kbd_in_path) { + Ok(kbd_in) => kbd_in, + Err(e) => { + bail!("failed to open keyboard device: {}", e) + } }; loop { @@ -269,10 +265,12 @@ impl Kanata { // Check if this keycode is mapped in the configuration. If it hasn't been mapped, send // it immediately. let kc: usize = key_event.code.into(); - if kc >= cfg::MAPPED_KEYS_LEN || !mapped_keys[kc] { + { let mut kanata = kanata.lock(); - kanata.kbd_out.write_key(key_event.code, key_event.value)?; - continue; + if kc >= cfg::MAPPED_KEYS_LEN || !kanata.mapped_keys[kc] { + kanata.kbd_out.write_key(key_event.code, key_event.value)?; + continue; + } } // Send key events to the processing loop @@ -295,11 +293,6 @@ impl Kanata { }; native_windows_gui::init()?; - let mapped_keys = { - let kanata = kanata.lock(); - kanata.mapped_keys - }; - // This callback should return `false` if the input event is **not** handled by the // callback and `true` if the input event **is** handled by the callback. Returning false // informs the callback caller that the input event should be handed back to the OS for @@ -308,7 +301,7 @@ impl Kanata { if input_event.code as usize >= cfg::MAPPED_KEYS_LEN { return false; } - if !mapped_keys[input_event.code as usize] { + if !kanata.lock().mapped_keys[input_event.code as usize] { return false; }