refactor(behaviors): use ZMK_BEHAVIOR_OPAQUE and ZMK_BEHAVIOR_TRANSPARENT

Use these instead of the magic return values 0 and 1 for
behavior_driver_api return values.
This commit is contained in:
Okke Formsma 2020-12-18 14:24:28 +01:00 committed by Pete Johanson
parent caa285852a
commit fa07ba9d32
10 changed files with 21 additions and 18 deletions

View file

@ -6,6 +6,9 @@
#pragma once
#define ZMK_BEHAVIOR_OPAQUE 0
#define ZMK_BEHAVIOR_TRANSPARENT 1
struct zmk_behavior_binding {
char *behavior_dev;
uint32_t param1;

View file

@ -39,7 +39,7 @@ static int behavior_bt_init(const struct device *dev) { return 0; };
static int on_keymap_binding_released(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {
return 0;
return ZMK_BEHAVIOR_OPAQUE;
}
static const struct behavior_driver_api behavior_bt_driver_api = {

View file

@ -43,7 +43,7 @@ static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
static int on_keymap_binding_released(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {
return 0;
return ZMK_BEHAVIOR_OPAQUE;
}
static int behavior_ext_power_init(const struct device *dev) { return 0; };

View file

@ -310,7 +310,7 @@ static int on_hold_tap_binding_pressed(struct zmk_behavior_binding *binding,
if (undecided_hold_tap != NULL) {
LOG_DBG("ERROR another hold-tap behavior is undecided.");
// if this happens, make sure the behavior events occur AFTER other position events.
return 0;
return ZMK_BEHAVIOR_OPAQUE;
}
struct active_hold_tap *hold_tap =
@ -318,7 +318,7 @@ static int on_hold_tap_binding_pressed(struct zmk_behavior_binding *binding,
if (hold_tap == NULL) {
LOG_ERR("unable to store hold-tap info, did you press more than %d hold-taps?",
ZMK_BHV_HOLD_TAP_MAX_HELD);
return 0;
return ZMK_BEHAVIOR_OPAQUE;
}
LOG_DBG("%d new undecided hold_tap", event.position);
@ -331,7 +331,7 @@ static int on_hold_tap_binding_pressed(struct zmk_behavior_binding *binding,
k_delayed_work_submit(&hold_tap->work, K_MSEC(tapping_term_ms_left));
}
return 0;
return ZMK_BEHAVIOR_OPAQUE;
}
static int on_hold_tap_binding_released(struct zmk_behavior_binding *binding,
@ -339,7 +339,7 @@ static int on_hold_tap_binding_released(struct zmk_behavior_binding *binding,
struct active_hold_tap *hold_tap = find_hold_tap(event.position);
if (hold_tap == NULL) {
LOG_ERR("ACTIVE_HOLD_TAP_CLEANED_UP_TOO_EARLY");
return 0;
return ZMK_BEHAVIOR_OPAQUE;
}
// If these events were queued, the timer event may be queued too late or not at all.
@ -379,7 +379,7 @@ static int on_hold_tap_binding_released(struct zmk_behavior_binding *binding,
clear_hold_tap(hold_tap);
}
return 0;
return ZMK_BEHAVIOR_OPAQUE;
}
static const struct behavior_driver_api behavior_hold_tap_driver_api = {

View file

@ -22,12 +22,12 @@ static int behavior_none_init(const struct device *dev) { return 0; };
static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {
return 0;
return ZMK_BEHAVIOR_OPAQUE;
}
static int on_keymap_binding_released(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {
return 0;
return ZMK_BEHAVIOR_OPAQUE;
}
static const struct behavior_driver_api behavior_none_driver_api = {

View file

@ -30,7 +30,7 @@ static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
// See
// https://github.com/adafruit/Adafruit_nRF52_Bootloader/blob/d6b28e66053eea467166f44875e3c7ec741cb471/src/main.c#L107
sys_reboot(cfg->type);
return 0;
return ZMK_BEHAVIOR_OPAQUE;
}
static const struct behavior_driver_api behavior_reset_driver_api = {

View file

@ -50,7 +50,7 @@ static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
static int on_keymap_binding_released(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {
return 0;
return ZMK_BEHAVIOR_OPAQUE;
}
static const struct behavior_driver_api behavior_rgb_underglow_driver_api = {

View file

@ -138,12 +138,12 @@ static int on_sticky_key_binding_pressed(struct zmk_behavior_binding *binding,
if (sticky_key == NULL) {
LOG_ERR("unable to store sticky key, did you press more than %d sticky_key?",
ZMK_BHV_STICKY_KEY_MAX_HELD);
return 0;
return ZMK_BEHAVIOR_OPAQUE;
}
press_sticky_key_behavior(sticky_key, event.timestamp);
LOG_DBG("%d new sticky_key", event.position);
return 0;
return ZMK_BEHAVIOR_OPAQUE;
}
static int on_sticky_key_binding_released(struct zmk_behavior_binding *binding,
@ -151,7 +151,7 @@ static int on_sticky_key_binding_released(struct zmk_behavior_binding *binding,
struct active_sticky_key *sticky_key = find_sticky_key(event.position);
if (sticky_key == NULL) {
LOG_ERR("ACTIVE STICKY KEY CLEARED TOO EARLY");
return 0;
return ZMK_BEHAVIOR_OPAQUE;
}
if (sticky_key->modified_key_usage_page != 0 && sticky_key->modified_key_keycode != 0) {
@ -167,7 +167,7 @@ static int on_sticky_key_binding_released(struct zmk_behavior_binding *binding,
if (ms_left > 0) {
k_delayed_work_submit(&sticky_key->release_timer, K_MSEC(ms_left));
}
return 0;
return ZMK_BEHAVIOR_OPAQUE;
}
static const struct behavior_driver_api behavior_sticky_key_driver_api = {

View file

@ -29,7 +29,7 @@ static int tog_keymap_binding_pressed(struct zmk_behavior_binding *binding,
static int tog_keymap_binding_released(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {
LOG_DBG("position %d layer %d", event.position, binding->param1);
return 0;
return ZMK_BEHAVIOR_OPAQUE;
}
static const struct behavior_driver_api behavior_tog_driver_api = {

View file

@ -22,12 +22,12 @@ static int behavior_transparent_init(const struct device *dev) { return 0; };
static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {
return 1;
return ZMK_BEHAVIOR_TRANSPARENT;
}
static int on_keymap_binding_released(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {
return 1;
return ZMK_BEHAVIOR_TRANSPARENT;
}
static const struct behavior_driver_api behavior_transparent_driver_api = {