aboutsummaryrefslogtreecommitdiff
path: root/keyboards/ploopyco/mouse/mouse.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/ploopyco/mouse/mouse.c')
-rw-r--r--keyboards/ploopyco/mouse/mouse.c66
1 files changed, 53 insertions, 13 deletions
diff --git a/keyboards/ploopyco/mouse/mouse.c b/keyboards/ploopyco/mouse/mouse.c
index 788a0a1f0..1a1e5648b 100644
--- a/keyboards/ploopyco/mouse/mouse.c
+++ b/keyboards/ploopyco/mouse/mouse.c
@@ -39,9 +39,15 @@
39#ifndef PLOOPY_DPI_DEFAULT 39#ifndef PLOOPY_DPI_DEFAULT
40# define PLOOPY_DPI_DEFAULT 0 40# define PLOOPY_DPI_DEFAULT 0
41#endif 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
43keyboard_config_t keyboard_config; 49keyboard_config_t keyboard_config;
44uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS; 50uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS;
45#define DPI_OPTION_SIZE (sizeof(dpi_array) / sizeof(uint16_t)) 51#define DPI_OPTION_SIZE (sizeof(dpi_array) / sizeof(uint16_t))
46 52
47// TODO: Implement libinput profiles 53// TODO: Implement libinput profiles
@@ -57,6 +63,7 @@ uint16_t lastScroll = 0; // Previous confirmed wheel event
57uint16_t lastMidClick = 0; // Stops scrollwheel from being read if it was pressed 63uint16_t lastMidClick = 0; // Stops scrollwheel from being read if it was pressed
58uint8_t OptLowPin = OPT_ENC1; 64uint8_t OptLowPin = OPT_ENC1;
59bool debug_encoder = false; 65bool debug_encoder = false;
66bool is_drag_scroll = false;
60 67
61__attribute__((weak)) void process_wheel_user(report_mouse_t* mouse_report, int16_t h, int16_t v) { 68__attribute__((weak)) void process_wheel_user(report_mouse_t* mouse_report, int16_t h, int16_t v) {
62 mouse_report->h = h; 69 mouse_report->h = h;
@@ -151,17 +158,34 @@ bool process_record_kb(uint16_t keycode, keyrecord_t* record) {
151 158
152 // Update Timer to prevent accidental scrolls 159 // Update Timer to prevent accidental scrolls
153 if ((record->event.key.col == 1) && (record->event.key.row == 0)) { 160 if ((record->event.key.col == 1) && (record->event.key.row == 0)) {
154 lastMidClick = timer_read(); 161 lastMidClick = timer_read();
155 is_scroll_clicked = record->event.pressed; 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 if (keycode == DPI_CONFIG && record->event.pressed) { 169 if (keycode == DPI_CONFIG && record->event.pressed) {
161 keyboard_config.dpi_config = (keyboard_config.dpi_config + 1) % DPI_OPTION_SIZE; 170 keyboard_config.dpi_config = (keyboard_config.dpi_config + 1) % DPI_OPTION_SIZE;
162 eeconfig_update_kb(keyboard_config.raw); 171 eeconfig_update_kb(keyboard_config.raw);
163 pmw_set_cpi(dpi_array[keyboard_config.dpi_config]); 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/* If Mousekeys is disabled, then use handle the mouse button 189/* If Mousekeys is disabled, then use handle the mouse button
166 * keycodes. This makes things simpler, and allows usage of 190 * keycodes. This makes things simpler, and allows usage of
167 * the keycodes in a consistent manner. But only do this if 191 * the keycodes in a consistent manner. But only do this if
@@ -223,24 +247,40 @@ void pointing_device_init(void) {
223 opt_encoder_init(); 247 opt_encoder_init();
224} 248}
225 249
226bool has_report_changed (report_mouse_t first, report_mouse_t second) { 250bool 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); }
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}
234 251
235void pointing_device_task(void) { 252void pointing_device_task(void) {
236 report_mouse_t mouse_report = pointing_device_get_report(); 253 report_mouse_t mouse_report = pointing_device_get_report();
237 process_wheel(&mouse_report); 254 process_wheel(&mouse_report);
238 process_mouse(&mouse_report); 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 pointing_device_set_report(mouse_report); 264 pointing_device_set_report(mouse_report);
241 if (has_report_changed(mouse_report, pointing_device_get_report())) { 265 pointing_device_send();
242 pointing_device_send(); 266}
267
268void 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
246void eeconfig_init_kb(void) { 286void eeconfig_init_kb(void) {