action.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. #pragma once
  15. #include <stdint.h>
  16. #include <stdbool.h>
  17. #include "keyboard.h"
  18. #include "keycode.h"
  19. #include "action_code.h"
  20. #include "action_macro.h"
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Disable macro and function features when LTO is enabled, since they break */
  25. #ifdef LTO_ENABLE
  26. # ifndef NO_ACTION_MACRO
  27. # define NO_ACTION_MACRO
  28. # endif
  29. # ifndef NO_ACTION_FUNCTION
  30. # define NO_ACTION_FUNCTION
  31. # endif
  32. #endif
  33. #ifndef TAP_CODE_DELAY
  34. # define TAP_CODE_DELAY 0
  35. #endif
  36. #ifndef TAP_HOLD_CAPS_DELAY
  37. # define TAP_HOLD_CAPS_DELAY 80
  38. #endif
  39. /* tapping count and state */
  40. typedef struct {
  41. bool interrupted : 1;
  42. bool reserved2 : 1;
  43. bool reserved1 : 1;
  44. bool reserved0 : 1;
  45. uint8_t count : 4;
  46. } tap_t;
  47. /* Key event container for recording */
  48. typedef struct {
  49. keyevent_t event;
  50. #ifndef NO_ACTION_TAPPING
  51. tap_t tap;
  52. #endif
  53. #ifdef COMBO_ENABLE
  54. uint16_t keycode;
  55. #endif
  56. } keyrecord_t;
  57. /* Execute action per keyevent */
  58. void action_exec(keyevent_t event);
  59. /* action for key */
  60. action_t action_for_key(uint8_t layer, keypos_t key);
  61. action_t action_for_keycode(uint16_t keycode);
  62. /* macro */
  63. const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt);
  64. /* user defined special function */
  65. void action_function(keyrecord_t *record, uint8_t id, uint8_t opt);
  66. /* keyboard-specific key event (pre)processing */
  67. bool process_record_quantum(keyrecord_t *record);
  68. /* Utilities for actions. */
  69. #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE)
  70. extern bool disable_action_cache;
  71. #endif
  72. /* Code for handling one-handed key modifiers. */
  73. #ifdef SWAP_HANDS_ENABLE
  74. extern bool swap_hands;
  75. extern const keypos_t PROGMEM hand_swap_config[MATRIX_ROWS][MATRIX_COLS];
  76. # if (MATRIX_COLS <= 8)
  77. typedef uint8_t swap_state_row_t;
  78. # elif (MATRIX_COLS <= 16)
  79. typedef uint16_t swap_state_row_t;
  80. # elif (MATRIX_COLS <= 32)
  81. typedef uint32_t swap_state_row_t;
  82. # else
  83. # error "MATRIX_COLS: invalid value"
  84. # endif
  85. void process_hand_swap(keyevent_t *record);
  86. #endif
  87. void process_record_nocache(keyrecord_t *record);
  88. void process_record(keyrecord_t *record);
  89. void process_record_handler(keyrecord_t *record);
  90. void post_process_record_quantum(keyrecord_t *record);
  91. void process_action(keyrecord_t *record, action_t action);
  92. void register_code(uint8_t code);
  93. void unregister_code(uint8_t code);
  94. void tap_code(uint8_t code);
  95. void tap_code_delay(uint8_t code, uint16_t delay);
  96. void register_mods(uint8_t mods);
  97. void unregister_mods(uint8_t mods);
  98. void register_weak_mods(uint8_t mods);
  99. void unregister_weak_mods(uint8_t mods);
  100. // void set_mods(uint8_t mods);
  101. void clear_keyboard(void);
  102. void clear_keyboard_but_mods(void);
  103. void clear_keyboard_but_mods_and_keys(void);
  104. void layer_switch(uint8_t new_layer);
  105. bool is_tap_key(keypos_t key);
  106. bool is_tap_record(keyrecord_t *record);
  107. bool is_tap_action(action_t action);
  108. #ifndef NO_ACTION_TAPPING
  109. void process_record_tap_hint(keyrecord_t *record);
  110. #endif
  111. /* debug */
  112. void debug_event(keyevent_t event);
  113. void debug_record(keyrecord_t record);
  114. void debug_action(action_t action);
  115. #ifdef __cplusplus
  116. }
  117. #endif