Skip to content

Commit 671cacc

Browse files
committed
core: action codes are action_t struct now
1 parent b4fdb27 commit 671cacc

File tree

4 files changed

+21
-23
lines changed

4 files changed

+21
-23
lines changed

common/action_code.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ typedef union {
181181

182182

183183
/* action utility */
184-
#define ACTION_NO 0
185-
#define ACTION_TRANSPARENT 1
186-
#define ACTION(kind, param) ((kind)<<12 | (param))
184+
#define ACTION_NO { .code = 0 }
185+
#define ACTION_TRANSPARENT { .code = 1 }
186+
#define ACTION(kind, param) { .code = ((kind)<<12 | (param)) }
187187

188188

189189
/*

common/action_layer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,15 @@ void layer_debug(void)
117117

118118
action_t layer_switch_get_action(keypos_t key)
119119
{
120-
action_t action = { .code = ACTION_TRANSPARENT };
120+
action_t action = ACTION_TRANSPARENT;
121121

122122
#ifndef NO_ACTION_LAYER
123123
uint32_t layers = layer_state | default_layer_state;
124124
/* check top layer first */
125125
for (int8_t i = 31; i >= 0; i--) {
126126
if (layers & (1UL<<i)) {
127127
action = action_for_key(i, key);
128-
if (action.code != ACTION_TRANSPARENT) {
128+
if (action.code != (action_t)ACTION_TRANSPARENT.code) {
129129
return action;
130130
}
131131
}

common/actionmap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2525

2626

2727
/* Keymapping with 16bit action codes */
28-
extern const uint16_t actionmaps[][MATRIX_ROWS][MATRIX_COLS];
28+
extern const action_t actionmaps[][MATRIX_ROWS][MATRIX_COLS];
2929

3030

3131
/* Modified key */

common/keymap.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ action_t action_for_key(uint8_t layer, keypos_t key)
5353
case KC_LALT:
5454
if (keymap_config.swap_lalt_lgui) {
5555
if (keymap_config.no_gui) {
56-
return keycode_to_action(ACTION_NO);
56+
return keycode_to_action(KC_NO);
5757
}
5858
return keycode_to_action(KC_LGUI);
5959
}
@@ -63,13 +63,13 @@ action_t action_for_key(uint8_t layer, keypos_t key)
6363
return keycode_to_action(KC_LALT);
6464
}
6565
if (keymap_config.no_gui) {
66-
return keycode_to_action(ACTION_NO);
66+
return keycode_to_action(KC_NO);
6767
}
6868
return keycode_to_action(KC_LGUI);
6969
case KC_RALT:
7070
if (keymap_config.swap_ralt_rgui) {
7171
if (keymap_config.no_gui) {
72-
return keycode_to_action(ACTION_NO);
72+
return keycode_to_action(KC_NO);
7373
}
7474
return keycode_to_action(KC_RGUI);
7575
}
@@ -79,7 +79,7 @@ action_t action_for_key(uint8_t layer, keypos_t key)
7979
return keycode_to_action(KC_RALT);
8080
}
8181
if (keymap_config.no_gui) {
82-
return keycode_to_action(ACTION_NO);
82+
return keycode_to_action(KC_NO);
8383
}
8484
return keycode_to_action(KC_RGUI);
8585
case KC_GRAVE:
@@ -133,34 +133,33 @@ void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
133133
/* translates keycode to action */
134134
static action_t keycode_to_action(uint8_t keycode)
135135
{
136-
action_t action = {};
137136
switch (keycode) {
138137
case KC_A ... KC_EXSEL:
139138
case KC_LCTRL ... KC_RGUI:
140-
action.code = ACTION_KEY(keycode);
139+
return (action_t)ACTION_KEY(keycode);
141140
break;
142141
case KC_SYSTEM_POWER ... KC_SYSTEM_WAKE:
143-
action.code = ACTION_USAGE_SYSTEM(KEYCODE2SYSTEM(keycode));
142+
return (action_t)ACTION_USAGE_SYSTEM(KEYCODE2SYSTEM(keycode));
144143
break;
145144
case KC_AUDIO_MUTE ... KC_WWW_FAVORITES:
146-
action.code = ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(keycode));
145+
return (action_t)ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(keycode));
147146
break;
148147
case KC_MS_UP ... KC_MS_ACCEL2:
149-
action.code = ACTION_MOUSEKEY(keycode);
148+
return (action_t)ACTION_MOUSEKEY(keycode);
150149
break;
151150
case KC_TRNS:
152-
action.code = ACTION_TRANSPARENT;
151+
return (action_t)ACTION_TRANSPARENT;
153152
break;
154153
case KC_BOOTLOADER:
155154
clear_keyboard();
156155
wait_ms(50);
157156
bootloader_jump(); // not return
158157
break;
159158
default:
160-
action.code = ACTION_NO;
159+
return (action_t)ACTION_NO;
161160
break;
162161
}
163-
return action;
162+
return (action_t)ACTION_NO;
164163
}
165164

166165

@@ -181,21 +180,20 @@ uint8_t keymap_key_to_keycode(uint8_t layer, keypos_t key)
181180
__attribute__ ((weak))
182181
action_t keymap_fn_to_action(uint8_t keycode)
183182
{
184-
action_t action = { .code = ACTION_NO };
185183
switch (keycode) {
186184
case KC_FN0 ... KC_FN31:
187185
{
188186
uint8_t layer = keymap_fn_layer(FN_INDEX(keycode));
189187
uint8_t key = keymap_fn_keycode(FN_INDEX(keycode));
190188
if (key) {
191-
action.code = ACTION_LAYER_TAP_KEY(layer, key);
189+
return (action_t)ACTION_LAYER_TAP_KEY(layer, key);
192190
} else {
193-
action.code = ACTION_LAYER_MOMENTARY(layer);
191+
return (action_t)ACTION_LAYER_MOMENTARY(layer);
194192
}
195193
}
196-
return action;
194+
return (action_t)ACTION_NO;
197195
default:
198-
return action;
196+
return (action_t)ACTION_NO;
199197
}
200198
}
201199
#endif

0 commit comments

Comments
 (0)