39
39
#ifndef PLOOPY_DPI_DEFAULT
40
40
# define PLOOPY_DPI_DEFAULT 0
41
41
#endif
42
+ #ifndef PLOOPY_DRAGSCROLL_DPI
43
+ # define PLOOPY_DRAGSCROLL_DPI 100 // Fixed-DPI Drag Scroll
44
+ #endif
45
+ #ifndef PLOOPY_DRAGSCROLL_MULTIPLIER
46
+ # define PLOOPY_DRAGSCROLL_MULTIPLIER 0.75 // Variable-DPI Drag Scroll
47
+ #endif
42
48
43
49
keyboard_config_t keyboard_config ;
44
- uint16_t dpi_array [] = PLOOPY_DPI_OPTIONS ;
50
+ uint16_t dpi_array [] = PLOOPY_DPI_OPTIONS ;
45
51
#define DPI_OPTION_SIZE (sizeof(dpi_array) / sizeof(uint16_t))
46
52
47
53
// TODO: Implement libinput profiles
@@ -57,6 +63,7 @@ uint16_t lastScroll = 0; // Previous confirmed wheel event
57
63
uint16_t lastMidClick = 0 ; // Stops scrollwheel from being read if it was pressed
58
64
uint8_t OptLowPin = OPT_ENC1 ;
59
65
bool debug_encoder = false;
66
+ bool is_drag_scroll = false;
60
67
61
68
__attribute__((weak )) void process_wheel_user (report_mouse_t * mouse_report , int16_t h , int16_t v ) {
62
69
mouse_report -> h = h ;
@@ -151,17 +158,34 @@ bool process_record_kb(uint16_t keycode, keyrecord_t* record) {
151
158
152
159
// Update Timer to prevent accidental scrolls
153
160
if ((record -> event .key .col == 1 ) && (record -> event .key .row == 0 )) {
154
- lastMidClick = timer_read ();
161
+ lastMidClick = timer_read ();
155
162
is_scroll_clicked = record -> event .pressed ;
156
163
}
157
164
158
- if (!process_record_user (keycode , record )) { return false; }
165
+ if (!process_record_user (keycode , record )) {
166
+ return false;
167
+ }
159
168
160
169
if (keycode == DPI_CONFIG && record -> event .pressed ) {
161
170
keyboard_config .dpi_config = (keyboard_config .dpi_config + 1 ) % DPI_OPTION_SIZE ;
162
171
eeconfig_update_kb (keyboard_config .raw );
163
172
pmw_set_cpi (dpi_array [keyboard_config .dpi_config ]);
164
173
}
174
+
175
+ if (keycode == DRAG_SCROLL ) {
176
+ #ifndef PLOOPY_DRAGSCROLL_MOMENTARY
177
+ if (record -> event .pressed )
178
+ #endif
179
+ {
180
+ is_drag_scroll ^= 1 ;
181
+ }
182
+ #ifdef PLOOPY_DRAGSCROLL_FIXED
183
+ pmw_set_cpi (is_drag_scroll ? PLOOPY_DRAGSCROLL_DPI : dpi_array [keyboard_config .dpi_config ]);
184
+ #else
185
+ pmw_set_cpi (is_drag_scroll ? (dpi_array [keyboard_config .dpi_config ] * PLOOPY_DRAGSCROLL_MULTIPLIER ) : dpi_array [keyboard_config .dpi_config ]);
186
+ #endif
187
+ }
188
+
165
189
/* If Mousekeys is disabled, then use handle the mouse button
166
190
* keycodes. This makes things simpler, and allows usage of
167
191
* the keycodes in a consistent manner. But only do this if
@@ -223,24 +247,40 @@ void pointing_device_init(void) {
223
247
opt_encoder_init ();
224
248
}
225
249
226
- bool has_report_changed (report_mouse_t first , report_mouse_t second ) {
227
- return !(
228
- (!first .buttons && first .buttons == second .buttons ) &&
229
- (!first .x && first .x == second .x ) &&
230
- (!first .y && first .y == second .y ) &&
231
- (!first .h && first .h == second .h ) &&
232
- (!first .v && first .v == second .v ) );
233
- }
250
+ bool has_report_changed (report_mouse_t new , report_mouse_t old ) { return (new .buttons != old .buttons ) || (new .x && new .x != old .x ) || (new .y && new .y != old .y ) || (new .h && new .h != old .h ) || (new .v && new .v != old .v ); }
234
251
235
252
void pointing_device_task (void ) {
236
253
report_mouse_t mouse_report = pointing_device_get_report ();
237
254
process_wheel (& mouse_report );
238
255
process_mouse (& mouse_report );
239
256
257
+ if (is_drag_scroll ) {
258
+ mouse_report .h = mouse_report .x ;
259
+ mouse_report .v = mouse_report .y ;
260
+ mouse_report .x = 0 ;
261
+ mouse_report .y = 0 ;
262
+ }
263
+
240
264
pointing_device_set_report (mouse_report );
241
- if (has_report_changed (mouse_report , pointing_device_get_report ())) {
242
- pointing_device_send ();
265
+ pointing_device_send ();
266
+ }
267
+
268
+ void pointing_device_send (void ) {
269
+ static report_mouse_t old_report = {};
270
+ report_mouse_t mouseReport = pointing_device_get_report ();
271
+
272
+ // If you need to do other things, like debugging, this is the place to do it.
273
+ if (has_report_changed (mouseReport , old_report )) {
274
+ host_mouse_send (& mouseReport );
243
275
}
276
+
277
+ // send it and 0 it out except for buttons, so those stay until they are explicity over-ridden using update_pointing_device
278
+ mouseReport .x = 0 ;
279
+ mouseReport .y = 0 ;
280
+ mouseReport .v = 0 ;
281
+ mouseReport .h = 0 ;
282
+ pointing_device_set_report (mouseReport );
283
+ old_report = mouseReport ;
244
284
}
245
285
246
286
void eeconfig_init_kb (void ) {
0 commit comments