|
18 | 18 | #include <zmk/events/position_state_changed.h> |
19 | 19 | #include <zmk/events/keycode_state_changed.h> |
20 | 20 | #include <zmk/behavior.h> |
21 | | -#include <zmk/keymap.h> |
22 | 21 |
|
23 | 22 | LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); |
24 | 23 |
|
@@ -77,6 +76,7 @@ struct behavior_hold_tap_data { |
77 | 76 | // this data is specific for each hold-tap |
78 | 77 | struct active_hold_tap { |
79 | 78 | int32_t position; |
| 79 | + uint8_t source; |
80 | 80 | uint32_t param_hold; |
81 | 81 | uint32_t param_tap; |
82 | 82 | int64_t timestamp; |
@@ -250,14 +250,16 @@ static struct active_hold_tap *find_hold_tap(uint32_t position) { |
250 | 250 | return NULL; |
251 | 251 | } |
252 | 252 |
|
253 | | -static struct active_hold_tap *store_hold_tap(uint32_t position, uint32_t param_hold, |
254 | | - uint32_t param_tap, int64_t timestamp, |
| 253 | +static struct active_hold_tap *store_hold_tap(uint32_t position, uint8_t source, |
| 254 | + uint32_t param_hold, uint32_t param_tap, |
| 255 | + int64_t timestamp, |
255 | 256 | const struct behavior_hold_tap_config *config) { |
256 | 257 | for (int i = 0; i < ZMK_BHV_HOLD_TAP_MAX_HELD; i++) { |
257 | 258 | if (active_hold_taps[i].position != ZMK_BHV_HOLD_TAP_POSITION_NOT_USED) { |
258 | 259 | continue; |
259 | 260 | } |
260 | 261 | active_hold_taps[i].position = position; |
| 262 | + active_hold_taps[i].source = source; |
261 | 263 | active_hold_taps[i].status = STATUS_UNDECIDED; |
262 | 264 | active_hold_taps[i].config = config; |
263 | 265 | active_hold_taps[i].param_hold = param_hold; |
@@ -400,45 +402,49 @@ static int press_hold_binding(struct active_hold_tap *hold_tap) { |
400 | 402 | struct zmk_behavior_binding_event event = { |
401 | 403 | .position = hold_tap->position, |
402 | 404 | .timestamp = hold_tap->timestamp, |
| 405 | + .source = hold_tap->source, |
403 | 406 | }; |
404 | 407 |
|
405 | 408 | struct zmk_behavior_binding binding = {.behavior_dev = hold_tap->config->hold_behavior_dev, |
406 | 409 | .param1 = hold_tap->param_hold}; |
407 | | - return behavior_keymap_binding_pressed(&binding, event); |
| 410 | + return zmk_behavior_invoke_binding(&binding, event, true); |
408 | 411 | } |
409 | 412 |
|
410 | 413 | static int press_tap_binding(struct active_hold_tap *hold_tap) { |
411 | 414 | struct zmk_behavior_binding_event event = { |
412 | 415 | .position = hold_tap->position, |
413 | 416 | .timestamp = hold_tap->timestamp, |
| 417 | + .source = hold_tap->source, |
414 | 418 | }; |
415 | 419 |
|
416 | 420 | struct zmk_behavior_binding binding = {.behavior_dev = hold_tap->config->tap_behavior_dev, |
417 | 421 | .param1 = hold_tap->param_tap}; |
418 | 422 | store_last_hold_tapped(hold_tap); |
419 | | - return behavior_keymap_binding_pressed(&binding, event); |
| 423 | + return zmk_behavior_invoke_binding(&binding, event, true); |
420 | 424 | } |
421 | 425 |
|
422 | 426 | static int release_hold_binding(struct active_hold_tap *hold_tap) { |
423 | 427 | struct zmk_behavior_binding_event event = { |
424 | 428 | .position = hold_tap->position, |
425 | 429 | .timestamp = hold_tap->timestamp, |
| 430 | + .source = hold_tap->source, |
426 | 431 | }; |
427 | 432 |
|
428 | 433 | struct zmk_behavior_binding binding = {.behavior_dev = hold_tap->config->hold_behavior_dev, |
429 | 434 | .param1 = hold_tap->param_hold}; |
430 | | - return behavior_keymap_binding_released(&binding, event); |
| 435 | + return zmk_behavior_invoke_binding(&binding, event, false); |
431 | 436 | } |
432 | 437 |
|
433 | 438 | static int release_tap_binding(struct active_hold_tap *hold_tap) { |
434 | 439 | struct zmk_behavior_binding_event event = { |
435 | 440 | .position = hold_tap->position, |
436 | 441 | .timestamp = hold_tap->timestamp, |
| 442 | + .source = hold_tap->source, |
437 | 443 | }; |
438 | 444 |
|
439 | 445 | struct zmk_behavior_binding binding = {.behavior_dev = hold_tap->config->tap_behavior_dev, |
440 | 446 | .param1 = hold_tap->param_tap}; |
441 | | - return behavior_keymap_binding_released(&binding, event); |
| 447 | + return zmk_behavior_invoke_binding(&binding, event, false); |
442 | 448 | } |
443 | 449 |
|
444 | 450 | static int press_binding(struct active_hold_tap *hold_tap) { |
@@ -597,8 +603,8 @@ static int on_hold_tap_binding_pressed(struct zmk_behavior_binding *binding, |
597 | 603 | return ZMK_BEHAVIOR_OPAQUE; |
598 | 604 | } |
599 | 605 |
|
600 | | - struct active_hold_tap *hold_tap = |
601 | | - store_hold_tap(event.position, binding->param1, binding->param2, event.timestamp, cfg); |
| 606 | + struct active_hold_tap *hold_tap = store_hold_tap(event.position, event.source, binding->param1, |
| 607 | + binding->param2, event.timestamp, cfg); |
602 | 608 | if (hold_tap == NULL) { |
603 | 609 | LOG_ERR("unable to store hold-tap info, did you press more than %d hold-taps?", |
604 | 610 | ZMK_BHV_HOLD_TAP_MAX_HELD); |
|
0 commit comments