feat(split): Make locality work nested behavior invocations

Co-authored-by: Tokazio <tokazio@hotmail.com>
This commit is contained in:
Cem Aksoylar
2023-01-17 19:05:04 +01:00
committed by Pete Johanson
parent 11f600d9e5
commit 9e36ebd525
13 changed files with 146 additions and 105 deletions

View File

@@ -5,6 +5,7 @@
*/
#include <zmk/behavior_queue.h>
#include <zmk/behavior.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
@@ -14,6 +15,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
struct q_item {
uint32_t position;
uint8_t source;
struct zmk_behavior_binding binding;
bool press : 1;
uint32_t wait : 31;
@@ -31,13 +33,13 @@ static void behavior_queue_process_next(struct k_work *work) {
LOG_DBG("Invoking %s: 0x%02x 0x%02x", item.binding.behavior_dev, item.binding.param1,
item.binding.param2);
struct zmk_behavior_binding_event event = {.position = item.position,
.timestamp = k_uptime_get()};
struct zmk_behavior_binding_event event = {
.position = item.position, .timestamp = k_uptime_get(), .source = item.source};
if (item.press) {
behavior_keymap_binding_pressed(&item.binding, event);
zmk_behavior_invoke_binding(&item.binding, event, true);
} else {
behavior_keymap_binding_released(&item.binding, event);
zmk_behavior_invoke_binding(&item.binding, event, false);
}
LOG_DBG("Processing next queued behavior in %dms", item.wait);
@@ -49,9 +51,10 @@ static void behavior_queue_process_next(struct k_work *work) {
}
}
int zmk_behavior_queue_add(uint32_t position, const struct zmk_behavior_binding binding, bool press,
uint32_t wait) {
struct q_item item = {.press = press, .binding = binding, .wait = wait};
int zmk_behavior_queue_add(uint32_t position, uint8_t source,
const struct zmk_behavior_binding binding, bool press, uint32_t wait) {
struct q_item item = {
.press = press, .binding = binding, .wait = wait, .position = position, .source = source};
const int ret = k_msgq_put(&zmk_behavior_queue_msgq, &item, K_NO_WAIT);
if (ret < 0) {