1 // this is the style you want to emulate.
2 // This is the canonical layout file for the Quantum project. If you want to add another keyboard,
10 // Each layer gets a name for readability, which is then used in the keymap matrix below.
11 // The underscores don't mean anything - you can have a layer called STUFF or any other name.
12 // Layer names don't all need to be of the same length, obviously, and you can also skip them
13 // entirely and just use numbers.
36 // Macro definitions for readability
45 #include "dynamic_macro.h"
47 #define LONGPRESS_DELAY 150
48 #define LAYER_TOGGLE_DELAY 900
50 // Fillers to make layering more clear
51 #define _______ KC_TRNS
52 #define __MOD__ KC_TRNS
55 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
56 [_QWERTY] = { /* QWERTY adapted to this crazy thing */
57 {KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P },
58 {KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN },
59 {SFT_T(KC_Z), KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, SFT_T(KC_SLSH) },
60 {XXXXXXX, KC_LCTL, M(ESCM), KC_TAB, KC_QUOT, KC_LEFT, KC_DOWN, KC_UP, KC_RIGHT, XXXXXXX },
61 {XXXXXXX, KC_LALT, KC_LGUI, KC_SPC, SHIFT, FNKEY, KC_BSPC, KC_ENT, MO(_ADJUST), XXXXXXX }
65 [_SHIFTED] = { /* Shifted Layer, layered so that tri_layer can be used, or selectively
66 able to modify individual key's shifted behaviour */
67 {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______ },
68 {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______ },
69 {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______ },
70 {XXXXXXX, __MOD__, KC_DEL, _______, _______, _______, _______, _______, _______, XXXXXXX },
71 {XXXXXXX, __MOD__, __MOD__, _______, __MOD__, __MOD__, _______, _______, KC_NO, XXXXXXX }
75 [_FUNCTIONPC] = { /* Function Layer mimicks planck's raise layer somewhat */
76 {KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0 },
77 {LCTL(KC_A), LCTL(KC_S), _______, LCTL(KC_F),_______, _______, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC },
78 {LCTL(KC_Z), LCTL(KC_X), LCTL(KC_C), LCTL(KC_V),_______, _______, KC_BSLS, _______, _______, KC_QUOT },
79 {XXXXXXX, __MOD__, KC_DEL, _______, KC_GRV, KC_HOME, KC_PGDN, KC_PGUP, KC_END, XXXXXXX },
80 {XXXXXXX, __MOD__, __MOD__, _______, __MOD__, __MOD__, _______, KC_PSCR, KC_NO, XXXXXXX }
83 [_FUNCTIONMAC] = { /* Function Layer mimicks planck's raise layer somewhat */
84 {KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0 },
85 {LGUI(KC_A), LGUI(KC_S), _______, LGUI(KC_F),_______, _______, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC },
86 {LGUI(KC_Z), LGUI(KC_X), LGUI(KC_C), LGUI(KC_V),_______, _______, KC_BSLS, _______, _______, KC_QUOT },
87 {XXXXXXX, __MOD__, KC_DEL, _______, KC_GRV, KC_HOME, KC_PGDN, KC_PGUP, KC_END, XXXXXXX },
88 {XXXXXXX, __MOD__, __MOD__, _______, __MOD__, __MOD__, _______, KC_PSCR, KC_NO, XXXXXXX }
91 [_FUNCSHIFT] = { /* Function Shifted Layer mimicks planck's lower layer somewhat */
92 {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______ },
93 {KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, _______, _______, KC_LCBR, KC_RCBR },
94 {KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______, _______, _______ },
95 {XXXXXXX, __MOD__, KC_DEL, _______, KC_TILD, _______, _______, _______, _______, XXXXXXX },
96 {XXXXXXX, __MOD__, __MOD__, _______, __MOD__, __MOD__, _______, _______, _______, XXXXXXX }
100 [_ADJUST] = { /* Adjust layer for fancy stuff and macros */
101 {RESET, FNPC, _______, _______, _______, _______, DYN_REC_START1, DYN_REC_START2, _______, _______ },
102 {FNMAC, _______, AU_ON, AU_OFF, _______, _______, _______, _______, MACSLEEP, _______ },
103 {MUV_DE, MUV_IN, MU_ON, MU_OFF, _______, _______, KC_MUTE, KC_MPRV, KC_MNXT, KC_MPLY },
104 {XXXXXXX, __MOD__, _______, _______, _______, _______, DYN_MACRO_PLAY1, DYN_MACRO_PLAY2, _______, XXXXXXX },
105 {XXXXXXX, __MOD__, __MOD__, _______, __MOD__, __MOD__, _______, _______, __MOD__, XXXXXXX }
112 float tone_startup[][2] = SONG(STARTUP_SOUND);
113 float tone_qwerty[][2] = SONG(QWERTY_SOUND);
114 float tone_dyn_macro_rec[][2] = SONG(DVORAK_SOUND);
115 float tone_dyn_macro_play[][2] = SONG(COLEMAK_SOUND);
116 float tone_fnpc[][2] = SONG(PLOVER_SOUND);
117 float tone_fnmac[][2] = SONG(PLOVER_GOODBYE_SOUND);
118 float music_scale[][2] = SONG(MUSIC_SCALE_SOUND);
120 float tone_goodbye[][2] = SONG(GOODBYE_SOUND);
123 const uint16_t PROGMEM fn_actions[] = {
126 static uint16_t function_layer = _FUNCTIONMAC;
127 static uint16_t key_timer;
129 void persistent_function_layer_set(uint16_t new_function_layer) {
130 // eeconfig_update_function_layer(new_function_layer);
131 function_layer = new_function_layer;
132 // should clear layers to avoid getting stuck.
135 const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
137 // MACRODOWN only works in this function
140 //switch multiplexing for media, short tap for volume up, long press for play/pause
142 if (record->event.pressed) {
143 key_timer = timer_read(); // if the key is being pressed, we start the timer.
144 } else { // this means the key was just released, so we can figure out how long it was pressed for (tap or "held down").
145 if (timer_elapsed(key_timer) > LONGPRESS_DELAY) { // LONGPRESS_DELAY being 150ms, the threshhold we pick for counting something as a tap.
146 return MACRO(T(MPLY), END);
148 return MACRO(T(VOLU), END);
153 //switch multiplexing for media, short tap for volume down, long press for next track
155 if (record->event.pressed) {
156 key_timer = timer_read();
158 if (timer_elapsed(key_timer) > LONGPRESS_DELAY) {
159 return MACRO(T(MNXT), END);
161 return MACRO(T(VOLD), END);
166 //switch multiplexing for escape, short tap for escape, long press for context menu
168 if (record->event.pressed) {
169 key_timer = timer_read();
171 if (timer_elapsed(key_timer) > LONGPRESS_DELAY) {
172 return MACRO(T(APP), END);
174 return MACRO(T(ESC), END);
182 static bool singular_key = false;
184 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
185 uint16_t macro_kc = (keycode == MO(_ADJUST) ? DYN_REC_STOP : keycode);
186 if (!process_record_dynamic_macro(macro_kc, record)) {
190 layer = biton32(layer_state); // get the current layer
192 //custom layer handling for tri_layer,
195 if (record->event.pressed) {
196 // ACTION_MODS_KEY(MOD_LCTL | MOD_LSFT, KC_POWER);
197 register_code(KC_RSFT);
198 register_code(KC_RCTL);
199 register_code(KC_POWER);
200 unregister_code(KC_POWER);
201 unregister_code(KC_RCTL);
202 unregister_code(KC_RSFT);
207 if (record->event.pressed) {
208 key_timer = timer_read();
210 // layer_on(_FUNCTION);
211 layer_on(function_layer);
213 if (timer_elapsed(key_timer) < LAYER_TOGGLE_DELAY || !singular_key) {
214 layer_off(function_layer);
217 update_tri_layer(function_layer, _SHIFTED, _FUNCSHIFT);
220 //SHIFT is handled as LSHIFT in the general case
222 if (record->event.pressed) {
223 key_timer = timer_read();
226 register_code(KC_LSFT);
228 if (timer_elapsed(key_timer) < LAYER_TOGGLE_DELAY || !singular_key) {
230 unregister_code(KC_LSFT);
233 update_tri_layer(function_layer, _SHIFTED, _FUNCSHIFT);
237 if (record->event.pressed) {
238 persistent_function_layer_set(_FUNCTIONPC);
240 PLAY_SONG(tone_fnpc);
246 if (record->event.pressed) {
247 persistent_function_layer_set(_FUNCTIONMAC);
249 PLAY_SONG(tone_fnmac);
255 if (record->event.pressed) {
257 PLAY_SONG(music_scale);
259 unregister_code(KC_M);
263 unregister_code(KC_A);
267 //If any other key was pressed during the layer mod hold period,
268 //then the layer mod was used momentarily, and should block latching
270 singular_key = false;
274 //FUNCSHIFT has been shifted by the SHIFT handling, some keys need to be excluded
275 if (layer == _FUNCSHIFT) {
276 //F1-F12 should be sent as unshifted keycodes,
277 //and ] needs to be unshifted or it is sent as }
278 if ( (keycode >= KC_F1 && keycode <= KC_F12)
279 || keycode == KC_RBRC ) {
280 if (record->event.pressed) {
281 unregister_mods(MOD_LSFT);
283 register_mods(MOD_LSFT);
295 _delay_ms(20); // gets rid of tick
296 PLAY_SONG(tone_startup);
301 PLAY_SONG(tone_goodbye);
306 void music_on_user(void)
311 void music_scale_user(void)
313 PLAY_SONG(music_scale);
318 void matrix_scan_user(void) {
319 uint8_t layer = biton32(layer_state);