]> git.gir.st - tmk_keyboard.git/blob - common/keymap.c
Merge branch 'transparent'
[tmk_keyboard.git] / common / keymap.c
1 /*
2 Copyright 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 #include "keymap.h"
18 #include "report.h"
19 #include "keycode.h"
20 #include "action.h"
21
22
23 /* layer */
24 uint8_t default_layer = 0;
25 uint8_t current_layer = 0;
26
27
28 action_t keymap_keycode_to_action(uint8_t keycode)
29 {
30 action_t action;
31 switch (keycode) {
32 case KC_A ... KC_EXSEL:
33 action.code = ACTION_KEY(keycode);
34 break;
35 case KC_LCTRL ... KC_LGUI:
36 action.code = ACTION_LMOD(keycode);
37 break;
38 case KC_RCTRL ... KC_RGUI:
39 action.code = ACTION_RMOD(keycode);
40 break;
41 case KC_SYSTEM_POWER ... KC_SYSTEM_WAKE:
42 action.code = ACTION_USAGE_SYSTEM(KEYCODE2SYSTEM(keycode));
43 break;
44 case KC_AUDIO_MUTE ... KC_WWW_FAVORITES:
45 action.code = ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(keycode));
46 break;
47 case KC_MS_UP ... KC_MS_ACCEL2:
48 action.code = ACTION_MOUSEKEY(keycode);
49 break;
50 case KC_TRNS:
51 action.code = ACTION_TRANSPARENT;
52 break;
53 default:
54 action.code = ACTION_NO;
55 break;
56 }
57 return action;
58 }
59
60 #ifndef NO_LEGACY_KEYMAP_SUPPORT
61 /* legacy support with weak reference */
62 __attribute__ ((weak))
63 action_t keymap_get_action(uint8_t layer, uint8_t row, uint8_t col)
64 {
65 /* convert from legacy keycode to action */
66 uint8_t keycode = keymap_get_keycode(layer, row, col);
67 action_t action;
68 switch (keycode) {
69 case KC_FN0 ... KC_FN31:
70 {
71 uint8_t layer = keymap_fn_layer(FN_INDEX(keycode));
72 uint8_t key = keymap_fn_keycode(FN_INDEX(keycode));
73 if (key) {
74 action.code = ACTION_LAYER_SET_TAP_KEY(layer, key);
75 } else {
76 action.code = ACTION_LAYER_SET_MOMENTARY(layer);
77 }
78 }
79 return action;
80 default:
81 return keymap_keycode_to_action(keycode);
82 }
83 }
84 #endif
85
86 __attribute__ ((weak))
87 void keymap_call_function(keyrecord_t *event, uint8_t id, uint8_t opt)
88 {
89 }
Imprint / Impressum