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.

160 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_BRIGHTNESS_DOWN:
  52. action.code = ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(keycode));
  53. break;
  54. #endif
  55. #ifdef MOUSEKEY_ENABLE
  56. case KC_MS_UP ... KC_MS_ACCEL2:
  57. action.code = ACTION_MOUSEKEY(keycode);
  58. break;
  59. #endif
  60. case KC_TRANSPARENT:
  61. action.code = ACTION_TRANSPARENT;
  62. break;
  63. case QK_MODS ... QK_MODS_MAX:;
  64. // Has a modifier
  65. // Split it up
  66. action.code = ACTION_MODS_KEY(keycode >> 8, keycode & 0xFF); // adds modifier to key
  67. break;
  68. #ifndef NO_ACTION_LAYER
  69. case QK_LAYER_TAP ... QK_LAYER_TAP_MAX:
  70. action.code = ACTION_LAYER_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF);
  71. break;
  72. case QK_TO ... QK_TO_MAX:;
  73. // Layer set "GOTO"
  74. action_layer = keycode & 0xFF;
  75. action.code = ACTION_LAYER_GOTO(action_layer);
  76. break;
  77. case QK_MOMENTARY ... QK_MOMENTARY_MAX:;
  78. // Momentary action_layer
  79. action_layer = keycode & 0xFF;
  80. action.code = ACTION_LAYER_MOMENTARY(action_layer);
  81. break;
  82. case QK_DEF_LAYER ... QK_DEF_LAYER_MAX:;
  83. // Set default action_layer
  84. action_layer = keycode & 0xFF;
  85. action.code = ACTION_DEFAULT_LAYER_SET(action_layer);
  86. break;
  87. case QK_TOGGLE_LAYER ... QK_TOGGLE_LAYER_MAX:;
  88. // Set toggle
  89. action_layer = keycode & 0xFF;
  90. action.code = ACTION_LAYER_TOGGLE(action_layer);
  91. break;
  92. #endif
  93. #ifndef NO_ACTION_ONESHOT
  94. case QK_ONE_SHOT_LAYER ... QK_ONE_SHOT_LAYER_MAX:;
  95. // OSL(action_layer) - One-shot action_layer
  96. action_layer = keycode & 0xFF;
  97. action.code = ACTION_LAYER_ONESHOT(action_layer);
  98. break;
  99. case QK_ONE_SHOT_MOD ... QK_ONE_SHOT_MOD_MAX:;
  100. // OSM(mod) - One-shot mod
  101. mod = mod_config(keycode & 0xFF);
  102. action.code = ACTION_MODS_ONESHOT(mod);
  103. break;
  104. #endif
  105. #ifndef NO_ACTION_LAYER
  106. case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:
  107. action.code = ACTION_LAYER_TAP_TOGGLE(keycode & 0xFF);
  108. break;
  109. case QK_LAYER_MOD ... QK_LAYER_MOD_MAX:
  110. mod = mod_config(keycode & 0xF);
  111. action_layer = (keycode >> 4) & 0xF;
  112. action.code = ACTION_LAYER_MODS(action_layer, mod);
  113. break;
  114. #endif
  115. #ifndef NO_ACTION_TAPPING
  116. case QK_MOD_TAP ... QK_MOD_TAP_MAX:
  117. mod = mod_config((keycode >> 0x8) & 0x1F);
  118. action.code = ACTION_MODS_TAP_KEY(mod, keycode & 0xFF);
  119. break;
  120. #endif
  121. #ifdef SWAP_HANDS_ENABLE
  122. case QK_SWAP_HANDS ... QK_SWAP_HANDS_MAX:
  123. action.code = ACTION(ACT_SWAP_HANDS, keycode & 0xff);
  124. break;
  125. #endif
  126. default:
  127. action.code = ACTION_NO;
  128. break;
  129. }
  130. return action;
  131. }
  132. // translates key to keycode
  133. __attribute__((weak)) uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key) {
  134. if (key.row < MATRIX_ROWS && key.col < MATRIX_COLS) {
  135. return pgm_read_word(&keymaps[layer][key.row][key.col]);
  136. }
  137. #ifdef ENCODER_MAP_ENABLE
  138. else if (key.row == KEYLOC_ENCODER_CW && key.col < NUM_ENCODERS) {
  139. return pgm_read_word(&encoder_map[layer][key.col][0]);
  140. } else if (key.row == KEYLOC_ENCODER_CCW && key.col < NUM_ENCODERS) {
  141. return pgm_read_word(&encoder_map[layer][key.col][1]);
  142. }
  143. #endif // ENCODER_MAP_ENABLE
  144. return KC_NO;
  145. }