diff options
| author | Drashna Jaelre <drashna@drashna.net> | 2023-05-06 06:38:45 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-06 06:38:45 -0700 |
| commit | 59eb8940b028bfa2a215231719b8eeca57701ed1 (patch) | |
| tree | 45f67dd68176d760df43baf340c822f5b17ed8f3 /quantum/pointing_device | |
| parent | 578102b40056693de8a92b49cd0c48e51ff4ad4a (diff) | |
Make Pointing Device Auto Layer more configurable (#20061)
Co-authored-by: Pablo MartÃnez <58857054+elpekenin@users.noreply.github.com>
Diffstat (limited to 'quantum/pointing_device')
| -rw-r--r-- | quantum/pointing_device/pointing_device_auto_mouse.c | 50 | ||||
| -rw-r--r-- | quantum/pointing_device/pointing_device_auto_mouse.h | 10 |
2 files changed, 55 insertions, 5 deletions
diff --git a/quantum/pointing_device/pointing_device_auto_mouse.c b/quantum/pointing_device/pointing_device_auto_mouse.c index 5e78817c7c..b008d18db5 100644 --- a/quantum/pointing_device/pointing_device_auto_mouse.c +++ b/quantum/pointing_device/pointing_device_auto_mouse.c | |||
| @@ -20,7 +20,11 @@ | |||
| 20 | # include "pointing_device_auto_mouse.h" | 20 | # include "pointing_device_auto_mouse.h" |
| 21 | 21 | ||
| 22 | /* local data structure for tracking auto mouse */ | 22 | /* local data structure for tracking auto mouse */ |
| 23 | static auto_mouse_context_t auto_mouse_context = {.config.layer = (uint8_t)AUTO_MOUSE_DEFAULT_LAYER}; | 23 | static auto_mouse_context_t auto_mouse_context = { |
| 24 | .config.layer = (uint8_t)(AUTO_MOUSE_DEFAULT_LAYER), | ||
| 25 | .config.timeout = (uint16_t)(AUTO_MOUSE_TIME), | ||
| 26 | .config.debounce = (uint8_t)(AUTO_MOUSE_DEBOUNCE), | ||
| 27 | }; | ||
| 24 | 28 | ||
| 25 | /* local functions */ | 29 | /* local functions */ |
| 26 | static bool is_mouse_record(uint16_t keycode, keyrecord_t* record); | 30 | static bool is_mouse_record(uint16_t keycode, keyrecord_t* record); |
| @@ -63,6 +67,24 @@ uint8_t get_auto_mouse_layer(void) { | |||
| 63 | } | 67 | } |
| 64 | 68 | ||
| 65 | /** | 69 | /** |
| 70 | * @brief Get the current timeout to turn off mouse layer | ||
| 71 | * | ||
| 72 | * @return uint16_t timeout in ms | ||
| 73 | */ | ||
| 74 | uint16_t get_auto_mouse_timeout(void) { | ||
| 75 | return auto_mouse_context.config.timeout; | ||
| 76 | } | ||
| 77 | |||
| 78 | /** | ||
| 79 | * @brief Get the auto mouse debouncing timeout | ||
| 80 | * | ||
| 81 | * @return uint8_t | ||
| 82 | */ | ||
| 83 | uint8_t get_auto_mouse_debounce(void) { | ||
| 84 | return auto_mouse_context.config.debounce; | ||
| 85 | } | ||
| 86 | |||
| 87 | /** | ||
| 66 | * @brief get layer_toggled value | 88 | * @brief get layer_toggled value |
| 67 | * | 89 | * |
| 68 | * @return bool of current layer_toggled state | 90 | * @return bool of current layer_toggled state |
| @@ -115,6 +137,28 @@ void set_auto_mouse_layer(uint8_t layer) { | |||
| 115 | } | 137 | } |
| 116 | 138 | ||
| 117 | /** | 139 | /** |
| 140 | * @brief Changes the timeout for the mouse auto layer to be disabled | ||
| 141 | * | ||
| 142 | * @param timeout | ||
| 143 | */ | ||
| 144 | void set_auto_mouse_timeout(uint16_t timeout) { | ||
| 145 | if (auto_mouse_context.config.timeout == timeout) return; | ||
| 146 | auto_mouse_context.config.timeout = timeout; | ||
| 147 | auto_mouse_reset(); | ||
| 148 | } | ||
| 149 | |||
| 150 | /** | ||
| 151 | * @brief Set the auto mouse key debounce | ||
| 152 | * | ||
| 153 | * @param debounce | ||
| 154 | */ | ||
| 155 | void set_auto_mouse_debounce(uint8_t debounce) { | ||
| 156 | if (auto_mouse_context.config.debounce == debounce) return; | ||
| 157 | auto_mouse_context.config.debounce = debounce; | ||
| 158 | auto_mouse_reset(); | ||
| 159 | } | ||
| 160 | |||
| 161 | /** | ||
| 118 | * @brief toggle mouse layer setting | 162 | * @brief toggle mouse layer setting |
| 119 | * | 163 | * |
| 120 | * Change state of local layer_toggled bool meant to track when the mouse layer is toggled on by other means | 164 | * Change state of local layer_toggled bool meant to track when the mouse layer is toggled on by other means |
| @@ -181,7 +225,7 @@ __attribute__((weak)) bool auto_mouse_activation(report_mouse_t mouse_report) { | |||
| 181 | */ | 225 | */ |
| 182 | void pointing_device_task_auto_mouse(report_mouse_t mouse_report) { | 226 | void pointing_device_task_auto_mouse(report_mouse_t mouse_report) { |
| 183 | // skip if disabled, delay timer running, or debounce | 227 | // skip if disabled, delay timer running, or debounce |
| 184 | if (!(AUTO_MOUSE_ENABLED) || timer_elapsed(auto_mouse_context.timer.active) <= AUTO_MOUSE_DEBOUNCE || timer_elapsed(auto_mouse_context.timer.delay) <= AUTO_MOUSE_DELAY) { | 228 | if (!(AUTO_MOUSE_ENABLED) || timer_elapsed(auto_mouse_context.timer.active) <= auto_mouse_context.config.debounce || timer_elapsed(auto_mouse_context.timer.delay) <= AUTO_MOUSE_DELAY) { |
| 185 | return; | 229 | return; |
| 186 | } | 230 | } |
| 187 | // update activation and reset debounce | 231 | // update activation and reset debounce |
| @@ -192,7 +236,7 @@ void pointing_device_task_auto_mouse(report_mouse_t mouse_report) { | |||
| 192 | if (!layer_state_is((AUTO_MOUSE_TARGET_LAYER))) { | 236 | if (!layer_state_is((AUTO_MOUSE_TARGET_LAYER))) { |
| 193 | layer_on((AUTO_MOUSE_TARGET_LAYER)); | 237 | layer_on((AUTO_MOUSE_TARGET_LAYER)); |
| 194 | } | 238 | } |
| 195 | } else if (layer_state_is((AUTO_MOUSE_TARGET_LAYER)) && timer_elapsed(auto_mouse_context.timer.active) > AUTO_MOUSE_TIME) { | 239 | } else if (layer_state_is((AUTO_MOUSE_TARGET_LAYER)) && timer_elapsed(auto_mouse_context.timer.active) > auto_mouse_context.config.timeout) { |
| 196 | layer_off((AUTO_MOUSE_TARGET_LAYER)); | 240 | layer_off((AUTO_MOUSE_TARGET_LAYER)); |
| 197 | auto_mouse_context.timer.active = 0; | 241 | auto_mouse_context.timer.active = 0; |
| 198 | } | 242 | } |
diff --git a/quantum/pointing_device/pointing_device_auto_mouse.h b/quantum/pointing_device/pointing_device_auto_mouse.h index 0f26af79e6..7db63bc6b8 100644 --- a/quantum/pointing_device/pointing_device_auto_mouse.h +++ b/quantum/pointing_device/pointing_device_auto_mouse.h | |||
| @@ -43,8 +43,10 @@ | |||
| 43 | /* data structure */ | 43 | /* data structure */ |
| 44 | typedef struct { | 44 | typedef struct { |
| 45 | struct { | 45 | struct { |
| 46 | bool is_enabled; | 46 | bool is_enabled; |
| 47 | uint8_t layer; | 47 | uint8_t layer; |
| 48 | uint16_t timeout; | ||
| 49 | uint8_t debounce; | ||
| 48 | } config; | 50 | } config; |
| 49 | struct { | 51 | struct { |
| 50 | uint16_t active; | 52 | uint16_t active; |
| @@ -62,6 +64,10 @@ void set_auto_mouse_enable(bool enable); // enabl | |||
| 62 | bool get_auto_mouse_enable(void); // get auto_mouse_enable | 64 | bool get_auto_mouse_enable(void); // get auto_mouse_enable |
| 63 | void set_auto_mouse_layer(uint8_t layer); // set target layer by index | 65 | void set_auto_mouse_layer(uint8_t layer); // set target layer by index |
| 64 | uint8_t get_auto_mouse_layer(void); // get target layer index | 66 | uint8_t get_auto_mouse_layer(void); // get target layer index |
| 67 | void set_auto_mouse_timeout(uint16_t timeout); // set layer timeout | ||
| 68 | uint16_t get_auto_mouse_timeout(void); // get layer timeout | ||
| 69 | void set_auto_mouse_debounce(uint8_t debounce); // set debounce | ||
| 70 | uint8_t get_auto_mouse_debounce(void); // get debounce | ||
| 65 | void auto_mouse_layer_off(void); // disable target layer if appropriate (DO NOT USE in layer_state_set stack!!) | 71 | void auto_mouse_layer_off(void); // disable target layer if appropriate (DO NOT USE in layer_state_set stack!!) |
| 66 | layer_state_t remove_auto_mouse_layer(layer_state_t state, bool force); // remove auto mouse target layer from state if appropriate (can be forced) | 72 | layer_state_t remove_auto_mouse_layer(layer_state_t state, bool force); // remove auto mouse target layer from state if appropriate (can be forced) |
| 67 | 73 | ||
