@@ -43,7 +43,7 @@ struct combo_cfg {
43
43
};
44
44
45
45
struct active_combo {
46
- struct combo_cfg * combo ;
46
+ const struct combo_cfg * combo ;
47
47
// key_positions_pressed is filled with key_positions when the combo is pressed.
48
48
// The keys are removed from this array when they are released.
49
49
// Once this array is empty, the behavior is released.
@@ -53,7 +53,7 @@ struct active_combo {
53
53
};
54
54
55
55
struct combo_candidate {
56
- struct combo_cfg * combo ;
56
+ const struct combo_cfg * combo ;
57
57
// the time after which this behavior should be removed from candidates.
58
58
// by keeping track of when the candidate should be cleared there is no
59
59
// possibility of accidental releases.
@@ -66,9 +66,9 @@ struct zmk_position_state_changed_event pressed_keys[CONFIG_ZMK_COMBO_MAX_KEYS_P
66
66
// the set of candidate combos based on the currently pressed_keys
67
67
struct combo_candidate candidates [CONFIG_ZMK_COMBO_MAX_COMBOS_PER_KEY ];
68
68
// the last candidate that was completely pressed
69
- struct combo_cfg * fully_pressed_combo = NULL ;
69
+ const struct combo_cfg * fully_pressed_combo = NULL ;
70
70
// a lookup dict that maps a key position to all combos on that position
71
- struct combo_cfg * combo_lookup [ZMK_KEYMAP_LEN ][CONFIG_ZMK_COMBO_MAX_COMBOS_PER_KEY ] = {NULL };
71
+ const struct combo_cfg * combo_lookup [ZMK_KEYMAP_LEN ][CONFIG_ZMK_COMBO_MAX_COMBOS_PER_KEY ] = {NULL };
72
72
// combos that have been activated and still have (some) keys pressed
73
73
// this array is always contiguous from 0.
74
74
struct active_combo active_combos [CONFIG_ZMK_COMBO_MAX_PRESSED_COMBOS ] = {NULL };
@@ -90,18 +90,18 @@ static void store_last_tapped(int64_t timestamp) {
90
90
91
91
// Store the combo key pointer in the combos array, one pointer for each key position
92
92
// The combos are sorted shortest-first, then by virtual-key-position.
93
- static int initialize_combo (struct combo_cfg * new_combo ) {
93
+ static int initialize_combo (const struct combo_cfg * new_combo ) {
94
94
for (int i = 0 ; i < new_combo -> key_position_len ; i ++ ) {
95
95
int32_t position = new_combo -> key_positions [i ];
96
96
if (position >= ZMK_KEYMAP_LEN ) {
97
97
LOG_ERR ("Unable to initialize combo, key position %d does not exist" , position );
98
98
return - EINVAL ;
99
99
}
100
100
101
- struct combo_cfg * insert_combo = new_combo ;
101
+ const struct combo_cfg * insert_combo = new_combo ;
102
102
bool set = false;
103
103
for (int j = 0 ; j < CONFIG_ZMK_COMBO_MAX_COMBOS_PER_KEY ; j ++ ) {
104
- struct combo_cfg * combo_at_j = combo_lookup [position ][j ];
104
+ const struct combo_cfg * combo_at_j = combo_lookup [position ][j ];
105
105
if (combo_at_j == NULL ) {
106
106
combo_lookup [position ][j ] = insert_combo ;
107
107
set = true;
@@ -125,7 +125,7 @@ static int initialize_combo(struct combo_cfg *new_combo) {
125
125
return 0 ;
126
126
}
127
127
128
- static bool combo_active_on_layer (struct combo_cfg * combo , uint8_t layer ) {
128
+ static bool combo_active_on_layer (const struct combo_cfg * combo , uint8_t layer ) {
129
129
if (combo -> layers [0 ] == -1 ) {
130
130
// -1 in the first layer position is global layer scope
131
131
return true;
@@ -138,15 +138,15 @@ static bool combo_active_on_layer(struct combo_cfg *combo, uint8_t layer) {
138
138
return false;
139
139
}
140
140
141
- static bool is_quick_tap (struct combo_cfg * combo , int64_t timestamp ) {
141
+ static bool is_quick_tap (const struct combo_cfg * combo , int64_t timestamp ) {
142
142
return (last_tapped_timestamp + combo -> require_prior_idle_ms ) > timestamp ;
143
143
}
144
144
145
145
static int setup_candidates_for_first_keypress (int32_t position , int64_t timestamp ) {
146
146
int number_of_combo_candidates = 0 ;
147
147
uint8_t highest_active_layer = zmk_keymap_highest_layer_active ();
148
148
for (int i = 0 ; i < CONFIG_ZMK_COMBO_MAX_COMBOS_PER_KEY ; i ++ ) {
149
- struct combo_cfg * combo = combo_lookup [position ][i ];
149
+ const struct combo_cfg * combo = combo_lookup [position ][i ];
150
150
if (combo == NULL ) {
151
151
return number_of_combo_candidates ;
152
152
}
@@ -166,8 +166,8 @@ static int filter_candidates(int32_t position) {
166
166
int matches = 0 , lookup_idx = 0 , candidate_idx = 0 ;
167
167
while (lookup_idx < CONFIG_ZMK_COMBO_MAX_COMBOS_PER_KEY &&
168
168
candidate_idx < CONFIG_ZMK_COMBO_MAX_COMBOS_PER_KEY ) {
169
- struct combo_cfg * candidate = candidates [candidate_idx ].combo ;
170
- struct combo_cfg * lookup = combo_lookup [position ][lookup_idx ];
169
+ const struct combo_cfg * candidate = candidates [candidate_idx ].combo ;
170
+ const struct combo_cfg * lookup = combo_lookup [position ][lookup_idx ];
171
171
if (candidate == NULL || lookup == NULL ) {
172
172
break ;
173
173
}
@@ -207,7 +207,7 @@ static int64_t first_candidate_timeout() {
207
207
return first_timeout ;
208
208
}
209
209
210
- static inline bool candidate_is_completely_pressed (struct combo_cfg * candidate ) {
210
+ static inline bool candidate_is_completely_pressed (const struct combo_cfg * candidate ) {
211
211
// this code assumes set(pressed_keys) <= set(candidate->key_positions)
212
212
// this invariant is enforced by filter_candidates
213
213
// since events may have been reraised after clearing one or more slots at
@@ -288,7 +288,7 @@ static int release_pressed_keys() {
288
288
return count ;
289
289
}
290
290
291
- static inline int press_combo_behavior (struct combo_cfg * combo , int32_t timestamp ) {
291
+ static inline int press_combo_behavior (const struct combo_cfg * combo , int32_t timestamp ) {
292
292
struct zmk_behavior_binding_event event = {
293
293
.position = combo -> virtual_key_position ,
294
294
.timestamp = timestamp ,
@@ -302,7 +302,7 @@ static inline int press_combo_behavior(struct combo_cfg *combo, int32_t timestam
302
302
return zmk_behavior_invoke_binding (& combo -> behavior , event , true);
303
303
}
304
304
305
- static inline int release_combo_behavior (struct combo_cfg * combo , int32_t timestamp ) {
305
+ static inline int release_combo_behavior (const struct combo_cfg * combo , int32_t timestamp ) {
306
306
struct zmk_behavior_binding_event event = {
307
307
.position = combo -> virtual_key_position ,
308
308
.timestamp = timestamp ,
@@ -330,7 +330,7 @@ static void move_pressed_keys_to_active_combo(struct active_combo *active_combo)
330
330
pressed_keys_count -= combo_length ;
331
331
}
332
332
333
- static struct active_combo * store_active_combo (struct combo_cfg * combo ) {
333
+ static struct active_combo * store_active_combo (const struct combo_cfg * combo ) {
334
334
for (int i = 0 ; i < CONFIG_ZMK_COMBO_MAX_PRESSED_COMBOS ; i ++ ) {
335
335
if (active_combos [i ].combo == NULL ) {
336
336
active_combos [i ].combo = combo ;
@@ -344,7 +344,7 @@ static struct active_combo *store_active_combo(struct combo_cfg *combo) {
344
344
return NULL ;
345
345
}
346
346
347
- static void activate_combo (struct combo_cfg * combo ) {
347
+ static void activate_combo (const struct combo_cfg * combo ) {
348
348
struct active_combo * active_combo = store_active_combo (combo );
349
349
if (active_combo == NULL ) {
350
350
// unable to store combo
@@ -438,7 +438,7 @@ static int position_state_down(const zmk_event_t *ev, struct zmk_position_state_
438
438
}
439
439
update_timeout_task ();
440
440
441
- struct combo_cfg * candidate_combo = candidates [0 ].combo ;
441
+ const struct combo_cfg * candidate_combo = candidates [0 ].combo ;
442
442
LOG_DBG ("combo: capturing position event %d" , data -> position );
443
443
int ret = capture_pressed_key (data );
444
444
switch (num_candidates ) {
@@ -521,7 +521,7 @@ ZMK_SUBSCRIPTION(combo, zmk_position_state_changed);
521
521
ZMK_SUBSCRIPTION (combo , zmk_keycode_state_changed );
522
522
523
523
#define COMBO_INST (n ) \
524
- static struct combo_cfg combo_config_##n = { \
524
+ static const struct combo_cfg combo_config_##n = { \
525
525
.timeout_ms = DT_PROP(n, timeout_ms), \
526
526
.require_prior_idle_ms = DT_PROP(n, require_prior_idle_ms), \
527
527
.key_positions = DT_PROP(n, key_positions), \
0 commit comments