From 59eb8940b028bfa2a215231719b8eeca57701ed1 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Sat, 6 May 2023 06:38:45 -0700 Subject: [PATCH] Make Pointing Device Auto Layer more configurable (#20061) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Pablo Martínez <58857054+elpekenin@users.noreply.github.com> --- docs/feature_pointing_device.md | 4 ++ .../pointing_device_auto_mouse.c | 50 +++++++++++++++++-- .../pointing_device_auto_mouse.h | 10 +++- 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/docs/feature_pointing_device.md b/docs/feature_pointing_device.md index e5a268e47b8d..909eff826de1 100644 --- a/docs/feature_pointing_device.md +++ b/docs/feature_pointing_device.md @@ -689,6 +689,10 @@ There are several functions that allow for more advanced interaction with the au | `auto_mouse_layer_off(void)` | Disable target layer if appropriate will call (makes call to `layer_state_set`) | | `void`(None) | | `auto_mouse_toggle(void)` | Toggle on/off target toggle state (disables layer deactivation when true) | | `void`(None) | | `get_auto_mouse_toggle(void)` | Return value of toggling state variable | | `bool` | +| `set_auto_mouse_timeout(uint16_t timeout)` | Change/set the timeout for turing off the layer | | `void`(None) | +| `get_auto_mouse_timeout(void)` | Return the current timeout for turing off the layer | | `uint16_t` | +| `set_auto_mouse_debounce(uint16_t timeout)` | Change/set the debounce for preventing layer activation | | `void`(None) | +| `get_auto_mouse_debounce(void)` | Return the current debounce for preventing layer activation | | `uint8_t` | _NOTES:_ - _Due to the nature of how some functions work, the `auto_mouse_trigger_reset`, and `auto_mouse_layer_off` functions should never be called in the `layer_state_set_*` stack as this can cause indefinite loops._ diff --git a/quantum/pointing_device/pointing_device_auto_mouse.c b/quantum/pointing_device/pointing_device_auto_mouse.c index 5e78817c7c5f..b008d18db54a 100644 --- a/quantum/pointing_device/pointing_device_auto_mouse.c +++ b/quantum/pointing_device/pointing_device_auto_mouse.c @@ -20,7 +20,11 @@ # include "pointing_device_auto_mouse.h" /* local data structure for tracking auto mouse */ -static auto_mouse_context_t auto_mouse_context = {.config.layer = (uint8_t)AUTO_MOUSE_DEFAULT_LAYER}; +static auto_mouse_context_t auto_mouse_context = { + .config.layer = (uint8_t)(AUTO_MOUSE_DEFAULT_LAYER), + .config.timeout = (uint16_t)(AUTO_MOUSE_TIME), + .config.debounce = (uint8_t)(AUTO_MOUSE_DEBOUNCE), +}; /* local functions */ static bool is_mouse_record(uint16_t keycode, keyrecord_t* record); @@ -62,6 +66,24 @@ uint8_t get_auto_mouse_layer(void) { return auto_mouse_context.config.layer; } +/** + * @brief Get the current timeout to turn off mouse layer + * + * @return uint16_t timeout in ms + */ +uint16_t get_auto_mouse_timeout(void) { + return auto_mouse_context.config.timeout; +} + +/** + * @brief Get the auto mouse debouncing timeout + * + * @return uint8_t + */ +uint8_t get_auto_mouse_debounce(void) { + return auto_mouse_context.config.debounce; +} + /** * @brief get layer_toggled value * @@ -114,6 +136,28 @@ void set_auto_mouse_layer(uint8_t layer) { auto_mouse_reset(); } +/** + * @brief Changes the timeout for the mouse auto layer to be disabled + * + * @param timeout + */ +void set_auto_mouse_timeout(uint16_t timeout) { + if (auto_mouse_context.config.timeout == timeout) return; + auto_mouse_context.config.timeout = timeout; + auto_mouse_reset(); +} + +/** + * @brief Set the auto mouse key debounce + * + * @param debounce + */ +void set_auto_mouse_debounce(uint8_t debounce) { + if (auto_mouse_context.config.debounce == debounce) return; + auto_mouse_context.config.debounce = debounce; + auto_mouse_reset(); +} + /** * @brief toggle mouse layer setting * @@ -181,7 +225,7 @@ __attribute__((weak)) bool auto_mouse_activation(report_mouse_t mouse_report) { */ void pointing_device_task_auto_mouse(report_mouse_t mouse_report) { // skip if disabled, delay timer running, or debounce - if (!(AUTO_MOUSE_ENABLED) || timer_elapsed(auto_mouse_context.timer.active) <= AUTO_MOUSE_DEBOUNCE || timer_elapsed(auto_mouse_context.timer.delay) <= AUTO_MOUSE_DELAY) { + 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) { return; } // update activation and reset debounce @@ -192,7 +236,7 @@ void pointing_device_task_auto_mouse(report_mouse_t mouse_report) { if (!layer_state_is((AUTO_MOUSE_TARGET_LAYER))) { layer_on((AUTO_MOUSE_TARGET_LAYER)); } - } else if (layer_state_is((AUTO_MOUSE_TARGET_LAYER)) && timer_elapsed(auto_mouse_context.timer.active) > AUTO_MOUSE_TIME) { + } else if (layer_state_is((AUTO_MOUSE_TARGET_LAYER)) && timer_elapsed(auto_mouse_context.timer.active) > auto_mouse_context.config.timeout) { layer_off((AUTO_MOUSE_TARGET_LAYER)); auto_mouse_context.timer.active = 0; } diff --git a/quantum/pointing_device/pointing_device_auto_mouse.h b/quantum/pointing_device/pointing_device_auto_mouse.h index 0f26af79e670..7db63bc6b8ab 100644 --- a/quantum/pointing_device/pointing_device_auto_mouse.h +++ b/quantum/pointing_device/pointing_device_auto_mouse.h @@ -43,8 +43,10 @@ /* data structure */ typedef struct { struct { - bool is_enabled; - uint8_t layer; + bool is_enabled; + uint8_t layer; + uint16_t timeout; + uint8_t debounce; } config; struct { uint16_t active; @@ -62,6 +64,10 @@ void set_auto_mouse_enable(bool enable); // enabl bool get_auto_mouse_enable(void); // get auto_mouse_enable void set_auto_mouse_layer(uint8_t layer); // set target layer by index uint8_t get_auto_mouse_layer(void); // get target layer index +void set_auto_mouse_timeout(uint16_t timeout); // set layer timeout +uint16_t get_auto_mouse_timeout(void); // get layer timeout +void set_auto_mouse_debounce(uint8_t debounce); // set debounce +uint8_t get_auto_mouse_debounce(void); // get debounce void auto_mouse_layer_off(void); // disable target layer if appropriate (DO NOT USE in layer_state_set stack!!) 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)