summaryrefslogtreecommitdiff
path: root/quantum/pointing_device
diff options
context:
space:
mode:
authorMarcel Robitaille <marcelrobitaille11@gmail.com>2024-01-09 05:16:50 -0500
committerGitHub <noreply@github.com>2024-01-09 21:16:50 +1100
commitce05dc6fa1ff0d508af1e5e79eeeb6359736df51 (patch)
tree092ad763645f001677f13d202f76ff597b86ae42 /quantum/pointing_device
parent66050bb809b2e173dbcf5ae59f81ed127b193df0 (diff)
Add option for auto mouse movement threshold (#21398)
Fixes #21396
Diffstat (limited to 'quantum/pointing_device')
-rw-r--r--quantum/pointing_device/pointing_device_auto_mouse.c15
-rw-r--r--quantum/pointing_device/pointing_device_auto_mouse.h10
2 files changed, 21 insertions, 4 deletions
diff --git a/quantum/pointing_device/pointing_device_auto_mouse.c b/quantum/pointing_device/pointing_device_auto_mouse.c
index 3135b9e531..1b11fffedb 100644
--- a/quantum/pointing_device/pointing_device_auto_mouse.c
+++ b/quantum/pointing_device/pointing_device_auto_mouse.c
@@ -17,6 +17,7 @@
17 17
18#ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE 18#ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE
19 19
20# include <stdlib.h>
20# include <string.h> 21# include <string.h>
21# include "pointing_device_auto_mouse.h" 22# include "pointing_device_auto_mouse.h"
22# include "debug.h" 23# include "debug.h"
@@ -217,7 +218,11 @@ void auto_mouse_layer_off(void) {
217 * @return bool of pointing_device activation 218 * @return bool of pointing_device activation
218 */ 219 */
219__attribute__((weak)) bool auto_mouse_activation(report_mouse_t mouse_report) { 220__attribute__((weak)) bool auto_mouse_activation(report_mouse_t mouse_report) {
220 return mouse_report.x != 0 || mouse_report.y != 0 || mouse_report.h != 0 || mouse_report.v != 0 || mouse_report.buttons; 221 auto_mouse_context.total_mouse_movement.x += mouse_report.x;
222 auto_mouse_context.total_mouse_movement.y += mouse_report.y;
223 auto_mouse_context.total_mouse_movement.h += mouse_report.h;
224 auto_mouse_context.total_mouse_movement.v += mouse_report.v;
225 return abs(auto_mouse_context.total_mouse_movement.x) > AUTO_MOUSE_THRESHOLD || abs(auto_mouse_context.total_mouse_movement.y) > AUTO_MOUSE_THRESHOLD || abs(auto_mouse_context.total_mouse_movement.h) > AUTO_MOUSE_THRESHOLD || abs(auto_mouse_context.total_mouse_movement.v) > AUTO_MOUSE_THRESHOLD || mouse_report.buttons;
221} 226}
222 227
223/** 228/**
@@ -235,14 +240,16 @@ void pointing_device_task_auto_mouse(report_mouse_t mouse_report) {
235 // update activation and reset debounce 240 // update activation and reset debounce
236 auto_mouse_context.status.is_activated = auto_mouse_activation(mouse_report); 241 auto_mouse_context.status.is_activated = auto_mouse_activation(mouse_report);
237 if (is_auto_mouse_active()) { 242 if (is_auto_mouse_active()) {
238 auto_mouse_context.timer.active = timer_read(); 243 auto_mouse_context.total_mouse_movement = (total_mouse_movement_t){.x = 0, .y = 0, .h = 0, .v = 0};
239 auto_mouse_context.timer.delay = 0; 244 auto_mouse_context.timer.active = timer_read();
245 auto_mouse_context.timer.delay = 0;
240 if (!layer_state_is((AUTO_MOUSE_TARGET_LAYER))) { 246 if (!layer_state_is((AUTO_MOUSE_TARGET_LAYER))) {
241 layer_on((AUTO_MOUSE_TARGET_LAYER)); 247 layer_on((AUTO_MOUSE_TARGET_LAYER));
242 } 248 }
243 } else if (layer_state_is((AUTO_MOUSE_TARGET_LAYER)) && timer_elapsed(auto_mouse_context.timer.active) > auto_mouse_context.config.timeout) { 249 } else if (layer_state_is((AUTO_MOUSE_TARGET_LAYER)) && timer_elapsed(auto_mouse_context.timer.active) > auto_mouse_context.config.timeout) {
244 layer_off((AUTO_MOUSE_TARGET_LAYER)); 250 layer_off((AUTO_MOUSE_TARGET_LAYER));
245 auto_mouse_context.timer.active = 0; 251 auto_mouse_context.timer.active = 0;
252 auto_mouse_context.total_mouse_movement = (total_mouse_movement_t){.x = 0, .y = 0, .h = 0, .v = 0};
246 } 253 }
247} 254}
248 255
diff --git a/quantum/pointing_device/pointing_device_auto_mouse.h b/quantum/pointing_device/pointing_device_auto_mouse.h
index 1343855e00..904f18b68e 100644
--- a/quantum/pointing_device/pointing_device_auto_mouse.h
+++ b/quantum/pointing_device/pointing_device_auto_mouse.h
@@ -42,9 +42,18 @@
42#ifndef AUTO_MOUSE_DEBOUNCE 42#ifndef AUTO_MOUSE_DEBOUNCE
43# define AUTO_MOUSE_DEBOUNCE 25 43# define AUTO_MOUSE_DEBOUNCE 25
44#endif 44#endif
45#ifndef AUTO_MOUSE_THRESHOLD
46# define AUTO_MOUSE_THRESHOLD 10
47#endif
45 48
46/* data structure */ 49/* data structure */
47typedef struct { 50typedef struct {
51 mouse_xy_report_t x;
52 mouse_xy_report_t y;
53 int8_t v;
54 int8_t h;
55} total_mouse_movement_t;
56typedef struct {
48 struct { 57 struct {
49 bool is_enabled; 58 bool is_enabled;
50 uint8_t layer; 59 uint8_t layer;
@@ -60,6 +69,7 @@ typedef struct {
60 bool is_toggled; 69 bool is_toggled;
61 int8_t mouse_key_tracker; 70 int8_t mouse_key_tracker;
62 } status; 71 } status;
72 total_mouse_movement_t total_mouse_movement;
63} auto_mouse_context_t; 73} auto_mouse_context_t;
64 74
65/* ----------Set up and control------------------------------------------------------------------------------ */ 75/* ----------Set up and control------------------------------------------------------------------------------ */