Skip to content

Commit c2564d2

Browse files
committed
refactor: Condition source props on CONFIG_ZMK_SPLIT
1 parent d21ba18 commit c2564d2

10 files changed

+79
-30
lines changed

app/include/zmk/behavior.h

+2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ struct zmk_behavior_binding_event {
2626
int layer;
2727
uint32_t position;
2828
int64_t timestamp;
29+
#if IS_ENABLED(CONFIG_ZMK_SPLIT)
2930
uint8_t source;
31+
#endif
3032
};
3133

3234
/**

app/include/zmk/behavior_queue.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
#include <stdint.h>
1111
#include <zmk/behavior.h>
1212

13-
int zmk_behavior_queue_add(uint32_t position, uint8_t source,
13+
int zmk_behavior_queue_add(struct zmk_behavior_binding_event *event,
1414
const struct zmk_behavior_binding behavior, bool press, uint32_t wait);

app/src/behavior.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ int zmk_invoke_behavior_binding(const struct zmk_behavior_binding *src_binding,
9595
case BEHAVIOR_LOCALITY_CENTRAL:
9696
return invoke_locally(&binding, event, pressed);
9797
case BEHAVIOR_LOCALITY_EVENT_SOURCE:
98-
#if ZMK_BLE_IS_CENTRAL
98+
#if ZMK_BLE_IS_CENTRAL // source is a member of event because CONFIG_ZMK_SPLIT is enabled
9999
if (event.source == ZMK_POSITION_STATE_CHANGE_SOURCE_LOCAL) {
100100
return invoke_locally(&binding, event, pressed);
101101
} else {

app/src/behavior_queue.c

+17-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
1515

1616
struct q_item {
1717
uint32_t position;
18+
#if IS_ENABLED(CONFIG_ZMK_SPLIT)
1819
uint8_t source;
20+
#endif
1921
struct zmk_behavior_binding binding;
2022
bool press : 1;
2123
uint32_t wait : 31;
@@ -34,7 +36,12 @@ static void behavior_queue_process_next(struct k_work *work) {
3436
item.binding.param2);
3537

3638
struct zmk_behavior_binding_event event = {
37-
.position = item.position, .timestamp = k_uptime_get(), .source = item.source};
39+
.position = item.position,
40+
.timestamp = k_uptime_get(),
41+
#if IS_ENABLED(CONFIG_ZMK_SPLIT)
42+
.source = item.source
43+
#endif
44+
};
3845

3946
if (item.press) {
4047
zmk_invoke_behavior_binding(&item.binding, event, true);
@@ -51,10 +58,17 @@ static void behavior_queue_process_next(struct k_work *work) {
5158
}
5259
}
5360

54-
int zmk_behavior_queue_add(uint32_t position, uint8_t source,
61+
int zmk_behavior_queue_add(struct zmk_behavior_binding_event *event,
5562
const struct zmk_behavior_binding binding, bool press, uint32_t wait) {
5663
struct q_item item = {
57-
.press = press, .binding = binding, .wait = wait, .position = position, .source = source};
64+
.press = press,
65+
.binding = binding,
66+
.wait = wait,
67+
.position = event->position,
68+
#if IS_ENABLED(CONFIG_ZMK_SPLIT)
69+
.source = event->source,
70+
#endif
71+
};
5872

5973
const int ret = k_msgq_put(&zmk_behavior_queue_msgq, &item, K_NO_WAIT);
6074
if (ret < 0) {

app/src/behaviors/behavior_hold_tap.c

+19-7
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ struct behavior_hold_tap_data {
7676
// this data is specific for each hold-tap
7777
struct active_hold_tap {
7878
int32_t position;
79+
#if IS_ENABLED(CONFIG_ZMK_SPLIT)
7980
uint8_t source;
81+
#endif
8082
uint32_t param_hold;
8183
uint32_t param_tap;
8284
int64_t timestamp;
@@ -250,21 +252,22 @@ static struct active_hold_tap *find_hold_tap(uint32_t position) {
250252
return NULL;
251253
}
252254

253-
static struct active_hold_tap *store_hold_tap(uint32_t position, uint8_t source,
255+
static struct active_hold_tap *store_hold_tap(struct zmk_behavior_binding_event *event,
254256
uint32_t param_hold, uint32_t param_tap,
255-
int64_t timestamp,
256257
const struct behavior_hold_tap_config *config) {
257258
for (int i = 0; i < ZMK_BHV_HOLD_TAP_MAX_HELD; i++) {
258259
if (active_hold_taps[i].position != ZMK_BHV_HOLD_TAP_POSITION_NOT_USED) {
259260
continue;
260261
}
261-
active_hold_taps[i].position = position;
262-
active_hold_taps[i].source = source;
262+
active_hold_taps[i].position = event->position;
263+
#if IS_ENABLED(CONFIG_ZMK_SPLIT)
264+
active_hold_taps[i].source = event->source;
265+
#endif
263266
active_hold_taps[i].status = STATUS_UNDECIDED;
264267
active_hold_taps[i].config = config;
265268
active_hold_taps[i].param_hold = param_hold;
266269
active_hold_taps[i].param_tap = param_tap;
267-
active_hold_taps[i].timestamp = timestamp;
270+
active_hold_taps[i].timestamp = event->timestamp;
268271
active_hold_taps[i].position_of_first_other_key_pressed = -1;
269272
return &active_hold_taps[i];
270273
}
@@ -402,7 +405,9 @@ static int press_hold_binding(struct active_hold_tap *hold_tap) {
402405
struct zmk_behavior_binding_event event = {
403406
.position = hold_tap->position,
404407
.timestamp = hold_tap->timestamp,
408+
#if IS_ENABLED(CONFIG_ZMK_SPLIT)
405409
.source = hold_tap->source,
410+
#endif
406411
};
407412

408413
struct zmk_behavior_binding binding = {.behavior_dev = hold_tap->config->hold_behavior_dev,
@@ -414,7 +419,9 @@ static int press_tap_binding(struct active_hold_tap *hold_tap) {
414419
struct zmk_behavior_binding_event event = {
415420
.position = hold_tap->position,
416421
.timestamp = hold_tap->timestamp,
422+
#if IS_ENABLED(CONFIG_ZMK_SPLIT)
417423
.source = hold_tap->source,
424+
#endif
418425
};
419426

420427
struct zmk_behavior_binding binding = {.behavior_dev = hold_tap->config->tap_behavior_dev,
@@ -427,7 +434,9 @@ static int release_hold_binding(struct active_hold_tap *hold_tap) {
427434
struct zmk_behavior_binding_event event = {
428435
.position = hold_tap->position,
429436
.timestamp = hold_tap->timestamp,
437+
#if IS_ENABLED(CONFIG_ZMK_SPLIT)
430438
.source = hold_tap->source,
439+
#endif
431440
};
432441

433442
struct zmk_behavior_binding binding = {.behavior_dev = hold_tap->config->hold_behavior_dev,
@@ -439,7 +448,9 @@ static int release_tap_binding(struct active_hold_tap *hold_tap) {
439448
struct zmk_behavior_binding_event event = {
440449
.position = hold_tap->position,
441450
.timestamp = hold_tap->timestamp,
451+
#if IS_ENABLED(CONFIG_ZMK_SPLIT)
442452
.source = hold_tap->source,
453+
#endif
443454
};
444455

445456
struct zmk_behavior_binding binding = {.behavior_dev = hold_tap->config->tap_behavior_dev,
@@ -603,8 +614,9 @@ static int on_hold_tap_binding_pressed(struct zmk_behavior_binding *binding,
603614
return ZMK_BEHAVIOR_OPAQUE;
604615
}
605616

606-
struct active_hold_tap *hold_tap = store_hold_tap(event.position, event.source, binding->param1,
607-
binding->param2, event.timestamp, cfg);
617+
struct active_hold_tap *hold_tap =
618+
store_hold_tap(&event, binding->param1, binding->param2, cfg);
619+
608620
if (hold_tap == NULL) {
609621
LOG_ERR("unable to store hold-tap info, did you press more than %d hold-taps?",
610622
ZMK_BHV_HOLD_TAP_MAX_HELD);

app/src/behaviors/behavior_macro.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ static void replace_params(struct behavior_macro_trigger_state *state,
158158
state->param2_source = PARAM_SOURCE_BINDING;
159159
}
160160

161-
static void queue_macro(uint32_t position, uint8_t source,
161+
static void queue_macro(struct zmk_behavior_binding_event *event,
162162
const struct zmk_behavior_binding bindings[],
163163
struct behavior_macro_trigger_state state,
164164
const struct zmk_behavior_binding *macro_binding) {
@@ -170,14 +170,14 @@ static void queue_macro(uint32_t position, uint8_t source,
170170

171171
switch (state.mode) {
172172
case MACRO_MODE_TAP:
173-
zmk_behavior_queue_add(position, source, binding, true, state.tap_ms);
174-
zmk_behavior_queue_add(position, source, binding, false, state.wait_ms);
173+
zmk_behavior_queue_add(event, binding, true, state.tap_ms);
174+
zmk_behavior_queue_add(event, binding, false, state.wait_ms);
175175
break;
176176
case MACRO_MODE_PRESS:
177-
zmk_behavior_queue_add(position, source, binding, true, state.wait_ms);
177+
zmk_behavior_queue_add(event, binding, true, state.wait_ms);
178178
break;
179179
case MACRO_MODE_RELEASE:
180-
zmk_behavior_queue_add(position, source, binding, false, state.wait_ms);
180+
zmk_behavior_queue_add(event, binding, false, state.wait_ms);
181181
break;
182182
default:
183183
LOG_ERR("Unknown macro mode: %d", state.mode);
@@ -198,7 +198,7 @@ static int on_macro_binding_pressed(struct zmk_behavior_binding *binding,
198198
.start_index = 0,
199199
.count = state->press_bindings_count};
200200

201-
queue_macro(event.position, event.source, cfg->bindings, trigger_state, binding);
201+
queue_macro(&event, cfg->bindings, trigger_state, binding);
202202

203203
return ZMK_BEHAVIOR_OPAQUE;
204204
}
@@ -209,7 +209,7 @@ static int on_macro_binding_released(struct zmk_behavior_binding *binding,
209209
const struct behavior_macro_config *cfg = dev->config;
210210
struct behavior_macro_state *state = dev->data;
211211

212-
queue_macro(event.position, event.source, cfg->bindings, state->release_state, binding);
212+
queue_macro(&event, cfg->bindings, state->release_state, binding);
213213

214214
return ZMK_BEHAVIOR_OPAQUE;
215215
}

app/src/behaviors/behavior_sticky_key.c

+12-5
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ struct behavior_sticky_key_config {
4040

4141
struct active_sticky_key {
4242
uint32_t position;
43+
#if IS_ENABLED(CONFIG_ZMK_SPLIT)
4344
uint8_t source;
45+
#endif
4446
uint32_t param1;
4547
uint32_t param2;
4648
const struct behavior_sticky_key_config *config;
@@ -56,7 +58,7 @@ struct active_sticky_key {
5658

5759
struct active_sticky_key active_sticky_keys[ZMK_BHV_STICKY_KEY_MAX_HELD] = {};
5860

59-
static struct active_sticky_key *store_sticky_key(uint32_t position, uint8_t source,
61+
static struct active_sticky_key *store_sticky_key(struct zmk_behavior_binding_event *event,
6062
uint32_t param1, uint32_t param2,
6163
const struct behavior_sticky_key_config *config) {
6264
for (int i = 0; i < ZMK_BHV_STICKY_KEY_MAX_HELD; i++) {
@@ -65,8 +67,10 @@ static struct active_sticky_key *store_sticky_key(uint32_t position, uint8_t sou
6567
sticky_key->timer_cancelled) {
6668
continue;
6769
}
68-
sticky_key->position = position;
69-
sticky_key->source = source;
70+
sticky_key->position = event->position;
71+
#if IS_ENABLED(CONFIG_ZMK_SPLIT)
72+
sticky_key->source = event->source;
73+
#endif
7074
sticky_key->param1 = param1;
7175
sticky_key->param2 = param2;
7276
sticky_key->config = config;
@@ -103,7 +107,9 @@ static inline int press_sticky_key_behavior(struct active_sticky_key *sticky_key
103107
struct zmk_behavior_binding_event event = {
104108
.position = sticky_key->position,
105109
.timestamp = timestamp,
110+
#if IS_ENABLED(CONFIG_ZMK_SPLIT)
106111
.source = sticky_key->source,
112+
#endif
107113
};
108114
return zmk_invoke_behavior_binding(&binding, event, true);
109115
}
@@ -118,7 +124,9 @@ static inline int release_sticky_key_behavior(struct active_sticky_key *sticky_k
118124
struct zmk_behavior_binding_event event = {
119125
.position = sticky_key->position,
120126
.timestamp = timestamp,
127+
#if IS_ENABLED(CONFIG_ZMK_SPLIT)
121128
.source = sticky_key->source,
129+
#endif
122130
};
123131

124132
clear_sticky_key(sticky_key);
@@ -153,8 +161,7 @@ static int on_sticky_key_binding_pressed(struct zmk_behavior_binding *binding,
153161
stop_timer(sticky_key);
154162
release_sticky_key_behavior(sticky_key, event.timestamp);
155163
}
156-
sticky_key =
157-
store_sticky_key(event.position, event.source, binding->param1, binding->param2, cfg);
164+
sticky_key = store_sticky_key(&event, binding->param1, binding->param2, cfg);
158165
if (sticky_key == NULL) {
159166
LOG_ERR("unable to store sticky key, did you press more than %d sticky_key?",
160167
ZMK_BHV_STICKY_KEY_MAX_HELD);

app/src/behaviors/behavior_tap_dance.c

+12-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ struct active_tap_dance {
3535
// Tap Dance Data
3636
int counter;
3737
uint32_t position;
38+
#if IS_ENABLED(CONFIG_ZMK_SPLIT)
3839
uint8_t source;
40+
#endif
3941
uint32_t param1;
4042
uint32_t param2;
4143
bool is_pressed;
@@ -60,15 +62,17 @@ static struct active_tap_dance *find_tap_dance(uint32_t position) {
6062
return NULL;
6163
}
6264

63-
static int new_tap_dance(uint32_t position, uint8_t source,
65+
static int new_tap_dance(struct zmk_behavior_binding_event *event,
6466
const struct behavior_tap_dance_config *config,
6567
struct active_tap_dance **tap_dance) {
6668
for (int i = 0; i < ZMK_BHV_TAP_DANCE_MAX_HELD; i++) {
6769
struct active_tap_dance *const ref_dance = &active_tap_dances[i];
6870
if (ref_dance->position == ZMK_BHV_TAP_DANCE_POSITION_FREE) {
6971
ref_dance->counter = 0;
70-
ref_dance->position = position;
71-
ref_dance->source = source;
72+
ref_dance->position = event->position;
73+
#if IS_ENABLED(CONFIG_ZMK_SPLIT)
74+
ref_dance->source = event->source;
75+
#endif
7276
ref_dance->config = config;
7377
ref_dance->release_at = 0;
7478
ref_dance->is_pressed = true;
@@ -111,7 +115,9 @@ static inline int press_tap_dance_behavior(struct active_tap_dance *tap_dance, i
111115
struct zmk_behavior_binding_event event = {
112116
.position = tap_dance->position,
113117
.timestamp = timestamp,
118+
#if IS_ENABLED(CONFIG_ZMK_SPLIT)
114119
.source = tap_dance->source,
120+
#endif
115121
};
116122
return zmk_invoke_behavior_binding(&binding, event, true);
117123
}
@@ -122,7 +128,9 @@ static inline int release_tap_dance_behavior(struct active_tap_dance *tap_dance,
122128
struct zmk_behavior_binding_event event = {
123129
.position = tap_dance->position,
124130
.timestamp = timestamp,
131+
#if IS_ENABLED(CONFIG_ZMK_SPLIT)
125132
.source = tap_dance->source,
133+
#endif
126134
};
127135
clear_tap_dance(tap_dance);
128136
return zmk_invoke_behavior_binding(&binding, event, false);
@@ -135,7 +143,7 @@ static int on_tap_dance_binding_pressed(struct zmk_behavior_binding *binding,
135143
struct active_tap_dance *tap_dance;
136144
tap_dance = find_tap_dance(event.position);
137145
if (tap_dance == NULL) {
138-
if (new_tap_dance(event.position, event.source, cfg, &tap_dance) == -ENOMEM) {
146+
if (new_tap_dance(&event, cfg, &tap_dance) == -ENOMEM) {
139147
LOG_ERR("Unable to create new tap dance. Insufficient space in active_tap_dances[].");
140148
return ZMK_BEHAVIOR_OPAQUE;
141149
}

app/src/combo.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,10 @@ static int release_pressed_keys() {
291291
static inline int press_combo_behavior(struct combo_cfg *combo, int32_t timestamp) {
292292
struct zmk_behavior_binding_event event = {
293293
.position = combo->virtual_key_position,
294-
.source = ZMK_POSITION_STATE_CHANGE_SOURCE_LOCAL,
295294
.timestamp = timestamp,
295+
#if IS_ENABLED(CONFIG_ZMK_SPLIT)
296+
.source = ZMK_POSITION_STATE_CHANGE_SOURCE_LOCAL,
297+
#endif
296298
};
297299

298300
last_combo_timestamp = timestamp;
@@ -303,8 +305,10 @@ static inline int press_combo_behavior(struct combo_cfg *combo, int32_t timestam
303305
static inline int release_combo_behavior(struct combo_cfg *combo, int32_t timestamp) {
304306
struct zmk_behavior_binding_event event = {
305307
.position = combo->virtual_key_position,
306-
.source = ZMK_POSITION_STATE_CHANGE_SOURCE_LOCAL,
307308
.timestamp = timestamp,
309+
#if IS_ENABLED(CONFIG_ZMK_SPLIT)
310+
.source = ZMK_POSITION_STATE_CHANGE_SOURCE_LOCAL,
311+
#endif
308312
};
309313

310314
return zmk_invoke_behavior_binding(&combo->behavior, event, false);

app/src/keymap.c

+2
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ int zmk_keymap_apply_position_state(uint8_t source, int layer, uint32_t position
164164
.layer = layer,
165165
.position = position,
166166
.timestamp = timestamp,
167+
#if IS_ENABLED(CONFIG_ZMK_SPLIT)
167168
.source = source,
169+
#endif
168170
};
169171

170172
LOG_DBG("layer: %d position: %d, binding name: %s", layer, position, binding->behavior_dev);

0 commit comments

Comments
 (0)