This commit is contained in:
Drashna Jaelre
2025-09-11 00:32:30 +08:00
committed by GitHub
3 changed files with 33 additions and 6 deletions

View File

@@ -771,7 +771,8 @@ There are a few ways to control the auto mouse feature with both `config.h` opti
| `AUTO_MOUSE_TIME` | (Optional) Time layer remains active after activation | _ideally_ (250-1000) | _ms_ | `650 ms` |
| `AUTO_MOUSE_DELAY` | (Optional) Lockout time after non-mouse key is pressed | _ideally_ (100-1000) | _ms_ | `TAPPING_TERM` or `200 ms` |
| `AUTO_MOUSE_DEBOUNCE` | (Optional) Time delay from last activation to next update | _ideally_ (10 - 100) | _ms_ | `25 ms` |
| `AUTO_MOUSE_THRESHOLD` | (Optional) Amount of mouse movement required to switch layers | 0 - | _units_ | `10 units` |
| `AUTO_MOUSE_THRESHOLD` | (Optional) Amount of mouse movement required to switch layers | 0 - 127 | _units_ | `10 units` |
| `AUTO_MOUSE_SCROLL_THRESHOLD` | (Optional) Amount of mouse wheel movement required to switch layers | 0 - 127 | _units_ | `10 units` |
### Adding mouse keys

View File

@@ -23,6 +23,9 @@
# include "debug.h"
# include "action_util.h"
# include "quantum_keycodes.h"
# ifdef LAYER_LOCK_ENABLE
# include "layer_lock.h"
# endif
/* local data structure for tracking auto mouse */
static auto_mouse_context_t auto_mouse_context = {
@@ -111,7 +114,7 @@ int8_t get_auto_mouse_key_tracker(void) {
* @brief Reset auto mouse context
*
* Clear timers and status
*
* NOTE: this will set is_toggled to false so careful when using it
*/
static void auto_mouse_reset(void) {
@@ -175,6 +178,7 @@ void set_auto_mouse_debounce(uint8_t debounce) {
/**
* @brief Changes the timeout for the mouse auto layer to be disabled
*
* @param key_tracker
*/
void set_auto_mouse_key_tracker(int8_t key_tracker) {
@@ -186,7 +190,8 @@ void set_auto_mouse_key_tracker(int8_t key_tracker) {
*
* Change state of local layer_toggled bool meant to track when the mouse layer is toggled on by other means
*
* NOTE: While is_toggled is true it will prevent deactiving target layer (but not activation)
* NOTE: While is_toggled is true it will prevent deactiving target layer (but not
activation)
*/
void auto_mouse_toggle(void) {
auto_mouse_context.status.is_toggled ^= 1;
@@ -240,7 +245,7 @@ __attribute__((weak)) bool auto_mouse_activation(report_mouse_t mouse_report) {
auto_mouse_context.total_mouse_movement.y += mouse_report.y;
auto_mouse_context.total_mouse_movement.h += mouse_report.h;
auto_mouse_context.total_mouse_movement.v += mouse_report.v;
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;
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_SCROLL_THRESHOLD || abs(auto_mouse_context.total_mouse_movement.v) > AUTO_MOUSE_SCROLL_THRESHOLD || mouse_report.buttons;
}
/**
@@ -265,6 +270,9 @@ void pointing_device_task_auto_mouse(report_mouse_t mouse_report) {
layer_on((AUTO_MOUSE_TARGET_LAYER));
}
} 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;
# endif
layer_off((AUTO_MOUSE_TARGET_LAYER));
auto_mouse_context.timer.active = 0;
auto_mouse_context.total_mouse_movement = (total_mouse_movement_t){.x = 0, .y = 0, .h = 0, .v = 0};
@@ -299,6 +307,9 @@ void auto_mouse_keyevent(bool pressed) {
*/
void auto_mouse_reset_trigger(bool pressed) {
if (pressed) {
# ifdef LAYER_LOCK_ENABLE
if (is_layer_locked(AUTO_MOUSE_DEFAULT_LAYER)) return;
# endif
if (layer_state_is((AUTO_MOUSE_TARGET_LAYER))) {
layer_off((AUTO_MOUSE_TARGET_LAYER));
};
@@ -334,14 +345,18 @@ bool process_auto_mouse(uint16_t keycode, keyrecord_t* record) {
if (!(AUTO_MOUSE_ENABLED)) return true;
switch (keycode) {
// Skip Mod keys to avoid layer reset
// Skip Mod keys, KC_NO, and layer lock to avoid layer reset
case KC_NO:
case KC_LEFT_CTRL ... KC_RIGHT_GUI:
case QK_MODS ... QK_MODS_MAX:
case QK_LLCK:
break;
// TO((AUTO_MOUSE_TARGET_LAYER))-------------------------------------------------------------------------------
case QK_TO ... QK_TO_MAX:
if (QK_TO_GET_LAYER(keycode) == (AUTO_MOUSE_TARGET_LAYER)) {
if (!(record->event.pressed)) auto_mouse_toggle();
} else {
auto_mouse_context.status.is_toggled = false;
}
break;
// TG((AUTO_MOUSE_TARGET_LAYER))-------------------------------------------------------------------------------
@@ -359,6 +374,7 @@ bool process_auto_mouse(uint16_t keycode, keyrecord_t* record) {
case QK_DEF_LAYER ... QK_DEF_LAYER_MAX:
// PDF --------------------------------------------------------------------------------------------------------
case QK_PERSISTENT_DEF_LAYER ... QK_PERSISTENT_DEF_LAYER_MAX:
# ifndef NO_ACTION_ONESHOT
// OSL((AUTO_MOUSE_TARGET_LAYER))------------------------------------------------------------------------------
case QK_ONE_SHOT_LAYER ... QK_ONE_SHOT_LAYER_MAX:
@@ -430,7 +446,14 @@ 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) || IS_MOUSEKEY(keycode)) return true;
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;
}

View File

@@ -45,6 +45,9 @@
#ifndef AUTO_MOUSE_THRESHOLD
# define AUTO_MOUSE_THRESHOLD 10
#endif
#ifndef AUTO_MOUSE_SCROLL_THRESHOLD
# define AUTO_MOUSE_SCROLL_THRESHOLD AUTO_MOUSE_THRESHOLD
#endif
/* data structure */
typedef struct {