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:
parent
5e2e1a9bad
commit
13ab1cefdc
5 changed files with 29 additions and 15 deletions
|
@ -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>
|
||||||
|
|
|
@ -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>;
|
||||||
};
|
};
|
||||||
|
|
|
@ -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>;
|
||||||
};
|
};
|
||||||
|
|
|
@ -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>;
|
||||||
};
|
};
|
||||||
|
|
|
@ -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,18 +178,23 @@ 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( \
|
||||||
.xy_swap = DT_INST_PROP(n, xy_swap), \
|
DT_NODE_HAS_STATUS(DT_INST_PHANDLE(n, device), okay), \
|
||||||
.x_invert = DT_INST_PROP(n, x_invert), \
|
(static const struct input_listener_config config_##n = \
|
||||||
.y_invert = DT_INST_PROP(n, y_invert), \
|
{ \
|
||||||
.scale_multiplier = DT_INST_PROP(n, scale_multiplier), \
|
.xy_swap = DT_INST_PROP(n, xy_swap), \
|
||||||
.scale_divisor = DT_INST_PROP(n, scale_divisor), \
|
.x_invert = DT_INST_PROP(n, x_invert), \
|
||||||
}; \
|
.y_invert = DT_INST_PROP(n, y_invert), \
|
||||||
static struct input_listener_data data_##n = {}; \
|
.scale_multiplier = DT_INST_PROP(n, scale_multiplier), \
|
||||||
void input_handler_##n(struct input_event *evt) { \
|
.scale_divisor = DT_INST_PROP(n, scale_divisor), \
|
||||||
input_handler(&config_##n, &data_##n, evt); \
|
}; \
|
||||||
} \
|
static struct input_listener_data data_##n = {}; \
|
||||||
INPUT_CALLBACK_DEFINE(DEVICE_DT_GET(DT_INST_PHANDLE(n, device)), input_handler_##n);
|
void input_handler_##n(struct input_event *evt) { \
|
||||||
|
input_handler(&config_##n, &data_##n, evt); \
|
||||||
|
} 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)
|
||||||
|
|
Loading…
Add table
Reference in a new issue