From 634e375f117674e3f3df7ef70f19618b793a4d52 Mon Sep 17 00:00:00 2001 From: Florian Didron Date: Mon, 29 Sep 2025 12:57:53 +0700 Subject: [PATCH] Feat/oneshot automouse (#421) * feat(automouse): one shot automouse * fix(automouse): one shot automouse status get reset when mouse is active * fix(automouse): remove stray defines --- .../pointing_device_auto_mouse.c | 23 +++++++++++++++++-- .../pointing_device_auto_mouse.h | 3 +++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/quantum/pointing_device/pointing_device_auto_mouse.c b/quantum/pointing_device/pointing_device_auto_mouse.c index 2b8cfdbf68..3cfb0ed464 100644 --- a/quantum/pointing_device/pointing_device_auto_mouse.c +++ b/quantum/pointing_device/pointing_device_auto_mouse.c @@ -32,6 +32,9 @@ 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), +#ifdef AUTO_MOUSE_ONESHOT + .one_shot = false, +#endif }; /* local functions */ @@ -49,7 +52,11 @@ static inline bool layer_hold_check(void) { /* check all layer activation criteria */ bool is_auto_mouse_active(void) { +#ifdef AUTO_MOUSE_ONESHOT + return auto_mouse_context.status.is_activated || auto_mouse_context.status.mouse_key_tracker || layer_hold_check() || auto_mouse_context.one_shot; +#else return auto_mouse_context.status.is_activated || auto_mouse_context.status.mouse_key_tracker || layer_hold_check(); +#endif } /** @@ -267,6 +274,11 @@ 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)); } +#ifdef AUTO_MOUSE_ONESHOT + if (!auto_mouse_context.one_shot) { + auto_mouse_context.one_shot = true; + } +#endif } else if (layer_state_is((AUTO_MOUSE_TARGET_LAYER)) && timer_elapsed(auto_mouse_context.timer.active) > auto_mouse_context.config.timeout) { #ifdef LAYER_LOCK_ENABLE if(is_layer_locked(AUTO_MOUSE_DEFAULT_LAYER)) return; @@ -429,6 +441,13 @@ bool process_auto_mouse(uint16_t keycode, keyrecord_t* record) { auto_mouse_context.status.mouse_key_tracker = 0; dprintf("key tracker error (<0) \n"); } + +#ifdef AUTO_MOUSE_ONESHOT + if (is_auto_mouse_active()) { + auto_mouse_context.one_shot = false; + } +#endif + return true; } @@ -444,13 +463,13 @@ bool process_auto_mouse(uint16_t keycode, keyrecord_t* record) { static bool is_mouse_record(uint16_t keycode, keyrecord_t* record) { // allow for keyboard to hook in and override if need be if (is_mouse_record_kb(keycode, record)) return true; - + // if it's a mouse key, only treat it as a mouse record if we're currently on the auto mouse target layer // this prevents mouse keys from activating the auto mouse layer when pressed on other layers if (IS_MOUSEKEY(keycode)) { return layer_state_is((AUTO_MOUSE_TARGET_LAYER)); } - + return false; } diff --git a/quantum/pointing_device/pointing_device_auto_mouse.h b/quantum/pointing_device/pointing_device_auto_mouse.h index 7689234eb4..cab4310904 100644 --- a/quantum/pointing_device/pointing_device_auto_mouse.h +++ b/quantum/pointing_device/pointing_device_auto_mouse.h @@ -73,6 +73,9 @@ typedef struct { int8_t mouse_key_tracker; } status; total_mouse_movement_t total_mouse_movement; +#ifdef AUTO_MOUSE_ONESHOT + bool one_shot; +#endif } auto_mouse_context_t; /* ----------Set up and control------------------------------------------------------------------------------ */