Skip to content

Commit

Permalink
Reorder methods
Browse files Browse the repository at this point in the history
  • Loading branch information
urob committed Dec 12, 2024
1 parent 14d29e4 commit baa6b94
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions src/behaviors/behavior_leader_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,32 @@ static bool release_key_in_leader_sequence(const struct zmk_key_param *key) {
return false;
}

static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {
if (release_count) {
LOG_ERR("Unable to activate leader key. Previous sequence is still pressed.");
return ZMK_BEHAVIOR_OPAQUE;
}
const struct device *dev = device_get_binding(binding->behavior_dev);
activate_leader_key(dev->config);
return ZMK_BEHAVIOR_OPAQUE;
}

static int on_keymap_binding_released(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {
return ZMK_BEHAVIOR_OPAQUE;
}

static const struct behavior_driver_api behavior_leader_key_driver_api = {
.binding_pressed = on_keymap_binding_pressed,
.binding_released = on_keymap_binding_released,
};

static int leader_keycode_state_changed_listener(const zmk_event_t *eh);

ZMK_LISTENER(behavior_leader_key, leader_keycode_state_changed_listener);
ZMK_SUBSCRIPTION(behavior_leader_key, zmk_keycode_state_changed);

static int leader_keycode_state_changed_listener(const zmk_event_t *eh) {
struct zmk_keycode_state_changed *ev = as_zmk_keycode_state_changed(eh);
if (ev == NULL) {
Expand Down Expand Up @@ -208,32 +234,8 @@ static int leader_keycode_state_changed_listener(const zmk_event_t *eh) {
return ZMK_EV_EVENT_BUBBLE;
}

ZMK_LISTENER(leader, leader_keycode_state_changed_listener);
ZMK_SUBSCRIPTION(leader, zmk_keycode_state_changed);

static int behavior_leader_key_init(const struct device *dev) { return 0; }

static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {
if (release_count) {
LOG_ERR("Unable to activate leader key. Previous sequence is still pressed.");
return ZMK_BEHAVIOR_OPAQUE;
}
const struct device *dev = device_get_binding(binding->behavior_dev);
activate_leader_key(dev->config);
return ZMK_BEHAVIOR_OPAQUE;
}

static int on_keymap_binding_released(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {
return ZMK_BEHAVIOR_OPAQUE;
}

static const struct behavior_driver_api behavior_leader_key_driver_api = {
.binding_pressed = on_keymap_binding_pressed,
.binding_released = on_keymap_binding_released,
};

#define SEQUENCE_ITEM(i, n, prop) ZMK_KEY_PARAM_DECODE(DT_PROP_BY_IDX(n, prop, i))

#define PROP_SEQUENCES(n, prop) \
Expand Down

0 comments on commit baa6b94

Please sign in to comment.