Skip to content

Commit

Permalink
Fix bug where mapped keys is not updated
Browse files Browse the repository at this point in the history
  • Loading branch information
jtroo committed Apr 27, 2022
1 parent d3d4370 commit 76cebbf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
[package]
name = "kanata"
version = "0.1.3"
version = "0.1.4"
authors = ["jtroo <[email protected]>"]
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"
Expand All @@ -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"

Expand All @@ -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 = [
Expand Down
29 changes: 11 additions & 18 deletions src/kanata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,11 @@ impl Kanata {
pub fn event_loop(kanata: Arc<Mutex<Self>>, tx: Sender<KeyEvent>) -> 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 {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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;
}

Expand Down

0 comments on commit 76cebbf

Please sign in to comment.