Skip to content

Commit

Permalink
refactor: clippy, rapid delay for chordsv2
Browse files Browse the repository at this point in the history
Most changes are fixing clippy warnings from upgrading Rust compiler
version.

Also included is a change to chordsv2 behaviour to always trigger the
rapid event delay to create a larger gap between any potential extra
events happening immediately after the chord activation.
  • Loading branch information
jtroo committed Nov 30, 2024
1 parent 71da952 commit 7edd868
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 36 deletions.
8 changes: 4 additions & 4 deletions keyberon/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub enum SequenceEvent<'a, T: 'a> {
Complete,
}

impl<'a, T> Debug for SequenceEvent<'a, T> {
impl<T> Debug for SequenceEvent<'_, T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::NoOp => write!(f, "NoOp"),
Expand Down Expand Up @@ -90,7 +90,7 @@ pub enum HoldTapConfig<'a> {
Custom(&'a (dyn Fn(QueuedIter) -> (Option<WaitingAction>, bool) + Send + Sync)),
}

impl<'a> Debug for HoldTapConfig<'a> {
impl Debug for HoldTapConfig<'_> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
HoldTapConfig::Default => f.write_str("Default"),
Expand All @@ -101,7 +101,7 @@ impl<'a> Debug for HoldTapConfig<'a> {
}
}

impl<'a> PartialEq for HoldTapConfig<'a> {
impl PartialEq for HoldTapConfig<'_> {
fn eq(&self, other: &Self) -> bool {
#[allow(clippy::match_like_matches_macro)]
match (self, other) {
Expand Down Expand Up @@ -392,7 +392,7 @@ where
Src,
}

impl<'a, T> Action<'a, T> {
impl<T> Action<'_, T> {
/// Gets the layer number if the action is the `Layer` action.
pub fn layer(self) -> Option<usize> {
match self {
Expand Down
8 changes: 4 additions & 4 deletions keyberon/src/chord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub struct ChordsV2<'a, T> {
next_coord: Cell<u16>,
}

impl<'a, T> std::fmt::Debug for ChordsV2<'a, T> {
impl<T> std::fmt::Debug for ChordsV2<'_, T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "ChordsV2")
}
Expand Down Expand Up @@ -179,17 +179,17 @@ impl<'a, T> ChordsV2<'a, T> {
&self.chords
}

pub(crate) fn get_action_chv2(&mut self) -> (QueuedAction<'a, T>, bool) {
pub(crate) fn get_action_chv2(&mut self) -> QueuedAction<'a, T> {
self.active_chords
.iter_mut()
.find_map(|ach| match ach.status {
Unread => {
ach.status = Releasable;
Some((Some(((0, ach.coordinate), ach.delay, ach.action)), false))
Some(Some(((0, ach.coordinate), ach.delay, ach.action)))
}
UnreadReleased => {
ach.status = Released;
Some((Some(((0, ach.coordinate), ach.delay, ach.action)), true))
Some(Some(((0, ach.coordinate), ach.delay, ach.action)))
}
Releasable | Released => None,
})
Expand Down
39 changes: 19 additions & 20 deletions keyberon/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ pub enum CustomEvent<'a, T: 'a> {
/// The given custom action key is released.
Release(&'a T),
}
impl<'a, T> CustomEvent<'a, T> {
impl<T> CustomEvent<'_, T> {
/// Update an event according to a new event.
///
///The event can only be modified in the order `NoEvent < Press <
Expand Down Expand Up @@ -286,8 +286,8 @@ pub enum State<'a, T: 'a> {
SeqCustomActive(&'a T),
Tombstone,
}
impl<'a, T> Copy for State<'a, T> {}
impl<'a, T> Clone for State<'a, T> {
impl<T> Copy for State<'_, T> {}
impl<T> Clone for State<'_, T> {
fn clone(&self) -> Self {
*self
}
Expand Down Expand Up @@ -390,7 +390,7 @@ pub struct TapDanceEagerState<'a, T: 'a> {
num_taps: u16,
}

impl<'a, T> TapDanceEagerState<'a, T> {
impl<T> TapDanceEagerState<'_, T> {
fn tick_tde(&mut self) {
self.timeout = self.timeout.saturating_sub(1);
}
Expand Down Expand Up @@ -885,8 +885,8 @@ pub struct OneShotState {
/// When too short, applications or desktop environments process
/// the key release before the next press,
/// even if temporally the release was sent after.
pub on_press_release_delay: u16,
/// If on_press_release_delay is used, this will be >0,
pub pause_input_processing_delay: u16,
/// If pause_input_processing_delay is used, this will be >0,
/// meaning input processing should be paused to prevent extra presses
/// from coming in while OneShot has not yet been released.
///
Expand Down Expand Up @@ -946,8 +946,8 @@ impl OneShotState {
self.end_config,
OneShotEndConfig::EndOnFirstPress | OneShotEndConfig::EndOnFirstPressOrRepress
) {
self.timeout = core::cmp::min(self.on_press_release_delay, self.timeout);
self.pause_input_processing_ticks = self.on_press_release_delay;
self.timeout = core::cmp::min(self.pause_input_processing_delay, self.timeout);
self.pause_input_processing_ticks = self.pause_input_processing_delay;
} else {
let _ = self.other_pressed_keys.push_back(pressed_coord);
}
Expand Down Expand Up @@ -1070,7 +1070,7 @@ impl<'a, const C: usize, const R: usize, T: 'a + Copy + std::fmt::Debug> Layout<
released_keys: ArrayDeque::new(),
other_pressed_keys: ArrayDeque::new(),
release_on_next_tick: false,
on_press_release_delay: 0,
pause_input_processing_delay: 0,
pause_input_processing_ticks: 0,
ticks_to_ignore_events: 0,
},
Expand Down Expand Up @@ -1204,9 +1204,9 @@ impl<'a, const C: usize, const R: usize, T: 'a + Copy + std::fmt::Debug> Layout<
}
}
// Similar issue happens for the quick tap-hold tap as with on-press release;
// the rapidity of the release can cause issues. See on_press_release_delay
// the rapidity of the release can cause issues. See pause_input_processing_delay
// comments for more detail.
self.oneshot.pause_input_processing_ticks = self.oneshot.on_press_release_delay;
self.oneshot.pause_input_processing_ticks = self.oneshot.pause_input_processing_delay;
ret
} else {
CustomEvent::NoEvent
Expand Down Expand Up @@ -1259,11 +1259,10 @@ impl<'a, const C: usize, const R: usize, T: 'a + Copy + std::fmt::Debug> Layout<
let active_layer = self.current_layer() as u16;
if let Some(chv2) = self.chords_v2.as_mut() {
self.queue.extend(chv2.tick_chv2(active_layer).drain(0..));
if let (qac @ Some(_), pause_input_processing) = chv2.get_action_chv2() {
self.action_queue.push_back(qac);
if pause_input_processing {
self.oneshot.pause_input_processing_ticks = self.oneshot.on_press_release_delay;
}
if let chord_action @ Some(_) = chv2.get_action_chv2() {
self.action_queue.push_back(chord_action);
self.oneshot.pause_input_processing_ticks =
self.oneshot.pause_input_processing_delay;
}
}
if let Some(Some((coord, delay, action))) = self.action_queue.pop_front() {
Expand Down Expand Up @@ -2861,7 +2860,7 @@ mod test {
k(B),
]]];
let mut layout = Layout::new(LAYERS);
layout.oneshot.on_press_release_delay = 1;
layout.oneshot.pause_input_processing_delay = 1;

// Test:
// 1. press one-shot
Expand Down Expand Up @@ -2973,7 +2972,7 @@ mod test {
k(B),
]]];
let mut layout = Layout::new(LAYERS);
layout.oneshot.on_press_release_delay = 1;
layout.oneshot.pause_input_processing_delay = 1;

// Test:
// 1. press one-shot
Expand Down Expand Up @@ -3284,7 +3283,7 @@ mod test {
[[k(A), k(B), k(C), k(D)]],
];
let mut layout = Layout::new(LAYERS);
layout.oneshot.on_press_release_delay = 1;
layout.oneshot.pause_input_processing_delay = 1;

layout.event(Press(0, 0));
layout.event(Release(0, 0));
Expand Down Expand Up @@ -3340,7 +3339,7 @@ mod test {
[[k(A), k(B), k(C)]],
];
let mut layout = Layout::new(LAYERS);
layout.oneshot.on_press_release_delay = 1;
layout.oneshot.pause_input_processing_delay = 1;

layout.event(Press(0, 0));
layout.event(Release(0, 0));
Expand Down
4 changes: 2 additions & 2 deletions keyberon/src/multikey_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub(crate) struct MultiKeyBuffer<'a, T> {
ac: *mut Action<'a, T>,
}

unsafe impl<'a, T> Send for MultiKeyBuffer<'a, T> {}
unsafe impl<T> Send for MultiKeyBuffer<'_, T> {}

impl<'a, T> MultiKeyBuffer<'a, T> {
/// Create a new instance of `MultiKeyBuffer`.
Expand Down Expand Up @@ -77,7 +77,7 @@ impl<'a, T> MultiKeyBuffer<'a, T> {
}
}

impl<'a, T> Drop for MultiKeyBuffer<'a, T> {
impl<T> Drop for MultiKeyBuffer<'_, T> {
fn drop(&mut self) {
unsafe {
drop(Box::from_raw(self.ac));
Expand Down
4 changes: 2 additions & 2 deletions parser/src/cfg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ pub fn new_from_str(cfg_text: &str, file_content: HashMap<String, String>) -> MR
);
layout.bm().chords_v2 = icfg.chords_v2;
layout.bm().quick_tap_hold_timeout = icfg.options.concurrent_tap_hold;
layout.bm().oneshot.on_press_release_delay = icfg.options.rapid_event_delay;
layout.bm().oneshot.pause_input_processing_delay = icfg.options.rapid_event_delay;
let mut fake_keys: HashMap<String, usize> = s
.virtual_keys
.iter()
Expand Down Expand Up @@ -363,7 +363,7 @@ fn parse_cfg(p: &Path) -> MResult<Cfg> {
);
layout.bm().chords_v2 = icfg.chords_v2;
layout.bm().quick_tap_hold_timeout = icfg.options.concurrent_tap_hold;
layout.bm().oneshot.on_press_release_delay = icfg.options.rapid_event_delay;
layout.bm().oneshot.pause_input_processing_delay = icfg.options.rapid_event_delay;
if let Some(s) = icfg.start_action {
layout.bm().action_queue.push_front(Some(((1, 0), 0, s)));
}
Expand Down
2 changes: 1 addition & 1 deletion parser/src/cfg/sexpr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ impl<'a> PositionCountingBytesIterator<'a> {
}
}

impl<'a> Iterator for PositionCountingBytesIterator<'a> {
impl Iterator for PositionCountingBytesIterator<'_> {
type Item = u8;

fn next(&mut self) -> Option<Self::Item> {
Expand Down
6 changes: 3 additions & 3 deletions src/tests/sim_tests/chord_sim_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ fn sim_chord_into_tap_hold() {
d:a t:50 d:b t:148 u:a u:b t:1000",
);
assert_eq!(
"t:199ms\nout:↓Y\nt:5ms\nout:↑Y\nt:198ms\nout:↓X\nt:10ms\nout:↑X",
"t:199ms\nout:↓Y\nt:10ms\nout:↑Y\nt:193ms\nout:↓X\nt:10ms\nout:↑X",
result
);
}
Expand Down Expand Up @@ -293,7 +293,7 @@ fn sim_chord_eager_tapholdpress_activation() {
)
.to_ascii();
assert_eq!(
"t:11ms dn:LCtrl t:2ms dn:BSpace t:97ms \
"t:11ms dn:LCtrl t:7ms dn:BSpace t:92ms \
dn:BSpace t:10ms dn:BSpace t:14ms up:BSpace t:96ms up:LCtrl",
result
);
Expand All @@ -315,7 +315,7 @@ fn sim_chord_eager_tapholdrelease_activation() {
)
.to_ascii();
assert_eq!(
"t:20ms dn:LCtrl t:2ms dn:BSpace t:5ms up:BSpace t:93ms up:LCtrl",
"t:20ms dn:LCtrl t:7ms dn:BSpace t:5ms up:BSpace t:88ms up:LCtrl",
result
);
}
Expand Down

0 comments on commit 7edd868

Please sign in to comment.