forked from sunaku/glove80-keymaps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keymap.dtsi.erb
1845 lines (1693 loc) · 58.6 KB
/
keymap.dtsi.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// NOTE: Use the many #define settings below to customize this keymap!
#define OPERATING_SYSTEM 'L' // choose 'L'inux, 'M'acOS, or 'W'indows
#define DIFFICULTY_LEVEL 0 // 0:custom, 1:easy -> 5:hard (see below)
#define ENFORCE_BILATERAL // cancels single-handed home row mod+tap
#define WORLD_USE_COMPOSE // use native Compose in place of Unicode
// TIP: Add more setting overrides here instead of editing them below.
//////////////////////////////////////////////////////////////////////////////
//
// Sunaku's Keymap v36 -- "Glorious Engrammer"
// - https://github.com/sunaku/glove80-keymaps
//
//////////////////////////////////////////////////////////////////////////////
//
// OPERATING_SYSTEM defines which operating system you intend to use
// with this keymap, because shortcuts vary across operating systems.
//
// - https://zmk.dev/docs/codes
// - https://en.wikipedia.org/wiki/Table_of_keyboard_shortcuts
//
// This setting also affects the UNICODE() function defined below, as
// each OS has different shortcuts for typing Unicode hex characters.
//
// NOTE: You may need to enable Unicode hexadecimal input in your OS:
// - (macOS) https://sevenseacat.net/posts/2018/unicode-in-qmk-on-osx/
// - (Linux) https://help.ubuntu.com/stable/ubuntu-help/tips-specialchars.html.en#ctrlshiftu
// - (Windows) https://github.com/samhocevar/wincompose
//
// Specifically, Windows users should be running the WinCompose tool,
// which lets you type Unicode characters via hexadecimal codepoints.
//
#ifndef OPERATING_SYSTEM
<%
OPERATING_SYSTEMS = {
linux: "'L'",
macos: "'M'",
windows: "'W'"
}.each_with_index do |(os, char), index|
%>
<%= "//" if index > 0 %>#define OPERATING_SYSTEM <%= char %> // <%= os %>
<%
end
%>
#endif
#if OPERATING_SYSTEM == <%= OPERATING_SYSTEMS[:macos] %>
#define _C LG
#define _A_TAB LGUI
#define _G_TAB LALT
#define _REDO _C(LS(Z))
#define _POWER K_POWER
#define _W LA
#define _HOME _C(LEFT)
#define _END _C(RIGHT)
#else
#define _C LC
#define _A_TAB LALT
#define _G_TAB LGUI
#define _REDO _C(Y)
#define _POWER C_POWER
#define _W _C
#define _HOME HOME
#define _END END
#endif
#define _SLEEP C_SLEEP
#if OPERATING_SYSTEM == <%= OPERATING_SYSTEMS[:windows] %>
#define _LOCK LG(L)
#elif OPERATING_SYSTEM == <%= OPERATING_SYSTEMS[:macos] %>
#define _LOCK _C(LC(Q))
#elif OPERATING_SYSTEM == <%= OPERATING_SYSTEMS[:linux] %>
#define _LOCK K_LOCK
#endif
#define _UNDO _C(Z)
#define _CUT _C(X)
#define _COPY _C(C)
#define _PASTE _C(V)
#define _FIND _C(F)
#define _FIND_NEXT _C(G)
#define _FIND_PREV _C(LS(G))
//
// USE_NUMPAD_KEYCODES puts `KP_*` keycodes into the Number layer.
//
<%
NUMPAD_KEYCODES = %w[
KP_N0 KP_N1 KP_N2 KP_N3 KP_N4 KP_N5 KP_N6 KP_N7 KP_N8 KP_N9
KP_PLUS KP_MINUS
KP_ASTERISK KP_SLASH
KP_COMMA KP_DOT
KP_EQUAL KP_ENTER
]
emit_numpad_keycodes = lambda do |strip_prefix|
NUMPAD_KEYCODES.each do |keycode|
normal_keycode = keycode.sub(/^KP_/, '')
target_keycode = strip_prefix ? normal_keycode : keycode
%>
#define _<%= keycode %> <%= target_keycode %>
<%
end
end
%>
#ifdef USE_NUMPAD_KEYCODES
<%
emit_numpad_keycodes.(false)
%>
#else
<%
emit_numpad_keycodes.(true)
%>
#endif
//
// Glove80 specific symbol overrides to support non "en-US" locales
//
#undef AMPS
#define AMPS LS(N7)
#undef AT
#define AT LS(N2)
#undef CARET
#define CARET LS(N6)
#undef COLON
#define COLON LS(SEMI)
#undef DLLR
#define DLLR LS(N4)
#undef DQT
#define DQT LS(SQT)
#undef EXCL
#define EXCL LS(N1)
#undef GT
#define GT LS(DOT)
#undef HASH
#define HASH LS(N3)
#undef LBRC
#define LBRC LS(LBKT)
#undef LPAR
#define LPAR LS(N9)
#undef LT
#define LT LS(COMMA)
#undef PIPE
#define PIPE LS(BSLH)
#undef PLUS
#define PLUS LS(EQUAL)
#undef PRCNT
#define PRCNT LS(N5)
#undef QMARK
#define QMARK LS(FSLH)
#undef RBRC
#define RBRC LS(RBKT)
#undef RPAR
#define RPAR LS(N0)
#undef STAR
#define STAR LS(N8)
#undef TILDE
#define TILDE LS(GRAVE)
#undef UNDER
#define UNDER LS(MINUS)
//
// Keymap specific knowledge of the base layer's alpha + ZMK layout
//
<%
keymap_zmk = File.readlines("keymap.zmk")
POSITION_BY_INDEX = keymap_zmk.grep(/^#define POS_[LR]H_\w+ \d+/).map do |line|
(_define, name, value) = line.split
[name, Integer(value)]
end.to_h.invert
require 'json'
keymap = JSON.load_file("keymap.json")
def resolve_nested_keystrokes(key)
if key
value = key["value"]
params = key.dig("params", 0)
if value == "&kp"
resolve_nested_keystrokes(params)
elsif nested = resolve_nested_keystrokes(params)
"#{value}(#{nested})"
else
value
end
end
end
layers = keymap["layer_names"].zip(keymap["layers"]).to_h
ALPHA_LAYERS_COUNT = keymap["layer_names"].find_index("Typing")
ALPHA_LAYERS = layers.first(ALPHA_LAYERS_COUNT).each do |layer_name, layer_keys|
layer_constant = "LAYER_#{layer_name}"
%>
#if defined(<%= layer_constant %>) && <%= layer_constant %> == 0
<%
layer_keys.each_with_index do |key, index|
behavior = key["value"]
params = key.dig("params", 0, "value")
tap = 0 # &kp 0 is functionally equivalent to &none
case behavior
when "&kp"
tap = resolve_nested_keystrokes(key)
when "Custom"
case params
when /(?:Left|Right)\w+\s*\(\s*(\w+)/
tap = $1
when /engram_(\w+)/
tap = $1
when /parang_left/
tap = "LPAR"
when /parang_right/
tap = "RPAR"
when /([A-Z0-9_]+)(\s+0)*$/
tap = $1
end
end
position = POSITION_BY_INDEX[index]
coords = position[/^POS_(.+)/, 1]
%>
#define KEY_<%= coords %> <%= tap %>
<%
end
%>
#endif
<%
end
%>
combos {
compatible = "zmk,combos";
//
// COMBO_FIRING_DECAY defines how much time you have left (milliseconds)
// after pressing the first key in a ZMK combo to finish the whole chord.
//
#ifndef COMBO_FIRING_DECAY
#define COMBO_FIRING_DECAY 50
#endif
#ifdef LAYER_Gaming
combo_gaming_layer_toggle {
timeout-ms = <COMBO_FIRING_DECAY>;
key-positions = <POS_LH_T3 POS_LH_T6>;
bindings = <&tog LAYER_Gaming>;
layers = <0 LAYER_Gaming>;
};
#endif
#ifdef _A_TAB
combo_alt_tab_switcher {
timeout-ms = <COMBO_FIRING_DECAY>;
key-positions = <POS_LH_T4 POS_LH_T1>;
bindings = <&mod_tab_chord _A_TAB LAYER_Cursor>;
layers = <<%= (0...ALPHA_LAYERS_COUNT).to_a.join(" ") %>>;
};
#endif
combo_ctrl_tab_switcher {
timeout-ms = <COMBO_FIRING_DECAY>;
key-positions = <POS_LH_T4 POS_LH_T5>;
bindings = <&mod_tab_chord LCTL LAYER_Cursor>;
layers = <<%= (0...ALPHA_LAYERS_COUNT).to_a.join(" ") %>>;
};
};
behaviors {
//////////////////////////////////////////////////////////////////////////
//
// Miryoku layers and home row mods (ported from my QMK endgame)
// - https://sunaku.github.io/home-row-mods.html#porting-to-zmk
// - https://github.com/urob/zmk-config#timeless-homerow-mods
//
//////////////////////////////////////////////////////////////////////////
//
// DIFFICULTY_LEVEL specifies your level of expertise with this keymap.
// It's meant to help newcomers gradually work their way up to mastery.
// You can disable this setting by omitting it or assigning a `0` zero.
//
// #define DIFFICULTY_LEVEL 0 // custom (see defaults below)
// #define DIFFICULTY_LEVEL 1 // novice (500ms)
// #define DIFFICULTY_LEVEL 2 // slower (400ms)
// #define DIFFICULTY_LEVEL 3 // normal (300ms)
// #define DIFFICULTY_LEVEL 4 // faster (200ms)
// #define DIFFICULTY_LEVEL 5 // expert (100ms)
//
#if defined(DIFFICULTY_LEVEL) && DIFFICULTY_LEVEL > 0
#define DIFFICULTY_LEVEL_HOLDING_TIME ((6 - DIFFICULTY_LEVEL) * 100)
#define DIFFICULTY_LEVEL_STREAK_DECAY (((6 - DIFFICULTY_LEVEL) * 50) + 100)
<%
emit_setting_ifndef = lambda do |name, value|
%>
#ifndef <%= name %>
#define <%= name %> <%= value %>
#endif
<%
end
%w[ HOMEY INDEX PLAIN SPACE ].each do |category|
%w[ HOLDING_TIME STREAK_DECAY ].each do |setting|
emit_setting_ifndef.("#{category}_#{setting}", "DIFFICULTY_LEVEL_#{setting}")
end
end
%>
#endif
//
// ENFORCE_BILATERAL cancels out single-handed home row mods activation by
// releasing any currently pressed mods and replacing them with plain taps.
//
// NOTE: You may still encounter "flashing mods" where an operating system
// action is triggered by the release of mods, such as LGUI which launches
// the Windows Start Menu and LALT which opens the Microsoft Office Ribbon.
//
//#define ENFORCE_BILATERAL
//
// The *_FINGER_MOD specify which modifiers are used by home row mod keys.
// Here, we use Miryoku's "GACS" (Win, Alt, Ctrl, Shift) order by default,
// unless OPERATING_SYSTEM is macOS, in which case Win & Ctrl are swapped.
//
#ifndef PINKY_FINGER_MOD
#if OPERATING_SYSTEM == <%= OPERATING_SYSTEMS[:macos] %>
#define PINKY_FINGER_MOD LCTL
#else
#define PINKY_FINGER_MOD LGUI
#endif
#endif
#ifndef RING1_FINGER_MOD
#define RING1_FINGER_MOD LALT
#endif
#ifndef RING2_FINGER_MOD
#define RING2_FINGER_MOD RALT
#endif
#ifndef MIDDY_FINGER_MOD
#if OPERATING_SYSTEM == <%= OPERATING_SYSTEMS[:macos] %>
#define MIDDY_FINGER_MOD LGUI
#else
#define MIDDY_FINGER_MOD LCTL
#endif
#endif
#ifndef INDEX_FINGER_MOD
#define INDEX_FINGER_MOD LSFT
#endif
//
// The following settings let you configure mods individually, per finger:
//
#ifndef LEFT_PINKY_MOD
#define LEFT_PINKY_MOD PINKY_FINGER_MOD
#endif
#ifndef RIGHT_PINKY_MOD
#define RIGHT_PINKY_MOD PINKY_FINGER_MOD
#endif
#ifndef LEFT_RING1_MOD
#define LEFT_RING1_MOD RING1_FINGER_MOD
#endif
#ifndef RIGHT_RING1_MOD
#define RIGHT_RING1_MOD RING1_FINGER_MOD
#endif
#ifndef LEFT_RING2_MOD
#define LEFT_RING2_MOD RING2_FINGER_MOD
#endif
#ifndef RIGHT_RING2_MOD
#define RIGHT_RING2_MOD RING2_FINGER_MOD
#endif
#ifndef LEFT_MIDDY_MOD
#define LEFT_MIDDY_MOD MIDDY_FINGER_MOD
#endif
#ifndef RIGHT_MIDDY_MOD
#define RIGHT_MIDDY_MOD MIDDY_FINGER_MOD
#endif
#ifndef LEFT_INDEX_MOD
#define LEFT_INDEX_MOD INDEX_FINGER_MOD
#endif
#ifndef RIGHT_INDEX_MOD
#define RIGHT_INDEX_MOD INDEX_FINGER_MOD
#endif
//
// HOMEY_HOLDING_TYPE defines the flavor of ZMK hold-tap behavior to use
// for the pinky, ring, and middle fingers (which are assigned to Super,
// Alt, and Ctrl respectively in the Miryoku system) on home row keys.
//
#ifndef HOMEY_HOLDING_TYPE
#define HOMEY_HOLDING_TYPE "tap-preferred"
#endif
//
// HOMEY_HOLDING_TIME defines how long you need to hold (milliseconds)
// home row mod keys in order to send their modifiers to the computer
// (i.e. "register" them) for mod-click mouse usage (e.g. Ctrl-Click).
//
#ifndef HOMEY_HOLDING_TIME
#define HOMEY_HOLDING_TIME 240 // TAPPING_TERM + ALLOW_CROSSOVER_AFTER
#endif
//
// HOMEY_STREAK_DECAY defines how long you need to wait (milliseconds)
// after typing before you can use home row mods again. It prevents
// unintended activation of home row mods when you're actively typing.
//
#ifndef HOMEY_STREAK_DECAY
#define HOMEY_STREAK_DECAY 160
#endif
//
// HOMEY_REPEAT_DECAY defines how much time you have left (milliseconds)
// after tapping a key to hold it again in order to make it auto-repeat.
//
#ifndef HOMEY_REPEAT_DECAY
#define HOMEY_REPEAT_DECAY 300 // "tap then hold" for key auto-repeat
#endif
//
// CHORD_HOLDING_TYPE defines the flavor of ZMK hold-tap behavior to use
// for chorded home row mods (secondary keypresses in multi-mod chords).
//
#ifndef CHORD_HOLDING_TYPE
#define CHORD_HOLDING_TYPE HOMEY_HOLDING_TYPE
#endif
//
// CHORD_HOLDING_TIME defines how long you need to hold (milliseconds)
// home row mod keys in order to send their modifiers to the computer
// (i.e. "register" them) for mod-click mouse usage (e.g. Ctrl-Click).
// This is specifically for secondary keypresses in multi-mod chords.
//
#ifndef CHORD_HOLDING_TIME
#define CHORD_HOLDING_TIME 150
#endif
//
// CHORD_STREAK_DECAY defines how long you need to wait (milliseconds)
// after typing before you can use home row mods again. It prevents
// unintended activation of home row mods when you're actively typing
// This is specifically for secondary keypresses in multi-mod chords.
//
#ifndef CHORD_STREAK_DECAY
#define CHORD_STREAK_DECAY HOMEY_STREAK_DECAY
#endif
//
// CHORD_REPEAT_DECAY defines how much time you have left (milliseconds)
// after tapping a key to hold it again in order to make it auto-repeat.
// This is specifically for secondary keypresses in multi-mod chords.
//
#ifndef CHORD_REPEAT_DECAY
#define CHORD_REPEAT_DECAY HOMEY_REPEAT_DECAY
#endif
//
// INDEX_HOLDING_TYPE defines the flavor of ZMK hold-tap behavior to use
// for index fingers (which Miryoku assigns to Shift) on home row keys.
//
// NOTE: The "tap-preferred" flavor of ZMK hold-tap for index finger keys
// allows faster activation of the Shift modifier (without having to wait
// for the modified key to be released as the "balanced" flavor requires).
// Typing streaks and the `hold-trigger-on-release` setting are disabled
// for the index fingers so as not to hinder their speed and dexterity.
//
#ifndef INDEX_HOLDING_TYPE
#define INDEX_HOLDING_TYPE "tap-preferred"
#endif
//
// INDEX_HOLDING_TIME defines how long you need to hold (milliseconds)
// index finger keys in order to send their modifiers to the computer
// (i.e. "register" them) for mod-click mouse usage (e.g. Shift-Click).
//
#ifndef INDEX_HOLDING_TIME
#define INDEX_HOLDING_TIME 180
#endif
//
// INDEX_STREAK_DECAY defines how long you need to wait (milliseconds)
// after typing before you can use home row mods again. It prevents
// unintended activation of home row mods when you're actively typing.
//
#ifndef INDEX_STREAK_DECAY
#define INDEX_STREAK_DECAY 100
#endif
//
// INDEX_REPEAT_DECAY defines how much time you have left (milliseconds)
// after tapping a key to hold it again in order to make it auto-repeat.
//
#ifndef INDEX_REPEAT_DECAY
#define INDEX_REPEAT_DECAY 300 // "tap then hold" for key auto-repeat
#endif
//
// PLAIN_HOLDING_TYPE defines the flavor of ZMK hold-tap behavior to use
// for index fingers (which Miryoku assigns to Shift) on home row keys.
//
// NOTE: The "tap-preferred" flavor of ZMK hold-tap for index finger keys
// allows faster activation of the Shift modifier (without having to wait
// for the modified key to be released as the "balanced" flavor requires).
// Typing streaks and the `hold-trigger-on-release` setting are disabled
// for the index fingers so as not to hinder their speed and dexterity.
//
#ifndef PLAIN_HOLDING_TYPE
#define PLAIN_HOLDING_TYPE HOMEY_HOLDING_TYPE
#endif
//
// PLAIN_HOLDING_TIME defines how long you need to hold (milliseconds)
// index finger keys in order to send their modifiers to the computer
// (i.e. "register" them) for mod-click mouse usage (e.g. Shift-Click).
//
#ifndef PLAIN_HOLDING_TIME
#define PLAIN_HOLDING_TIME HOMEY_HOLDING_TIME
#endif
//
// PLAIN_STREAK_DECAY defines how long you need to wait (milliseconds)
// after typing before you can use home row mods again. It prevents
// unintended activation of home row mods when you're actively typing.
//
#ifndef PLAIN_STREAK_DECAY
#define PLAIN_STREAK_DECAY HOMEY_STREAK_DECAY
#endif
//
// PLAIN_REPEAT_DECAY defines how much time you have left (milliseconds)
// after tapping a key to hold it again in order to make it auto-repeat.
//
#ifndef PLAIN_REPEAT_DECAY
#define PLAIN_REPEAT_DECAY 300 // "tap then hold" for key auto-repeat
#endif
//
// THUMB_HOLDING_TYPE defines the flavor of ZMK hold-tap behavior to use
// for the thumbs (which are assigned to 6 layers in the Miryoku system).
//
// NOTE: The "balanced" flavor of ZMK hold-tap provides instant modifier
// activation for the symbol layer (if the tapped symbol key is released
// while the thumb layer key is still held down) for quicker programming.
//
#ifndef THUMB_HOLDING_TYPE
#define THUMB_HOLDING_TYPE "balanced"
#endif
//
// THUMB_HOLDING_TIME defines how long you need to hold (milliseconds)
// a thumb key to activate a layer. Shorter holds are treated as taps.
//
#ifndef THUMB_HOLDING_TIME
#define THUMB_HOLDING_TIME 200
#endif
//
// THUMB_REPEAT_DECAY defines how much time you have left (milliseconds)
// after tapping a key to hold it again in order to make it auto-repeat.
//
#ifndef THUMB_REPEAT_DECAY
#define THUMB_REPEAT_DECAY 300 // "tap then hold" for key auto-repeat
#endif
//
// SPACE_HOLDING_TYPE defines the flavor of ZMK hold-tap behavior to use
// for spacebar (assigned to the right thumb's home position by default).
//
// NOTE: The "balanced" flavor of ZMK hold-tap provides instant modifier
// activation for the symbol layer (if the tapped symbol key is released
// while the thumb layer key is still held down) for quicker programming.
//
#ifndef SPACE_HOLDING_TYPE
#define SPACE_HOLDING_TYPE THUMB_HOLDING_TYPE
#endif
//
// SPACE_HOLDING_TIME defines how long you need to hold (milliseconds)
// the space thumb key to activate. Shorter holds are treated as taps.
//
#ifndef SPACE_HOLDING_TIME
#define SPACE_HOLDING_TIME THUMB_HOLDING_TIME
#endif
//
// SPACE_REPEAT_DECAY defines how much time you have left (milliseconds)
// after tapping a key to hold it again in order to make it auto-repeat.
//
#ifndef SPACE_REPEAT_DECAY
#define SPACE_REPEAT_DECAY 150
#endif
//
// Glove80 key positions index for positional hold-tap
// - https://discord.com/channels/877392805654306816/937645688244826154/1066713913351221248
// - https://media.discordapp.net/attachments/937645688244826154/1066713913133121556/image.png
//
// |------------------------|------------------------|
// | LEFT_HAND_KEYS | RIGHT_HAND_KEYS |
// | | |
// | 0 1 2 3 4 | 5 6 7 8 9 |
// | 10 11 12 13 14 15 | 16 17 18 19 20 21 |
// | 22 23 24 25 26 27 | 28 29 30 31 32 33 |
// | 34 35 36 37 38 39 | 40 41 42 43 44 45 |
// | 46 47 48 49 50 51 | 58 59 60 61 62 63 |
// | 64 65 66 67 68 | 75 76 77 78 79 |
// | 69 52 | 57 74 |
// | 70 53 | 56 73 |
// | 71 54 | 55 72 |
// |------------------------|------------------------|
//
<%
HANDS = %w[ left right ]
FINGERS = %w[ pinky ring1 ring2 middy index ]
PAIRED_HANDS = HANDS.cycle.each_cons(2).take(2).to_h
%>
#define LEFT_HAND_KEYS \
0 1 2 3 4 \
10 11 12 13 14 15 \
22 23 24 25 26 27 \
34 35 36 37 38 39 \
46 47 48 49 50 51 \
64 65 66 67 68
#define RIGHT_HAND_KEYS \
5 6 7 8 9 \
16 17 18 19 20 21 \
28 29 30 31 32 33 \
40 41 42 43 44 45 \
58 59 60 61 62 63 \
75 76 77 78 79
#define THUMB_KEYS \
69 52 57 74 \
70 53 56 73 \
71 54 55 72
#define LEFT_PINKY_KEY KEY_LH_C5R4
#define LEFT_RING1_KEY KEY_LH_C4R4
#define LEFT_RING2_KEY KEY_LH_C4R3
#define LEFT_MIDDY_KEY KEY_LH_C3R4
#define LEFT_INDEX_KEY KEY_LH_C2R4
#define LEFT_PLAIN_KEY KEY_LH_C1R4
#define RIGHT_PINKY_KEY KEY_RH_C5R4
#define RIGHT_RING1_KEY KEY_RH_C4R4
#define RIGHT_RING2_KEY KEY_RH_C4R3
#define RIGHT_MIDDY_KEY KEY_RH_C3R4
#define RIGHT_INDEX_KEY KEY_RH_C2R4
#define RIGHT_PLAIN_KEY KEY_RH_C1R4
#if defined(LAYER_Engram) && LAYER_Engram == 0
#define LeftPlainKey engram_COMMA
#define RightPlainKey engram_DOT
#else
#define LeftPlainKey kp LEFT_PLAIN_KEY
#define RightPlainKey kp RIGHT_PLAIN_KEY
#endif
//
// Home row mods with bilateral combinations support
//
<%
HOME_ROW_MOD_SETTINGS = %w[
HOLDING_TYPE
HOLDING_TIME
STREAK_DECAY
REPEAT_DECAY
]
def snake_case(*components)
components.join("_")
end
def camel_case(*components)
components.map(&:capitalize).join
end
def format_constant(*components)
snake_case(*components).upcase
end
HOME_ROW_MOD_INSTANCES =
FINGERS.flat_map do |finger|
HANDS.map do |hand|
[hand, finger]
end
end
FINGERS.each do |finger|
HOME_ROW_MOD_SETTINGS.each do |suffix|
finger_setting = format_constant(finger, suffix)
finger_chord_setting = format_constant(finger, :chord, suffix)
emit_setting_ifndef.(finger_setting, "HOMEY_#{suffix}")
emit_setting_ifndef.(finger_chord_setting, "CHORD_#{suffix}")
HANDS.each do |hand|
hand_finger_chord_setting = format_constant(hand, finger, :chord, suffix)
emit_setting_ifndef.(hand_finger_chord_setting, finger_chord_setting)
end
end
end
emit_home_row_mod = lambda do |hand, finger, chord|
source = snake_case(hand, finger) # without chord
target_components = [hand, finger, chord].compact
target_CamelCase = camel_case(*target_components)
target = snake_case(*target_components)
HOME_ROW_MOD_SETTINGS.each do |suffix|
setting = format_constant(target, suffix)
inherit_components =
if chord
[source, :chord, suffix]
else
[finger, suffix]
end
inherit = format_constant(*inherit_components)
emit_setting_ifndef.(setting, inherit)
end
for target_variant in [nil, :_bilateral] do
%>
<%= target %><%= target_variant %>: homey_<%= target %><%= target_variant %> {
compatible = "zmk,behavior-hold-tap";
flavor = <%= source.upcase %>_HOLDING_TYPE;
hold-trigger-key-positions = <<%= PAIRED_HANDS[hand].upcase %>_HAND_KEYS THUMB_KEYS>;
hold-trigger-on-release; // wait for other home row mods
tapping-term-ms = <<%= source.upcase %>_HOLDING_TIME>;
quick-tap-ms = <<%= source.upcase %>_REPEAT_DECAY>;
require-prior-idle-ms = <<%= source.upcase %>_STREAK_DECAY>;
#binding-cells = <2>;
<%
if target_variant
if chord
%>
bindings = <&kp>, <&<%= source %>_tap>;
<%
else
%>
bindings = <&<%= target %>_hold>, <&kp>;
<%
end
else
%>
bindings = <&kp>, <&kp>;
<%
end
%>
};
<%
end
if chord
constant = format_constant(hand, chord)
%>
#define <%= target_CamelCase %> <%= target %>_bilateral <%= constant %>_MOD <%= constant %>_KEY
<%
else
constant = format_constant(hand, finger)
%>
<%= target %>_hold: homey_<%= target %>_hold {
compatible = "zmk,behavior-macro-one-param";
wait-ms = <0>;
tap-ms = <0>;
#binding-cells = <1>;
bindings
= <¯o_param_1to1>
, <¯o_press &kp MACRO_PLACEHOLDER>
#ifdef LAYER_<%= target_CamelCase %>
, <¯o_press &mo LAYER_<%= target_CamelCase %>>
#endif
, <¯o_pause_for_release>
, <¯o_param_1to1>
, <¯o_release &kp MACRO_PLACEHOLDER>
#ifdef LAYER_<%= target_CamelCase %>
, <¯o_release &mo LAYER_<%= target_CamelCase %>>
#endif
;
};
<%= target %>_tap: homey_<%= target %>_tap {
compatible = "zmk,behavior-macro-one-param";
wait-ms = <0>;
tap-ms = <0>;
#binding-cells = <1>;
bindings
= <¯o_release
&kp LSFT &kp RSFT
&kp LALT &kp RALT
&kp LCTL &kp RCTL
&kp LGUI &kp RGUI>
, <¯o_tap &kp <%= target.upcase %>_KEY>
, <¯o_param_1to1>
, <¯o_tap &kp MACRO_PLACEHOLDER>
;
};
#define <%= target_CamelCase %>(key, layer_index) <%= target_CamelCase %>_unroll(layer_index) (key)
#define <%= target_CamelCase %>_unroll(layer_index) <%= target_CamelCase %>_concat(<%= target_CamelCase %>_layer, layer_index)
#define <%= target_CamelCase %>_concat(prefix, layer_index) prefix ## layer_index
#ifdef ENFORCE_BILATERAL
#define <%= target %>_layer0_variant <%= target %>_bilateral
#else
#define <%= target %>_layer0_variant <%= target %>
#endif
<%
ALPHA_LAYERS.each_with_index do |(layer_name, _layer_keys), layer_index|
%>
#define <%= target_CamelCase %>_layer<%= layer_index %>(key) <%= target %><%= "_layer0_variant" if layer_index.zero? %> <%= constant %>_MOD key
<%
end
end
end
# level 1 for mod-tap keys on base layer
HOME_ROW_MOD_INSTANCES.each do |(hand,finger)|
emit_home_row_mod.(hand, finger, nil)
end
# level 2 for unilateral multi-mod chords
HOME_ROW_MOD_INSTANCES.permutation(2).each do
|((hand1,finger1), (hand2,finger2))|
if hand1 == hand2
emit_home_row_mod.(hand2, finger2, finger1)
end
end
%>
//
// Key repetition access keys on the index fingers
//
plain: plain_typing_layer {
compatible = "zmk,behavior-hold-tap";
flavor = PLAIN_HOLDING_TYPE;
tapping-term-ms = <PLAIN_HOLDING_TIME>;
quick-tap-ms = <PLAIN_REPEAT_DECAY>; // enable repeat
require-prior-idle-ms = <PLAIN_STREAK_DECAY>;
#binding-cells = <2>;
bindings = <&mo>, <&kp>;
retro-tap; // tap on standalone hold
};
plain_engram_COMMA: plain_typing_layer_engram_COMMA {
compatible = "zmk,behavior-hold-tap";
flavor = PLAIN_HOLDING_TYPE;
tapping-term-ms = <PLAIN_HOLDING_TIME>;
quick-tap-ms = <PLAIN_REPEAT_DECAY>; // enable repeat
require-prior-idle-ms = <PLAIN_STREAK_DECAY>;
#binding-cells = <2>;
bindings = <&mo>, <&engram_COMMA>;
retro-tap; // tap on standalone hold
};
plain_engram_DOT: plain_typing_layer_engram_DOT {
compatible = "zmk,behavior-hold-tap";
flavor = PLAIN_HOLDING_TYPE;
tapping-term-ms = <PLAIN_HOLDING_TIME>;
quick-tap-ms = <PLAIN_REPEAT_DECAY>; // enable repeat
require-prior-idle-ms = <PLAIN_STREAK_DECAY>;
#binding-cells = <2>;
bindings = <&mo>, <&engram_DOT>;
retro-tap; // tap on standalone hold
};
//
// Thumb cluster hold-tap keys for Miryoku layers
//
thumb: thumb_layer_access {
compatible = "zmk,behavior-hold-tap";
flavor = THUMB_HOLDING_TYPE;
tapping-term-ms = <THUMB_HOLDING_TIME>;
quick-tap-ms = <THUMB_REPEAT_DECAY>; // enable repeat
#binding-cells = <2>;
bindings = <&mo>, <&kp>;
};
thumb_parang_left: thumb_layer_access_parang_left {
compatible = "zmk,behavior-hold-tap";
flavor = THUMB_HOLDING_TYPE;
tapping-term-ms = <THUMB_HOLDING_TIME>;
quick-tap-ms = <THUMB_REPEAT_DECAY>; // enable repeat
#binding-cells = <2>;
bindings = <&mo>, <¶ng_left>;
};
thumb_lower_shift: lower_layer_or_sticky_shift {
compatible = "zmk,behavior-hold-tap";
flavor = "tap-preferred";
tapping-term-ms = <THUMB_HOLDING_TIME>;
#binding-cells = <2>;
bindings = <&mo>, <&sticky_key_oneshot>;
};
space: thumb_layer_access_spacebar {
compatible = "zmk,behavior-hold-tap";
flavor = SPACE_HOLDING_TYPE;
tapping-term-ms = <SPACE_HOLDING_TIME>;
quick-tap-ms = <SPACE_REPEAT_DECAY>; // enable repeat
#binding-cells = <2>;
bindings = <&mo>, <&kp>;
};
//
// Shift + LEFT_PARENTHESIS = LESS_THAN
//
parang_left: left_parenthesis_and_less_than {
compatible = "zmk,behavior-mod-morph";
#binding-cells = <0>;
bindings = <&kp LPAR>, <&kp LT>;
mods = <(MOD_LSFT|MOD_RSFT)>;
};
//
// Shift + RIGHT_PARENTHESIS = GREATER_THAN
//
parang_right: right_parenthesis_and_greater_than {
compatible = "zmk,behavior-mod-morph";
#binding-cells = <0>;
bindings = <&kp RPAR>, <&kp GT>;
mods = <(MOD_LSFT|MOD_RSFT)>;
};
//
// Custom shifted pairs for the Engram layout
// - https://engram.dev/
// - https://sunaku.github.io/engram-keyboard-layout.html
//
<%
{
"N1" => "PIPE",
"N2" => "EQUAL",
"N3" => "TILDE",
"N4" => "PLUS",
"N5" => "LT",
"N6" => "GT",
"N7" => "CARET",
"N8" => "AMPS",
"N9" => "PRCNT",
"N0" => "STAR",
"SQT" => "LPAR",
"DQT" => "RPAR",
"COMMA" => "SEMI",
"DOT" => "COLON",
"QMARK" => "EXCL",
"HASH" => "DLLR",
"AT" => "GRAVE",
"FSLH" => "BSLH",
}
.each do |normal, shifted|
%>
engram_<%= normal %>: engram_shift_<%= normal %>_<%= shifted %> {
compatible = "zmk,behavior-mod-morph";
#binding-cells = <0>;
bindings = <&kp <%= normal %>>, <&kp <%= shifted %>>;
mods = <(MOD_LSFT|MOD_RSFT)>;
};
<%
end
%>
//////////////////////////////////////////////////////////////////////////
//
// &sk (sticky key) variant that is truly one-shot
//
//////////////////////////////////////////////////////////////////////////
//
// STICKY_1SHOT_DECAY defines how much time you have left (milliseconds)
// after tapping a sticky key before it expires (won't apply to next tap).
//
#ifndef STICKY_1SHOT_DECAY
#define STICKY_1SHOT_DECAY 500
#endif
//
// STICKY_HOLDING_TIME defines how long you need to hold (milliseconds)
// sticky one-shot keys in order to trigger their hold (not tap) action.
//
#ifndef STICKY_HOLDING_TIME
#define STICKY_HOLDING_TIME CHORD_HOLDING_TIME
#endif
sticky_key_modtap: sticky_key_modtap {
compatible = "zmk,behavior-hold-tap";
flavor = "tap-preferred";
tapping-term-ms = <STICKY_HOLDING_TIME>;
#binding-cells = <2>;
bindings = <&kp>, <&sticky_key_oneshot>;
};
sticky_key_oneshot: sticky_key_oneshot_macro {
compatible = "zmk,behavior-macro-one-param";
wait-ms = <0>;
tap-ms = <0>;
#binding-cells = <1>;
bindings
= <¯o_param_1to1>
, <¯o_tap &sticky_key_quickrel MACRO_PLACEHOLDER>
;
};
sticky_key_quickrel: sticky_key_quick_release {
compatible = "zmk,behavior-sticky-key";
#binding-cells = <1>;
bindings = <&kp>;
release-after-ms = <STICKY_1SHOT_DECAY>;
quick-release;
ignore-modifiers;
};