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

feat: yet-another-chording feature: zippychord #1301

Merged
merged 55 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
800ea2d
initial commit
jtroo Jun 7, 2024
bc66d84
add todo around smart spacing
jtroo Oct 20, 2024
a724438
add test, fix bug, found new unfixed bug
jtroo Oct 20, 2024
d507886
fix bspc count hopefully
jtroo Oct 20, 2024
af0e60a
use expected result for overlap test
jtroo Oct 20, 2024
9fdf668
hopefully actually fix backspace now
jtroo Oct 20, 2024
da9a461
one more backspacing fix...
jtroo Oct 20, 2024
336be8f
remove option for prev activation
jtroo Oct 20, 2024
9980ab3
adjust extra press/release and maintain shift state properly
jtroo Oct 20, 2024
a0c1280
fix clippy
jtroo Oct 20, 2024
5874454
update tests
jtroo Oct 20, 2024
241dc17
add more tests
jtroo Oct 20, 2024
20a32b6
fmt
jtroo Oct 20, 2024
c30ded3
documentation
jtroo Oct 21, 2024
074b5e1
clippy fixes
jtroo Oct 21, 2024
717fd81
parse space in output, more backspace fixes
jtroo Oct 21, 2024
1d07838
clippy
jtroo Oct 21, 2024
178e4b2
Reset state correctly
jtroo Oct 23, 2024
1cb3962
parse configurations
jtroo Oct 21, 2024
43fec15
wip zippy configuration
jtroo Oct 21, 2024
0d47960
add deadline configuration
jtroo Oct 24, 2024
d40399f
rename/move/adjust quick enable function, add wip doc
jtroo Oct 25, 2024
6805250
fix a comment
jtroo Oct 25, 2024
4399230
disable properly in waitenable
jtroo Oct 25, 2024
c98da8b
change reset behaviours
jtroo Oct 25, 2024
a321bd0
move enable to soft reset
jtroo Oct 25, 2024
8fad871
maybe fix sequential activation
jtroo Oct 25, 2024
2122c25
fix state
jtroo Oct 26, 2024
575dd1b
progress in map parsing
jtroo Oct 26, 2024
8640408
completed output mapping
jtroo Oct 27, 2024
3cea3c2
output mapping
jtroo Oct 27, 2024
8e35e31
disable quick enable, add washington test
jtroo Oct 27, 2024
860a4ba
remove dead code
jtroo Oct 27, 2024
fe39869
add workaround for interception driver weirdness
jtroo Oct 27, 2024
5209ef1
add basic kanata.kbd example
jtroo Oct 27, 2024
42b9c27
fix disable bug
jtroo Oct 27, 2024
ec40feb
Merge remote-tracking branch 'origin/main' into zippywip
jtroo Oct 27, 2024
c790b81
config doc
jtroo Oct 28, 2024
ca37d95
fix and docs
jtroo Oct 28, 2024
b6ad679
update config.adoc
jtroo Oct 28, 2024
f24556b
fix formatting
jtroo Oct 28, 2024
310666b
adjust wording
jtroo Oct 28, 2024
49503f5
smartspace wip
jtroo Oct 28, 2024
1443f6b
wip smart space
jtroo Oct 28, 2024
f662db0
add tests
jtroo Oct 28, 2024
8593abf
add more prefix tests and fix
jtroo Oct 28, 2024
5402f8e
fmt
jtroo Oct 28, 2024
cee6d2b
clippy
jtroo Oct 28, 2024
4956f1f
doc for smart space
jtroo Oct 29, 2024
b464822
doc, ignore more keys
jtroo Oct 29, 2024
de8122f
fix test
jtroo Oct 30, 2024
2eef329
fix smartspace followups and overlaps
jtroo Oct 31, 2024
a689247
Allow custom punctuation
jtroo Nov 1, 2024
5662b1a
use set for punc; update docs
jtroo Nov 1, 2024
691eb40
add tests and 1 minor fix for smart space
jtroo Nov 2, 2024
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
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ indoc = { version = "2.0.4", optional = true }
regex = { version = "1.10.4", optional = true }

[features]
default = ["tcp_server","win_sendinput_send_scancodes"]
default = ["tcp_server","win_sendinput_send_scancodes", "zippychord"]
perf_logging = []
tcp_server = ["serde_json"]
win_sendinput_send_scancodes = ["kanata-parser/win_sendinput_send_scancodes"]
Expand All @@ -136,6 +136,7 @@ gui = ["win_manifest","kanata-parser/gui",
"winapi/processthreadsapi",
"native-windows-gui/tray-notification","native-windows-gui/message-window","native-windows-gui/menu","native-windows-gui/cursor","native-windows-gui/high-dpi","native-windows-gui/embed-resource","native-windows-gui/image-decoder","native-windows-gui/notice","native-windows-gui/animation-timer",
]
zippychord = ["kanata-parser/zippychord"]

[profile.release]
opt-level = "z"
Expand Down
42 changes: 42 additions & 0 deletions cfg_samples/kanata.kbd
Original file line number Diff line number Diff line change
Expand Up @@ -1391,3 +1391,45 @@ Syntax (5-tuples):
(a b z) (macro h e l l o) 250 first-release (arrows)
(a b z y) (macro b y e) 400 first-release (arrows)
)

#|

Yet another chording implementation - zippychord:


;; This is a sample for US international layout.
(defzippy-experimental
zippy.txt
on-first-press-chord-deadline 500
idle-reactivate-time 500
smart-space-punctuation (? ! . , ; :)
output-character-mappings (
! S-1
? S-/
% S-5
"(" S-9
")" S-0
: S-;
< S-,
> S-.
r#"""# S-'
| S-\
_ S--
® AG-r
)
)

Example file content of zippy.txt:
---
dy day
dy 1 Monday
abc Alphabet
r df recipient
w a Washington
rq request
rqa request assistance
---

You can read about zippychord in more detail in the configuration guide.

|#
259 changes: 259 additions & 0 deletions docs/config.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3975,3 +3975,262 @@ And key names are defined in the https://github.com/jtroo/kanata/blob/main/parse
for example, `1` for the numeric key 1 or `kp1`/`🔢₁` for the keypad numeric key 1

Using unicode symbols `🕐`,`↓`,`↑`,`⟳` allows skipping the `:` separator, e.g., `↓k` ≝ `↓:k` ≝ `d:k`

[[zippychord]]
=== Zippychord
<<table-of-contents,Back to ToC>>

==== Reference

You may define a single `+defzippy-experimental+` configuration item.
As suggested by the -experimental label, this feature is relatively recent.
When using this you are at higher likelihood of bugs and breaking changes.

===== Configuration syntax within the kanata configuration

[source]
----
(defzippy-experimental
$zippy-filename ;; required
on-first-press-chord-deadline $deadline-millis ;; optional
idle-reactivate-time $idle-time-millis ;; optional
smart-space $smart-space-cfg ;; optional
smart-space-punctuation ( ;; optional
$punc1 $punc2 ... $puncN)
output-character-mappings ( ;; optional
$character1 $output-mapping1
$character2 $output-mapping2
;; ...
$characterN $output-mappingN
)
)
----

[cols="1,2"]
|===
| `$zippy-filename`
| Relative or absolute file path.
If relative, its path is relative to
the directory containing the kanata configuration file.
This must be the first item following `defzippy-experimental`.

| `$deadline-millis` for `on-first-press-chord-deadline`
| Number of milliseconds.
After the first press while zippy is enabled,
if no chord activates within this configured time,
zippy is temporarily disabled.

| `$idle-time-millis` for `idle-reactivate-time`
| Number of milliseconds.
After typing ends and this configured number of milliseconds elapses,
zippy will be re-enabled from being temporarily disabled.

| `$smart-space-cfg` for `smart-space`
| Determines the smart space behaviour.
The options are `none | add-space-only | full`.
With `none`, outputs are typed as-is.
With `add-space-only`, spaces are automatically added after outputs
which end with neither a space or a backspace ⌫.
With `full`, the `add-space-only` behaviour applies
and additional behaviour is active:
typing punctuation — US-layout `, . ;` by default —
after a zippy activation will delete a prior automatically-added space.

| `$puncN` for `smart-space-punctuation`
| A character defined in `output-character-mappings`
or a known key name, which shall be considered as punctuation.
The full list within `smart-space-punctuation`
will overwrite the default punctuation list
considered by smart-space.

| `$characterN` for `output-character-mappings`
| A single unicode character for use
in the output column of the zippy configuration file.

| `$output-mappingN` for `output-character-mappings`
| Key or output chord to tell kanata how to type `$characterN`
when seen in the zippy file output column.
Must be a single key or output chord.
The output chord may contain `AG-` to tell kanata to press with AltGr
and may contain `S-` to tell kanata to press with Shift.
|===

Regarding output mappings,
you can configure the output of the special-lisp-syntax characters
`+) ( "+` via these lines:

[source]
----
")" $right-paren-output
"(" $left-paren-output
r#"""# $double-quote-output
----

As an example, for the US layout these should be the correct lines:

[source]
----
")" S-0
"(" S-9
r#"""# S-'
----

===== Configuration syntax within the zippy configuration file

[source]
----
// This is a comment.
// inputs ↹ outputs
$chord1 $follow-chord1.1...1.M $output1
$chord2 $follow-chord2.1...2.M $output2
// ...
$chordN $follow-chordN.1...N.M $outputN
----

The format is two columns separated by a single Tab character.
The first column is input and the second is output.

[cols="1,2"]
|===
|`$chordN`
| A set of characters.
You can use space by including it as the first character in the chord;
for an example see `Alphabet` in the sample below.
With 0 optional follow chords,
the corresponding output on the same line (`$outputN`)
will activate when zippy is enabled
and all the defined chord keys are pressed simultaneously.
The order of presses is not important.

| `$chord-followN.M`
| 0 or more chords, used the same way as `$chordN`.
Having follow chords means the `$outputN` on the same line
will activate upon first activating the earlier chord(s) in the same line,
releasing all keys, and pressing the keys in `$chord-followN.M`.
Follow chords are separated from the previous chord by a space.
If using a space in the follow chord, use two spaces;
for an example see `Washington` in the sample below.

| `$outputN`
| The characters to type when the chord and optional follow chord(s)
are all pressed by the user.
This is separated from the input `$chordN $follow-chordN.1...N.M` column
by a single Tab character.
The characters are typed in sequence
and must all be singular-name key names
as one would configure in `defsrc`.
As an exception, capitalized single-character key names
will be parsed successfully
and these will be outputted alongside Shift to output the capital key.
Additionally, `output-character-mappings` configuration can be used
to inform kanata of additional mappings that may use Shift or AltGr.
|===

==== Sample kanata configuration

[source]
----
(defzippy-experimental
zippy.txt
on-first-press-chord-deadline 500
idle-reactivate-time 500
smart-space-punctuation (? ! . , ; :)
output-character-mappings (
;; This should work for US international.
! S-1
? S-/
% S-5
"(" S-9
")" S-0
: S-;
< S-,
> S-.
r#"""# S-'
| S-\
_ S--
® AG-r
)
)
----

==== Sample zippy file content

[source]
----
dy day
dy 1 Monday
dy 2 Tuesday
abc alphabet
w a Washington
gi git
gi f p git fetch -p
----

==== Description

Zippychord is yet another chording mechanism in Kanata.
The inspiration behind it is primarily the
https://github.com/psoukie/zipchord[zipchord project].
The name is similar; it is named "zippy" instead of "zip" because
Kanata's implementation is not a port and does not aim for 100%
behavioural compatibility.

The intended use case is shorthands, or accelerating character output.
Within zippychord, inputs are keycode chords or sequences,
and the outputs are also purely keycodes.
In other words, all other actions are unsupported;
e.g. layers, switch, one-shot.

Zippychord behaves on outputted keycodes, i.e. the key outputs
after kanata has finished processing your
inputs, layers, switch logic and other configurations.
This is similar to how sequences operate
and is unlike chords(v1) and chordsv2.
Furthermore, outputs are all eager like `visible-backspaced` on sequences.
If a zippchord activation occurs, typed keys are backspaced.

To give an example, if one configures zippychord with a line like:

[source]
----
gi git
----

then either of the following typing event sequences
will erase the input characters
and then proceed to type the output "git"
like if it was `(macro bspc bspc g i t)`.

[source]
----
(press g) (press i)
(press i) (press g)
----

Note that there aren't any release events listed.
To contrast, the following event sequence would not result in an activation:

[source]
----
(press g) (release g) (press i)
----

Zippychord supports fully overlapping chords and sequences.
For example, this configuration is allowed:

[source]
----
gi git␣
gi s git␣status
gi c git checkout␣
gi c b git checkout -b␣
gi c a git commit --amend␣
gi c n git commit --amend --no-edit
gi c a m git commit --amend -m 'FIX_THIS_COMMIT_MESSAGE'
----

When you begin with the `(g i)` chord, you can follow up
with various character sequences to output different git commands.
This use case is quite similar to git aliases.
One advantage of zippychord is that it eagerly shows you
the true underlying command as you type.
1 change: 1 addition & 0 deletions parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ gui = []
lsp = []
win_llhook_read_scancodes = []
win_sendinput_send_scancodes = []
zippychord = []
Loading
Loading