]> git.donarmstrong.com Git - qmk_firmware.git/blob - keyboards/mitosis/keymaps/default/keymap.c
Merge remote-tracking branch 'bigtunaio/layouts/adam-lee' into dev
[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 "mitosis.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 };
23
24
25 // Macro definitions for readability
26 enum mitosis_macros
27 {
28         VOLU,
29         VOLD,
30         ESCM
31 };
32
33 #define LONGPRESS_DELAY 150
34 #define LAYER_TOGGLE_DELAY 300
35
36 // Fillers to make layering more clear
37 #define _______ KC_TRNS
38 #define XXXXXXX KC_NO
39
40 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
41 [_MALT] = { /* Malt Layout, customised for reduced columns (ex: quote and shift locations) */
42   {KC_Q,    KC_P,    KC_Y,    KC_C,    KC_B,           KC_V,    KC_M,    KC_U,    KC_Z,    KC_L    },
43   {KC_A,    KC_N,    KC_I,    KC_S,    KC_F,           KC_D,    KC_T,    KC_H,    KC_O,    KC_R    },
44   {KC_COMM, KC_DOT,  KC_J,    KC_G,    KC_SLSH,        KC_SCLN, KC_W,    KC_K,    KC_QUOT, KC_X    },
45   {XXXXXXX, M(VOLU), M(ESCM), KC_TAB,  KC_LCTL,        KC_LALT, KC_ENT,  KC_DEL,  KC_PGUP, XXXXXXX },
46   {XXXXXXX, M(VOLD), KC_LGUI, KC_E,    FNKEY,          SHIFT,   KC_SPC,  KC_BSPC, KC_PGDN, XXXXXXX }
47 },
48
49
50 [_SHIFTED] = { /* Shifted Layer, layered so that tri_layer can be used, or selectively
51                                  able to modify individual key's shifted behaviour */
52   {_______, _______, _______, _______, _______,       _______, _______, _______, _______, _______ },
53   {_______, _______, _______, _______, _______,       _______, _______, _______, _______, _______ },
54   {_______, _______, _______, _______, _______,       _______, _______, _______, _______, _______ },
55   {XXXXXXX, _______, _______, _______, _______,       _______, _______, _______, _______, XXXXXXX },
56   {XXXXXXX, _______, _______, _______, _______,       _______, _______, _______, _______, XXXXXXX }
57 },
58
59
60
61 [_FUNCTION] = { /* Function Layer, primary alternative layer featuring numpad on right hand,
62                                    cursor keys on left hand, and all symbols*/
63   {KC_AMPR, KC_PERC, KC_UP,   KC_CIRC, KC_PIPE,       KC_LBRC, KC_7,    KC_8,    KC_9,    KC_MINS },
64   {KC_AT,   KC_LEFT, KC_DOWN, KC_RGHT, KC_HASH,       KC_LPRN, KC_4,    KC_5,    KC_6,    KC_PLUS },
65   {KC_ASTR, KC_UNDS, KC_EXLM, KC_DLR,  KC_BSLS,       KC_LCBR, KC_1,    KC_2,    KC_3,    KC_ENT  },
66   {XXXXXXX, KC_HOME, KC_GRV,  KC_PWR,  _______,       _______, KC_EQL,  KC_TILD, KC_DOT,  XXXXXXX },
67   {XXXXXXX, KC_END,  _______, _______, _______,       _______, KC_0,    _______, KC_PSCR, XXXXXXX }
68 },
69
70
71 [_FUNCSHIFT] = { /* Function Shifted Layer, secondary alternative layer with closing brackets,
72                                             and F-keys under their numpad equivalents*/
73   {_______, _______, _______, _______, _______,       KC_RBRC, KC_F7,   KC_F8,   KC_F9,   KC_F10  },
74   {_______, _______, _______, _______, _______,       KC_RPRN, KC_F4,   KC_F5,   KC_F6,   KC_F11  },
75   {_______, _______, _______, _______, _______,       KC_RCBR, KC_F1,   KC_F2,   KC_F3,   KC_F12  },
76   {XXXXXXX, _______, _______, _______, _______,       _______, _______, _______, _______, XXXXXXX },
77   {XXXXXXX, _______, _______, _______, _______,       _______, _______, _______, _______, XXXXXXX }
78 }
79
80 };
81
82
83 const uint16_t PROGMEM fn_actions[] = {
84
85 };
86
87 static uint16_t key_timer;
88
89 const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
90 {
91   // MACRODOWN only works in this function
92     switch(id) {
93
94         //switch multiplexing for media, short tap for volume up, long press for play/pause
95         case VOLU:
96             if (record->event.pressed) {
97                 key_timer = timer_read(); // if the key is being pressed, we start the timer.
98                 } else { // this means the key was just released, so we can figure out how long it was pressed for (tap or "held down").
99                 if (timer_elapsed(key_timer) > LONGPRESS_DELAY) { // LONGPRESS_DELAY being 150ms, the threshhold we pick for counting something as a tap.
100                   return MACRO(T(MPLY), END);
101                 } else {
102                   return MACRO(T(VOLU), END);
103                 }
104                 }
105                 break;
106
107                 //switch multiplexing for media, short tap for volume down, long press for next track
108         case VOLD:
109             if (record->event.pressed) {
110                 key_timer = timer_read();
111                 } else {
112                 if (timer_elapsed(key_timer) > LONGPRESS_DELAY) {
113                   return MACRO(T(MNXT), END);
114                 } else {
115                   return MACRO(T(VOLD), END);
116                 }
117                 }
118                 break;
119
120         //switch multiplexing for escape, short tap for escape, long press for context menu
121         case ESCM:
122             if (record->event.pressed) {
123                 key_timer = timer_read();
124                 } else {
125                 if (timer_elapsed(key_timer) > LONGPRESS_DELAY) {
126                   return MACRO(T(APP), END);
127                 } else {
128                   return MACRO(T(ESC), END);
129                 }
130                 }
131                 break;     
132
133         break;
134     }
135     return MACRO_NONE;
136 };
137
138 static bool singular_key = false;
139
140 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
141
142         uint8_t layer;
143   layer = biton32(layer_state);  // get the current layer
144
145   //custom layer handling for tri_layer,
146   switch (keycode) {
147   case FNKEY:
148         if (record->event.pressed) {
149       key_timer = timer_read();
150       singular_key = true;
151         layer_on(_FUNCTION);
152         } else {
153       if (timer_elapsed(key_timer) < LAYER_TOGGLE_DELAY || !singular_key) {
154         layer_off(_FUNCTION);
155       }
156         }
157     update_tri_layer(_FUNCTION, _SHIFTED, _FUNCSHIFT);
158         return false;
159         break;
160   //SHIFT is handled as LSHIFT in the general case
161   case SHIFT:
162         if (record->event.pressed) {
163       key_timer = timer_read();
164       singular_key = true;
165         layer_on(_SHIFTED);
166         register_code(KC_LSFT);
167         } else {
168         if (timer_elapsed(key_timer) < LAYER_TOGGLE_DELAY || !singular_key) {
169         layer_off(_SHIFTED);
170           unregister_code(KC_LSFT);
171       }
172     }
173     update_tri_layer(_FUNCTION, _SHIFTED, _FUNCSHIFT);
174         return false;
175         break;
176
177   //If any other key was pressed during the layer mod hold period,
178   //then the layer mod was used momentarily, and should block latching
179   default:
180     singular_key = false;
181     break;
182   }
183
184   //FUNCSHIFT has been shifted by the SHIFT handling, some keys need to be excluded
185   if (layer == _FUNCSHIFT) {
186         //F1-F12 should be sent as unshifted keycodes, 
187         //and ] needs to be unshifted or it is sent as }
188         if ( (keycode >= KC_F1 && keycode <= KC_F12)
189            || keycode == KC_RBRC ) {
190                 if (record->event.pressed) {
191               unregister_mods(MOD_LSFT);
192           } else {
193               register_mods(MOD_LSFT);
194           }
195         }
196   }
197
198   return true;
199 };
200
201 void matrix_scan_user(void) {
202     uint8_t layer = biton32(layer_state);
203     
204     switch (layer) {
205         case _MALT:
206                 set_led_off;
207                 break;
208         case _FUNCTION:
209             set_led_blue;
210             break;
211         case _SHIFTED:
212             set_led_red;
213             break;
214         case _FUNCSHIFT:
215                 set_led_green;
216                 break;
217         default:
218             break;
219     }
220 };
221