-
Notifications
You must be signed in to change notification settings - Fork 114
/
keymap.dtsi.erb
1803 lines (1650 loc) · 59 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 SHIFT_FORGIVENESS // requires 24.08-beta1 or newer firmware
#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 v39 -- "Glorious Engrammer"
// - https://github.com/sunaku/glove80-keymaps
//
//////////////////////////////////////////////////////////////////////////////
<%
emit_setting_ifndef = lambda do |name, value|
%>
#ifndef <%= name %>
#define <%= name %> <%= value %>
#endif
<%
end
%>
//
// 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://uknowit.uwgb.edu/page.php?id=22623
// and https://github.com/ldanet/unicode-hex-input-fix
// - (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.
//
<%
emit_setting_ifndef.(:COMBO_FIRING_DECAY, 50)
%>
#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(" ") %>>;
};
combo_sticky_hyper_right {
timeout-ms = <COMBO_FIRING_DECAY>;
key-positions = <POS_RH_T1 POS_RH_T4>;
bindings = <&sk LG(LA(LC(LSHFT)))>;
layers = <<%= (0...ALPHA_LAYERS_COUNT).to_a.join(" ") %>>;
};
combo_sticky_meh_right {
timeout-ms = <COMBO_FIRING_DECAY>;
key-positions = <POS_RH_T4 POS_RH_T5>;
bindings = <&sk LA(LC(LSHFT))>;
layers = <<%= (0...ALPHA_LAYERS_COUNT).to_a.join(" ") %>>;
};
combo_sticky_1shot_shift_left {
timeout-ms = <COMBO_FIRING_DECAY>;
key-positions = <POS_LH_T4 POS_LH_C2R4>;
bindings = <&sticky_key_oneshot LSFT>;
layers = <<%= (0...ALPHA_LAYERS_COUNT).to_a.join(" ") %>>;
};
combo_sticky_1shot_shift_right {
timeout-ms = <COMBO_FIRING_DECAY>;
key-positions = <POS_RH_T4 POS_RH_C2R4>;
bindings = <&sticky_key_oneshot LSFT>;
layers = <<%= (0...ALPHA_LAYERS_COUNT).to_a.join(" ") %>>;
};
combo_caps_word_left {
timeout-ms = <COMBO_FIRING_DECAY>;
key-positions = <POS_LH_T1 POS_LH_C2R4>;
bindings = <&caps_word>;
layers = <<%= (0...ALPHA_LAYERS_COUNT).to_a.join(" ") %>>;
};
combo_caps_word_right {
timeout-ms = <COMBO_FIRING_DECAY>;
key-positions = <POS_RH_T1 POS_RH_C2R4>;
bindings = <&caps_word>;
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.
//
// #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)
//
// You can disable this setting by omitting it or assigning a `0` zero,
// in which case it will default to my personal set of time thresholds.
//
// #define DIFFICULTY_LEVEL 0 // sunaku (150ms)
//
// No matter what difficulty level you choose, you can always override
// any settings in this keymap at the beginning of this configuration.
//
#ifdef DIFFICULTY_LEVEL
#if DIFFICULTY_LEVEL > 0 && DIFFICULTY_LEVEL < 6
#ifndef TAPPING_RESOLUTION
#define TAPPING_RESOLUTION ((6 - DIFFICULTY_LEVEL) * 100)
#endif
#endif
#endif
//
// TAPPING_RESOLUTION specifies the maximum speed at which the keyboard
// confuses your taps as being holds when you type on home row mod keys.
// When you lower this value, the same confusion should still occur; but
// when you raise this value, you should be able to type normally again.
//
<%
TAPPING_RESOLUTION = 150 # my personal threshold on Kailh Choc v1 Reds
emit_setting_ifndef.(:TAPPING_RESOLUTION, TAPPING_RESOLUTION)
resolve_tap_timing = lambda do |milliseconds|
delta = milliseconds - TAPPING_RESOLUTION
if delta == 0
"TAPPING_RESOLUTION"
else
"(TAPPING_RESOLUTION #{delta > 0 ? "+ #{delta}" : "- #{-delta}"})"
end
end
%>
//
// 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
//
// SHIFT_FORGIVENESS taps when home row shift is merely held and released,
// without any other key having been tapped while the shift was held down.
// For example, suppose you hold a home row shift key and, before pressing
// another key, suddenly decide that you don't want to use shift after all:
//
// <1> If this setting is enabled, the underlying tap behavior is triggered
// to type a single character when you release that home row shift key.
//
// <2> Otherwise, nothing happens when you release that home row shift key.
//
// This requires the "hold-while-undecided" ZMK feature in a beta firmware:
// please select "v24.08-beta1" or newer from the drop-down menu located at
// Glove80 Layout Editor > Settings > Advanced Settings > Firmware Version.
//
// CAUTION: This can interfere with mod-click mouse usage where you hold a
// home row shift key and perform mouse actions (move, click, drag & drop):
// when you release that home row shift key, its underlying character would
// be typed, potentially triggering an unexpected action on your selection!
// To prevent the underlying character from being typed, press another key
// (such as a dedicated shift key, a neighboring home row mod key, or even
// a layer access key) before you release the original home row shift key.
//
// NOTE: You may potentially encounter "flashing mods" where an application
// or operating system action is triggered by a standalone tap of a shift,
// but this is unlikely as people regularly tap shift without consequence.
//
//#define SHIFT_FORGIVENESS
//
// 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,
// unless MACOS_USE_GACS is also defined to suppress that Win & Ctrl swap.
//
#ifndef PINKY_FINGER_MOD
#if OPERATING_SYSTEM == <%= OPERATING_SYSTEMS[:macos] %> && !defined(MACOS_USE_GACS)
#define PINKY_FINGER_MOD LCTL
#else
#define PINKY_FINGER_MOD LGUI
#endif
#endif
<%
emit_setting_ifndef.(:RING1_FINGER_MOD, :LALT)
emit_setting_ifndef.(:RING2_FINGER_MOD, :RALT)
%>
#ifndef MIDDY_FINGER_MOD
#if OPERATING_SYSTEM == <%= OPERATING_SYSTEMS[:macos] %> && !defined(MACOS_USE_GACS)
#define MIDDY_FINGER_MOD LGUI
#else
#define MIDDY_FINGER_MOD LCTL
#endif
#endif
<%
emit_setting_ifndef.(:INDEX_FINGER_MOD, :LSFT)
%>
//
// The following settings let you configure mods individually, per finger:
//
<%
emit_setting_ifndef.(:LEFT_PINKY_MOD, :PINKY_FINGER_MOD)
emit_setting_ifndef.(:RIGHT_PINKY_MOD, :PINKY_FINGER_MOD)
emit_setting_ifndef.(:LEFT_RING1_MOD, :RING1_FINGER_MOD)
emit_setting_ifndef.(:RIGHT_RING1_MOD, :RING1_FINGER_MOD)
emit_setting_ifndef.(:LEFT_RING2_MOD, :RING2_FINGER_MOD)
emit_setting_ifndef.(:RIGHT_RING2_MOD, :RING2_FINGER_MOD)
emit_setting_ifndef.(:LEFT_MIDDY_MOD, :MIDDY_FINGER_MOD)
emit_setting_ifndef.(:RIGHT_MIDDY_MOD, :MIDDY_FINGER_MOD)
emit_setting_ifndef.(:LEFT_INDEX_MOD, :INDEX_FINGER_MOD)
emit_setting_ifndef.(:RIGHT_INDEX_MOD, :INDEX_FINGER_MOD)
%>
//
// 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.
//
<%
emit_setting_ifndef.(:HOMEY_HOLDING_TYPE, '"tap-preferred"')
%>
//
// 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).
//
<%
emit_setting_ifndef.(:HOMEY_HOLDING_TIME, resolve_tap_timing.(240))
INDEX_HOLDING_TIME = TAPPING_RESOLUTION + 20 # 170ms
MIDDY_HOLDING_TIME = INDEX_HOLDING_TIME + 40 # 210ms
RING1_HOLDING_TIME = MIDDY_HOLDING_TIME + 30 # 240ms
PINKY_HOLDING_TIME = RING1_HOLDING_TIME + 20 # 260ms
emit_setting_ifndef.(:INDEX_HOLDING_TIME, resolve_tap_timing.(INDEX_HOLDING_TIME))
emit_setting_ifndef.(:MIDDY_HOLDING_TIME, resolve_tap_timing.(MIDDY_HOLDING_TIME))
emit_setting_ifndef.(:RING1_HOLDING_TIME, resolve_tap_timing.(RING1_HOLDING_TIME))
emit_setting_ifndef.(:RING2_HOLDING_TIME, :RING1_HOLDING_TIME)
emit_setting_ifndef.(:PINKY_HOLDING_TIME, resolve_tap_timing.(PINKY_HOLDING_TIME))
%>
//
// 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.
//
<%
emit_setting_ifndef.(:HOMEY_STREAK_DECAY, resolve_tap_timing.(150))
%>
//
// 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.
//
<%
emit_setting_ifndef.(:HOMEY_REPEAT_DECAY, resolve_tap_timing.(300))
%> // "tap then hold" for key auto-repeat
//
// CHORD_HOLDING_TYPE defines the flavor of ZMK hold-tap behavior to use
// for chorded home row mods (secondary keypresses in multi-mod chords).
//
<%
emit_setting_ifndef.(:CHORD_HOLDING_TYPE, :HOMEY_HOLDING_TYPE)
%>
//
// 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.
//
<%
emit_setting_ifndef.(:CHORD_HOLDING_TIME, resolve_tap_timing.(150))
%>
//
// 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.
//
<%
emit_setting_ifndef.(:CHORD_STREAK_DECAY, :HOMEY_STREAK_DECAY)
%>
//
// 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.
//
<%
emit_setting_ifndef.(:CHORD_REPEAT_DECAY, :HOMEY_REPEAT_DECAY)
%>
//
// 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).
//
<%
emit_setting_ifndef.(:INDEX_HOLDING_TYPE, '"tap-preferred"')
%>
//
// 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.
//
<%
emit_setting_ifndef.(:INDEX_STREAK_DECAY, resolve_tap_timing.(100))
%>
//
// 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.
//
<%
emit_setting_ifndef.(:INDEX_REPEAT_DECAY, resolve_tap_timing.(300))
%> // "tap then hold" for key auto-repeat
//
// 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).
//
<%
emit_setting_ifndef.(:PLAIN_HOLDING_TYPE, :INDEX_HOLDING_TYPE)
%>
//
// 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).
//
<%
emit_setting_ifndef.(:PLAIN_HOLDING_TIME, resolve_tap_timing.(200))
%>
//
// 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.
//
<%
emit_setting_ifndef.(:PLAIN_STREAK_DECAY, :HOMEY_STREAK_DECAY)
%>
//
// 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.
//
<%
emit_setting_ifndef.(:PLAIN_REPEAT_DECAY, resolve_tap_timing.(300))
%> // "tap then hold" for key auto-repeat
//
// 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.
//
<%
emit_setting_ifndef.(:THUMB_HOLDING_TYPE, '"balanced"')
%>
//
// THUMB_HOLDING_TIME defines how long you need to hold (milliseconds)
// a thumb key to activate a layer. Shorter holds are treated as taps.
//
<%
emit_setting_ifndef.(:THUMB_HOLDING_TIME, resolve_tap_timing.(200))
%>
//
// 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.
//
<%
emit_setting_ifndef.(:THUMB_REPEAT_DECAY, resolve_tap_timing.(300))
%> // "tap then hold" for key auto-repeat
//
// 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).
//
<%
emit_setting_ifndef.(:SPACE_HOLDING_TYPE, :THUMB_HOLDING_TYPE)
%>
//
// SPACE_HOLDING_TIME defines how long you need to hold (milliseconds)
// the space thumb key to activate. Shorter holds are treated as taps.
//
<%
emit_setting_ifndef.(:SPACE_HOLDING_TIME, resolve_tap_timing.(170))
%>
//
// 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.
//
<%
emit_setting_ifndef.(:SPACE_REPEAT_DECAY, resolve_tap_timing.(150))
%>
//
// 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
unless chord
%>
#ifdef SHIFT_FORGIVENESS
#if <%= target.upcase %>_MOD == LSFT || <%= target.upcase %>_MOD == RSFT
hold-while-undecided; // requires 24.08-beta1 or newer firmware
retro-tap; // tap on standalone hold
#endif
#endif
<%
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>;
};
crumb: thumb_layer_access_retro_tap {
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>;
retro-tap;
};
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>;
retro-tap; // tap on standalone hold
};
//
// 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)>;
};