-
Notifications
You must be signed in to change notification settings - Fork 2
tap-hold pending_output (speculative Hold) #708
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
Open
rgoulter
wants to merge
6
commits into
master
Choose a base branch
from
pending-output
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
371a9a2
core: add System::pending_output hook
rgoulter bd6b2a2
ncl: tap-hold pending_output authoring and codegen
rgoulter 9626002
core: tap-hold pending_output profile and speculative state
rgoulter c2fbcfb
test: refresh expected.rs snapshots for PendingKeyState<Ref>
rgoulter a0bd1fe
test: add pending_output integration tests
rgoulter 5bede79
test: add pending_output cucumber feature
rgoulter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
features/keymap/key/tap_hold-config-pending_output.feature
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| Feature: TapHold Key (configure pending_output) | ||
|
|
||
| The `pending_output` config for tap-hold keys controls speculative HID | ||
| while the tap-vs-hold decision is still pending. | ||
|
|
||
| Default `NoOutput` produces no output while pending. | ||
| No HID is emitted until timeout, interrupt, or release settles tap vs hold. | ||
| `Hold` emits the hold binding's HID while still pending, then keeps it | ||
| or retracts it when tap vs hold settles. Decision logic is unchanged. | ||
| Only the timing of hold appearance changes. | ||
|
|
||
| This matches FAK `eager_decision = 'hold'`, ZMK | ||
| `hold-while-undecided`, and QMK Speculative Hold. | ||
|
|
||
| For examples of this key in other smart keyboard firmware, see e.g.: | ||
|
|
||
| - [FAK's eager_decision](https://github.com/semickolon/fak) | ||
|
|
||
| - [ZMK's hold-while-undecided](https://zmk.dev/docs/keymaps/behaviors/hold-tap#hold-while-undecided) | ||
|
|
||
| - [QMK's Speculative Hold](https://docs.qmk.fm/tap_hold#speculative-hold) | ||
|
|
||
| Background: | ||
|
|
||
| Given a keymap.ncl: | ||
| """ | ||
| let K = import "keys.ncl" in | ||
| { | ||
| config.tap_hold.pending_output = "Hold", | ||
| keys = [ | ||
| K.A & K.hold K.LeftCtrl, | ||
| K.B | ||
| ] | ||
| } | ||
| """ | ||
|
|
||
| Example: Hold with timeout shows mod from first tick and stays hold | ||
|
|
||
| When the keymap registers the following input | ||
| """ | ||
| [ | ||
| press (K.A & K.hold K.LeftCtrl), | ||
| wait 1, | ||
| ] | ||
| """ | ||
| Then the HID keyboard report should equal | ||
| """ | ||
| { modifiers = { left_ctrl = true } } | ||
| """ | ||
|
|
||
| Example: Hold with quick release retracts mod and ends as tap | ||
|
|
||
| When the keymap registers the following input | ||
| """ | ||
| [ | ||
| press (K.A & K.hold K.LeftCtrl), | ||
| wait 1, | ||
| release (K.A & K.hold K.LeftCtrl), | ||
| ] | ||
| """ | ||
| Then the HID keyboard report should equal | ||
| """ | ||
| { key_codes = [K.A] } | ||
| """ | ||
|
|
||
| Example: Hold with HoldOnKeyPress interrupt shows mod already down when other key taps | ||
|
|
||
| Given a keymap.ncl: | ||
| """ | ||
| let K = import "keys.ncl" in | ||
| { | ||
| config.tap_hold.interrupt_response = "HoldOnKeyPress", | ||
| keys = [ | ||
| K.A & K.hold K.LeftCtrl, | ||
| K.B | ||
| ] | ||
| } | ||
| """ | ||
| When the keymap registers the following input | ||
| """ | ||
| [ | ||
| press (K.A & K.hold K.LeftCtrl), | ||
| wait 1, | ||
| tap K.B, | ||
| ] | ||
| """ | ||
| Then the HID keyboard report should equal | ||
| """ | ||
| { modifiers = { left_ctrl = true }, key_codes = [K.B] } | ||
| """ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -575,6 +575,25 @@ Ref::%{f.variant}(key_ref) => { | |
| ) | ||
| ++ "\n(_, _) => None,", | ||
|
|
||
| pending_output_arms = | ||
| if pending_systems == [] then | ||
| "_ => None," | ||
| else | ||
| ( | ||
| pending_systems | ||
| |> std.array.map (fun f => | ||
| if f.variant == "TapHold" then | ||
| m%"PendingKeyState::%{f.variant}(pks) => pks.speculative_output(|spec| match spec { | ||
| Ref::Keyboard(kb_ref) => self.keyboard.key_output(kb_ref, &smart_keymap::key::keyboard::KeyState), | ||
| _ => None, | ||
| }),"% | ||
|
Comment on lines
+586
to
+589
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm. Not sure about this. |
||
| else | ||
| m%"PendingKeyState::%{f.variant}(_) => None,"% | ||
| ) | ||
| |> join | ||
| ) | ||
| ++ "\n_ => None,", | ||
|
|
||
| key_state_from_family = | ||
| systems | ||
| |> std.array.map (fun f => | ||
|
|
@@ -861,6 +880,15 @@ pub mod key_system { | |
| %{key_output_arms} | ||
| } | ||
| } | ||
|
|
||
| fn pending_output( | ||
| &self, | ||
| pending_key_state: &Self::PendingKeyState, | ||
| ) -> Option<key::KeyOutput> { | ||
| match pending_key_state { | ||
| %{pending_output_arms} | ||
| } | ||
| } | ||
| } | ||
| } | ||
| "%, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,6 +102,15 @@ | |
| ] | ||
| ), | ||
|
|
||
| TapHoldPendingOutputJson = | ||
| std.contract.from_validator ( | ||
| validators.is_elem_of [ | ||
| "NoOutput", | ||
| "Hold", | ||
| "None", | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? |
||
| ] | ||
| ), | ||
|
|
||
| module = "smart_keymap::key::tap_hold", | ||
|
|
||
| hold_trigger_positions_expr = fun positions => | ||
|
|
@@ -156,6 +165,18 @@ | |
| } | ||
| else | ||
| {} | ||
| ) | ||
| & ( | ||
| if std.record.has_field "pending_output" c then | ||
| { | ||
| pending_output = | ||
| if c.pending_output == "None" then | ||
| "%{module}::PendingOutput::NoOutput" | ||
| else | ||
| "%{module}::PendingOutput::%{c.pending_output}", | ||
| } | ||
| else | ||
| {} | ||
| ), | ||
|
|
||
| profile_rust_expr = fun c => | ||
|
|
@@ -297,6 +318,7 @@ | |
| required_idle_time | optional | Number, | ||
| hold_trigger_key_positions | optional | Array Number, | ||
| quick_tap_ms | optional | Number, | ||
| pending_output | optional | TapHoldPendingOutputJson, | ||
| }, | ||
|
|
||
| # Lowered JSON form: nested default_profile + profiles array. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Emdash remains a sign of cringe. (LLMs still lack taste about what a good comment is).
Should help try rearrange to more 'semantic' linebreaks.