action_util.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. Copyright 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 "compiler_support.h"
  17. #include "report.h"
  18. #include "modifiers.h"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. typedef union {
  23. uint8_t raw;
  24. struct {
  25. bool left_ctrl : 1;
  26. bool left_shift : 1;
  27. bool left_alt : 1;
  28. bool left_gui : 1;
  29. bool right_ctrl : 1;
  30. bool right_shift : 1;
  31. bool right_alt : 1;
  32. bool right_gui : 1;
  33. };
  34. } PACKED mod_t;
  35. STATIC_ASSERT(sizeof(mod_t) == sizeof(uint8_t), "Invalid size for 'mod_t'");
  36. extern report_keyboard_t *keyboard_report;
  37. #ifdef NKRO_ENABLE
  38. extern report_nkro_t *nkro_report;
  39. #endif
  40. void send_keyboard_report(void);
  41. /* key */
  42. inline void add_key(uint8_t key) {
  43. add_key_to_report(key);
  44. }
  45. inline void del_key(uint8_t key) {
  46. del_key_from_report(key);
  47. }
  48. inline void clear_keys(void) {
  49. clear_keys_from_report();
  50. }
  51. /* modifier */
  52. uint8_t get_mods(void);
  53. mod_t get_mod_state(void);
  54. void add_mods(uint8_t mods);
  55. void del_mods(uint8_t mods);
  56. void set_mods(uint8_t mods);
  57. void clear_mods(void);
  58. /* weak modifier */
  59. uint8_t get_weak_mods(void);
  60. mod_t get_weak_mod_state(void);
  61. void add_weak_mods(uint8_t mods);
  62. void del_weak_mods(uint8_t mods);
  63. void set_weak_mods(uint8_t mods);
  64. void clear_weak_mods(void);
  65. /* oneshot modifier */
  66. uint8_t get_oneshot_mods(void);
  67. mod_t get_oneshot_mod_state(void);
  68. void add_oneshot_mods(uint8_t mods);
  69. void del_oneshot_mods(uint8_t mods);
  70. void set_oneshot_mods(uint8_t mods);
  71. void clear_oneshot_mods(void);
  72. bool has_oneshot_mods_timed_out(void);
  73. uint8_t get_oneshot_locked_mods(void);
  74. mod_t get_oneshot_locked_mod_state(void);
  75. void add_oneshot_locked_mods(uint8_t mods);
  76. void set_oneshot_locked_mods(uint8_t mods);
  77. void clear_oneshot_locked_mods(void);
  78. void del_oneshot_locked_mods(uint8_t mods);
  79. typedef enum { ONESHOT_PRESSED = 0b01, ONESHOT_OTHER_KEY_PRESSED = 0b10, ONESHOT_START = 0b11, ONESHOT_TOGGLED = 0b100 } oneshot_fullfillment_t;
  80. void set_oneshot_layer(uint8_t layer, uint8_t state);
  81. uint8_t get_oneshot_layer(void);
  82. void clear_oneshot_layer_state(oneshot_fullfillment_t state);
  83. void reset_oneshot_layer(void);
  84. bool is_oneshot_layer_active(void);
  85. uint8_t get_oneshot_layer_state(void);
  86. bool has_oneshot_layer_timed_out(void);
  87. bool has_oneshot_swaphands_timed_out(void);
  88. void oneshot_locked_mods_changed_user(uint8_t mods);
  89. void oneshot_locked_mods_changed_kb(uint8_t mods);
  90. void oneshot_mods_changed_user(uint8_t mods);
  91. void oneshot_mods_changed_kb(uint8_t mods);
  92. void oneshot_layer_changed_user(uint8_t layer);
  93. void oneshot_layer_changed_kb(uint8_t layer);
  94. void oneshot_toggle(void);
  95. void oneshot_enable(void);
  96. void oneshot_disable(void);
  97. bool is_oneshot_enabled(void);
  98. /* inspect */
  99. uint8_t has_anymod(void);
  100. #ifdef SWAP_HANDS_ENABLE
  101. void set_oneshot_swaphands(void);
  102. void release_oneshot_swaphands(void);
  103. void use_oneshot_swaphands(void);
  104. void clear_oneshot_swaphands(void);
  105. #endif
  106. #ifdef DUMMY_MOD_NEUTRALIZER_KEYCODE
  107. // KC_A is used as the lowerbound instead of QK_BASIC because the range QK_BASIC...KC_A includes
  108. // internal keycodes like KC_NO and KC_TRANSPARENT which are unsuitable for use with `tap_code(kc)`.
  109. # if !(KC_A <= DUMMY_MOD_NEUTRALIZER_KEYCODE && DUMMY_MOD_NEUTRALIZER_KEYCODE <= QK_BASIC_MAX)
  110. # error "DUMMY_MOD_NEUTRALIZER_KEYCODE must be a basic, unmodified, HID keycode!"
  111. # endif
  112. void neutralize_flashing_modifiers(uint8_t active_mods);
  113. #endif
  114. #ifndef MODS_TO_NEUTRALIZE
  115. # define MODS_TO_NEUTRALIZE {MOD_BIT(KC_LEFT_ALT), MOD_BIT(KC_LEFT_GUI)}
  116. #endif
  117. #ifdef __cplusplus
  118. }
  119. #endif