You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
5.2 KiB

Process combos earlier & overlapping combos (#8591) * Combo processing improvements. Now it is possible to use ModTap and LayerTap keys as part of combos. Overlapping combos also don't trigger all the combos, just exactly the one that you press. New settings: - COMBO_MUST_HOLD_MODS - COMBO_MOD_TERM - COMBO_TERM_PER_COMBO - COMBO_MUST_HOLD_PER_COMBO - COMBO_STRICT_TIMER - COMBO_NO_TIMER * Remove the size flags from combo_t struct boolean members. This in the end actually saves space as the members are accessed so many times. The amount of operations needed to access the bits uses more memory than setting the size saves. * Fix `process_combo_key_release` not called correctly with tap-only combos * Fix not passing a pointer when NO_ACTION_TAPPING is defined. * Docs for `COMBO_ONLY_FROM_LAYER` * Update docs/feature_combo.md Co-authored-by: precondition <57645186+precondition@users.noreply.github.com> * Update quantum/process_keycode/process_combo.c Co-authored-by: precondition <57645186+precondition@users.noreply.github.com> * Add `EXTRA_SHORT_COMBOS` option. Stuff combo's `disabled` and `active` flags into `state`. Possibly can save some space. * Add more examples and clarify things with dict management system. - Simple examples now has a combo that has modifiers included. - The slightly more advanced examples now are actually more advanced instead of just `tap_code16(<modded-keycode>)`. - Added a note that `COMBO_ACTION`s are not needed anymore as you can just use custom keycodes. - Added a note that the `g/keymap_combo.h` macros use the `process_combo_event` function and that it is not usable in one's keymap afterwards. * Update docs/feature_combo.md Co-authored-by: precondition <57645186+precondition@users.noreply.github.com> * Update docs/feature_combo.md Co-authored-by: precondition <57645186+precondition@users.noreply.github.com> * Update docs/feature_combo.md Co-authored-by: precondition <57645186+precondition@users.noreply.github.com> * Update docs/feature_combo.md Co-authored-by: precondition <57645186+precondition@users.noreply.github.com> * Update docs/feature_combo.md Co-authored-by: precondition <57645186+precondition@users.noreply.github.com> * Change "the" combo action example to "email" example. * Update docs/feature_combo.md Co-authored-by: precondition <57645186+precondition@users.noreply.github.com> * Fix sneaky infinite loop with `combo_disable()` No need to call `dump_key_buffer` when disabling combos because the buffer is either being dumped if a combo-key was pressed, or the buffer is empty if a non-combo-key is pressed. * Update docs/feature_combo.md Co-authored-by: precondition <57645186+precondition@users.noreply.github.com> * Update docs/feature_combo.md Co-authored-by: precondition <57645186+precondition@users.noreply.github.com> Co-authored-by: precondition <57645186+precondition@users.noreply.github.com> Co-authored-by: Drashna Jaelre <drashna@live.com>
2 years ago
Process combos earlier & overlapping combos (#8591) * Combo processing improvements. Now it is possible to use ModTap and LayerTap keys as part of combos. Overlapping combos also don't trigger all the combos, just exactly the one that you press. New settings: - COMBO_MUST_HOLD_MODS - COMBO_MOD_TERM - COMBO_TERM_PER_COMBO - COMBO_MUST_HOLD_PER_COMBO - COMBO_STRICT_TIMER - COMBO_NO_TIMER * Remove the size flags from combo_t struct boolean members. This in the end actually saves space as the members are accessed so many times. The amount of operations needed to access the bits uses more memory than setting the size saves. * Fix `process_combo_key_release` not called correctly with tap-only combos * Fix not passing a pointer when NO_ACTION_TAPPING is defined. * Docs for `COMBO_ONLY_FROM_LAYER` * Update docs/feature_combo.md Co-authored-by: precondition <57645186+precondition@users.noreply.github.com> * Update quantum/process_keycode/process_combo.c Co-authored-by: precondition <57645186+precondition@users.noreply.github.com> * Add `EXTRA_SHORT_COMBOS` option. Stuff combo's `disabled` and `active` flags into `state`. Possibly can save some space. * Add more examples and clarify things with dict management system. - Simple examples now has a combo that has modifiers included. - The slightly more advanced examples now are actually more advanced instead of just `tap_code16(<modded-keycode>)`. - Added a note that `COMBO_ACTION`s are not needed anymore as you can just use custom keycodes. - Added a note that the `g/keymap_combo.h` macros use the `process_combo_event` function and that it is not usable in one's keymap afterwards. * Update docs/feature_combo.md Co-authored-by: precondition <57645186+precondition@users.noreply.github.com> * Update docs/feature_combo.md Co-authored-by: precondition <57645186+precondition@users.noreply.github.com> * Update docs/feature_combo.md Co-authored-by: precondition <57645186+precondition@users.noreply.github.com> * Update docs/feature_combo.md Co-authored-by: precondition <57645186+precondition@users.noreply.github.com> * Update docs/feature_combo.md Co-authored-by: precondition <57645186+precondition@users.noreply.github.com> * Change "the" combo action example to "email" example. * Update docs/feature_combo.md Co-authored-by: precondition <57645186+precondition@users.noreply.github.com> * Fix sneaky infinite loop with `combo_disable()` No need to call `dump_key_buffer` when disabling combos because the buffer is either being dumped if a combo-key was pressed, or the buffer is empty if a non-combo-key is pressed. * Update docs/feature_combo.md Co-authored-by: precondition <57645186+precondition@users.noreply.github.com> * Update docs/feature_combo.md Co-authored-by: precondition <57645186+precondition@users.noreply.github.com> Co-authored-by: precondition <57645186+precondition@users.noreply.github.com> Co-authored-by: Drashna Jaelre <drashna@live.com>
2 years ago
  1. /*
  2. Copyright 2012-2017 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. #include "keymap.h"
  15. #include "report.h"
  16. #include "keycode.h"
  17. #include "action_layer.h"
  18. #include "action.h"
  19. #include "debug.h"
  20. #include "quantum.h"
  21. #ifdef BACKLIGHT_ENABLE
  22. # include "backlight.h"
  23. #endif
  24. #ifdef MIDI_ENABLE
  25. # include "process_midi.h"
  26. #endif
  27. extern keymap_config_t keymap_config;
  28. #include <inttypes.h>
  29. /* converts key to action */
  30. action_t action_for_key(uint8_t layer, keypos_t key) {
  31. // 16bit keycodes - important
  32. uint16_t keycode = keymap_key_to_keycode(layer, key);
  33. return action_for_keycode(keycode);
  34. };
  35. action_t action_for_keycode(uint16_t keycode) {
  36. // keycode remapping
  37. keycode = keycode_config(keycode);
  38. action_t action = {};
  39. uint8_t action_layer, mod;
  40. (void)action_layer;
  41. (void)mod;
  42. switch (keycode) {
  43. case KC_A ... KC_EXSEL:
  44. case KC_LEFT_CTRL ... KC_RIGHT_GUI:
  45. action.code = ACTION_KEY(keycode);
  46. break;
  47. #ifdef EXTRAKEY_ENABLE
  48. case KC_SYSTEM_POWER ... KC_SYSTEM_WAKE:
  49. action.code = ACTION_USAGE_SYSTEM(KEYCODE2SYSTEM(keycode));
  50. break;
  51. case KC_AUDIO_MUTE ... KC_ASSISTANT:
  52. action.code = ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(keycode));
  53. break;
  54. #endif
  55. case KC_MS_UP ... KC_MS_ACCEL2:
  56. action.code = ACTION_MOUSEKEY(keycode);
  57. break;
  58. case KC_TRANSPARENT:
  59. action.code = ACTION_TRANSPARENT;
  60. break;
  61. case QK_MODS ... QK_MODS_MAX:;
  62. // Has a modifier
  63. // Split it up
  64. action.code = ACTION_MODS_KEY(keycode >> 8, keycode & 0xFF); // adds modifier to key
  65. break;
  66. #ifndef NO_ACTION_LAYER
  67. case QK_LAYER_TAP ... QK_LAYER_TAP_MAX:
  68. action.code = ACTION_LAYER_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF);
  69. break;
  70. case QK_TO ... QK_TO_MAX:;
  71. // Layer set "GOTO"
  72. action_layer = keycode & 0xFF;
  73. action.code = ACTION_LAYER_GOTO(action_layer);
  74. break;
  75. case QK_MOMENTARY ... QK_MOMENTARY_MAX:;
  76. // Momentary action_layer
  77. action_layer = keycode & 0xFF;
  78. action.code = ACTION_LAYER_MOMENTARY(action_layer);
  79. break;
  80. case QK_DEF_LAYER ... QK_DEF_LAYER_MAX:;
  81. // Set default action_layer
  82. action_layer = keycode & 0xFF;
  83. action.code = ACTION_DEFAULT_LAYER_SET(action_layer);
  84. break;
  85. case QK_TOGGLE_LAYER ... QK_TOGGLE_LAYER_MAX:;
  86. // Set toggle
  87. action_layer = keycode & 0xFF;
  88. action.code = ACTION_LAYER_TOGGLE(action_layer);
  89. break;
  90. #endif
  91. #ifndef NO_ACTION_ONESHOT
  92. case QK_ONE_SHOT_LAYER ... QK_ONE_SHOT_LAYER_MAX:;
  93. // OSL(action_layer) - One-shot action_layer
  94. action_layer = keycode & 0xFF;
  95. action.code = ACTION_LAYER_ONESHOT(action_layer);
  96. break;
  97. case QK_ONE_SHOT_MOD ... QK_ONE_SHOT_MOD_MAX:;
  98. // OSM(mod) - One-shot mod
  99. mod = mod_config(keycode & 0x1F);
  100. action.code = ACTION_MODS_ONESHOT(mod);
  101. break;
  102. #endif
  103. #ifndef NO_ACTION_LAYER
  104. case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:
  105. action.code = ACTION_LAYER_TAP_TOGGLE(keycode & 0xFF);
  106. break;
  107. case QK_LAYER_MOD ... QK_LAYER_MOD_MAX:
  108. mod = mod_config(keycode & 0x1F);
  109. action_layer = (keycode >> 5) & 0xF;
  110. action.code = ACTION_LAYER_MODS(action_layer, mod);
  111. break;
  112. #endif
  113. #ifndef NO_ACTION_TAPPING
  114. case QK_MOD_TAP ... QK_MOD_TAP_MAX:
  115. mod = mod_config((keycode >> 0x8) & 0x1F);
  116. action.code = ACTION_MODS_TAP_KEY(mod, keycode & 0xFF);
  117. break;
  118. #endif
  119. #ifdef SWAP_HANDS_ENABLE
  120. case QK_SWAP_HANDS ... QK_SWAP_HANDS_MAX:
  121. action.code = ACTION(ACT_SWAP_HANDS, keycode & 0xff);
  122. break;
  123. #endif
  124. default:
  125. action.code = ACTION_NO;
  126. break;
  127. }
  128. return action;
  129. }
  130. // translates key to keycode
  131. __attribute__((weak)) uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key) {
  132. if (key.row < MATRIX_ROWS && key.col < MATRIX_COLS) {
  133. return keycode_at_keymap_location(layer, key.row, key.col);
  134. }
  135. #ifdef ENCODER_MAP_ENABLE
  136. else if (key.row == KEYLOC_ENCODER_CW && key.col < NUM_ENCODERS) {
  137. return keycode_at_encodermap_location(layer, key.col, true);
  138. } else if (key.row == KEYLOC_ENCODER_CCW && key.col < NUM_ENCODERS) {
  139. return keycode_at_encodermap_location(layer, key.col, false);
  140. }
  141. #endif // ENCODER_MAP_ENABLE
  142. return KC_NO;
  143. }