Skip to content

Commit

Permalink
Scroll snap mode, manually managed
Browse files Browse the repository at this point in the history
  • Loading branch information
koron committed Apr 15, 2024
1 parent 9d423f9 commit 9d4d4c5
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 3 deletions.
48 changes: 46 additions & 2 deletions qmk_firmware/keyboards/keyball/lib/keyball/keyball.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -218,6 +218,17 @@ __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
}
#endif
}

Expand Down Expand Up @@ -496,6 +507,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;
}
Expand Down Expand Up @@ -540,6 +565,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
}

Expand Down Expand Up @@ -642,6 +671,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);
Expand Down Expand Up @@ -670,6 +702,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());
Expand Down
26 changes: 25 additions & 1 deletion qmk_firmware/keyboards/keyball/lib/keyball/keyball.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# 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
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 9d4d4c5

Please sign in to comment.