Skip to content

Commit

Permalink
fix(block-unmapped): only block unspecified actions
Browse files Browse the repository at this point in the history
  • Loading branch information
jtroo committed Jun 15, 2024
1 parent dc16586 commit d3ef95d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions keyberon/src/key_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub enum KeyCode {
/// The POST fail error.
PostFail,
/// An undefined error occured.
/// In Kanata, used to mark an unspecified key.
ErrorUndefined,
/// `a` and `A`.
A,
Expand Down
7 changes: 5 additions & 2 deletions parser/src/cfg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3102,8 +3102,11 @@ fn parse_layers(
}
}
for (osc, layer_action) in layers_cfg[layer_level][0].iter_mut().enumerate() {
if s.block_unmapped_keys && *layer_action == Action::Trans && !is_a_button(osc as u16) {
*layer_action = Action::NoOp;
if *layer_action == DEFAULT_ACTION {
*layer_action = match s.block_unmapped_keys && !is_a_button(osc as u16) {
true => Action::NoOp,
false => Action::Trans,
};
}
}

Expand Down
7 changes: 3 additions & 4 deletions parser/src/layers.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use kanata_keyberon::key_code::KeyCode;
use kanata_keyberon::layout::*;

use crate::cfg::alloc::*;
Expand All @@ -10,6 +11,7 @@ use std::sync::Arc;
// OsCode::KEY_MAX is the biggest OsCode
pub const KEYS_IN_ROW: usize = OsCode::KEY_MAX as usize;
pub const LAYER_ROWS: usize = 2;
pub const DEFAULT_ACTION: KanataAction = KanataAction::KeyCode(KeyCode::ErrorUndefined);

pub type IntermediateLayers = Box<[[Row; LAYER_ROWS]]>;

Expand Down Expand Up @@ -37,10 +39,7 @@ pub fn new_layers(layers: usize) -> IntermediateLayers {
// The stack will overflow because of lack of placement new.
let mut layers = Vec::with_capacity(actual_num_layers);
for _ in 0..actual_num_layers {
layers.push([
[KanataAction::Trans; KEYS_IN_ROW],
[KanataAction::Trans; KEYS_IN_ROW],
]);
layers.push([[DEFAULT_ACTION; KEYS_IN_ROW], [DEFAULT_ACTION; KEYS_IN_ROW]]);
}
layers.into_boxed_slice()
}
Expand Down

0 comments on commit d3ef95d

Please sign in to comment.