pointing_device_auto_mouse.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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(KC_MS_BTN1, &(keyrecord_t){})
  37. #endif
  38. #ifndef AUTO_MOUSE_DEBOUNCE
  39. # define AUTO_MOUSE_DEBOUNCE 25
  40. #endif
  41. /* data structure */
  42. typedef struct {
  43. struct {
  44. bool is_enabled;
  45. uint8_t layer;
  46. uint16_t timeout;
  47. uint8_t debounce;
  48. } config;
  49. struct {
  50. uint16_t active;
  51. uint16_t delay;
  52. } timer;
  53. struct {
  54. bool is_activated;
  55. bool is_toggled;
  56. int8_t mouse_key_tracker;
  57. } status;
  58. } auto_mouse_context_t;
  59. /* ----------Set up and control------------------------------------------------------------------------------ */
  60. void set_auto_mouse_enable(bool enable); // enable/disable auto mouse feature
  61. bool get_auto_mouse_enable(void); // get auto_mouse_enable
  62. void set_auto_mouse_layer(uint8_t layer); // set target layer by index
  63. uint8_t get_auto_mouse_layer(void); // get target layer index
  64. void set_auto_mouse_timeout(uint16_t timeout); // set layer timeout
  65. uint16_t get_auto_mouse_timeout(void); // get layer timeout
  66. void set_auto_mouse_debounce(uint8_t debounce); // set debounce
  67. uint8_t get_auto_mouse_debounce(void); // get debounce
  68. void auto_mouse_layer_off(void); // disable target layer if appropriate (DO NOT USE in layer_state_set stack!!)
  69. 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)
  70. /* ----------For custom pointing device activation----------------------------------------------------------- */
  71. bool auto_mouse_activation(report_mouse_t mouse_report); // handles pointing device trigger conditions for target layer activation (overwritable)
  72. /* ----------Handling keyevents------------------------------------------------------------------------------ */
  73. void auto_mouse_keyevent(bool pressed); // trigger auto mouse keyevent: mouse_keytracker increment/decrement on press/release
  74. void auto_mouse_reset_trigger(bool pressed); // trigger non mouse keyevent: reset and start delay timer (DO NOT USE in layer_state_set stack!!)
  75. void auto_mouse_toggle(void); // toggle mouse layer flag disables mouse layer deactivation while on (meant for tap toggle or toggle of target)
  76. bool get_auto_mouse_toggle(void); // get toggle mouse layer flag value
  77. /* ----------Callbacks for adding keycodes to mouse record checking------------------------------------------ */
  78. bool is_mouse_record_kb(uint16_t keycode, keyrecord_t* record);
  79. bool is_mouse_record_user(uint16_t keycode, keyrecord_t* record);
  80. /* ----------Core functions (only used in custom pointing devices or key processing)------------------------- */
  81. void pointing_device_task_auto_mouse(report_mouse_t mouse_report); // add to pointing_device_task_*
  82. bool process_auto_mouse(uint16_t keycode, keyrecord_t* record); // add to process_record_*
  83. /* ----------Macros/Aliases---------------------------------------------------------------------------------- */
  84. #define AUTO_MOUSE_TARGET_LAYER get_auto_mouse_layer()
  85. #define AUTO_MOUSE_ENABLED get_auto_mouse_enable()