action.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. /* tapping count and state */
  25. typedef struct {
  26. bool interrupted :1;
  27. bool reserved2 :1;
  28. bool reserved1 :1;
  29. bool reserved0 :1;
  30. uint8_t count :4;
  31. } tap_t;
  32. /* Key event container for recording */
  33. typedef struct {
  34. keyevent_t event;
  35. #ifndef NO_ACTION_TAPPING
  36. tap_t tap;
  37. #endif
  38. } keyrecord_t;
  39. /* Execute action per keyevent */
  40. void action_exec(keyevent_t event);
  41. /* action for key */
  42. action_t action_for_key(uint8_t layer, keypos_t key);
  43. /* macro */
  44. const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt);
  45. /* user defined special function */
  46. void action_function(keyrecord_t *record, uint8_t id, uint8_t opt);
  47. /* keyboard-specific key event (pre)processing */
  48. bool process_record_quantum(keyrecord_t *record);
  49. /* Utilities for actions. */
  50. #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS)
  51. extern bool disable_action_cache;
  52. #endif
  53. /* Code for handling one-handed key modifiers. */
  54. #ifdef SWAP_HANDS_ENABLE
  55. extern bool swap_hands;
  56. extern const keypos_t hand_swap_config[MATRIX_ROWS][MATRIX_COLS];
  57. #if (MATRIX_COLS <= 8)
  58. typedef uint8_t swap_state_row_t;
  59. #elif (MATRIX_COLS <= 16)
  60. typedef uint16_t swap_state_row_t;
  61. #elif (MATRIX_COLS <= 32)
  62. typedef uint32_t swap_state_row_t;
  63. #else
  64. #error "MATRIX_COLS: invalid value"
  65. #endif
  66. void process_hand_swap(keyevent_t *record);
  67. #endif
  68. void process_record_nocache(keyrecord_t *record);
  69. void process_record(keyrecord_t *record);
  70. void process_action(keyrecord_t *record, action_t action);
  71. void register_code(uint8_t code);
  72. void unregister_code(uint8_t code);
  73. void register_mods(uint8_t mods);
  74. void unregister_mods(uint8_t mods);
  75. //void set_mods(uint8_t mods);
  76. void clear_keyboard(void);
  77. void clear_keyboard_but_mods(void);
  78. void layer_switch(uint8_t new_layer);
  79. bool is_tap_key(keypos_t key);
  80. #ifndef NO_ACTION_TAPPING
  81. void process_record_tap_hint(keyrecord_t *record);
  82. #endif
  83. /* debug */
  84. void debug_event(keyevent_t event);
  85. void debug_record(keyrecord_t record);
  86. void debug_action(action_t action);
  87. #ifdef __cplusplus
  88. }
  89. #endif