logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

pointing_device_auto_mouse.h (5162B)


  1. /* Copyright 2022 Alabastard
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #pragma once
  17. #include <stdint.h>
  18. #include <stdbool.h>
  19. #include "pointing_device.h"
  20. #include "keycodes.h"
  21. #include "action.h"
  22. #include "report.h"
  23. #include "action_layer.h"
  24. #include "action_tapping.h"
  25. /* check settings and set defaults */
  26. #ifndef POINTING_DEVICE_AUTO_MOUSE_ENABLE
  27. # error "POINTING_DEVICE_AUTO_MOUSE_ENABLE not defined! check config settings"
  28. #endif
  29. #ifndef AUTO_MOUSE_DEFAULT_LAYER
  30. # define AUTO_MOUSE_DEFAULT_LAYER 1
  31. #endif
  32. #ifndef AUTO_MOUSE_TIME
  33. # define AUTO_MOUSE_TIME 650
  34. #endif
  35. #ifndef AUTO_MOUSE_DELAY
  36. # define AUTO_MOUSE_DELAY GET_TAPPING_TERM(QK_MOUSE_BUTTON_1, &(keyrecord_t){})
  37. #endif
  38. #ifndef AUTO_MOUSE_DEBOUNCE
  39. # define AUTO_MOUSE_DEBOUNCE 25
  40. #endif
  41. #ifndef AUTO_MOUSE_THRESHOLD
  42. # define AUTO_MOUSE_THRESHOLD 10
  43. #endif
  44. /* data structure */
  45. typedef struct {
  46. mouse_xy_report_t x;
  47. mouse_xy_report_t y;
  48. int8_t v;
  49. int8_t h;
  50. } total_mouse_movement_t;
  51. typedef struct {
  52. struct {
  53. bool is_enabled;
  54. uint8_t layer;
  55. uint16_t timeout;
  56. uint8_t debounce;
  57. } config;
  58. struct {
  59. uint16_t active;
  60. uint16_t delay;
  61. } timer;
  62. struct {
  63. bool is_activated;
  64. bool is_toggled;
  65. int8_t mouse_key_tracker;
  66. } status;
  67. total_mouse_movement_t total_mouse_movement;
  68. } auto_mouse_context_t;
  69. /* ----------Set up and control------------------------------------------------------------------------------ */
  70. void set_auto_mouse_enable(bool enable); // enable/disable auto mouse feature
  71. bool get_auto_mouse_enable(void); // get auto_mouse_enable
  72. void set_auto_mouse_layer(uint8_t layer); // set target layer by index
  73. uint8_t get_auto_mouse_layer(void); // get target layer index
  74. void set_auto_mouse_timeout(uint16_t timeout); // set layer timeout
  75. uint16_t get_auto_mouse_timeout(void); // get layer timeout
  76. void set_auto_mouse_debounce(uint8_t debounce); // set debounce
  77. uint8_t get_auto_mouse_debounce(void); // get debounce
  78. void set_auto_mouse_key_tracker(int8_t key_tracker); // set key tracker
  79. int8_t get_auto_mouse_key_tracker(void); // get key tracker
  80. void auto_mouse_layer_off(void); // disable target layer if appropriate (DO NOT USE in layer_state_set stack!!)
  81. 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)
  82. bool is_auto_mouse_active(void); // check if target layer is active
  83. /* ----------For custom pointing device activation----------------------------------------------------------- */
  84. bool auto_mouse_activation(report_mouse_t mouse_report); // handles pointing device trigger conditions for target layer activation (overwritable)
  85. /* ----------Handling keyevents------------------------------------------------------------------------------ */
  86. void auto_mouse_keyevent(bool pressed); // trigger auto mouse keyevent: mouse_keytracker increment/decrement on press/release
  87. void auto_mouse_reset_trigger(bool pressed); // trigger non mouse keyevent: reset and start delay timer (DO NOT USE in layer_state_set stack!!)
  88. void auto_mouse_toggle(void); // toggle mouse layer flag disables mouse layer deactivation while on (meant for tap toggle or toggle of target)
  89. bool get_auto_mouse_toggle(void); // get toggle mouse layer flag value
  90. /* ----------Callbacks for adding keycodes to mouse record checking------------------------------------------ */
  91. bool is_mouse_record_kb(uint16_t keycode, keyrecord_t* record);
  92. bool is_mouse_record_user(uint16_t keycode, keyrecord_t* record);
  93. /* ----------Core functions (only used in custom pointing devices or key processing)------------------------- */
  94. void pointing_device_task_auto_mouse(report_mouse_t mouse_report); // add to pointing_device_task_*
  95. bool process_auto_mouse(uint16_t keycode, keyrecord_t* record); // add to process_record_*
  96. /* ----------Macros/Aliases---------------------------------------------------------------------------------- */
  97. #define AUTO_MOUSE_TARGET_LAYER get_auto_mouse_layer()
  98. #define AUTO_MOUSE_ENABLED get_auto_mouse_enable()