]> git.donarmstrong.com Git - qmk_firmware.git/blob - keyboards/mitosis/keymaps/default/keymap.c
Remove/migrate action_get_macro()s from default keymaps (#5625)
[qmk_firmware.git] / keyboards / mitosis / keymaps / default / keymap.c
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,
3
4 #include QMK_KEYBOARD_H
5
6 // Each layer gets a name for readability, which is then used in the keymap matrix below.
7 // The underscores don't mean anything - you can have a layer called STUFF or any other name.
8 // Layer names don't all need to be of the same length, obviously, and you can also skip them
9 // entirely and just use numbers.
10 enum mitosis_layers
11 {
12         _MALT,
13         _SHIFTED,
14         _FUNCTION,
15         _FUNCSHIFT
16 };
17
18 enum mitosis_keycodes
19 {
20   FNKEY = SAFE_RANGE,
21   SHIFT,
22   M_VOLU,
23   M_VOLD,
24   M_ESCM
25 };
26
27 #define LONGPRESS_DELAY 150
28 #define LAYER_TOGGLE_DELAY 300
29
30 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
31
32   [_MALT] = LAYOUT( /* Malt Layout, customised for reduced columns (ex: quote and shift locations) */
33     KC_Q,    KC_P,    KC_Y,    KC_C,    KC_B,           KC_V,    KC_M,    KC_U,    KC_Z,    KC_L,
34     KC_A,    KC_N,    KC_I,    KC_S,    KC_F,           KC_D,    KC_T,    KC_H,    KC_O,    KC_R,
35     KC_COMM, KC_DOT,  KC_J,    KC_G,    KC_SLSH,        KC_SCLN, KC_W,    KC_K,    KC_QUOT, KC_X,
36              M_VOLU,  M_ESCM,  KC_TAB,  KC_LCTL,        KC_LALT, KC_ENT,  KC_DEL,  KC_PGUP,
37              M_VOLD,  KC_LGUI, KC_E,    FNKEY,          SHIFT,   KC_SPC,  KC_BSPC, KC_PGDN
38   ),
39
40
41   [_SHIFTED] = LAYOUT( /* Shifted Layer, layered so that tri_layer can be used, or selectively
42                                          able to modify individual key's shifted behaviour */
43     _______, _______, _______, _______, _______,       _______, _______, _______, _______, _______,
44     _______, _______, _______, _______, _______,       _______, _______, _______, _______, _______,
45     _______, _______, _______, _______, _______,       _______, _______, _______, _______, _______,
46              _______, _______, _______, _______,       _______, _______, _______, _______,
47              _______, _______, _______, _______,       _______, _______, _______, _______
48   ),
49
50
51
52   [_FUNCTION] = LAYOUT( /* Function Layer, primary alternative layer featuring numpad on right hand,
53                                            cursor keys on left hand, and all symbols*/
54     KC_AMPR, KC_PERC, KC_UP,   KC_CIRC, KC_PIPE,       KC_LBRC, KC_7,    KC_8,    KC_9,    KC_MINS,
55     KC_AT,   KC_LEFT, KC_DOWN, KC_RGHT, KC_HASH,       KC_LPRN, KC_4,    KC_5,    KC_6,    KC_PLUS,
56     KC_ASTR, KC_UNDS, KC_EXLM, KC_DLR,  KC_BSLS,       KC_LCBR, KC_1,    KC_2,    KC_3,    KC_ENT,
57              KC_HOME, KC_GRV,  KC_PWR,  _______,       _______, KC_EQL,  KC_TILD, KC_DOT,
58              KC_END,  _______, _______, _______,       _______, KC_0,    _______, KC_PSCR
59   ),
60
61
62   [_FUNCSHIFT] = LAYOUT( /* Function Shifted Layer, secondary alternative layer with closing brackets,
63                                                     and F-keys under their numpad equivalents*/
64     _______, _______, _______, _______, _______,       KC_RBRC, KC_F7,   KC_F8,   KC_F9,   KC_F10,
65     _______, _______, _______, _______, _______,       KC_RPRN, KC_F4,   KC_F5,   KC_F6,   KC_F11,
66     _______, _______, _______, _______, _______,       KC_RCBR, KC_F1,   KC_F2,   KC_F3,   KC_F12,
67              _______, _______, _______, _______,       _______, _______, _______, _______,
68              _______, _______, _______, _______,       _______, _______, _______, _______
69   )
70
71 };
72
73 static uint16_t key_timer;
74
75 static bool singular_key = false;
76
77 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
78
79         uint8_t layer;
80   layer = biton32(layer_state);  // get the current layer
81
82   //custom layer handling for tri_layer,
83   switch (keycode) {
84   case FNKEY:
85         if (record->event.pressed) {
86       key_timer = timer_read();
87       singular_key = true;
88         layer_on(_FUNCTION);
89         } else {
90       if (timer_elapsed(key_timer) < LAYER_TOGGLE_DELAY || !singular_key) {
91         layer_off(_FUNCTION);
92       }
93         }
94     update_tri_layer(_FUNCTION, _SHIFTED, _FUNCSHIFT);
95         return false;
96         break;
97   //SHIFT is handled as LSHIFT in the general case
98   case SHIFT:
99         if (record->event.pressed) {
100       key_timer = timer_read();
101       singular_key = true;
102         layer_on(_SHIFTED);
103         register_code(KC_LSFT);
104         } else {
105         if (timer_elapsed(key_timer) < LAYER_TOGGLE_DELAY || !singular_key) {
106         layer_off(_SHIFTED);
107           unregister_code(KC_LSFT);
108       }
109     }
110     update_tri_layer(_FUNCTION, _SHIFTED, _FUNCSHIFT);
111         return false;
112         break;
113   //switch multiplexing for media, short tap for volume up, long press for play/pause
114   case M_VOLU:
115       if (record->event.pressed) {
116         key_timer = timer_read(); // if the key is being pressed, we start the timer.
117       } else { // this means the key was just released, so we can figure out how long it was pressed for (tap or "held down").
118         if (timer_elapsed(key_timer) > LONGPRESS_DELAY) { // LONGPRESS_DELAY being 150ms, the threshhold we pick for counting something as a tap.
119             tap_code(KC_MPLY);
120           } else {
121             tap_code(KC_VOLU);
122           }
123       }
124       return false;
125
126   //switch multiplexing for media, short tap for volume down, long press for next track
127   case M_VOLD:
128       if (record->event.pressed) {
129         key_timer = timer_read();
130       } else {
131         if (timer_elapsed(key_timer) > LONGPRESS_DELAY) {
132             tap_code(KC_MNXT);
133           } else {
134             tap_code(KC_VOLD);
135           }
136       }
137       return false;
138
139   //switch multiplexing for escape, short tap for escape, long press for context menu
140   case M_ESCM:
141       if (record->event.pressed) {
142         key_timer = timer_read();
143       } else {
144         if (timer_elapsed(key_timer) > LONGPRESS_DELAY) {
145             tap_code(KC_APP);
146           } else {
147             tap_code(KC_ESC);
148           }
149       }
150       return false;
151
152   //If any other key was pressed during the layer mod hold period,
153   //then the layer mod was used momentarily, and should block latching
154   default:
155     singular_key = false;
156     break;
157   }
158
159   //FUNCSHIFT has been shifted by the SHIFT handling, some keys need to be excluded
160   if (layer == _FUNCSHIFT) {
161         //F1-F12 should be sent as unshifted keycodes,
162         //and ] needs to be unshifted or it is sent as }
163         if ( (keycode >= KC_F1 && keycode <= KC_F12)
164            || keycode == KC_RBRC ) {
165                 if (record->event.pressed) {
166               unregister_mods(MOD_LSFT);
167           } else {
168               register_mods(MOD_LSFT);
169           }
170         }
171   }
172
173   return true;
174 };
175
176 void matrix_scan_user(void) {
177     uint8_t layer = biton32(layer_state);
178
179     switch (layer) {
180         case _MALT:
181                 set_led_off;
182                 break;
183         case _FUNCTION:
184             set_led_blue;
185             break;
186         case _SHIFTED:
187             set_led_red;
188             break;
189         case _FUNCSHIFT:
190                 set_led_green;
191                 break;
192         default:
193             break;
194     }
195 };
196