Skip to content

Commit

Permalink
Merge pull request kmonad#670 from JakobBruenker/master
Browse files Browse the repository at this point in the history
feat: add tap-next-press
  • Loading branch information
slotThe authored Jan 3, 2023
2 parents b9798a7 + d5b133c commit a0af5b8
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 1 deletion.
7 changes: 7 additions & 0 deletions doc/quick-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,13 @@ to be the most comfortable.
(defalias tnr (tap-next-release a sft))
```

+ `tap-next-press`: like `tap-next` but decide whether to tap or hold
based on whether another key is pressed before this one is released.

```clojure
(defalias tnp (tap-next-press a sft))
```

+ `tap-hold-next-release`: like `tap-next-release` but with an
additional timeout. This is just like `tap-next-release`, but with
`tap-next` swapped out for `tap-next-release`.
Expand Down
14 changes: 13 additions & 1 deletion keymap/tutorial.kbd
Original file line number Diff line number Diff line change
Expand Up @@ -760,9 +760,20 @@
Tesc Ta -> xa
Pa Pesc Ra Resc -> ax (because 'a' was already pressed when we started, so
foo decides it is tapping)
Pesc Pa Resc Ra -> xa (because the first release we encounter is of esc)
Pesc Ta Resc -> A (because a was pressed *and* released after we started,
so foo decides it is holding)

`tap-next-press` is also a lot like `tap-next`, but decides whether to tap or
hold based on whether another key is pressed before this one is released.
Using the minilanguage:
(tap-next-press x lsft)
Then:
Tesc Ta -> xa
Pa Pesc Ra Resc -> ax (because esc is released before another key is pressed)
Pesc Pa Resc Ra -> A (because a is pressed before esc is released)
Pesc Ta Resc -> A (a is pressed before esc is released here as well)

These increasingly stranger buttons are, I think, coming from the stubborn
drive of some of my more eccentric (and I mean that in the most positive way)
users to make typing with modifiers on the home-row more comfortable.
Expand All @@ -785,6 +796,7 @@
xth (tap-hold 400 x lsft) ;; Long delay for easier testing
thn (tap-hold-next 400 x lsft)
tnr (tap-next-release x lsft)
tnp (tap-next-press x lsft)
tnh (tap-hold-next-release 2000 x lsft)

;; Used it the colemak layer
Expand All @@ -797,7 +809,7 @@
_ _ _ _ _ _ _ _ _ _ _ _ _ _
@thn _ _ _ _ _ _ _ _ _ _ _ _
@xtn _ _ _ _ _ _ _ _ _ _ @xth
@tnr _ _ _ _ _ _ @tnh
@tnr @tnp _ _ _ _ _ @tnh
)


Expand Down
1 change: 1 addition & 0 deletions src/KMonad/Args/Joiner.hs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ joinButton ns als =
KTapNextRelease t h -> jst $ tapNextRelease <$> go t <*> go h
KTapHoldNextRelease ms t h mtb
-> jst $ tapHoldNextRelease (fi ms) <$> go t <*> go h <*> traverse go mtb
KTapNextPress t h -> jst $ tapNextPress <$> go t <*> go h
KAroundNext b -> jst $ aroundNext <$> go b
KAroundNextSingle b -> jst $ aroundNextSingle <$> go b
KAroundNextTimeout ms b t -> jst $ aroundNextTimeout (fi ms) <$> go b <*> go t
Expand Down
2 changes: 2 additions & 0 deletions src/KMonad/Args/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ keywordButtons =
, ("tap-hold-next-release"
, KTapHoldNextRelease <$> lexeme numP <*> buttonP <*> buttonP
<*> optional (keywordP "timeout-button" buttonP))
, ("tap-next-press"
, KTapNextPress <$> buttonP <*> buttonP)
, ("tap-next" , KTapNext <$> buttonP <*> buttonP)
, ("layer-toggle" , KLayerToggle <$> lexeme word)
, ("momentary-layer" , KLayerToggle <$> lexeme word)
Expand Down
1 change: 1 addition & 0 deletions src/KMonad/Args/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ data DefButton
| KTapNextRelease DefButton DefButton -- ^ Do 2 things based on behavior
| KTapHoldNextRelease Int DefButton DefButton (Maybe DefButton)
-- ^ Like KTapNextRelease but with a timeout
| KTapNextPress DefButton DefButton -- ^ Like KTapNextRelease but also hold on presses
| KAroundNext DefButton -- ^ Surround a future button
| KAroundNextSingle DefButton -- ^ Surround a future button
| KMultiTap [(Int, DefButton)] DefButton -- ^ Do things depending on tap-count
Expand Down
28 changes: 28 additions & 0 deletions src/KMonad/Model/Button.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ module KMonad.Model.Button
, tapHoldNext
, tapNextRelease
, tapHoldNextRelease
, tapNextPress
, tapMacro
, tapMacroRelease
, stickyKey