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