pointing_device_auto_mouse.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 <string.h>
  18. #include "quantum.h"
  19. #include "pointing_device.h"
  20. #include "print.h"
  21. /* check settings and set defaults */
  22. #ifndef POINTING_DEVICE_AUTO_MOUSE_ENABLE
  23. # error "POINTING_DEVICE_AUTO_MOUSE_ENABLE not defined! check config settings"
  24. #endif
  25. #ifndef AUTO_MOUSE_DEFAULT_LAYER
  26. # define AUTO_MOUSE_DEFAULT_LAYER 1
  27. #endif
  28. #ifndef AUTO_MOUSE_TIME
  29. # define AUTO_MOUSE_TIME 650
  30. #endif
  31. #ifndef AUTO_MOUSE_DELAY
  32. #define AUTO_MOUSE_DELAY GET_TAPPING_TERM(KC_MS_BTN1, &(keyrecord_t){})
  33. #endif
  34. #ifndef AUTO_MOUSE_DEBOUNCE
  35. # define AUTO_MOUSE_DEBOUNCE 25
  36. #endif
  37. /* data structure */
  38. typedef struct {
  39. struct {
  40. bool is_enabled;
  41. uint8_t layer;
  42. } config;
  43. struct {
  44. uint16_t active;
  45. uint16_t delay;
  46. } timer;
  47. struct {
  48. bool is_activated;
  49. bool is_toggled;
  50. int8_t mouse_key_tracker;
  51. } status;
  52. } auto_mouse_context_t;
  53. /* ----------Set up and control------------------------------------------------------------------------------ */
  54. void set_auto_mouse_enable(bool enable); // enable/disable auto mouse feature
  55. bool get_auto_mouse_enable(void); // get auto_mouse_enable
  56. void set_auto_mouse_layer(uint8_t layer); // set target layer by index
  57. uint8_t get_auto_mouse_layer(void); // get target layer index
  58. void auto_mouse_layer_off(void); // disable target layer if appropriate (DO NOT USE in layer_state_set stack!!)
  59. 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)
  60. /* ----------For custom pointing device activation----------------------------------------------------------- */
  61. bool auto_mouse_activation(report_mouse_t mouse_report); // handles pointing device trigger conditions for target layer activation (overwritable)
  62. /* ----------Handling keyevents------------------------------------------------------------------------------ */
  63. void auto_mouse_keyevent(bool pressed); // trigger auto mouse keyevent: mouse_keytracker increment/decrement on press/release
  64. void auto_mouse_reset_trigger(bool pressed); // trigger non mouse keyevent: reset and start delay timer (DO NOT USE in layer_state_set stack!!)
  65. void auto_mouse_toggle(void); // toggle mouse layer flag disables mouse layer deactivation while on (meant for tap toggle or toggle of target)
  66. bool get_auto_mouse_toggle(void); // get toggle mouse layer flag value
  67. /* ----------Callbacks for adding keycodes to mouse record checking------------------------------------------ */
  68. bool is_mouse_record_kb(uint16_t keycode, keyrecord_t* record);
  69. bool is_mouse_record_user(uint16_t keycode, keyrecord_t* record);
  70. /* ----------Core functions (only used in custom pointing devices or key processing)------------------------- */
  71. void pointing_device_task_auto_mouse(report_mouse_t mouse_report); // add to pointing_device_task_*
  72. bool process_auto_mouse(uint16_t keycode, keyrecord_t* record); // add to process_record_*
  73. /* ----------Macros/Aliases---------------------------------------------------------------------------------- */
  74. #define AUTO_MOUSE_TARGET_LAYER get_auto_mouse_layer()
  75. #define AUTO_MOUSE_ENABLED get_auto_mouse_enable()