]>
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"
26 static action_t
keycode_to_action(uint8_t keycode
);
29 /* converts key to action */
30 action_t
action_for_key(uint8_t layer
, keypos_t key
)
32 uint8_t keycode
= keymap_key_to_keycode(layer
, key
);
34 case KC_FN0
... KC_FN31
:
35 return keymap_fn_to_action(keycode
);
36 #ifdef BOOTMAGIC_ENABLE
39 if (keymap_config
.swap_control_capslock
|| keymap_config
.capslock_to_control
) {
40 return keycode_to_action(KC_LCTL
);
42 return keycode_to_action(keycode
);
44 if (keymap_config
.swap_control_capslock
) {
45 return keycode_to_action(KC_CAPSLOCK
);
47 return keycode_to_action(KC_LCTL
);
49 if (keymap_config
.swap_lalt_lgui
) {
50 if (keymap_config
.no_gui
) {
51 return keycode_to_action(ACTION_NO
);
53 return keycode_to_action(KC_LGUI
);
55 return keycode_to_action(KC_LALT
);
57 if (keymap_config
.swap_lalt_lgui
) {
58 return keycode_to_action(KC_LALT
);
60 if (keymap_config
.no_gui
) {
61 return keycode_to_action(ACTION_NO
);
63 return keycode_to_action(KC_LGUI
);
65 if (keymap_config
.swap_ralt_rgui
) {
66 if (keymap_config
.no_gui
) {
67 return keycode_to_action(ACTION_NO
);
69 return keycode_to_action(KC_RGUI
);
71 return keycode_to_action(KC_RALT
);
73 if (keymap_config
.swap_ralt_rgui
) {
74 return keycode_to_action(KC_RALT
);
76 if (keymap_config
.no_gui
) {
77 return keycode_to_action(ACTION_NO
);
79 return keycode_to_action(KC_RGUI
);
81 if (keymap_config
.swap_grave_esc
) {
82 return keycode_to_action(KC_ESC
);
84 return keycode_to_action(KC_GRAVE
);
86 if (keymap_config
.swap_grave_esc
) {
87 return keycode_to_action(KC_GRAVE
);
89 return keycode_to_action(KC_ESC
);
91 if (keymap_config
.swap_backslash_backspace
) {
92 return keycode_to_action(KC_BSPACE
);
94 return keycode_to_action(KC_BSLASH
);
96 if (keymap_config
.swap_backslash_backspace
) {
97 return keycode_to_action(KC_BSLASH
);
99 return keycode_to_action(KC_BSPACE
);
102 return keycode_to_action(keycode
);
108 __attribute__ ((weak
))
109 const macro_t
*action_get_macro(keyrecord_t
*record
, uint8_t id
, uint8_t opt
)
118 __attribute__ ((weak
))
119 void action_function(keyrecord_t
*record
, uint8_t id
, uint8_t opt
)
128 /* translates keycode to action */
129 static action_t
keycode_to_action(uint8_t keycode
)
133 case KC_A
... KC_EXSEL
:
134 case KC_LCTRL
... KC_RGUI
:
135 action
.code
= ACTION_KEY(keycode
);
137 case KC_SYSTEM_POWER
... KC_SYSTEM_WAKE
:
138 action
.code
= ACTION_USAGE_SYSTEM(KEYCODE2SYSTEM(keycode
));
140 case KC_AUDIO_MUTE
... KC_MEDIA_REWIND
:
141 action
.code
= ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(keycode
));
143 case KC_MS_UP
... KC_MS_ACCEL2
:
144 action
.code
= ACTION_MOUSEKEY(keycode
);
147 action
.code
= ACTION_TRANSPARENT
;
150 action
.code
= ACTION_NO
;
158 #ifdef USE_LEGACY_KEYMAP
160 * Legacy keymap support
161 * Consider using new keymap API instead.
163 __attribute__ ((weak
))
164 uint8_t keymap_key_to_keycode(uint8_t layer
, keypos_t key
)
166 return keymap_get_keycode(layer
, key
.row
, key
.col
);
170 /* Legacy keymap support */
171 __attribute__ ((weak
))
172 action_t
keymap_fn_to_action(uint8_t keycode
)
174 action_t action
= { .code
= ACTION_NO
};
176 case KC_FN0
... KC_FN31
:
178 uint8_t layer
= keymap_fn_layer(FN_INDEX(keycode
));
179 uint8_t key
= keymap_fn_keycode(FN_INDEX(keycode
));
181 action
.code
= ACTION_LAYER_TAP_KEY(layer
, key
);
183 action
.code
= ACTION_LAYER_MOMENTARY(layer
);