Review edits: macro, event override fix, cosmetics
This commit is contained in:
parent
a29ee0033a
commit
33518ef5c9
4 changed files with 24 additions and 20 deletions
|
@ -18,13 +18,16 @@
|
||||||
|
|
||||||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
||||||
|
|
||||||
|
#define WHEEL_HORIZONTAL(encoded) (((encoded)&0xFF00) >> 8)
|
||||||
|
#define WHEEL_VERTICAL(encoded) ((encoded)&0x00FF)
|
||||||
|
|
||||||
static int behavior_mouse_wheel_init(const struct device *dev) { return 0; };
|
static int behavior_mouse_wheel_init(const struct device *dev) { return 0; };
|
||||||
|
|
||||||
static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
|
static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
|
||||||
struct zmk_behavior_binding_event event) {
|
struct zmk_behavior_binding_event event) {
|
||||||
LOG_DBG("position %d keycode 0x%02X", event.position, binding->param1);
|
LOG_DBG("position %d keycode 0x%02X", event.position, binding->param1);
|
||||||
int32_t x = (binding->param1 & 0xFF00) >> 8;
|
int32_t x = WHEEL_HORIZONTAL(binding->param1);
|
||||||
int32_t y = binding->param1 & 0x00FF;
|
int32_t y = WHEEL_VERTICAL(binding->param1);
|
||||||
zmk_hid_mouse_wheel_press(x, y);
|
zmk_hid_mouse_wheel_press(x, y);
|
||||||
return zmk_endpoints_send_mouse_report();
|
return zmk_endpoints_send_mouse_report();
|
||||||
}
|
}
|
||||||
|
@ -32,8 +35,8 @@ static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
|
||||||
static int on_keymap_binding_released(struct zmk_behavior_binding *binding,
|
static int on_keymap_binding_released(struct zmk_behavior_binding *binding,
|
||||||
struct zmk_behavior_binding_event event) {
|
struct zmk_behavior_binding_event event) {
|
||||||
LOG_DBG("position %d keycode 0x%02X", event.position, binding->param1);
|
LOG_DBG("position %d keycode 0x%02X", event.position, binding->param1);
|
||||||
int32_t x = (binding->param1 & 0xFF00) >> 8;
|
int32_t x = WHEEL_HORIZONTAL(binding->param1);
|
||||||
int32_t y = binding->param1 & 0x00FF;
|
int32_t y = WHEEL_VERTICAL(binding->param1);
|
||||||
zmk_hid_mouse_wheel_release(x, y);
|
zmk_hid_mouse_wheel_release(x, y);
|
||||||
return zmk_endpoints_send_mouse_report();
|
return zmk_endpoints_send_mouse_report();
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,9 +181,9 @@ static int16_t curr_y = 0;
|
||||||
static int8_t curr_hor = 0;
|
static int8_t curr_hor = 0;
|
||||||
static int8_t curr_vert = 0;
|
static int8_t curr_vert = 0;
|
||||||
|
|
||||||
#define SET_MOUSE_BUTTONS(butts) \
|
#define SET_MOUSE_BUTTONS(btns) \
|
||||||
{ \
|
{ \
|
||||||
mouse_report.body.buttons = butts; \
|
mouse_report.body.buttons = btns; \
|
||||||
LOG_DBG("Mouse buttons set to 0x%02X", mouse_report.body.buttons); \
|
LOG_DBG("Mouse buttons set to 0x%02X", mouse_report.body.buttons); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -125,22 +125,23 @@ static int hid_listener_mouse_released(const struct zmk_mouse_state_changed *ev)
|
||||||
}
|
}
|
||||||
|
|
||||||
int hid_listener(const zmk_event_t *eh) {
|
int hid_listener(const zmk_event_t *eh) {
|
||||||
const struct zmk_keycode_state_changed *ev = as_zmk_keycode_state_changed(eh);
|
const struct zmk_keycode_state_changed *kc_ev = as_zmk_keycode_state_changed(eh);
|
||||||
if (ev) {
|
if (kc_ev) {
|
||||||
if (ev->state) {
|
if (kc_ev->state) {
|
||||||
hid_listener_keycode_pressed(ev);
|
hid_listener_keycode_pressed(kc_ev);
|
||||||
} else {
|
} else {
|
||||||
hid_listener_keycode_released(ev);
|
hid_listener_keycode_released(kc_ev);
|
||||||
}
|
}
|
||||||
} else {
|
return 0;
|
||||||
const struct zmk_mouse_state_changed *ev = as_zmk_mouse_state_changed(eh);
|
}
|
||||||
if (ev) {
|
const struct zmk_mouse_state_changed *ms_ev = as_zmk_mouse_state_changed(eh);
|
||||||
if (ev->state) {
|
if (ms_ev) {
|
||||||
hid_listener_mouse_pressed(ev);
|
if (ms_ev->state) {
|
||||||
} else {
|
hid_listener_mouse_pressed(ms_ev);
|
||||||
hid_listener_mouse_released(ev);
|
} else {
|
||||||
}
|
hid_listener_mouse_released(ms_ev);
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue