]> git.donarmstrong.com Git - qmk_firmware.git/blob - quantum/keymap.h
Merge pull request #822 from jackhumbert/hotfix/simplify_to
[qmk_firmware.git] / quantum / keymap.h
1 /*
2 Copyright 2012,2013 Jun Wako <wakojun@gmail.com>
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifndef KEYMAP_H
19 #define KEYMAP_H
20
21 #include <stdint.h>
22 #include <stdbool.h>
23 #include "action.h"
24 #if defined(__AVR__)
25 #include <avr/pgmspace.h>
26 #endif
27 #include "keycode.h"
28 #include "action_macro.h"
29 #include "report.h"
30 #include "host.h"
31 // #include "print.h"
32 #include "debug.h"
33 #include "keycode_config.h"
34
35 // ChibiOS uses RESET in its FlagStatus enumeration
36 // Therefore define it as QK_RESET here, to avoid name collision
37 #if defined(PROTOCOL_CHIBIOS)
38 #define RESET QK_RESET
39 #endif
40
41 /* translates key to keycode */
42 uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key);
43
44 extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
45 extern const uint16_t fn_actions[];
46
47 enum quantum_keycodes {
48     // Ranges used in shortucuts - not to be used directly
49     QK_TMK                = 0x0000,
50     QK_TMK_MAX            = 0x00FF,
51     QK_MODS               = 0x0100,
52     QK_LCTL               = 0x0100,
53     QK_LSFT               = 0x0200,
54     QK_LALT               = 0x0400,
55     QK_LGUI               = 0x0800,
56     QK_RCTL               = 0x1100,
57     QK_RSFT               = 0x1200,
58     QK_RALT               = 0x1400,
59     QK_RGUI               = 0x1800,
60     QK_MODS_MAX           = 0x1FFF,
61     QK_FUNCTION           = 0x2000,
62     QK_FUNCTION_MAX       = 0x2FFF,
63     QK_MACRO              = 0x3000,
64     QK_MACRO_MAX          = 0x3FFF,
65     QK_LAYER_TAP          = 0x4000,
66     QK_LAYER_TAP_MAX      = 0x4FFF,
67     QK_TO                 = 0x5000,
68     QK_TO_MAX             = 0x50FF,
69     QK_MOMENTARY          = 0x5100,
70     QK_MOMENTARY_MAX      = 0x51FF,
71     QK_DEF_LAYER          = 0x5200,
72     QK_DEF_LAYER_MAX      = 0x52FF,
73     QK_TOGGLE_LAYER       = 0x5300,
74     QK_TOGGLE_LAYER_MAX   = 0x53FF,
75     QK_ONE_SHOT_LAYER     = 0x5400,
76     QK_ONE_SHOT_LAYER_MAX = 0x54FF,
77     QK_ONE_SHOT_MOD       = 0x5500,
78     QK_ONE_SHOT_MOD_MAX   = 0x55FF,
79 #ifndef DISABLE_CHORDING
80     QK_CHORDING           = 0x5600,
81     QK_CHORDING_MAX       = 0x56FF,
82 #endif
83     QK_MOD_TAP            = 0x6000,
84     QK_MOD_TAP_MAX        = 0x6FFF,
85     QK_TAP_DANCE          = 0x7100,
86     QK_TAP_DANCE_MAX      = 0x71FF,
87 #ifdef UNICODE_ENABLE
88     QK_UNICODE            = 0x8000,
89     QK_UNICODE_MAX        = 0xFFFF,
90 #endif
91
92     // Loose keycodes - to be used directly
93
94     RESET = 0x7000,
95     DEBUG,
96     MAGIC_SWAP_CONTROL_CAPSLOCK,
97     MAGIC_CAPSLOCK_TO_CONTROL,
98     MAGIC_SWAP_LALT_LGUI,
99     MAGIC_SWAP_RALT_RGUI,
100     MAGIC_NO_GUI,
101     MAGIC_SWAP_GRAVE_ESC,
102     MAGIC_SWAP_BACKSLASH_BACKSPACE,
103     MAGIC_HOST_NKRO,
104     MAGIC_SWAP_ALT_GUI,
105     MAGIC_UNSWAP_CONTROL_CAPSLOCK,
106     MAGIC_UNCAPSLOCK_TO_CONTROL,
107     MAGIC_UNSWAP_LALT_LGUI,
108     MAGIC_UNSWAP_RALT_RGUI,
109     MAGIC_UNNO_GUI,
110     MAGIC_UNSWAP_GRAVE_ESC,
111     MAGIC_UNSWAP_BACKSLASH_BACKSPACE,
112     MAGIC_UNHOST_NKRO,
113     MAGIC_UNSWAP_ALT_GUI,
114     MAGIC_TOGGLE_NKRO,
115
116     // Leader key
117 #ifndef DISABLE_LEADER
118     KC_LEAD,
119 #endif
120
121     // Audio on/off/toggle
122     AU_ON,
123     AU_OFF,
124     AU_TOG,
125
126     // Music mode on/off/toggle
127     MU_ON,
128     MU_OFF,
129     MU_TOG,
130
131     // Music voice iterate
132     MUV_IN,
133     MUV_DE,
134
135     // Midi mode on/off
136     MIDI_ON,
137     MIDI_OFF,
138
139     // Backlight functionality
140     BL_0,
141     BL_1,
142     BL_2,
143     BL_3,
144     BL_4,
145     BL_5,
146     BL_6,
147     BL_7,
148     BL_8,
149     BL_9,
150     BL_10,
151     BL_11,
152     BL_12,
153     BL_13,
154     BL_14,
155     BL_15,
156     BL_DEC,
157     BL_INC,
158     BL_TOGG,
159     BL_STEP,
160
161     // RGB functionality
162     RGB_TOG,
163     RGB_MOD,
164     RGB_HUI,
165     RGB_HUD,
166     RGB_SAI,
167     RGB_SAD,
168     RGB_VAI,
169     RGB_VAD,
170
171     // Left shift, open paren
172     KC_LSPO,
173
174     // Right shift, close paren
175     KC_RSPC,
176
177     // always leave at the end
178     SAFE_RANGE
179 };
180
181 // Ability to use mods in layouts
182 #define LCTL(kc) (kc | QK_LCTL)
183 #define LSFT(kc) (kc | QK_LSFT)
184 #define LALT(kc) (kc | QK_LALT)
185 #define LGUI(kc) (kc | QK_LGUI)
186 #define RCTL(kc) (kc | QK_RCTL)
187 #define RSFT(kc) (kc | QK_RSFT)
188 #define RALT(kc) (kc | QK_RALT)
189 #define RGUI(kc) (kc | QK_RGUI)
190
191 #define HYPR(kc) (kc | QK_LCTL | QK_LSFT | QK_LALT | QK_LGUI)
192 #define MEH(kc)  (kc | QK_LCTL | QK_LSFT | QK_LALT)
193 #define LCAG(kc) (kc | QK_LCTL | QK_LALT | QK_LGUI)
194 #define ALTG(kc) (kc | QK_RCTL | QK_RALT)
195
196 #define MOD_HYPR 0xf
197 #define MOD_MEH 0x7
198
199
200 // Aliases for shifted symbols
201 // Each key has a 4-letter code, and some have longer aliases too.
202 // While the long aliases are descriptive, the 4-letter codes
203 // make for nicer grid layouts (everything lines up), and are
204 // the preferred style for Quantum.
205 #define KC_TILD LSFT(KC_GRV)    // ~
206 #define KC_TILDE    KC_TILD
207
208 #define KC_EXLM LSFT(KC_1)      // !
209 #define KC_EXCLAIM  KC_EXLM
210
211 #define KC_AT   LSFT(KC_2)      // @
212
213 #define KC_HASH LSFT(KC_3)      // #
214
215 #define KC_DLR  LSFT(KC_4)      // $
216 #define KC_DOLLAR   KC_DLR
217
218 #define KC_PERC LSFT(KC_5)      // %
219 #define KC_PERCENT  KC_PERC
220
221 #define KC_CIRC LSFT(KC_6)      // ^
222 #define KC_CIRCUMFLEX   KC_CIRC
223
224 #define KC_AMPR LSFT(KC_7)      // &
225 #define KC_AMPERSAND    KC_AMPR
226
227 #define KC_ASTR LSFT(KC_8)      // *
228 #define KC_ASTERISK KC_ASTR
229
230 #define KC_LPRN LSFT(KC_9)      // (
231 #define KC_LEFT_PAREN   KC_LPRN
232
233 #define KC_RPRN LSFT(KC_0)      // )
234 #define KC_RIGHT_PAREN  KC_RPRN
235
236 #define KC_UNDS LSFT(KC_MINS)   // _
237 #define KC_UNDERSCORE   KC_UNDS
238
239 #define KC_PLUS LSFT(KC_EQL)    // +
240
241 #define KC_LCBR LSFT(KC_LBRC)   // {
242 #define KC_LEFT_CURLY_BRACE KC_LCBR
243
244 #define KC_RCBR LSFT(KC_RBRC)   // }
245 #define KC_RIGHT_CURLY_BRACE    KC_RCBR
246
247 #define KC_LABK LSFT(KC_COMM)   // <
248 #define KC_LEFT_ANGLE_BRACKET   KC_LABK
249
250 #define KC_RABK LSFT(KC_DOT)    // >
251 #define KC_RIGHT_ANGLE_BRACKET  KC_RABK
252
253 #define KC_COLN LSFT(KC_SCLN)   // :
254 #define KC_COLON    KC_COLN
255
256 #define KC_PIPE LSFT(KC_BSLS)   // |
257
258 #define KC_LT LSFT(KC_COMM)     // <
259
260 #define KC_GT LSFT(KC_DOT)      // >
261
262 #define KC_QUES LSFT(KC_SLSH)   // ?
263 #define KC_QUESTION KC_QUES
264
265 #define KC_DQT LSFT(KC_QUOT)   // "
266 #define KC_DOUBLE_QUOTE KC_DQT
267 #define KC_DQUO KC_DQT
268
269 #define KC_DELT KC_DELETE // Del key (four letter code)
270
271 // Alias for function layers than expand past FN31
272 #define FUNC(kc) (kc | QK_FUNCTION)
273
274 // Aliases
275 #define S(kc) LSFT(kc)
276 #define F(kc) FUNC(kc)
277
278 #define M(kc) (kc | QK_MACRO)
279
280 #define MACRODOWN(...) (record->event.pressed ? MACRO(__VA_ARGS__) : MACRO_NONE)
281
282 // L-ayer, T-ap - 256 keycode max, 16 layer max
283 #define LT(layer, kc) (kc | QK_LAYER_TAP | ((layer & 0xF) << 8))
284
285 #define AG_SWAP MAGIC_SWAP_ALT_GUI
286 #define AG_NORM MAGIC_UNSWAP_ALT_GUI
287
288 #define BL_ON  BL_9
289 #define BL_OFF BL_0
290
291 #define MI_ON MIDI_ON
292 #define MI_OFF MIDI_OFF
293
294 // GOTO layer - 16 layers max
295 // when:
296 // ON_PRESS    = 1
297 // ON_RELEASE  = 2
298 // Unless you have a good reason not to do so, prefer  ON_PRESS (1) as your default.
299 // In fact, we changed it to assume ON_PRESS for sanity/simplicity. If needed, you can add your own
300 // keycode modeled after the old version, kept below for this.
301 /* #define TO(layer, when) (layer | QK_TO | (when << 0x4)) */
302 #define TO(layer) (layer | QK_TO | (ON_PRESS << 0x4))
303
304 // Momentary switch layer - 256 layer max
305 #define MO(layer) (layer | QK_MOMENTARY)
306
307 // Set default layer - 256 layer max
308 #define DF(layer) (layer | QK_DEF_LAYER)
309
310 // Toggle to layer - 256 layer max
311 #define TG(layer) (layer | QK_TOGGLE_LAYER)
312
313 // One-shot layer - 256 layer max
314 #define OSL(layer) (layer | QK_ONE_SHOT_LAYER)
315
316 // One-shot mod
317 #define OSM(mod) (mod | QK_ONE_SHOT_MOD)
318
319 // M-od, T-ap - 256 keycode max
320 #define MT(mod, kc) (kc | QK_MOD_TAP | ((mod & 0xF) << 8))
321 #define CTL_T(kc) MT(MOD_LCTL, kc)
322 #define SFT_T(kc) MT(MOD_LSFT, kc)
323 #define ALT_T(kc) MT(MOD_LALT, kc)
324 #define GUI_T(kc) MT(MOD_LGUI, kc)
325 #define C_S_T(kc) MT((MOD_LCTL | MOD_LSFT), kc) // Control + Shift e.g. for gnome-terminal
326 #define MEH_T(kc) MT((MOD_LCTL | MOD_LSFT | MOD_LALT), kc) // Meh is a less hyper version of the Hyper key -- doesn't include Win or Cmd, so just alt+shift+ctrl
327 #define LCAG_T(kc) MT((MOD_LCTL | MOD_LALT | MOD_LGUI), kc) // Left control alt and gui
328 #define ALL_T(kc) MT((MOD_LCTL | MOD_LSFT | MOD_LALT | MOD_LGUI), kc) // see http://brettterpstra.com/2012/12/08/a-useful-caps-lock-key/
329
330 // Dedicated keycode versions for Hyper and Meh, if you want to use them as standalone keys rather than mod-tap
331 #define KC_HYPR HYPR(KC_NO)
332 #define KC_MEH  MEH(KC_NO)
333
334 #ifdef UNICODE_ENABLE
335     // For sending unicode codes.
336     // You may not send codes over 7FFF -- this supports most of UTF8.
337     // To have a key that sends out Œ, go UC(0x0152)
338     #define UNICODE(n) (n | QK_UNICODE)
339     #define UC(n) UNICODE(n)
340 #endif
341
342
343 #endif