Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Sequences (aka macros) #30

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3a83060
Fixed description and updated the either dependency to 1.6
riskable Oct 15, 2020
6e5e068
Added support for Sequence Actions (aka macros) whereby multiple key …
riskable Oct 16, 2020
b56de4f
Added support for Sequence Actions (aka macros) whereby multiple key …
riskable Oct 16, 2020
7df7519
Modified per TeXitoi's instructions (as best I understood them) and a…
riskable Oct 19, 2020
d65daac
Merge branch 'master' of github.com:riskable/keyberon
riskable Oct 19, 2020
6067648
Removed some leftover commented-out cruft
riskable Oct 19, 2020
95650fd
Made some changes to make Clippy happy.
riskable Oct 19, 2020
255c4d3
Unit tests for sequences and improved tick start
riskable Oct 19, 2020
18fb401
Minor fixes to make Clippy happy
riskable Oct 19, 2020
37e6b31
Support for sequences of nearly limitless length!
riskable Oct 20, 2020
b7a77d3
Make Clippy happy
riskable Oct 20, 2020
999b9f2
Changed do_action() to make Clippy happy
riskable Oct 20, 2020
ab0bfe1
Fixed a bug where Delay() wasn't working properly
riskable Oct 20, 2020
0785151
Added the ability to cancel running sequences
riskable Oct 20, 2020
60b08b9
Fixed an edge case with CancelSequence
riskable Oct 20, 2020
0d89989
Added `SequenceEvent::Tap`
riskable Oct 23, 2020
0660d2b
CHANGELOG and more doc for custom actionmagnet:?xt=urn:btih:a6721ad2e…
TeXitoi Dec 11, 2020
f3ad3ff
Merge remote-tracking branch 'upstream/master'
riskable Dec 14, 2020
3fe71e5
Changed how sequences are processed (MUCH simpler).
riskable Dec 15, 2020
43ed3e5
Merge remote-tracking branch 'upstream/master'
riskable May 3, 2021
f93d8ec
Added SequenceEvent back to layout.rs (got removed with last merge of…
riskable May 3, 2021
f0e7d65
Merge remote-tracking branch 'upstream/master'
riskable Sep 22, 2021
a26a3b6
Merged upstream
riskable Dec 25, 2021
4604ec7
Added some Sequence test cases
riskable May 2, 2022
2585845
Merge remote-tracking branch 'upstream/master'
riskable May 2, 2022
c990d9d
Fixed Sequence tests to use the new syntax
riskable May 2, 2022
d93436d
Removed unused enum variant and modified to use a const generic va…
riskable May 2, 2022
8e2dfa9
Merged upstream
riskable Oct 4, 2022
883a2d1
Merge remote-tracking branch 'upstream/master' into sequences
riskable Oct 4, 2022
5e67102
Added SequenceEvent back to action.rs
riskable Oct 4, 2022
16be78a
Fixed duplicate HoldTapConfig lines
riskable Oct 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 50 additions & 2 deletions src/action.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,48 @@
//! The different actions that can be done.
//! The different actions that can be executed via any given key.

use crate::key_code::KeyCode;

/// The different types of actions we support for key macros
#[non_exhaustive] // Definitely NOT exhaustive! Let's add more! Mouse events maybe? :)
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum SequenceEvent {
/// A keypress/keydown
Press(KeyCode),
/// Key release/keyup
Release(KeyCode),
/// A shortcut for `Press(KeyCode), Release(KeyCode)`
Tap(KeyCode),
/// For sequences that need to wait a bit before continuing
Delay {
/// A delay (in ticks) to wait before executing the next SequenceEvent
since: u32,
/// Number of ticks to wait before removing the Delay
ticks: u32,
TeXitoi marked this conversation as resolved.
Show resolved Hide resolved
},
/// A marker that indicates there's more of the macro than would fit
/// in the 'sequenced' ArrayDeque
Continue {
riskable marked this conversation as resolved.
Show resolved Hide resolved
/// The current chunk
index: usize,
/// The full list of Sequence Events (that aren't Continue())
events: &'static [SequenceEvent],
},
/// Cancels the running sequence and can be used to mark the end of a sequence
/// instead of using a number of Release() events
Complete,
}

impl SequenceEvent {
/// Returns the keycode associated with the given Press/Release event
pub fn keycode(&self) -> Option<KeyCode> {
TeXitoi marked this conversation as resolved.
Show resolved Hide resolved
match *self {
SequenceEvent::Press(keycode) => Some(keycode),
SequenceEvent::Release(keycode) => Some(keycode),
_ => None,
}
}
}

/// The different actions that can be done.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
Expand Down Expand Up @@ -41,6 +82,13 @@ pub enum Action {
/// The tap action.
tap: &'static Action,
},
/// A sequence of SequenceEvents
Sequence {
/// An array of SequenceEvents that will be triggered (in order)
events: &'static [SequenceEvent],
},
/// Cancels any running sequences
CancelSequence,
}
impl Action {
/// Gets the layer number if the action is the `Layer` action.
Expand Down Expand Up @@ -78,7 +126,7 @@ pub const fn d(layer: usize) -> Action {
Action::DefaultLayer(layer)
}

/// A shortcut to create a `Action::KeyCode`, useful to create compact
/// A shortcut to create `Action::MultipleKeyCodes`, useful to create compact
/// layout.
pub const fn m(kcs: &'static [KeyCode]) -> Action {
Action::MultipleKeyCodes(kcs)
Expand Down
Loading