Skip to content

Commit

Permalink
feat: unblock and forward buttons properly (#972)
Browse files Browse the repository at this point in the history
Closes #968. For now there is no way to block mouse buttons that are
being forwarded to kanata. If someone requests it or opens a PR, the
feature may be included, but for now I don't see a reason why it's
necessary. It seems much more sensible for someone to want to block
their unused keyboard buttons to force the learning of new typing habits
compared to blocking mouse buttons for a similar reason.
  • Loading branch information
jtroo authored Apr 23, 2024
1 parent 0eba84f commit 4c5a313
Show file tree
Hide file tree
Showing 19 changed files with 509 additions and 224 deletions.
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ sha256sums output_dir:
cd {{output_dir}}; sha256sum * > sha256sums

test:
cargo test --verbose -p kanata -p kanata-parser -p kanata-keyberon -- --nocapture
cargo test -p kanata -p kanata-parser -p kanata-keyberon -- --nocapture
cargo clippy --all

fmt:
Expand Down
204 changes: 84 additions & 120 deletions keyberon/src/action/switch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1094,16 +1094,13 @@ fn bool_evaluation_test_not_0() {
OpCode::new_key(KeyCode::F),
];
let keycodes = [KeyCode::A, KeyCode::B, KeyCode::D, KeyCode::F];
assert_eq!(
false,
evaluate_boolean(
opcodes.as_slice(),
keycodes.iter().copied(),
[].iter().copied(),
[].iter().copied(),
[].iter().copied(),
)
);
assert!(!evaluate_boolean(
opcodes.as_slice(),
keycodes.iter().copied(),
[].iter().copied(),
[].iter().copied(),
[].iter().copied(),
));
}

#[test]
Expand All @@ -1115,16 +1112,13 @@ fn bool_evaluation_test_not_1() {
OpCode::new_key(KeyCode::B),
];
let keycodes = [KeyCode::A, KeyCode::B, KeyCode::D, KeyCode::F];
assert_eq!(
false,
evaluate_boolean(
opcodes.as_slice(),
keycodes.iter().copied(),
[].iter().copied(),
[].iter().copied(),
[].iter().copied()
)
);
assert!(!evaluate_boolean(
opcodes.as_slice(),
keycodes.iter().copied(),
[].iter().copied(),
[].iter().copied(),
[].iter().copied()
));
}

#[test]
Expand All @@ -1136,16 +1130,13 @@ fn bool_evaluation_test_not_2() {
OpCode::new_key(KeyCode::Y),
];
let keycodes = [KeyCode::A, KeyCode::B, KeyCode::D, KeyCode::F];
assert_eq!(
true,
evaluate_boolean(
opcodes.as_slice(),
keycodes.iter().copied(),
[].iter().copied(),
[].iter().copied(),
[].iter().copied()
)
);
assert!(evaluate_boolean(
opcodes.as_slice(),
keycodes.iter().copied(),
[].iter().copied(),
[].iter().copied(),
[].iter().copied()
));
}

#[test]
Expand All @@ -1156,16 +1147,13 @@ fn bool_evaluation_test_not_3() {
OpCode::new_key(KeyCode::D),
];
let keycodes = [KeyCode::A, KeyCode::B, KeyCode::D, KeyCode::F];
assert_eq!(
false,
evaluate_boolean(
opcodes.as_slice(),
keycodes.iter().copied(),
[].iter().copied(),
[].iter().copied(),
[].iter().copied()
)
);
assert!(!evaluate_boolean(
opcodes.as_slice(),
keycodes.iter().copied(),
[].iter().copied(),
[].iter().copied(),
[].iter().copied()
));
}

#[test]
Expand All @@ -1183,16 +1171,13 @@ fn bool_evaluation_test_not_4() {
OpCode::new_key(KeyCode::F),
];
let keycodes = [KeyCode::A, KeyCode::B, KeyCode::D, KeyCode::F];
assert_eq!(
false,
evaluate_boolean(
opcodes.as_slice(),
keycodes.iter().copied(),
[].iter().copied(),
[].iter().copied(),
[].iter().copied()
)
);
assert!(!evaluate_boolean(
opcodes.as_slice(),
keycodes.iter().copied(),
[].iter().copied(),
[].iter().copied(),
[].iter().copied()
));
}

#[test]
Expand All @@ -1204,16 +1189,13 @@ fn bool_evaluation_test_not_5() {
OpCode::new_key(KeyCode::D),
];
let keycodes = [KeyCode::A, KeyCode::B, KeyCode::D, KeyCode::F];
assert_eq!(
true,
evaluate_boolean(
opcodes.as_slice(),
keycodes.iter().copied(),
[].iter().copied(),
[].iter().copied(),
[].iter().copied()
)
);
assert!(evaluate_boolean(
opcodes.as_slice(),
keycodes.iter().copied(),
[].iter().copied(),
[].iter().copied(),
[].iter().copied()
));
}

#[test]
Expand All @@ -1226,16 +1208,13 @@ fn bool_evaluation_test_not_6() {
OpCode::new_key(KeyCode::D),
];
let keycodes = [KeyCode::A, KeyCode::B, KeyCode::D, KeyCode::F];
assert_eq!(
false,
evaluate_boolean(
opcodes.as_slice(),
keycodes.iter().copied(),
[].iter().copied(),
[].iter().copied(),
[].iter().copied()
)
);
assert!(!evaluate_boolean(
opcodes.as_slice(),
keycodes.iter().copied(),
[].iter().copied(),
[].iter().copied(),
[].iter().copied()
));
}

#[test]
Expand All @@ -1247,16 +1226,13 @@ fn bool_evaluation_test_or_equivalency_not_6() {
OpCode::new_key(KeyCode::D),
];
let keycodes = [KeyCode::A, KeyCode::B, KeyCode::D, KeyCode::F];
assert_eq!(
false,
evaluate_boolean(
opcodes.as_slice(),
keycodes.iter().copied(),
[].iter().copied(),
[].iter().copied(),
[].iter().copied()
)
);
assert!(!evaluate_boolean(
opcodes.as_slice(),
keycodes.iter().copied(),
[].iter().copied(),
[].iter().copied(),
[].iter().copied()
));
}

#[test]
Expand All @@ -1268,16 +1244,13 @@ fn bool_evaluation_test_not_7() {
OpCode::new_key(KeyCode::E),
];
let keycodes = [KeyCode::A, KeyCode::B, KeyCode::D, KeyCode::F];
assert_eq!(
false,
evaluate_boolean(
opcodes.as_slice(),
keycodes.iter().copied(),
[].iter().copied(),
[].iter().copied(),
[].iter().copied()
)
);
assert!(!evaluate_boolean(
opcodes.as_slice(),
keycodes.iter().copied(),
[].iter().copied(),
[].iter().copied(),
[].iter().copied()
));
}

#[test]
Expand All @@ -1289,16 +1262,13 @@ fn bool_evaluation_test_or_equivalency_not_7() {
OpCode::new_key(KeyCode::E),
];
let keycodes = [KeyCode::A, KeyCode::B, KeyCode::D, KeyCode::F];
assert_eq!(
false,
evaluate_boolean(
opcodes.as_slice(),
keycodes.iter().copied(),
[].iter().copied(),
[].iter().copied(),
[].iter().copied()
)
);
assert!(!evaluate_boolean(
opcodes.as_slice(),
keycodes.iter().copied(),
[].iter().copied(),
[].iter().copied(),
[].iter().copied()
));
}

#[test]
Expand All @@ -1310,16 +1280,13 @@ fn bool_evaluation_test_not_8() {
OpCode::new_key(KeyCode::A),
];
let keycodes = [KeyCode::A, KeyCode::B, KeyCode::D, KeyCode::F];
assert_eq!(
false,
evaluate_boolean(
opcodes.as_slice(),
keycodes.iter().copied(),
[].iter().copied(),
[].iter().copied(),
[].iter().copied()
)
);
assert!(!evaluate_boolean(
opcodes.as_slice(),
keycodes.iter().copied(),
[].iter().copied(),
[].iter().copied(),
[].iter().copied()
));
}

#[test]
Expand All @@ -1331,16 +1298,13 @@ fn bool_evaluation_test_not_9() {
OpCode::new_key(KeyCode::C),
];
let keycodes = [KeyCode::A, KeyCode::B, KeyCode::D, KeyCode::F];
assert_eq!(
true,
evaluate_boolean(
opcodes.as_slice(),
keycodes.iter().copied(),
[].iter().copied(),
[].iter().copied(),
[].iter().copied()
)
);
assert!(evaluate_boolean(
opcodes.as_slice(),
keycodes.iter().copied(),
[].iter().copied(),
[].iter().copied(),
[].iter().copied()
));
}

#[test]
Expand Down
6 changes: 2 additions & 4 deletions keyberon/src/chord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@ impl<'a, T> ChordsV2<'a, T> {
return;
};
let Some(possible_chords) = self.chords.mapping.get(starting_press) else {
dbg!("no chord activations");
no_chord_activations!(self, "no chords for key");
return;
};
Expand Down Expand Up @@ -403,7 +402,6 @@ impl<'a, T> ChordsV2<'a, T> {
.iter()
.all(|pk| accumulated_presses.contains(pk))
{
dbg!("got exact chord match");
let ach = get_active_chord(cch, since, coord, relevant_release_found);
let overflow = self.active_chords.push(ach);
assert!(overflow.is_ok(), "active chords has room");
Expand Down Expand Up @@ -448,7 +446,7 @@ impl<'a, T> ChordsV2<'a, T> {
}
_ => {}
}
self.ticks_until_next_state_change = dbg!(min_timeout.saturating_sub(since));
self.ticks_until_next_state_change = min_timeout.saturating_sub(since);
prev_count = count_possible;
}
if self.ticks_until_next_state_change == 0 || relevant_release_found {
Expand Down Expand Up @@ -553,6 +551,6 @@ fn get_active_chord<'a, T>(
} else {
ActiveChordStatus::Unread
},
delay: dbg!(since),
delay: since,
}
}
4 changes: 4 additions & 0 deletions keyberon/src/key_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,10 @@ pub enum KeyCode {
K742,
K743,
K744,
MWU,
MWD,
MWL,
MWR,
KeyMax,
}

Expand Down
Loading

0 comments on commit 4c5a313

Please sign in to comment.