Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dragscroll combo option for Ploopy devices. #24876

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion keyboards/ploopyco/ploopyco.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
#ifndef ENCODER_BUTTON_COL
# define ENCODER_BUTTON_COL 0
#endif
#ifdef PLOOPY_DRAGSCROLL_COMBO
# ifndef PLOOPY_DRAGSCROLL_COMBO_THRESHOLD
# define PLOOPY_DRAGSCROLL_COMBO_THRESHOLD 0.5
# endif
#endif

keyboard_config_t keyboard_config;
uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS;
Expand All @@ -68,6 +73,10 @@ bool is_drag_scroll = false;
float scroll_accumulated_h = 0;
float scroll_accumulated_v = 0;

#ifdef PLOOPY_DRAGSCROLL_COMBO
bool combo_scroll_should_toggle = false;
#endif

#ifdef ENCODER_ENABLE
uint16_t lastScroll = 0; // Previous confirmed wheel event
uint16_t lastMidClick = 0; // Stops scrollwheel from being read if it was pressed
Expand Down Expand Up @@ -143,6 +152,18 @@ report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) {
scroll_accumulated_h += (float)mouse_report.x / PLOOPY_DRAGSCROLL_DIVISOR_H;
scroll_accumulated_v += (float)mouse_report.y / PLOOPY_DRAGSCROLL_DIVISOR_V;

#ifdef PLOOPY_DRAGSCROLL_COMBO
if (combo_scroll_should_toggle && (
abs(scroll_accumulated_h) > PLOOPY_DRAGSCROLL_COMBO_THRESHOLD ||
abs(scroll_accumulated_v) > PLOOPY_DRAGSCROLL_COMBO_THRESHOLD
)) {
// The user moved the ball past the threshold so we'll cancel the
// toggle. This keeps the trackball scrolling until the user lifts
// the drag scroll key.
combo_scroll_should_toggle = false;
}
#endif

// Assign integer parts of accumulated scroll values to the mouse report
mouse_report.h = (int8_t)scroll_accumulated_h;
#ifdef PLOOPY_DRAGSCROLL_INVERT
Expand Down Expand Up @@ -188,7 +209,24 @@ bool process_record_kb(uint16_t keycode, keyrecord_t* record) {
}

if (keycode == DRAG_SCROLL) {
#ifdef PLOOPY_DRAGSCROLL_MOMENTARY
#ifdef PLOOPY_DRAGSCROLL_COMBO
if (record->event.pressed) {
// The user is holding down the drag scroll key, we'll enable a flag
// to assert if it should be treated as a toggle.
combo_scroll_should_toggle = true;
toggle_drag_scroll();
} else {
if (combo_scroll_should_toggle) {
// The user lifted the drag scroll key and did not move it, so
// the scroll state will stay on (toggled).
combo_scroll_should_toggle = false;
} else {
// The user has moved the trackball while holding the drag scroll
// key so we cancel the toggle/scroll once the key is lifted.
is_drag_scroll = false;
}
}
#elif defined(PLOOPY_DRAGSCROLL_MOMENTARY)
is_drag_scroll = record->event.pressed;
#else
if (record->event.pressed) {
Expand Down
1 change: 1 addition & 0 deletions keyboards/ploopyco/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ Nothing needs to be enabled to use this functionality. Just add the `DRAG_SCROL
* `#define PLOOPY_DRAGSCROLL_DIVISOR_H 8.0` - Sets the horizontal movement divisor to use when drag scroll is enabled.
* `#define PLOOPY_DRAGSCROLL_DIVISOR_V 8.0` - Sets the vertical movement divisor to use when drag scroll is enabled.
* `#define PLOOPY_DRAGSCROLL_INVERT` - This reverses the direction that the scroll is performed.
* `#define PLOOPY_DRAGSCROLL_COMBO` - Makes the key into a momentary key when held and scrolled, but toggle when pressed without scrolling.
Loading