aboutsummaryrefslogtreecommitdiff
path: root/common/keymap.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/keymap.c')
-rw-r--r--common/keymap.c56
1 files changed, 36 insertions, 20 deletions
diff --git a/common/keymap.c b/common/keymap.c
index 8302c2704..2782ea9d6 100644
--- a/common/keymap.c
+++ b/common/keymap.c
@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
17#include "keymap.h" 17#include "keymap.h"
18#include "report.h" 18#include "report.h"
19#include "keycode.h" 19#include "keycode.h"
20#include "action.h"
20 21
21 22
22/* layer */ 23/* layer */
@@ -24,47 +25,62 @@ uint8_t default_layer = 0;
24uint8_t current_layer = 0; 25uint8_t current_layer = 0;
25 26
26 27
27#ifndef NO_LEGACY_KEYMAP_SUPPORT 28action_t keymap_keycode_to_action(uint8_t keycode)
28/* legacy support with weak reference */
29__attribute__ ((weak))
30action_t keymap_get_action(uint8_t layer, uint8_t row, uint8_t col)
31{ 29{
32 /* convert from legacy keycode to action */
33 uint8_t key = keymap_get_keycode(layer, row, col);
34 action_t action; 30 action_t action;
35 switch (key) { 31 switch (keycode) {
36 case KC_A ... KC_EXSEL: 32 case KC_A ... KC_EXSEL:
37 action.code = ACTION_KEY(key); 33 action.code = ACTION_KEY(keycode);
38 break; 34 break;
39 case KC_LCTRL ... KC_LGUI: 35 case KC_LCTRL ... KC_LGUI:
40 action.code = ACTION_LMOD(key); 36 action.code = ACTION_LMOD(keycode);
41 break; 37 break;
42 case KC_RCTRL ... KC_RGUI: 38 case KC_RCTRL ... KC_RGUI:
43 action.code = ACTION_RMOD(key); 39 action.code = ACTION_RMOD(keycode);
44 break; 40 break;
45 case KC_SYSTEM_POWER ... KC_SYSTEM_WAKE: 41 case KC_SYSTEM_POWER ... KC_SYSTEM_WAKE:
46 action.code = ACTION_USAGE_SYSTEM(KEYCODE2SYSTEM(key)); 42 action.code = ACTION_USAGE_SYSTEM(KEYCODE2SYSTEM(keycode));
47 break; 43 break;
48 case KC_AUDIO_MUTE ... KC_WWW_FAVORITES: 44 case KC_AUDIO_MUTE ... KC_WWW_FAVORITES:
49 action.code = ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(key)); 45 action.code = ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(keycode));
50 break; 46 break;
51 case KC_MS_UP ... KC_MS_ACCEL2: 47 case KC_MS_UP ... KC_MS_ACCEL2:
52 action.code = ACTION_MOUSEKEY(key); 48 action.code = ACTION_MOUSEKEY(keycode);
53 break; 49 break;
54 case KC_FN0 ... KC_FN31: 50 case KC_TRNS:
55 { 51 action.code = ACTION_TRANSPARENT;
56 uint8_t layer = keymap_fn_layer(FN_INDEX(key));
57 uint8_t code = keymap_fn_keycode(FN_INDEX(key));
58 action.code = ACTION_LAYER_SET_TAP_KEY(layer, code);
59 }
60 break; 52 break;
61 case KC_NO ... KC_UNDEFINED:
62 default: 53 default:
63 action.code = ACTION_NO; 54 action.code = ACTION_NO;
64 break; 55 break;
65 } 56 }
66 return action; 57 return action;
67} 58}
59
60#ifndef NO_LEGACY_KEYMAP_SUPPORT
61/* legacy support with weak reference */
62__attribute__ ((weak))
63action_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}
68#endif 84#endif
69 85
70__attribute__ ((weak)) 86__attribute__ ((weak))