action.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. Copyright 2012,2013 Jun Wako <wakojun@gmail.com>
  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. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #ifndef ACTION_H
  15. #define ACTION_H
  16. #include <stdint.h>
  17. #include <stdbool.h>
  18. #include "keyboard.h"
  19. #include "keycode.h"
  20. #include "action_code.h"
  21. #include "action_macro.h"
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Disable macro and function features when LTO is enabled, since they break */
  26. #ifdef LTO_ENABLE
  27. # ifndef NO_ACTION_MACRO
  28. # define NO_ACTION_MACRO
  29. # endif
  30. # ifndef NO_ACTION_FUNCTION
  31. # define NO_ACTION_FUNCTION
  32. # endif
  33. #endif
  34. /* tapping count and state */
  35. typedef struct {
  36. bool interrupted : 1;
  37. bool reserved2 : 1;
  38. bool reserved1 : 1;
  39. bool reserved0 : 1;
  40. uint8_t count : 4;
  41. } tap_t;
  42. /* Key event container for recording */
  43. typedef struct {
  44. keyevent_t event;
  45. #ifndef NO_ACTION_TAPPING
  46. tap_t tap;
  47. #endif
  48. } keyrecord_t;
  49. /* Execute action per keyevent */
  50. void action_exec(keyevent_t event);
  51. /* action for key */
  52. action_t action_for_key(uint8_t layer, keypos_t key);
  53. /* macro */
  54. const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt);
  55. /* user defined special function */
  56. void action_function(keyrecord_t *record, uint8_t id, uint8_t opt);
  57. /* keyboard-specific key event (pre)processing */
  58. bool process_record_quantum(keyrecord_t *record);
  59. /* Utilities for actions. */
  60. #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE)
  61. extern bool disable_action_cache;
  62. #endif
  63. /* Code for handling one-handed key modifiers. */
  64. #ifdef SWAP_HANDS_ENABLE
  65. extern bool swap_hands;
  66. extern const keypos_t hand_swap_config[MATRIX_ROWS][MATRIX_COLS];
  67. # if (MATRIX_COLS <= 8)
  68. typedef uint8_t swap_state_row_t;
  69. # elif (MATRIX_COLS <= 16)
  70. typedef uint16_t swap_state_row_t;
  71. # elif (MATRIX_COLS <= 32)
  72. typedef uint32_t swap_state_row_t;
  73. # else
  74. # error "MATRIX_COLS: invalid value"
  75. # endif
  76. void process_hand_swap(keyevent_t *record);
  77. #endif
  78. void process_record_nocache(keyrecord_t *record);
  79. void process_record(keyrecord_t *record);
  80. void process_record_handler(keyrecord_t *record);
  81. void post_process_record_quantum(keyrecord_t *record);
  82. void process_action(keyrecord_t *record, action_t action);
  83. void register_code(uint8_t code);
  84. void unregister_code(uint8_t code);
  85. void tap_code(uint8_t code);
  86. void register_mods(uint8_t mods);
  87. void unregister_mods(uint8_t mods);
  88. void register_weak_mods(uint8_t mods);
  89. void unregister_weak_mods(uint8_t mods);
  90. // void set_mods(uint8_t mods);
  91. void clear_keyboard(void);
  92. void clear_keyboard_but_mods(void);
  93. void clear_keyboard_but_mods_and_keys(void);
  94. void layer_switch(uint8_t new_layer);
  95. bool is_tap_key(keypos_t key);
  96. bool is_tap_action(action_t action);
  97. #ifndef NO_ACTION_TAPPING
  98. void process_record_tap_hint(keyrecord_t *record);
  99. #endif
  100. /* debug */
  101. void debug_event(keyevent_t event);
  102. void debug_record(keyrecord_t record);
  103. void debug_action(action_t action);
  104. #ifdef __cplusplus
  105. }
  106. #endif
  107. #endif /* ACTION_H */