logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

action.h (4207B)


  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 keyrecord_t {
  40. keyevent_t event;
  41. #ifndef NO_ACTION_TAPPING
  42. tap_t tap;
  43. #endif
  44. #if defined(COMBO_ENABLE) || defined(REPEAT_KEY_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. /**
  73. * @brief Enable swap hands
  74. */
  75. void swap_hands_on(void);
  76. /**
  77. * @brief Disable swap hands
  78. */
  79. void swap_hands_off(void);
  80. /**
  81. * @brief Toggle swap hands enable state
  82. */
  83. void swap_hands_toggle(void);
  84. /**
  85. * @brief Get the swap hands enable state
  86. *
  87. * @return true
  88. * @return false
  89. */
  90. bool is_swap_hands_on(void);
  91. void process_hand_swap(keyevent_t *record);
  92. #endif
  93. void process_record_nocache(keyrecord_t *record);
  94. void process_record(keyrecord_t *record);
  95. void process_record_handler(keyrecord_t *record);
  96. void post_process_record_quantum(keyrecord_t *record);
  97. void process_action(keyrecord_t *record, action_t action);
  98. void register_code(uint8_t code);
  99. void unregister_code(uint8_t code);
  100. void tap_code(uint8_t code);
  101. void tap_code_delay(uint8_t code, uint16_t delay);
  102. void register_mods(uint8_t mods);
  103. void unregister_mods(uint8_t mods);
  104. void register_weak_mods(uint8_t mods);
  105. void unregister_weak_mods(uint8_t mods);
  106. // void set_mods(uint8_t mods);
  107. void clear_keyboard(void);
  108. void clear_keyboard_but_mods(void);
  109. void clear_keyboard_but_mods_and_keys(void);
  110. void layer_switch(uint8_t new_layer);
  111. bool is_tap_record(keyrecord_t *record);
  112. bool is_tap_action(action_t action);
  113. /**
  114. * Given an MT or LT keycode, returns the tap keycode. Otherwise returns the
  115. * original keycode unchanged.
  116. */
  117. uint16_t get_tap_keycode(uint16_t keycode);
  118. #ifndef NO_ACTION_TAPPING
  119. void process_record_tap_hint(keyrecord_t *record);
  120. #endif
  121. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  122. // Helpers
  123. #ifdef ACTION_DEBUG
  124. # include "debug.h"
  125. # include "print.h"
  126. # define ac_dprintf(...) dprintf(__VA_ARGS__)
  127. #else
  128. # define ac_dprintf(...) \
  129. do { \
  130. } while (0)
  131. #endif
  132. void debug_event(keyevent_t event);
  133. void debug_record(keyrecord_t record);
  134. void debug_action(action_t action);
  135. #ifdef __cplusplus
  136. }
  137. #endif