mirror of https://github.com/zmkfirmware/zmk.git
fixup! feat: Refactor behaviors, sensor to raise behavior_binding_event
This commit is contained in:
parent
43051e780f
commit
e4b44ace6d
|
|
@ -21,15 +21,21 @@ struct zmk_behavior_binding {
|
|||
uint32_t param2;
|
||||
};
|
||||
|
||||
enum trigger_type { PRESS, RELEASE, SENSOR };
|
||||
enum zmk_behavior_trigger_type {
|
||||
ZMK_BEHAVIOR_TRIG_TYPE_PRESS,
|
||||
ZMK_BEHAVIOR_TRIG_TYPE_RELEASE,
|
||||
ZMK_BEHAVIOR_TRIG_TYPE_SENSOR,
|
||||
};
|
||||
|
||||
struct zmk_behavior_binding_event {
|
||||
const struct zmk_behavior_binding *binding;
|
||||
int layer;
|
||||
uint32_t position;
|
||||
int64_t timestamp;
|
||||
enum trigger_type type;
|
||||
enum zmk_behavior_trigger_type type;
|
||||
uint8_t layer;
|
||||
#if IS_ENABLED(CONFIG_ZMK_SPLIT)
|
||||
uint8_t source;
|
||||
#endif
|
||||
};
|
||||
|
||||
ZMK_EVENT_DECLARE(zmk_behavior_binding_event);
|
||||
|
|
@ -90,8 +90,12 @@ int zmk_keymap_save_changes(void);
|
|||
int zmk_keymap_discard_changes(void);
|
||||
int zmk_keymap_reset_settings(void);
|
||||
|
||||
int zmk_keymap_raise_binding_event_at_layer_index(zmk_keymap_layer_id_t layer_index, uint8_t source,
|
||||
uint32_t position, enum trigger_type type,
|
||||
int zmk_keymap_raise_binding_event_at_layer_index(zmk_keymap_layer_id_t layer_index,
|
||||
#if IS_ENABLED(CONFIG_ZMK_SPLIT)
|
||||
uint8_t source,
|
||||
#endif
|
||||
uint32_t position,
|
||||
enum zmk_behavior_trigger_type type,
|
||||
int64_t timestamp);
|
||||
|
||||
#define ZMK_KEYMAP_EXTRACT_BINDING(idx, drv_inst) \
|
||||
|
|
|
|||
|
|
@ -58,16 +58,17 @@ const struct device *z_impl_behavior_get_binding(const char *name) {
|
|||
}
|
||||
|
||||
// TODO: Delete this method as part of a breaking release
|
||||
int zmk_behavior_invoke_binding(const struct zmk_behavior_binding *src_binding,
|
||||
struct zmk_behavior_binding_event event, bool pressed) {
|
||||
LOG_DBG("`zmk_behavior_invoke_binding` is deprecated. Please raise a "
|
||||
__deprecated int zmk_behavior_invoke_binding(const struct zmk_behavior_binding *src_binding,
|
||||
struct zmk_behavior_binding_event event,
|
||||
bool pressed) {
|
||||
LOG_WRN("`zmk_behavior_invoke_binding` is deprecated. Please raise a "
|
||||
"`zmk_behavior_binding_event` instead.");
|
||||
return raise_zmk_behavior_binding_event((struct zmk_behavior_binding_event){
|
||||
.binding = src_binding,
|
||||
.layer = event.layer,
|
||||
.position = event.position,
|
||||
.timestamp = event.timestamp,
|
||||
.type = pressed ? PRESS : RELEASE,
|
||||
.type = pressed ? ZMK_BEHAVIOR_TRIG_TYPE_PRESS : ZMK_BEHAVIOR_TRIG_TYPE_RELEASE,
|
||||
#if IS_ENABLED(CONFIG_ZMK_SPLIT)
|
||||
.source = event.source,
|
||||
#endif
|
||||
|
|
@ -79,11 +80,11 @@ int zmk_behavior_invoke_binding(const struct zmk_behavior_binding *src_binding,
|
|||
static int invoke_locally(struct zmk_behavior_binding *binding,
|
||||
struct zmk_behavior_binding_event *event) {
|
||||
switch (event->type) {
|
||||
case PRESS:
|
||||
case ZMK_BEHAVIOR_TRIG_TYPE_PRESS:
|
||||
return behavior_keymap_binding_pressed(binding, *event);
|
||||
case RELEASE:
|
||||
case ZMK_BEHAVIOR_TRIG_TYPE_RELEASE:
|
||||
return behavior_keymap_binding_released(binding, *event);
|
||||
case SENSOR:
|
||||
case ZMK_BEHAVIOR_TRIG_TYPE_SENSOR:
|
||||
return behavior_sensor_keymap_binding_process(binding, *event);
|
||||
default:
|
||||
return -EINVAL;
|
||||
|
|
|
|||
|
|
@ -36,12 +36,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 = {.binding = &item.binding,
|
||||
.position = item.position,
|
||||
.timestamp = k_uptime_get(),
|
||||
.type = item.press ? PRESS : RELEASE,
|
||||
struct zmk_behavior_binding_event event = {
|
||||
.binding = &item.binding,
|
||||
.position = item.position,
|
||||
.timestamp = k_uptime_get(),
|
||||
.type = item.press ? ZMK_BEHAVIOR_TRIG_TYPE_PRESS : ZMK_BEHAVIOR_TRIG_TYPE_RELEASE,
|
||||
#if IS_ENABLED(CONFIG_ZMK_SPLIT)
|
||||
.source = item.source
|
||||
.source = item.source
|
||||
#endif
|
||||
};
|
||||
ret = raise_zmk_behavior_binding_event(event);
|
||||
|
|
|
|||
|
|
@ -20,11 +20,15 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
|||
static int on_keymap_binding_trigger(struct zmk_behavior_binding *binding,
|
||||
struct zmk_behavior_binding_event event) {
|
||||
// Avoid uint8_t overflow resulting in an infinite loop
|
||||
if (LAYER_ID_TO_INDEX(event.layer) == 0) {
|
||||
zmk_keymap_layer_id_t layer_index = LAYER_ID_TO_INDEX(event.layer);
|
||||
if (layer_index == 0) {
|
||||
return 0;
|
||||
}
|
||||
return zmk_keymap_raise_binding_event_at_layer_index(LAYER_ID_TO_INDEX(event.layer) - 1,
|
||||
event.source, event.position, event.type,
|
||||
return zmk_keymap_raise_binding_event_at_layer_index(layer_index - 1,
|
||||
#if IS_ENABLED(CONFIG_ZMK_SPLIT)
|
||||
event.source,
|
||||
#endif
|
||||
event.position, event.type,
|
||||
event.timestamp);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -698,8 +698,12 @@ int zmk_keymap_reset_settings(void) { return -ENOTSUP; }
|
|||
|
||||
#endif // IS_ENABLED(CONFIG_ZMK_KEYMAP_SETTINGS_STORAGE)
|
||||
|
||||
int zmk_keymap_raise_binding_event_at_layer_index(zmk_keymap_layer_id_t layer_index, uint8_t source,
|
||||
uint32_t position, enum trigger_type type,
|
||||
int zmk_keymap_raise_binding_event_at_layer_index(zmk_keymap_layer_id_t layer_index,
|
||||
#if IS_ENABLED(CONFIG_ZMK_SPLIT)
|
||||
uint8_t source,
|
||||
#endif
|
||||
uint32_t position,
|
||||
enum zmk_behavior_trigger_type type,
|
||||
int64_t timestamp) {
|
||||
// We use int here to be sure we don't loop layer_idx back to UINT8_MAX
|
||||
for (int layer_idx = layer_index; layer_idx >= 0; layer_idx--) {
|
||||
|
|
@ -752,9 +756,13 @@ static int zmk_keymap_position_state_changed(uint8_t source, uint32_t position,
|
|||
if (pressed) {
|
||||
zmk_keymap_active_behavior_layer[position] = _zmk_keymap_layer_state;
|
||||
}
|
||||
enum trigger_type type = pressed ? PRESS : RELEASE;
|
||||
enum zmk_behavior_trigger_type type =
|
||||
pressed ? ZMK_BEHAVIOR_TRIG_TYPE_PRESS : ZMK_BEHAVIOR_TRIG_TYPE_RELEASE;
|
||||
|
||||
int ret = zmk_keymap_raise_binding_event_at_layer_index(ZMK_KEYMAP_LAYERS_LEN - 1, source,
|
||||
int ret = zmk_keymap_raise_binding_event_at_layer_index(ZMK_KEYMAP_LAYERS_LEN - 1,
|
||||
#if IS_ENABLED(CONFIG_ZMK_SPLIT)
|
||||
source,
|
||||
#endif
|
||||
position, type, timestamp);
|
||||
if (ret < 0) {
|
||||
LOG_DBG("Behavior returned error: %d", ret);
|
||||
|
|
|
|||
|
|
@ -173,7 +173,9 @@ int sensor_listener(const zmk_event_t *eh) {
|
|||
int position = ZMK_VIRTUAL_KEY_POSITION_SENSOR(sensor_index);
|
||||
// Source is set to local for the time being, to be improved in the future
|
||||
int ret = zmk_keymap_raise_binding_event_at_layer_index(ZMK_KEYMAP_LAYERS_LEN - 1,
|
||||
#if IS_ENABLED(CONFIG_ZMK_SPLIT)
|
||||
ZMK_POSITION_STATE_CHANGE_SOURCE_LOCAL,
|
||||
#endif
|
||||
position, SENSOR, sensor_ev->timestamp);
|
||||
if (ret < 0) {
|
||||
LOG_DBG("Behavior returned error: %d", ret);
|
||||
|
|
|
|||
Loading…
Reference in New Issue