]>
git.gir.st - tmk_keyboard.git/blob - tmk_core/common/keymap.c
2 Copyright 2013 Jun Wako <wakojun@gmail.com>
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.
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.
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/>.
20 #include "action_layer.h"
22 #include "action_macro.h"
25 #include "bootloader.h"
28 static action_t
keycode_to_action(uint8_t keycode
);
31 /* converts key to action */
32 action_t
action_for_key(uint8_t layer
, keypos_t key
)
34 uint8_t keycode
= keymap_key_to_keycode(layer
, key
);
36 case KC_FN0
... KC_FN31
:
37 return keymap_fn_to_action(keycode
);
38 #ifdef BOOTMAGIC_ENABLE
41 if (keymap_config
.swap_control_capslock
|| keymap_config
.capslock_to_control
) {
42 return keycode_to_action(KC_LCTL
);
44 return keycode_to_action(keycode
);
46 if (keymap_config
.swap_control_capslock
) {
47 return keycode_to_action(KC_CAPSLOCK
);
49 return keycode_to_action(KC_LCTL
);
51 if (keymap_config
.swap_lalt_lgui
) {
52 if (keymap_config
.no_gui
) {
53 return keycode_to_action(ACTION_NO
);
55 return keycode_to_action(KC_LGUI
);
57 return keycode_to_action(KC_LALT
);
59 if (keymap_config
.swap_lalt_lgui
) {
60 return keycode_to_action(KC_LALT
);
62 if (keymap_config
.no_gui
) {
63 return keycode_to_action(ACTION_NO
);
65 return keycode_to_action(KC_LGUI
);
67 if (keymap_config
.swap_ralt_rgui
) {
68 if (keymap_config
.no_gui
) {
69 return keycode_to_action(ACTION_NO
);
71 return keycode_to_action(KC_RGUI
);
73 return keycode_to_action(KC_RALT
);
75 if (keymap_config
.swap_ralt_rgui
) {
76 return keycode_to_action(KC_RALT
);
78 if (keymap_config
.no_gui
) {
79 return keycode_to_action(ACTION_NO
);
81 return keycode_to_action(KC_RGUI
);
83 if (keymap_config
.swap_grave_esc
) {
84 return keycode_to_action(KC_ESC
);
86 return keycode_to_action(KC_GRAVE
);
88 if (keymap_config
.swap_grave_esc
) {
89 return keycode_to_action(KC_GRAVE
);
91 return keycode_to_action(KC_ESC
);
93 if (keymap_config
.swap_backslash_backspace
) {
94 return keycode_to_action(KC_BSPACE
);
96 return keycode_to_action(KC_BSLASH
);
98 if (keymap_config
.swap_backslash_backspace
) {
99 return keycode_to_action(KC_BSLASH
);
101 return keycode_to_action(KC_BSPACE
);
104 return keycode_to_action(keycode
);
110 __attribute__ ((weak
))
111 const macro_t
*action_get_macro(keyrecord_t
*record
, uint8_t id
, uint8_t opt
)
120 __attribute__ ((weak
))
121 void action_function(keyrecord_t
*record
, uint8_t id
, uint8_t opt
)
130 /* translates keycode to action */
131 static action_t
keycode_to_action(uint8_t keycode
)
135 case KC_A
... KC_EXSEL
:
136 case KC_LCTRL
... KC_RGUI
:
137 action
.code
= ACTION_KEY(keycode
);
139 case KC_SYSTEM_POWER
... KC_SYSTEM_WAKE
:
140 action
.code
= ACTION_USAGE_SYSTEM(KEYCODE2SYSTEM(keycode
));
142 case KC_AUDIO_MUTE
... KC_MEDIA_REWIND
:
143 action
.code
= ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(keycode
));
145 case KC_MS_UP
... KC_MS_ACCEL2
:
146 action
.code
= ACTION_MOUSEKEY(keycode
);
149 action
.code
= ACTION_TRANSPARENT
;
154 bootloader_jump(); // not return
157 action
.code
= ACTION_NO
;
165 #ifdef USE_LEGACY_KEYMAP
167 * Legacy keymap support
168 * Consider using new keymap API instead.
170 __attribute__ ((weak
))
171 uint8_t keymap_key_to_keycode(uint8_t layer
, keypos_t key
)
173 return keymap_get_keycode(layer
, key
.row
, key
.col
);
177 /* Legacy keymap support */
178 __attribute__ ((weak
))
179 action_t
keymap_fn_to_action(uint8_t keycode
)
181 action_t action
= { .code
= ACTION_NO
};
183 case KC_FN0
... KC_FN31
:
185 uint8_t layer
= keymap_fn_layer(FN_INDEX(keycode
));
186 uint8_t key
= keymap_fn_keycode(FN_INDEX(keycode
));
188 action
.code
= ACTION_LAYER_TAP_KEY(layer
, key
);
190 action
.code
= ACTION_LAYER_MOMENTARY(layer
);