refactor(mouse): Tweak behavior inclusion, listener code

* Always import mouse keys behavior and their associated listeners.
* Tweak listener code to only add listener nodes when
  listener and the associated input device are enabled.
This commit is contained in:
Peter Johanson 2024-04-10 02:13:51 +00:00 committed by kB01
parent 5e2e1a9bad
commit 13ab1cefdc
5 changed files with 29 additions and 15 deletions

View file

@ -30,3 +30,4 @@
#include <behaviors/mouse_move.dtsi> #include <behaviors/mouse_move.dtsi>
#include <behaviors/mouse_scroll.dtsi> #include <behaviors/mouse_scroll.dtsi>
#include <behaviors/macros.dtsi> #include <behaviors/macros.dtsi>
#include <behaviors/mouse_keys.dtsi>

View file

@ -17,7 +17,7 @@
}; };
}; };
mkp_input_listener { mkp_input_listener: mkp_input_listener {
compatible = "zmk,input-listener"; compatible = "zmk,input-listener";
device = <&mkp>; device = <&mkp>;
}; };

View file

@ -18,7 +18,7 @@
}; };
}; };
mmv_input_listener { mmv_input_listener: mmv_input_listener {
compatible = "zmk,input-listener"; compatible = "zmk,input-listener";
device = <&mmv>; device = <&mmv>;
}; };

View file

@ -1,3 +1,4 @@
/* /*
* Copyright (c) 2024 The ZMK Contributors * Copyright (c) 2024 The ZMK Contributors
* *
@ -18,7 +19,7 @@
}; };
}; };
msc_input_listener { msc_input_listener: msc_input_listener {
compatible = "zmk,input-listener"; compatible = "zmk,input-listener";
device = <&msc>; device = <&msc>;
}; };

View file

@ -15,6 +15,13 @@
#include <zmk/endpoints.h> #include <zmk/endpoints.h>
#include <zmk/hid.h> #include <zmk/hid.h>
#define ONE_IF_DEV_OK(n) \
COND_CODE_1(DT_NODE_HAS_STATUS(DT_INST_PHANDLE(n, device), okay), (1 +), (0 +))
#define VALID_LISTENER_COUNT (DT_INST_FOREACH_STATUS_OKAY(ONE_IF_DEV_OK) 0)
#if VALID_LISTENER_COUNT > 0
enum input_listener_xy_data_mode { enum input_listener_xy_data_mode {
INPUT_LISTENER_XY_DATA_MODE_NONE, INPUT_LISTENER_XY_DATA_MODE_NONE,
INPUT_LISTENER_XY_DATA_MODE_REL, INPUT_LISTENER_XY_DATA_MODE_REL,
@ -171,8 +178,13 @@ static void input_handler(const struct input_listener_config *config,
} }
} }
#endif // VALID_LISTENER_COUNT > 0
#define IL_INST(n) \ #define IL_INST(n) \
static const struct input_listener_config config_##n = { \ COND_CODE_1( \
DT_NODE_HAS_STATUS(DT_INST_PHANDLE(n, device), okay), \
(static const struct input_listener_config config_##n = \
{ \
.xy_swap = DT_INST_PROP(n, xy_swap), \ .xy_swap = DT_INST_PROP(n, xy_swap), \
.x_invert = DT_INST_PROP(n, x_invert), \ .x_invert = DT_INST_PROP(n, x_invert), \
.y_invert = DT_INST_PROP(n, y_invert), \ .y_invert = DT_INST_PROP(n, y_invert), \
@ -182,7 +194,7 @@ static void input_handler(const struct input_listener_config *config,
static struct input_listener_data data_##n = {}; \ static struct input_listener_data data_##n = {}; \
void input_handler_##n(struct input_event *evt) { \ void input_handler_##n(struct input_event *evt) { \
input_handler(&config_##n, &data_##n, evt); \ input_handler(&config_##n, &data_##n, evt); \
} \ } INPUT_CALLBACK_DEFINE(DEVICE_DT_GET(DT_INST_PHANDLE(n, device)), input_handler_##n);), \
INPUT_CALLBACK_DEFINE(DEVICE_DT_GET(DT_INST_PHANDLE(n, device)), input_handler_##n); ())
DT_INST_FOREACH_STATUS_OKAY(IL_INST) DT_INST_FOREACH_STATUS_OKAY(IL_INST)