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.
35 // Macro definitions for readability
44 #include "dynamic_macro.h"
46 #define LONGPRESS_DELAY 150
47 #define LAYER_TOGGLE_DELAY 900
49 // Fillers to make layering more clear
50 #define _______ KC_TRNS
51 #define __MOD__ KC_TRNS
54 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
55 [_QWERTY] = { /* QWERTY adapted to this crazy thing */
56 {KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P },
57 {KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN },
58 {SFT_T(KC_Z), KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, SFT_T(KC_SLSH) },
59 {XXXXXXX, KC_LCTL, M(ESCM), KC_TAB, KC_QUOT, KC_LEFT, KC_DOWN, KC_UP, KC_RIGHT, XXXXXXX },
60 {XXXXXXX, KC_LALT, KC_LGUI, KC_SPC, SHIFT, FNKEY, KC_BSPC, KC_ENT, MO(_ADJUST), XXXXXXX }
64 [_SHIFTED] = { /* Shifted Layer, layered so that tri_layer can be used, or selectively
65 able to modify individual key's shifted behaviour */
66 {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______ },
67 {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______ },
68 {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______ },
69 {XXXXXXX, __MOD__, KC_DEL, _______, _______, _______, _______, _______, _______, XXXXXXX },
70 {XXXXXXX, __MOD__, __MOD__, _______, __MOD__, __MOD__, _______, _______, KC_NO, XXXXXXX }
74 [_FUNCTIONPC] = { /* Function Layer mimicks planck's raise layer somewhat */
75 {KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0 },
76 {LCTL(KC_A), LCTL(KC_S), _______, LCTL(KC_F),_______, _______, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC },
77 {LCTL(KC_Z), LCTL(KC_X), LCTL(KC_C), LCTL(KC_V),_______, _______, KC_BSLS, _______, _______, KC_QUOT },
78 {XXXXXXX, __MOD__, KC_DEL, _______, KC_GRV, KC_HOME, KC_PGDN, KC_PGUP, KC_END, XXXXXXX },
79 {XXXXXXX, __MOD__, __MOD__, _______, __MOD__, __MOD__, _______, KC_PSCR, KC_NO, XXXXXXX }
82 [_FUNCTIONMAC] = { /* Function Layer mimicks planck's raise layer somewhat */
83 {KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0 },
84 {LGUI(KC_A), LGUI(KC_S), _______, LGUI(KC_F),_______, _______, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC },
85 {LGUI(KC_Z), LGUI(KC_X), LGUI(KC_C), LGUI(KC_V),_______, _______, KC_BSLS, _______, _______, KC_QUOT },
86 {XXXXXXX, __MOD__, KC_DEL, _______, KC_GRV, KC_HOME, KC_PGDN, KC_PGUP, KC_END, XXXXXXX },
87 {XXXXXXX, __MOD__, __MOD__, _______, __MOD__, __MOD__, _______, KC_PSCR, KC_NO, XXXXXXX }
90 [_FUNCSHIFT] = { /* Function Shifted Layer mimicks planck's lower layer somewhat */
91 {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______ },
92 {KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, _______, _______, KC_LCBR, KC_RCBR },
93 {KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______, _______, _______ },
94 {XXXXXXX, __MOD__, KC_DEL, _______, KC_TILD, _______, _______, _______, _______, XXXXXXX },
95 {XXXXXXX, __MOD__, __MOD__, _______, __MOD__, __MOD__, _______, _______, _______, XXXXXXX }
99 [_ADJUST] = { /* Adjust layer for fancy stuff and macros */
100 {RESET, FNPC, _______, _______, _______, _______, DYN_REC_START1, DYN_REC_START2, _______, _______ },
101 {FNMAC, _______, AU_ON, AU_OFF, _______, _______, _______, _______, MACSLEEP, _______ },
102 {MUV_DE, MUV_IN, MU_ON, MU_OFF, _______, _______, KC_MUTE, KC_MPRV, KC_MNXT, KC_MPLY },
103 {XXXXXXX, __MOD__, _______, _______, _______, _______, DYN_MACRO_PLAY1, DYN_MACRO_PLAY2, _______, XXXXXXX },
104 {XXXXXXX, __MOD__, __MOD__, _______, __MOD__, __MOD__, _______, _______, __MOD__, XXXXXXX }
111 float tone_startup[][2] = SONG(STARTUP_SOUND);
112 float tone_qwerty[][2] = SONG(QWERTY_SOUND);
113 float tone_dyn_macro_rec[][2] = SONG(DVORAK_SOUND);
114 float tone_dyn_macro_play[][2] = SONG(COLEMAK_SOUND);
115 float tone_fnpc[][2] = SONG(PLOVER_SOUND);
116 float tone_fnmac[][2] = SONG(PLOVER_GOODBYE_SOUND);
117 float music_scale[][2] = SONG(MUSIC_SCALE_SOUND);
119 float tone_goodbye[][2] = SONG(GOODBYE_SOUND);
122 const uint16_t PROGMEM fn_actions[] = {
125 static uint16_t function_layer = _FUNCTIONMAC;
126 static uint16_t key_timer;
128 void persistent_function_layer_set(uint16_t new_function_layer) {
129 // eeconfig_update_function_layer(new_function_layer);
130 function_layer = new_function_layer;
131 // should clear layers to avoid getting stuck.
134 const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
136 // MACRODOWN only works in this function
139 //switch multiplexing for media, short tap for volume up, long press for play/pause
141 if (record->event.pressed) {
142 key_timer = timer_read(); // if the key is being pressed, we start the timer.
143 } else { // this means the key was just released, so we can figure out how long it was pressed for (tap or "held down").
144 if (timer_elapsed(key_timer) > LONGPRESS_DELAY) { // LONGPRESS_DELAY being 150ms, the threshhold we pick for counting something as a tap.
145 return MACRO(T(MPLY), END);
147 return MACRO(T(VOLU), END);
152 //switch multiplexing for media, short tap for volume down, long press for next track
154 if (record->event.pressed) {
155 key_timer = timer_read();
157 if (timer_elapsed(key_timer) > LONGPRESS_DELAY) {
158 return MACRO(T(MNXT), END);
160 return MACRO(T(VOLD), END);
165 //switch multiplexing for escape, short tap for escape, long press for context menu
167 if (record->event.pressed) {
168 key_timer = timer_read();
170 if (timer_elapsed(key_timer) > LONGPRESS_DELAY) {
171 return MACRO(T(APP), END);
173 return MACRO(T(ESC), END);
181 static bool singular_key = false;
183 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
184 uint16_t macro_kc = (keycode == MO(_ADJUST) ? DYN_REC_STOP : keycode);
185 if (!process_record_dynamic_macro(macro_kc, record)) {
189 layer = biton32(layer_state); // get the current layer
191 //custom layer handling for tri_layer,
194 if (record->event.pressed) {
195 // ACTION_MODS_KEY(MOD_LCTL | MOD_LSFT, KC_POWER);
196 register_code(KC_RSFT);
197 register_code(KC_RCTL);
198 register_code(KC_POWER);
199 unregister_code(KC_POWER);
200 unregister_code(KC_RCTL);
201 unregister_code(KC_RSFT);
206 if (record->event.pressed) {
207 key_timer = timer_read();
209 // layer_on(_FUNCTION);
210 layer_on(function_layer);
212 if (timer_elapsed(key_timer) < LAYER_TOGGLE_DELAY || !singular_key) {
213 layer_off(function_layer);
216 update_tri_layer(function_layer, _SHIFTED, _FUNCSHIFT);
219 //SHIFT is handled as LSHIFT in the general case
221 if (record->event.pressed) {
222 key_timer = timer_read();
225 register_code(KC_LSFT);
227 if (timer_elapsed(key_timer) < LAYER_TOGGLE_DELAY || !singular_key) {
229 unregister_code(KC_LSFT);
232 update_tri_layer(function_layer, _SHIFTED, _FUNCSHIFT);
236 if (record->event.pressed) {
237 persistent_function_layer_set(_FUNCTIONPC);
239 PLAY_NOTE_ARRAY(tone_fnpc, false, 0);
245 if (record->event.pressed) {
246 persistent_function_layer_set(_FUNCTIONMAC);
248 PLAY_NOTE_ARRAY(tone_fnmac, false, 0);
253 //If any other key was pressed during the layer mod hold period,
254 //then the layer mod was used momentarily, and should block latching
256 singular_key = false;
260 //FUNCSHIFT has been shifted by the SHIFT handling, some keys need to be excluded
261 if (layer == _FUNCSHIFT) {
262 //F1-F12 should be sent as unshifted keycodes,
263 //and ] needs to be unshifted or it is sent as }
264 if ( (keycode >= KC_F1 && keycode <= KC_F12)
265 || keycode == KC_RBRC ) {
266 if (record->event.pressed) {
267 unregister_mods(MOD_LSFT);
269 register_mods(MOD_LSFT);
281 _delay_ms(20); // gets rid of tick
282 PLAY_NOTE_ARRAY(tone_startup, false, 0);
287 PLAY_NOTE_ARRAY(tone_goodbye, false, 0);
292 void music_on_user(void)
297 void music_scale_user(void)
299 PLAY_NOTE_ARRAY(music_scale, false, 0);
304 void matrix_scan_user(void) {
305 uint8_t layer = biton32(layer_state);