From 409d4748f62ad82d79334a7ad019465812d691ee Mon Sep 17 00:00:00 2001 From: MURAOKA Taro Date: Tue, 16 Apr 2024 00:43:17 +0900 Subject: [PATCH] Scroll snap mode, manually managed for https://github.com/Yowkees/keyball/issues/559 --- .../keyboards/keyball/lib/keyball/keyball.c | 49 ++++++++++++++++++- .../keyboards/keyball/lib/keyball/keyball.h | 26 +++++++++- 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/qmk_firmware/keyboards/keyball/lib/keyball/keyball.c b/qmk_firmware/keyboards/keyball/lib/keyball/keyball.c index a19d8bc73..838b01c65 100644 --- a/qmk_firmware/keyboards/keyball/lib/keyball/keyball.c +++ b/qmk_firmware/keyboards/keyball/lib/keyball/keyball.c @@ -206,8 +206,8 @@ __attribute__((weak)) void keyball_on_apply_motion_to_mouse_scroll(keyball_motio # error("unknown Keyball model") #endif -#if KEYBALL_SCROLLSNAP_ENABLE - // scroll snap. +#if KEYBALL_SCROLLSNAP_ENABLE == 1 + // scroll snap (behavior up to 1.3.2) uint32_t now = timer_read32(); if (r->h != 0 || r->v != 0) { keyball.scroll_snap_last = now; @@ -218,6 +218,18 @@ __attribute__((weak)) void keyball_on_apply_motion_to_mouse_scroll(keyball_motio keyball.scroll_snap_tension_h += y; r->h = 0; } +#elif KEYBALL_SCROLLSNAP_ENABLE == 2 + switch (keyball.scrollsnap_mode) { + case KEYBALL_SCROLLSNAP_MODE_VERTICAL: + r->h = 0; + break; + case KEYBALL_SCROLLSNAP_MODE_HORIZONTAL: + r->v = 0; + break; + case KEYBALL_SCROLLSNAP_MODE_FREE: + // pass by without doing anything + break; + } #endif } @@ -496,6 +508,20 @@ void keyball_set_scroll_mode(bool mode) { keyball.scroll_mode = mode; } +keyball_scrollsnap_mode_t keyball_get_scrollsnap_mode(void) { +#if KEYBALL_SCROLLSNAP_ENABLE == 2 + return keyball.scrollsnap_mode; +#else + return 0; +#endif +} + +void keyball_set_scrollsnap_mode(keyball_scrollsnap_mode_t mode) { +#if KEYBALL_SCROLLSNAP_ENABLE == 2 + keyball.scrollsnap_mode = mode; +#endif +} + uint8_t keyball_get_scroll_div(void) { return keyball.scroll_div == 0 ? KEYBALL_SCROLL_DIV_DEFAULT : keyball.scroll_div; } @@ -540,6 +566,10 @@ void keyboard_post_init_kb(void) { #ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE set_auto_mouse_enable(c.amle); set_auto_mouse_timeout(c.amlto == 0 ? AUTO_MOUSE_TIME : (c.amlto + 1) * AML_TIMEOUT_QU); +#endif +#if KEYBALL_SCROLLSNAP_ENABLE == 2 + keyball.scrollsnap_mode = c.ssnap; + keyball_set_scrollsnap_mode(c.ssnap); #endif } @@ -642,6 +672,9 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) { #ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE .amle = get_auto_mouse_enable(), .amlto = (get_auto_mouse_timeout() / AML_TIMEOUT_QU) - 1, +#endif +#if KEYBALL_SCROLLSNAP_ENABLE == 2 + .ssnap = keyball_get_scrollsnap_mode(), #endif }; eeconfig_update_kb(c.raw); @@ -670,6 +703,18 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) { add_scroll_div(-1); break; +#if KEYBALL_SCROLLSNAP_ENABLE == 2 + case SSNP_HOR: + keyball_set_scrollsnap_mode(KEYBALL_SCROLLSNAP_MODE_HORIZONTAL); + break; + case SSNP_VER: + keyball_set_scrollsnap_mode(KEYBALL_SCROLLSNAP_MODE_VERTICAL); + break; + case SSNP_FRE: + keyball_set_scrollsnap_mode(KEYBALL_SCROLLSNAP_MODE_FREE); + break; +#endif + #ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE case AML_TO: set_auto_mouse_enable(!get_auto_mouse_enable()); diff --git a/qmk_firmware/keyboards/keyball/lib/keyball/keyball.h b/qmk_firmware/keyboards/keyball/lib/keyball/keyball.h index 7074ed372..b59470253 100644 --- a/qmk_firmware/keyboards/keyball/lib/keyball/keyball.h +++ b/qmk_firmware/keyboards/keyball/lib/keyball/keyball.h @@ -36,8 +36,9 @@ along with this program. If not, see . # define KEYBALL_SCROLLBALL_INHIVITOR 50 #endif +/// To disable scroll snap feature, define 0 in your config.h #ifndef KEYBALL_SCROLLSNAP_ENABLE -# define KEYBALL_SCROLLSNAP_ENABLE 1 +# define KEYBALL_SCROLLSNAP_ENABLE 2 #endif #ifndef KEYBALL_SCROLLSNAP_RESET_TIMER @@ -104,6 +105,10 @@ enum keyball_keycodes { SCRL_DVI = QK_KB_8, // Increment scroll divider SCRL_DVD = QK_KB_9, // Decrement scroll divider + SSNP_VER = QK_KB_13, // Set scroll snap mode as horizontal + SSNP_HOR = QK_KB_14, // Set scroll snap mode as vertical + SSNP_FRE = QK_KB_15, // Set scroll snap mode as disable (free scroll) + // Auto mouse layer control keycodes. // Only works when POINTING_DEVICE_AUTO_MOUSE_ENABLE is defined. AML_TO = QK_KB_10, // Toggle automatic mouse layer @@ -122,6 +127,9 @@ typedef union { #ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE uint8_t amle : 1; // automatic mouse layer enabled uint16_t amlto : 5; // automatic mouse layer timeout +#endif +#if KEYBALL_SCROLLSNAP_ENABLE == 2 + uint8_t ssnap : 2; // scroll snap mode #endif }; } keyball_config_t; @@ -137,6 +145,12 @@ typedef struct { typedef uint8_t keyball_cpi_t; +typedef enum { + KEYBALL_SCROLLSNAP_MODE_VERTICAL = 0, + KEYBALL_SCROLLSNAP_MODE_HORIZONTAL = 1, + KEYBALL_SCROLLSNAP_MODE_FREE = 2, +} keyball_scrollsnap_mode_t; + typedef struct { bool this_have_ball; bool that_enable; @@ -152,8 +166,12 @@ typedef struct { uint32_t scroll_mode_changed; uint8_t scroll_div; +#if KEYBALL_SCROLLSNAP_ENABLE == 1 uint32_t scroll_snap_last; int8_t scroll_snap_tension_h; +#elif KEYBALL_SCROLLSNAP_ENABLE == 2 + keyball_scrollsnap_mode_t scrollsnap_mode; +#endif uint16_t last_kc; keypos_t last_pos; @@ -212,6 +230,12 @@ bool keyball_get_scroll_mode(void); /// keyball_set_scroll_mode modify scroll mode. void keyball_set_scroll_mode(bool mode); +/// TODO: document +keyball_scrollsnap_mode_t keyball_get_scrollsnap_mode(void); + +/// TODO: document +void keyball_set_scrollsnap_mode(keyball_scrollsnap_mode_t mode); + // TODO: document uint8_t keyball_get_scroll_div(void);