action.h 3.3 KB

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