feat(mouse): Add mouse move and scroll support (#2477)

* feat(mouse): Add mouse move and scroll support

    * Use Zephyr input subsystem for all pointers.
    * Input processors for modifying events, e.g. scaling, swapping
      codes, temporary (mouse) layers, etc.
    * Mouse move/scroll behaviors.
    * Infrastructure in place for physical pointer input devices.

* feat: Add input split support.

* docs: Add initial pointer docs.

---------

Co-authored-by: Cem Aksoylar <caksoylar@users.noreply.github.com>
Co-authored-by: Alexander Krikun <krikun98@gmail.com>
Co-authored-by: Robert U <urob@users.noreply.github.com>
Co-authored-by: Shawn Meier <ftc@users.noreply.github.com>
Co-authored-by: Chris Andreae <chris@andreae.gen.nz>
Co-authored-by: Anant Thazhemadam <47104651+thazhemadam@users.noreply.github.com>
Co-authored-by: Erik Tollerud <erik.tollerud@gmail.com>
Co-authored-by: Nicolas Munnich <98408764+Nick-Munnich@users.noreply.github.com>
This commit is contained in:
Pete Johanson
2024-12-09 17:45:41 -07:00
committed by GitHub
parent 7e8c542c94
commit 6b40bfda53
119 changed files with 4223 additions and 229 deletions

View File

@@ -25,12 +25,13 @@ static uint8_t keys_held = 0;
#endif /* IS_ENABLED(CONFIG_ZMK_USB_BOOT) */
#if IS_ENABLED(CONFIG_ZMK_MOUSE)
#if IS_ENABLED(CONFIG_ZMK_POINTING)
static struct zmk_hid_mouse_report mouse_report = {.report_id = ZMK_HID_REPORT_ID_MOUSE,
.body = {.buttons = 0}};
static struct zmk_hid_mouse_report mouse_report = {
.report_id = ZMK_HID_REPORT_ID_MOUSE,
.body = {.buttons = 0, .d_x = 0, .d_y = 0, .d_scroll_y = 0}};
#endif // IS_ENABLED(CONFIG_ZMK_MOUSE)
#endif // IS_ENABLED(CONFIG_ZMK_POINTING)
// Keep track of how often a modifier was pressed.
// Only release the modifier if the count is 0.
@@ -370,7 +371,7 @@ bool zmk_hid_is_pressed(uint32_t usage) {
return false;
}
#if IS_ENABLED(CONFIG_ZMK_MOUSE)
#if IS_ENABLED(CONFIG_ZMK_POINTING)
// Keep track of how often a button was pressed.
// Only release the button if the count is 0.
@@ -431,16 +432,48 @@ int zmk_hid_mouse_buttons_release(zmk_mouse_button_flags_t buttons) {
}
return 0;
}
void zmk_hid_mouse_clear(void) { memset(&mouse_report.body, 0, sizeof(mouse_report.body)); }
#endif // IS_ENABLED(CONFIG_ZMK_MOUSE)
void zmk_hid_mouse_movement_set(int16_t hwheel, int16_t wheel) {
mouse_report.body.d_x = hwheel;
mouse_report.body.d_y = wheel;
LOG_DBG("Mouse movement set to %d/%d", mouse_report.body.d_x, mouse_report.body.d_y);
}
void zmk_hid_mouse_movement_update(int16_t hwheel, int16_t wheel) {
mouse_report.body.d_x += hwheel;
mouse_report.body.d_y += wheel;
LOG_DBG("Mouse movement updated to %d/%d", mouse_report.body.d_x, mouse_report.body.d_y);
}
void zmk_hid_mouse_scroll_set(int8_t hwheel, int8_t wheel) {
mouse_report.body.d_scroll_x = hwheel;
mouse_report.body.d_scroll_y = wheel;
LOG_DBG("Mouse scroll set to %d/%d", mouse_report.body.d_scroll_x,
mouse_report.body.d_scroll_y);
}
void zmk_hid_mouse_scroll_update(int8_t hwheel, int8_t wheel) {
mouse_report.body.d_scroll_x += hwheel;
mouse_report.body.d_scroll_y += wheel;
LOG_DBG("Mouse scroll updated to X: %d/%d", mouse_report.body.d_scroll_x,
mouse_report.body.d_scroll_y);
}
void zmk_hid_mouse_clear(void) {
LOG_DBG("Mouse report cleared");
memset(&mouse_report.body, 0, sizeof(mouse_report.body));
}
#endif // IS_ENABLED(CONFIG_ZMK_POINTING)
struct zmk_hid_keyboard_report *zmk_hid_get_keyboard_report(void) { return &keyboard_report; }
struct zmk_hid_consumer_report *zmk_hid_get_consumer_report(void) { return &consumer_report; }
#if IS_ENABLED(CONFIG_ZMK_MOUSE)
#if IS_ENABLED(CONFIG_ZMK_POINTING)
struct zmk_hid_mouse_report *zmk_hid_get_mouse_report(void) { return &mouse_report; }
#endif // IS_ENABLED(CONFIG_ZMK_MOUSE)
#endif // IS_ENABLED(CONFIG_ZMK_POINTING)