From d0747a690442204da21db511ee2cf4b891dc39e9 Mon Sep 17 00:00:00 2001 From: Ilya Zhuravlev Date: Thu, 1 Jul 2021 20:43:35 -0400 Subject: [PATCH] qmk_settings: wrap mouse keys --- quantum/mousekey.c | 13 +++++++------ quantum/mousekey.h | 2 ++ quantum/qmk_settings.c | 31 +++++++++++++++++++++++++++++++ quantum/qmk_settings.h | 18 +++++++++++++++++- 4 files changed, 57 insertions(+), 7 deletions(-) diff --git a/quantum/mousekey.c b/quantum/mousekey.c index 7ad797042b..036e98aaf9 100644 --- a/quantum/mousekey.c +++ b/quantum/mousekey.c @@ -22,6 +22,7 @@ #include "print.h" #include "debug.h" #include "mousekey.h" +#include "qmk_settings.h" inline int8_t times_inv_sqrt2(int8_t x) { // 181/256 is pretty close to 1/sqrt(2) @@ -74,17 +75,17 @@ uint8_t mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX; static uint8_t move_unit(void) { uint16_t unit; if (mousekey_accel & (1 << 0)) { - unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed) / 4; + unit = (QS_mousekey_move_delta * mk_max_speed) / 4; } else if (mousekey_accel & (1 << 1)) { - unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed) / 2; + unit = (QS_mousekey_move_delta * mk_max_speed) / 2; } else if (mousekey_accel & (1 << 2)) { - unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed); + unit = (QS_mousekey_move_delta * mk_max_speed); } else if (mousekey_repeat == 0) { - unit = MOUSEKEY_MOVE_DELTA; + unit = QS_mousekey_move_delta; } else if (mousekey_repeat >= mk_time_to_max) { - unit = MOUSEKEY_MOVE_DELTA * mk_max_speed; + unit = QS_mousekey_move_delta * mk_max_speed; } else { - unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed * mousekey_repeat) / mk_time_to_max; + unit = (QS_mousekey_move_delta * mk_max_speed * mousekey_repeat) / mk_time_to_max; } return (unit > MOUSEKEY_MOVE_MAX ? MOUSEKEY_MOVE_MAX : (unit == 0 ? 1 : unit)); } diff --git a/quantum/mousekey.h b/quantum/mousekey.h index 70dc4bb5c5..1e56e3ca03 100644 --- a/quantum/mousekey.h +++ b/quantum/mousekey.h @@ -165,6 +165,8 @@ extern uint8_t mk_delay; extern uint8_t mk_interval; extern uint8_t mk_max_speed; extern uint8_t mk_time_to_max; +extern uint8_t mk_wheel_delay; +extern uint8_t mk_wheel_interval; extern uint8_t mk_wheel_max_speed; extern uint8_t mk_wheel_time_to_max; diff --git a/quantum/qmk_settings.c b/quantum/qmk_settings.c index 2c66d90c30..586fcf7759 100644 --- a/quantum/qmk_settings.c +++ b/quantum/qmk_settings.c @@ -6,6 +6,7 @@ #include "progmem.h" #include "dynamic_keymap.h" #include "process_auto_shift.h" +#include "mousekey.h" qmk_settings_t QS; @@ -16,6 +17,17 @@ static void auto_shift_timeout_apply(void) { set_autoshift_timeout(QS.auto_shift_timeout); } +static void mousekey_apply(void) { + mk_delay = QS.mousekey_delay / 10; + mk_interval = QS.mousekey_interval; + mk_max_speed = QS.mousekey_max_speed; + mk_time_to_max = QS.mousekey_time_to_max; + mk_wheel_delay = QS.mousekey_wheel_delay / 10; + mk_wheel_interval = QS.mousekey_wheel_interval; + mk_wheel_max_speed = QS.mousekey_wheel_max_speed; + mk_wheel_time_to_max = QS.mousekey_wheel_time_to_max; +} + static const qmk_settings_proto_t protos[] PROGMEM = { DECLARE_SETTING(1, grave_esc_override), DECLARE_SETTING(2, debounce_time), @@ -25,6 +37,15 @@ static const qmk_settings_proto_t protos[] PROGMEM = { DECLARE_SETTING(6, osk_timeout), DECLARE_SETTING(7, tapping_term), DECLARE_SETTING(8, tap_hold), + DECLARE_SETTING_CB(9, mousekey_delay, mousekey_apply), + DECLARE_SETTING_CB(10, mousekey_interval, mousekey_apply), + DECLARE_SETTING_CB(11, mousekey_move_delta, mousekey_apply), + DECLARE_SETTING_CB(12, mousekey_max_speed, mousekey_apply), + DECLARE_SETTING_CB(13, mousekey_time_to_max, mousekey_apply), + DECLARE_SETTING_CB(14, mousekey_wheel_delay, mousekey_apply), + DECLARE_SETTING_CB(15, mousekey_wheel_interval, mousekey_apply), + DECLARE_SETTING_CB(16, mousekey_wheel_max_speed, mousekey_apply), + DECLARE_SETTING_CB(17, mousekey_wheel_time_to_max, mousekey_apply), }; static const qmk_settings_proto_t *find_setting(uint16_t qsid) { @@ -74,6 +95,16 @@ void qmk_settings_reset(void) { QS.tapping_term = 200; QS.tap_hold = 0; + QS.mousekey_delay = MOUSEKEY_DELAY; + QS.mousekey_interval = MOUSEKEY_INTERVAL; + QS.mousekey_move_delta = MOUSEKEY_MOVE_DELTA; + QS.mousekey_max_speed = MOUSEKEY_MAX_SPEED; + QS.mousekey_time_to_max = MOUSEKEY_TIME_TO_MAX; + QS.mousekey_wheel_delay = MOUSEKEY_WHEEL_DELAY; + QS.mousekey_wheel_interval = MOUSEKEY_WHEEL_INTERVAL; + QS.mousekey_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED; + QS.mousekey_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX; + save_settings(); /* to trigger all callbacks */ qmk_settings_init(); diff --git a/quantum/qmk_settings.h b/quantum/qmk_settings.h index ac1521861a..0c2105ca54 100644 --- a/quantum/qmk_settings.h +++ b/quantum/qmk_settings.h @@ -91,8 +91,18 @@ typedef struct { uint16_t auto_shift_timeout; uint16_t osk_timeout; uint16_t tapping_term; + + uint16_t mousekey_delay; + uint16_t mousekey_interval; + uint16_t mousekey_move_delta; + uint16_t mousekey_max_speed; + uint16_t mousekey_time_to_max; + uint16_t mousekey_wheel_delay; + uint16_t mousekey_wheel_interval; + uint16_t mousekey_wheel_max_speed; + uint16_t mousekey_wheel_time_to_max; } qmk_settings_t; -_Static_assert(sizeof(qmk_settings_t) == 12, "unexpected size of the qmk_settings_t structure"); +_Static_assert(sizeof(qmk_settings_t) == 30, "unexpected size of the qmk_settings_t structure"); typedef void (*qmk_setting_callback_t)(void); @@ -131,6 +141,9 @@ extern qmk_settings_t QS; #define QS_oneshot_tap_toggle (QS.osk_tap_toggle) #define QS_oneshot_timeout (QS.osk_timeout) +/* Mouse keys */ +#define QS_mousekey_move_delta (QS.mousekey_move_delta) + #else /* dynamic settings framework is disabled => hardcode the settings and let the compiler optimize extra branches out */ @@ -153,4 +166,7 @@ extern qmk_settings_t QS; #define QS_oneshot_tap_toggle ONESHOT_TAP_TOGGLE #define QS_oneshot_timeout ONESHOT_TIMEOUT +/* Mouse keys */ +#define QS_mousekey_move_delta MOUSEKEY_MOVE_DELTA + #endif