Repository navigation
Expand file tree
/
Copy pathkeymap.c
More file actions
719 lines (653 loc) · 27.5 KB
/
Copy pathkeymap.c
File metadata and controls
719 lines (653 loc) · 27.5 KB
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
/* Copyright 2023 Brian Low — default header retained where applicable.
* Key placements mirror the user's VIA/web config screenshots (layers 0 & 1).
*/
#include QMK_KEYBOARD_H
#ifdef RGB_MATRIX_ENABLE
# include "rgb_matrix.h"
#endif
#ifdef SPLIT_KEYBOARD
# include "transactions.h"
#endif
#include <string.h>
/*
* Layer order matters: nav overlays MUST be the highest layer numbers.
* QMK resolves keys from the highest active layer downward.
*
* _NAV_SYM and _NAV_SYM_WIN are separate so Windows can use LCTL (not LALT) for
* word/line navigation while Mac/Linux keep LALT; both share F1–F10 on the left
* and right-hand I/J/K/L arrows.
*
* Stack examples:
* Mac typing: layer 0
* Mac + nav: layers 0 + 2 → highest 2 (_NAV_SYM)
* Win typing: layer 1
* Win + nav: layers 1 + 3 → highest 3 (_NAV_SYM_WIN)
*/
enum sofle_layers { _BASE = 0, _BASE_WIN = 1, _NAV_SYM = 2, _NAV_SYM_WIN = 3 };
/*
* Nav-layer keys where raw QMK aliases misbehave (always emit the shifted char).
*
* PLU_EQ — `=` unshifted, `+` with Shift (KC_PLUS / KC_EQL)
* LBR_BRC — `[` unshifted, `{` with Shift (KC_LCBR is Shift+LBRC only)
* RBR_BRC — `]` unshifted, `}` with Shift (KC_RCBR is Shift+RBRC only)
* ZOOM_IN — browser/page zoom in using the active profile's native shortcut:
* Command+Plus on macOS or Ctrl+Plus on Windows.
* ZOOM_OUT — the inverse action used when the nav key is held:
* Command+Minus on macOS or Ctrl+Minus on Windows.
*/
enum custom_keycodes { PLU_EQ = SAFE_RANGE, LBR_BRC, RBR_BRC, ZOOM_IN, ZOOM_OUT };
/*
* Profile = is the _BASE_WIN bit set in the (split-synced) layer_state.
*
* Mac: layer_state = 0b001 (default layer 0 only)
* Win: layer_state = 0b011 (default 0 + _BASE_WIN toggled on)
* Mac + nav: layer_state = 0b101 (+ MO(_NAV_SYM))
* Win + nav: layer_state = 0b1011 (+ MO(_NAV_SYM_WIN))
*
* Because SPLIT_LAYER_STATE_ENABLE is set in config.h, both halves see the same
* layer_state, so both OLEDs render the same icon.
*/
static bool is_windows_profile_active(void) {
return (layer_state & (1UL << _BASE_WIN)) != 0;
}
/*
* Split boards: only the USB-connected half is "master" for RGB. The other half's `rgb_matrix_config`
* is overwritten every transport frame from the master (`PUT_RGB_MATRIX` in split_common). Running
* EEPROM fixes on the slave does nothing visible because the master keeps pushing its state.
*
* Also, `eeconfig_update_rgb_matrix_default()` updates RAM + EEPROM but does not bump `rgb_task_state`,
* so the running animation can stick until something restarts the effect; `rgb_matrix_mode_noeeprom`
* forces a fresh STARTING phase.
*/
#ifdef RGB_MATRIX_ENABLE
/*
* Layer color palette (HSV 0–255). Brightness is still capped by RGB_MATRIX_MAXIMUM_BRIGHTNESS.
*
* Mac base (_BASE) — neon light blue
* Windows base (_BASE_WIN) — deep amethyst purple
* Nav overlays (_NAV_SYM*) — white (in-between / held-nav cue)
*/
static void set_layer_rgb(layer_state_t state) {
if (!is_keyboard_master()) {
return;
}
rgb_matrix_mode_noeeprom(RGB_MATRIX_SOLID_COLOR);
switch (get_highest_layer(state)) {
case _NAV_SYM:
case _NAV_SYM_WIN:
/* Nav overlay — white so held-nav reads as a clean “in between” state. */
rgb_matrix_sethsv_noeeprom(0, 0, 255);
break;
case _BASE_WIN:
/* Windows typing profile — deep amethyst purple. */
rgb_matrix_sethsv_noeeprom(191, 255, 255);
break;
case _BASE:
default:
/* Mac typing profile — bright neon light blue. */
rgb_matrix_sethsv_noeeprom(128, 255, 255);
break;
}
}
#endif
/*
* ---------------------------------------------------------------------------
* Lifetime keypress counter (replaces the old WPM readout)
* ---------------------------------------------------------------------------
*
* Counts every physical key press - not releases, and not encoder turns, which
* also arrive at process_record_user() but as ENCODER_*_EVENT rather than
* KEY_EVENT. Both OLEDs show the running total as 437 / 11.345k / 1.234m,
* with the digits after the decimal point drawn small.
*
* Persistence: the live total lives in RAM and is flushed to user EEPROM only
* periodically. Writing on every keystroke would destroy the chip - EEPROM cells
* endure on the order of 100k writes, which at typing speed is a matter of hours.
* Instead we flush when either:
* - CHARCOUNT_FLUSH_CHARS presses have accumulated since the last write, or
* - typing has been idle for CHARCOUNT_IDLE_MS with at least
* CHARCOUNT_IDLE_MIN presses pending.
*
* Net effect: a few dozen writes a day (many years of EEPROM life). The most a
* hard unplug can cost you is the presses since the last flush - and since the
* idle flush fires 30 s after you stop typing, in practice that is usually zero.
*/
#define CHARCOUNT_FLUSH_CHARS 2000
#define CHARCOUNT_IDLE_MS 30000
#define CHARCOUNT_IDLE_MIN 20
/* Byte offsets inside the user EEPROM datablock (total size set in config.h). */
#define EE_OFFSET_CHARCOUNT 0 /* uint32_t lifetime keypress total */
#define EE_OFFSET_PROFILE 4 /* uint8_t 1 = Windows, 0 = Mac */
static uint32_t charcount_total = 0; /* live total rendered on both OLEDs */
static uint32_t charcount_saved = 0; /* last total written to EEPROM */
static uint32_t charcount_last_key = 0; /* timer for the idle flush */
/*
* QMK calls this when the user EEPROM block is missing or stale (a fresh board,
* or after an EEPROM clear). Seed the stored total at zero.
*/
void eeconfig_init_user_datablock(void) {
uint32_t zero_count = 0;
uint8_t zero_profile = 0;
eeconfig_update_user_datablock(&zero_count, EE_OFFSET_CHARCOUNT, sizeof(zero_count));
eeconfig_update_user_datablock(&zero_profile, EE_OFFSET_PROFILE, sizeof(zero_profile));
}
/*
* Windows-profile persistence.
*
* The profile is just the _BASE_WIN bit in layer_state, flipped by TG(_BASE_WIN) on
* the nav overlay. Nothing in QMK persists a toggled (non-default) layer, so before
* this the board always came back up on the Mac profile. We mirror the bit into
* EEPROM whenever it changes and re-apply it at boot.
*
* profile_tracking stays false until the stored value has been loaded, so the
* layer_on() call below cannot write the value straight back out again.
*/
static bool profile_tracking = false;
static bool profile_stored_win = false;
static void user_eeprom_load(void) {
uint8_t stored_profile = 0;
if (eeconfig_is_user_datablock_valid()) {
eeconfig_read_user_datablock(&charcount_total, EE_OFFSET_CHARCOUNT, sizeof(charcount_total));
eeconfig_read_user_datablock(&stored_profile, EE_OFFSET_PROFILE, sizeof(stored_profile));
} else {
charcount_total = 0;
eeconfig_init_user_datablock();
}
charcount_saved = charcount_total;
profile_stored_win = (stored_profile != 0);
}
static void charcount_flush(void) {
if (charcount_total == charcount_saved) {
return;
}
eeconfig_update_user_datablock(&charcount_total, EE_OFFSET_CHARCOUNT, sizeof(charcount_total));
charcount_saved = charcount_total;
}
static void charcount_maybe_flush(void) {
uint32_t pending = charcount_total - charcount_saved;
if (pending == 0) {
return;
}
if (pending >= CHARCOUNT_FLUSH_CHARS || (pending >= CHARCOUNT_IDLE_MIN && timer_elapsed32(charcount_last_key) >= CHARCOUNT_IDLE_MS)) {
charcount_flush();
}
}
#ifdef SPLIT_KEYBOARD
/*
* Slave side of the CHARCOUNT_SYNC transaction: only the USB master runs
* process_record_user(), so the slave has no way to count. It just adopts
* whatever total the master pushes, which keeps both OLEDs showing the same number.
*/
static void charcount_sync_handler(uint8_t in_len, const void *in_data, uint8_t out_len, void *out_data) {
if (in_len == sizeof(uint32_t)) {
memcpy(&charcount_total, in_data, sizeof(uint32_t));
}
}
#endif
void keyboard_post_init_user(void) {
#ifdef SPLIT_KEYBOARD
/* Both halves register: the slave needs the receive callback installed. */
transaction_register_rpc(CHARCOUNT_SYNC, charcount_sync_handler);
#endif
if (is_keyboard_master()) {
user_eeprom_load();
/*
* Re-apply the stored profile. SPLIT_LAYER_STATE_ENABLE pushes the resulting
* layer_state to the other half, so both OLED badges and both RGB sides follow.
*/
if (profile_stored_win) {
layer_on(_BASE_WIN);
}
profile_tracking = true;
}
#ifdef RGB_MATRIX_ENABLE
if (!is_keyboard_master()) {
return;
}
eeconfig_update_rgb_matrix_default();
set_layer_rgb(layer_state);
#endif
}
void housekeeping_task_user(void) {
if (!is_keyboard_master()) {
return;
}
charcount_maybe_flush();
#ifdef SPLIT_KEYBOARD
/* Push the total to the slave at most ~4x a second, and only when it moved. */
static uint32_t last_push_at = 0;
static uint32_t last_push_value = UINT32_MAX;
if (charcount_total != last_push_value && timer_elapsed32(last_push_at) > 250) {
if (transaction_rpc_send(CHARCOUNT_SYNC, sizeof(charcount_total), &charcount_total)) {
last_push_value = charcount_total;
}
last_push_at = timer_read32();
}
#endif
}
layer_state_t layer_state_set_user(layer_state_t state) {
#ifdef RGB_MATRIX_ENABLE
set_layer_rgb(state);
#endif
/*
* Persist the profile only when the _BASE_WIN bit actually flips. This hook also
* fires for every nav-layer hold, and writing EEPROM on those would be both
* pointless and hard on the cells.
*/
if (profile_tracking && is_keyboard_master()) {
bool win = (state & (1UL << _BASE_WIN)) != 0;
if (win != profile_stored_win) {
profile_stored_win = win;
uint8_t stored_profile = win ? 1 : 0;
eeconfig_update_user_datablock(&stored_profile, EE_OFFSET_PROFILE, sizeof(stored_profile));
}
}
return state;
}
/*
* Profile switching is just `TG(_BASE_WIN)` on the nav layer — see keymap below.
* TG flips the _BASE_WIN layer bit on/off, which:
* - Mac (off) → Windows (on): layer_state gets bit 1 set, _BASE_WIN keys win over _BASE
* - Windows (on) → Mac (off): bit 1 cleared, _BASE keys are top of stack again
* No custom keycode handler needed — QMK + split_layer_state do the rest.
*/
#ifdef OLED_ENABLE
#include "oled_font.h"
/*
* Landscape OLED view: one large centred number, the lifetime keypress total.
*
* Design goal:
* - no labels (layer text, modifiers, etc.), just the number plus the OS badge
* - abbreviate once it gets long: 437 -> 11.345k -> 1.234m, with the digits after the
* decimal point drawn small
*
* Implementation note:
* The digits are 1-bit bitmaps of the Oswald typeface in oled_font.h (generated by
* tools/gen_oled_font.py), blitted with oled_write_pixel so we are not limited by
* the tiny built-in 6x8 text font. About 0.8 KB of flash.
*
* Orientation (128 w x 32 h). The readout runs along the long axis of the panel
* because that is the only way a 7-glyph number (12.345m) fits at a legible size -
* the 32 px short axis only ever had room for two 13 px digits.
*
* If the display reads upside down on your build, change this to OLED_ROTATION_0.
*/
oled_rotation_t oled_init_user(oled_rotation_t rotation) {
return OLED_ROTATION_180;
}
/*
* Profile badges: a pine tree on the right edge of the OLED, 16 px wide and the
* full 30 px tall. Mac shows the plain tree; Windows shows it snowed in, with
* falling flakes, snow lines on the branches and a drift at its base.
*
* One uint16_t per row; bit 15 (MSB) is the leftmost pixel (col 0), bit 0 the
* rightmost (col 15). The comment on each row is the pixel art ('X' = lit).
* The bottom row sits level with the bottom of the digits.
*/
#define ICON_W 16
#define ICON_H 30
static const uint16_t PROGMEM icon_tree_mac[ICON_H] = {
0x0000, /* ................ */
0x0000, /* ................ */
0x0000, /* ................ */
0x0000, /* ................ */
0x0100, /* .......X........ */
0x0380, /* ......XXX....... */
0x0100, /* .......X........ */
0x0100, /* .......X........ */
0x0380, /* ......XXX....... */
0x07C0, /* .....XXXXX...... */
0x0FE0, /* ....XXXXXXX..... */
0x0380, /* ......XXX....... */
0x07C0, /* .....XXXXX...... */
0x0FE0, /* ....XXXXXXX..... */
0x1FF0, /* ...XXXXXXXXX.... */
0x3FF8, /* ..XXXXXXXXXXX... */
0x07C0, /* .....XXXXX...... */
0x0FE0, /* ....XXXXXXX..... */
0x1FF0, /* ...XXXXXXXXX.... */
0x3FF8, /* ..XXXXXXXXXXX... */
0x7FFC, /* .XXXXXXXXXXXXX.. */
0x0FE0, /* ....XXXXXXX..... */
0x1FF0, /* ...XXXXXXXXX.... */
0x3FF8, /* ..XXXXXXXXXXX... */
0x7FFC, /* .XXXXXXXXXXXXX.. */
0xFFFE, /* XXXXXXXXXXXXXXX. */
0x0380, /* ......XXX....... */
0x0380, /* ......XXX....... */
0x0380, /* ......XXX....... */
0x0380, /* ......XXX....... */
};
static const uint16_t PROGMEM icon_tree_win[ICON_H] = {
0x4000, /* .X.............. */
0x0004, /* .............X.. */
0x1010, /* ...X.......X.... */
0x0100, /* .......X........ */
0x0380, /* ......XXX....... */
0x4104, /* .X.....X.....X.. */
0x0100, /* .......X........ */
0x0380, /* ......XXX....... */
0x07C4, /* .....XXXXX...X.. */
0x4AA0, /* .X..X.X.X.X..... */
0x0380, /* ......XXX....... */
0x07C0, /* .....XXXXX...... */
0x0FE0, /* ....XXXXXXX..... */
0x9552, /* X..X.X.X.X.X..X. */
0x3FF8, /* ..XXXXXXXXXXX... */
0x07C0, /* .....XXXXX...... */
0x0FE0, /* ....XXXXXXX..... */
0x1FF0, /* ...XXXXXXXXX.... */
0x2AA8, /* ..X.X.X.X.X.X... */
0x7FFC, /* .XXXXXXXXXXXXX.. */
0x0FE0, /* ....XXXXXXX..... */
0x1FF0, /* ...XXXXXXXXX.... */
0x3FF8, /* ..XXXXXXXXXXX... */
0x5554, /* .X.X.X.X.X.X.X.. */
0xFFFE, /* XXXXXXXXXXXXXXX. */
0x0380, /* ......XXX....... */
0x0380, /* ......XXX....... */
0x3FFC, /* ..XXXXXXXXXXXX.. */
0x7FFE, /* .XXXXXXXXXXXXXX. */
0xFFFF, /* XXXXXXXXXXXXXXXX */
};
/* Blit one ICON_W x ICON_H badge with its top-left corner at (ox, oy). */
static void draw_profile_icon(uint8_t ox, uint8_t oy, const uint16_t *icon) {
for (uint8_t row = 0; row < ICON_H; row++) {
uint16_t bits = pgm_read_word(&icon[row]);
for (uint8_t col = 0; col < ICON_W; col++) {
if (bits & (0x8000 >> col)) {
oled_write_pixel((uint8_t)(ox + col), (uint8_t)(oy + row), true);
}
}
}
}
/* Layout of the landscape readout. */
#define GLYPH_GAP 3 /* space between adjacent glyphs */
#define GLYPH_SMALL_GAP 2 /* tighter spacing between two small glyphs */
#define GLYPH_BASELINE 30 /* first pixel row below the digits' baseline */
/*
* Glyph codes, matching the oled_glyphs[] table in oled_font.h:
* 0-9 big digits, 10 '.', 11 'k', 12 'm', 16-25 small digits.
* The whole part of the number is big; everything after the decimal point,
* and the k / m suffix, is small and sits on the same baseline.
*/
#define GLYPH_DOT 10
#define GLYPH_K 11
#define GLYPH_M 12
#define GLYPH_SMALL(d) ((uint8_t)(16 + (d)))
#define GLYPH_IS_SMALL(code) ((code) == GLYPH_K || (code) == GLYPH_M || ((code) >= 16 && (code) <= 25))
static oled_glyph_t glyph_info(uint8_t code) {
oled_glyph_t g;
memcpy_P(&g, &oled_glyphs[code], sizeof(g));
return g;
}
/* Width a glyph takes up in the layout. */
static uint8_t glyph_width(uint8_t code) {
return glyph_info(code).cell;
}
/* Space between two adjacent glyphs: small ones pack tighter together. */
static uint8_t glyph_gap(uint8_t prev, uint8_t next) {
return (GLYPH_IS_SMALL(prev) && GLYPH_IS_SMALL(next)) ? GLYPH_SMALL_GAP : GLYPH_GAP;
}
/* Blit one glyph with its cell's left edge at x and its bottom row on the baseline. */
static void draw_glyph(uint8_t x, uint8_t code) {
const oled_glyph_t g = glyph_info(code);
const uint8_t stride = (uint8_t)((g.w + 7) / 8);
const uint8_t top = (uint8_t)(GLYPH_BASELINE - g.h);
for (uint8_t row = 0; row < g.h; row++) {
for (uint8_t col = 0; col < g.w; col++) {
uint8_t byte = pgm_read_byte(&oled_glyph_bits[g.offset + row * stride + col / 8]);
if (byte & (0x80 >> (col % 8))) {
oled_write_pixel((uint8_t)(x + g.xoff + col), (uint8_t)(top + row), true);
}
}
}
}
/*
* Format the running total into at most 7 glyph cells. The whole part is drawn
* big; everything after the decimal point is drawn small (shown here after the
* '|', which is not drawn):
* 0 - 999 -> 437
* 1k - 999k -> 1.|234k 12.|345k 123.|45k
* 1m and above -> 1.|234m 12.|345m 123.|45m
*
* Below 100k / 100m that is exact to 1 press / 1,000 presses. From 100 upward
* there is only room for two small decimals (exact to 10 / 10,000). The widest
* case, 888.|88m, still fits the 108 px field. Values are truncated, never
* rounded up, so the readout behaves like an odometer. Returns the number of glyphs written to out[].
*/
static uint8_t charcount_format(uint32_t v, uint8_t *out) {
uint8_t n = 0;
if (v < 1000UL) {
if (v >= 100UL) out[n++] = (uint8_t)(v / 100UL % 10UL);
if (v >= 10UL) out[n++] = (uint8_t)(v / 10UL % 10UL);
out[n++] = (uint8_t)(v % 10UL);
return n;
}
uint8_t suffix;
uint32_t milli; /* the value rescaled into thousandths of the suffix unit */
if (v < 1000000UL) {
suffix = GLYPH_K;
milli = v;
} else {
suffix = GLYPH_M;
milli = v / 1000UL;
}
/* Clamp so a uint32 near its ceiling still fits the layout (tops out at 999.99m). */
if (milli > 999999UL) {
milli = 999999UL;
}
uint32_t whole = milli / 1000UL;
uint16_t frac = (uint16_t)(milli % 1000UL); /* three decimal places */
if (whole >= 100UL) {
out[n++] = (uint8_t)(whole / 100UL % 10UL);
out[n++] = (uint8_t)(whole / 10UL % 10UL);
out[n++] = (uint8_t)(whole % 10UL);
out[n++] = GLYPH_DOT;
out[n++] = GLYPH_SMALL(frac / 100U);
out[n++] = GLYPH_SMALL(frac / 10U % 10U);
} else {
if (whole >= 10UL) out[n++] = (uint8_t)(whole / 10UL % 10UL);
out[n++] = (uint8_t)(whole % 10UL);
out[n++] = GLYPH_DOT;
out[n++] = GLYPH_SMALL(frac / 100U);
out[n++] = GLYPH_SMALL(frac / 10U % 10U);
out[n++] = GLYPH_SMALL(frac % 10U);
}
out[n++] = suffix;
return n;
}
bool oled_task_user(void) {
oled_clear();
uint8_t glyphs[8];
uint8_t n = charcount_format(charcount_total, glyphs);
uint16_t total_w = 0;
for (uint8_t i = 0; i < n; i++) {
total_w = (uint16_t)(total_w + glyph_width(glyphs[i]));
if (i > 0) {
total_w = (uint16_t)(total_w + glyph_gap(glyphs[i - 1], glyphs[i]));
}
}
/*
* Landscape canvas: 128 w x 32 h.
* The profile badge (tree) keeps its cell flush to the right edge, bottom row
* level with the digits' bottom row; the number is centred in what is left.
*/
const uint8_t icon_x = 128 - ICON_W;
const uint8_t icon_y = GLYPH_BASELINE - ICON_H;
const uint8_t field_w = icon_x - 4;
uint8_t x = (total_w < field_w) ? (uint8_t)((field_w - total_w) / 2) : 0;
for (uint8_t i = 0; i < n; i++) {
if (i > 0) {
x = (uint8_t)(x + glyph_gap(glyphs[i - 1], glyphs[i]));
}
draw_glyph(x, glyphs[i]);
x = (uint8_t)(x + glyph_width(glyphs[i]));
}
if (is_windows_profile_active()) {
draw_profile_icon(icon_x, icon_y, icon_tree_win);
} else {
draw_profile_icon(icon_x, icon_y, icon_tree_mac);
}
return false;
}
#endif /* OLED_ENABLE */
/*
* Tap a US-layout key as unshifted or Shift+key, stripping held Shift first so
* layer/thumb shift does not force the shifted symbol every time (same fix as PLU_EQ).
*/
static void tap_us_key_shifted(uint16_t keycode) {
if (mod_config(get_mods()) & MOD_MASK_SHIFT) {
uint8_t mods = get_mods();
del_mods(MOD_MASK_SHIFT);
tap_code16(S(keycode));
set_mods(mods);
} else {
tap_code16(keycode);
}
}
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
if (!record->event.pressed) {
return true;
}
/*
* Count real key presses only. With ENCODER_MAP_ENABLE the knobs dispatch through
* here too, but as ENCODER_CW/CCW_EVENT - IS_KEYEVENT() filters those out so
* spinning the volume knob does not inflate the total.
*/
if (IS_KEYEVENT(record->event)) {
charcount_total++;
charcount_last_key = timer_read32();
}
switch (keycode) {
case PLU_EQ:
tap_us_key_shifted(KC_EQL);
return false;
case LBR_BRC:
tap_us_key_shifted(KC_LBRC);
return false;
case RBR_BRC:
tap_us_key_shifted(KC_RBRC);
return false;
case ZOOM_IN:
/*
* The encoder's push switch is a normal matrix key. Send one complete
* zoom shortcut per press instead of holding the modifiers while the
* knob remains depressed. The Windows base-layer bit is split-synced,
* so this also behaves correctly when the left half is not USB master.
*/
if (is_windows_profile_active()) {
tap_code16(C(KC_PLUS));
} else {
tap_code16(G(KC_PLUS));
}
return false;
case ZOOM_OUT:
/*
* The nav overlay replaces ZOOM_IN with ZOOM_OUT at the same physical
* encoder-switch position. Minus is already an unshifted key, so only
* the operating system's Command/Ctrl modifier needs to be added.
*/
if (is_windows_profile_active()) {
tap_code16(C(KC_MINS));
} else {
tap_code16(G(KC_MINS));
}
return false;
}
return true;
}
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
/*
* Layer 0 (base) - from your screenshots
* LEFT
* Row0: Esc 1-5
* Row1: Tab Q W E R T
* Row2: LCtl A S D F G (Lcrl on screenshot = KC_LCTL)
* Row3: LSft Z X C V B inner tall: mute
* Thumbs horizontal (outer→inner): Cmd Alt Ctrl Alt · tall Space (matrix order below)
*
* BETWEEN HALVES row4: left encoder press = page zoom in;
* right encoder press = media play/pause
*
* RIGHT
* Row0 (number row above home): 6-0 + KC_GRV (tilde/~ key legend)
* Row1: Y U I O P KC_BSLS
* Row3: H J K L ; '
* Row4: VOLU vertical inner | N M , . / RSft
* Thumbs tall Enter · BSPC MO(1) ___ RCTL
* - `MO(_NAV_SYM)` = hold for layer 1, release to return to base
* - no toggles (`TG`/`TO`) so accidental persistent layer lock is removed
*/
[_BASE] = LAYOUT(
KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_GRV,
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSLS,
KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, ZOOM_IN, KC_MPLY, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT,
KC_LCTL, KC_LALT, KC_LGUI, MO(_NAV_SYM), KC_SPC, KC_ENT, KC_BSPC, KC_LALT, KC_LGUI, KC_RCTL
),
/*
* Windows profile — same as _BASE except left thumb outer/inner swap:
* Mac thumb order (outer→inner): Ctrl Alt Gui | Win: Gui Alt Ctrl
* So copy/paste on Windows uses Ctrl on the thumb where Mac used Gui.
*/
[_BASE_WIN] = LAYOUT(
KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_GRV,
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSLS,
KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, ZOOM_IN, KC_MPLY, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT,
KC_LGUI, KC_LALT, KC_LCTL, MO(_NAV_SYM_WIN), KC_SPC, KC_ENT, KC_BSPC, KC_LALT, KC_LGUI, KC_RCTL
),
/*
* Mac / Linux nav overlay (_NAV_SYM):
* - TG(_BASE_WIN) top-left toggles the Windows profile (tap while holding nav).
* - Pressing the left encoder while nav is held zooms the page out.
* - F1–F10 on left rows 0–1 (1–5 and Q–T); arrows on right hand only (I/J/K/L).
* - Homerow LALT on A/S so Option+arrows still work when combined with arrow keys.
* - -/+ shifted one right to ; and ' (KC_MINS / PLU_EQ).
* KC_NO everywhere else so accidental keys do nothing.
*/
[_NAV_SYM] = LAYOUT(
TG(_BASE_WIN), KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_NO, KC_NO, KC_NO, LBR_BRC, RBR_BRC, KC_NO,
KC_NO, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_NO, KC_NO, KC_UP, KC_NO, KC_NO, KC_NO,
KC_LALT, KC_LALT, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_LEFT, KC_DOWN, KC_RGHT, KC_MINS, PLU_EQ,
KC_LSFT, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, ZOOM_OUT, KC_MPLY, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO,
KC_NO, KC_NO, KC_LGUI, KC_NO, KC_SPC, KC_LALT, KC_BSPC, KC_NO, KC_NO, KC_NO
),
/*
* Windows nav overlay (_NAV_SYM_WIN):
* - Same layout as _NAV_SYM, but LCTL replaces LALT so Ctrl+arrows match Windows
* word/paragraph navigation (same finger positions as Mac Option+arrows).
* - Pressing the left encoder while nav is held zooms the page out.
* - F1–F10 on left rows 0–1 (1–5 and Q–T); F11 on `; Tab → F12.
* - Arrows on right hand only (I/J/K/L); H → Ctrl+Alt+Del.
* - -/+ shifted one right to ; and ' (KC_MINS / PLU_EQ).
* - TG(_BASE_WIN) top-left switches back to Mac/Linux profile.
*/
[_NAV_SYM_WIN] = LAYOUT(
TG(_BASE_WIN), KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_NO, KC_NO, KC_NO, LBR_BRC, RBR_BRC, KC_F11,
KC_TAB, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, C(A(KC_DEL)), KC_NO, KC_UP, KC_NO, KC_NO, KC_F12,
KC_LCTL, KC_LCTL, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_LEFT, KC_DOWN, KC_RGHT, KC_MINS, PLU_EQ,
KC_LSFT, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, ZOOM_OUT, KC_MPLY, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO,
KC_NO, KC_NO, KC_LCTL, KC_NO, KC_SPC, KC_LCTL, KC_BSPC, KC_NO, KC_NO, KC_NO
)
};
#if defined(ENCODER_MAP_ENABLE)
/*
* Encoder 0 is the left knob and sends horizontal mouse-wheel movement. Most
* browsers, editors, and other scrollable views interpret this as side-to-side
* scrolling without requiring Shift to be held.
*
* Encoder 1 is the right knob and controls system volume.
* ENCODER_CCW_CW(ccw, cw) lists the counter-clockwise action first. Both pairs
* intentionally look reversed from the usual logical order because these
* physical encoders are mounted with the opposite rotational orientation.
* Every layer repeats the mapping so both knobs remain predictable while nav is held.
*/
const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = {
[_BASE] = { ENCODER_CCW_CW(MS_WHLR, MS_WHLL), ENCODER_CCW_CW(KC_VOLU, KC_VOLD) },
[_NAV_SYM] = { ENCODER_CCW_CW(MS_WHLR, MS_WHLL), ENCODER_CCW_CW(KC_VOLU, KC_VOLD) },
[_NAV_SYM_WIN] = { ENCODER_CCW_CW(MS_WHLR, MS_WHLL), ENCODER_CCW_CW(KC_VOLU, KC_VOLD) },
[_BASE_WIN] = { ENCODER_CCW_CW(MS_WHLR, MS_WHLL), ENCODER_CCW_CW(KC_VOLU, KC_VOLD) },
};
#endif