1
0

core: action codes are action_t struct now

This commit is contained in:
tmk 2016-03-30 03:37:57 +09:00
parent 9839bb83d9
commit e5cb8469af
4 changed files with 21 additions and 23 deletions

View File

@ -181,9 +181,9 @@ typedef union {
/* action utility */ /* action utility */
#define ACTION_NO 0 #define ACTION_NO { .code = 0 }
#define ACTION_TRANSPARENT 1 #define ACTION_TRANSPARENT { .code = 1 }
#define ACTION(kind, param) ((kind)<<12 | (param)) #define ACTION(kind, param) { .code = ((kind)<<12 | (param)) }
/* /*

View File

@ -117,7 +117,7 @@ void layer_debug(void)
action_t layer_switch_get_action(keypos_t key) action_t layer_switch_get_action(keypos_t key)
{ {
action_t action = { .code = ACTION_TRANSPARENT }; action_t action = ACTION_TRANSPARENT;
#ifndef NO_ACTION_LAYER #ifndef NO_ACTION_LAYER
uint32_t layers = layer_state | default_layer_state; uint32_t layers = layer_state | default_layer_state;
@ -125,7 +125,7 @@ action_t layer_switch_get_action(keypos_t key)
for (int8_t i = 31; i >= 0; i--) { for (int8_t i = 31; i >= 0; i--) {
if (layers & (1UL<<i)) { if (layers & (1UL<<i)) {
action = action_for_key(i, key); action = action_for_key(i, key);
if (action.code != ACTION_TRANSPARENT) { if (action.code != (action_t)ACTION_TRANSPARENT.code) {
return action; return action;
} }
} }

View File

@ -25,7 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* Keymapping with 16bit action codes */ /* Keymapping with 16bit action codes */
extern const uint16_t actionmaps[][MATRIX_ROWS][MATRIX_COLS]; extern const action_t actionmaps[][MATRIX_ROWS][MATRIX_COLS];
/* Modified key */ /* Modified key */

View File

@ -53,7 +53,7 @@ action_t action_for_key(uint8_t layer, keypos_t key)
case KC_LALT: case KC_LALT:
if (keymap_config.swap_lalt_lgui) { if (keymap_config.swap_lalt_lgui) {
if (keymap_config.no_gui) { if (keymap_config.no_gui) {
return keycode_to_action(ACTION_NO); return keycode_to_action(KC_NO);
} }
return keycode_to_action(KC_LGUI); return keycode_to_action(KC_LGUI);
} }
@ -63,13 +63,13 @@ action_t action_for_key(uint8_t layer, keypos_t key)
return keycode_to_action(KC_LALT); return keycode_to_action(KC_LALT);
} }
if (keymap_config.no_gui) { if (keymap_config.no_gui) {
return keycode_to_action(ACTION_NO); return keycode_to_action(KC_NO);
} }
return keycode_to_action(KC_LGUI); return keycode_to_action(KC_LGUI);
case KC_RALT: case KC_RALT:
if (keymap_config.swap_ralt_rgui) { if (keymap_config.swap_ralt_rgui) {
if (keymap_config.no_gui) { if (keymap_config.no_gui) {
return keycode_to_action(ACTION_NO); return keycode_to_action(KC_NO);
} }
return keycode_to_action(KC_RGUI); return keycode_to_action(KC_RGUI);
} }
@ -79,7 +79,7 @@ action_t action_for_key(uint8_t layer, keypos_t key)
return keycode_to_action(KC_RALT); return keycode_to_action(KC_RALT);
} }
if (keymap_config.no_gui) { if (keymap_config.no_gui) {
return keycode_to_action(ACTION_NO); return keycode_to_action(KC_NO);
} }
return keycode_to_action(KC_RGUI); return keycode_to_action(KC_RGUI);
case KC_GRAVE: case KC_GRAVE:
@ -133,23 +133,22 @@ void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
/* translates keycode to action */ /* translates keycode to action */
static action_t keycode_to_action(uint8_t keycode) static action_t keycode_to_action(uint8_t keycode)
{ {
action_t action = {};
switch (keycode) { switch (keycode) {
case KC_A ... KC_EXSEL: case KC_A ... KC_EXSEL:
case KC_LCTRL ... KC_RGUI: case KC_LCTRL ... KC_RGUI:
action.code = ACTION_KEY(keycode); return (action_t)ACTION_KEY(keycode);
break; break;
case KC_SYSTEM_POWER ... KC_SYSTEM_WAKE: case KC_SYSTEM_POWER ... KC_SYSTEM_WAKE:
action.code = ACTION_USAGE_SYSTEM(KEYCODE2SYSTEM(keycode)); return (action_t)ACTION_USAGE_SYSTEM(KEYCODE2SYSTEM(keycode));
break; break;
case KC_AUDIO_MUTE ... KC_WWW_FAVORITES: case KC_AUDIO_MUTE ... KC_WWW_FAVORITES:
action.code = ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(keycode)); return (action_t)ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(keycode));
break; break;
case KC_MS_UP ... KC_MS_ACCEL2: case KC_MS_UP ... KC_MS_ACCEL2:
action.code = ACTION_MOUSEKEY(keycode); return (action_t)ACTION_MOUSEKEY(keycode);
break; break;
case KC_TRNS: case KC_TRNS:
action.code = ACTION_TRANSPARENT; return (action_t)ACTION_TRANSPARENT;
break; break;
case KC_BOOTLOADER: case KC_BOOTLOADER:
clear_keyboard(); clear_keyboard();
@ -157,10 +156,10 @@ static action_t keycode_to_action(uint8_t keycode)
bootloader_jump(); // not return bootloader_jump(); // not return
break; break;
default: default:
action.code = ACTION_NO; return (action_t)ACTION_NO;
break; break;
} }
return action; return (action_t)ACTION_NO;
} }
@ -181,21 +180,20 @@ uint8_t keymap_key_to_keycode(uint8_t layer, keypos_t key)
__attribute__ ((weak)) __attribute__ ((weak))
action_t keymap_fn_to_action(uint8_t keycode) action_t keymap_fn_to_action(uint8_t keycode)
{ {
action_t action = { .code = ACTION_NO };
switch (keycode) { switch (keycode) {
case KC_FN0 ... KC_FN31: case KC_FN0 ... KC_FN31:
{ {
uint8_t layer = keymap_fn_layer(FN_INDEX(keycode)); uint8_t layer = keymap_fn_layer(FN_INDEX(keycode));
uint8_t key = keymap_fn_keycode(FN_INDEX(keycode)); uint8_t key = keymap_fn_keycode(FN_INDEX(keycode));
if (key) { if (key) {
action.code = ACTION_LAYER_TAP_KEY(layer, key); return (action_t)ACTION_LAYER_TAP_KEY(layer, key);
} else { } else {
action.code = ACTION_LAYER_MOMENTARY(layer); return (action_t)ACTION_LAYER_MOMENTARY(layer);
} }
} }
return action; return (action_t)ACTION_NO;
default: default:
return action; return (action_t)ACTION_NO;
} }
} }
#endif #endif