leader.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #include "leader.h"
  2. #ifdef RGBLIGHT_ENABLE
  3. extern rgblight_config_t rgblight_config;
  4. #endif
  5. bool leader_succeed;
  6. LEADER_EXTERNS();
  7. void matrix_scan_user(void) {
  8. static bool has_ran_yet;
  9. if (!has_ran_yet) {
  10. has_ran_yet = true;
  11. startup_user();
  12. }
  13. #ifdef TAP_DANCE_ENABLE // Run Diablo 3 macro checking code.
  14. // run_diablo_macro_check();
  15. #endif
  16. #ifdef RGBLIGHT_ENABLE
  17. matrix_scan_rgb();
  18. #endif
  19. LEADER_DICTIONARY() {
  20. leader_succeed = leading = false;
  21. SEQ_ONE_KEY(KC_W) {
  22. // vim/tmux: Use in command mode in vim: write to file, switch tmux pane in the current session window and repeat the last command
  23. SEND_STRING(":w" SS_TAP(X_ENTER));
  24. tmux_pane_switch_repeat();
  25. leader_succeed = true;
  26. } else
  27. SEQ_ONE_KEY(KC_T) {
  28. // Send the Tmux Prefix
  29. tmux_prefix();
  30. leader_succeed = true;
  31. } else
  32. SEQ_ONE_KEY(KC_A) {
  33. // tmux: Send the prefix and press 'right' arrow
  34. tmux_prefix();
  35. tap_code(KC_RIGHT);
  36. leader_succeed = true;
  37. } else
  38. SEQ_TWO_KEYS(KC_T, KC_T) {
  39. // tmux: Send the prefix to a nested session
  40. tmux_prefix();
  41. tmux_prefix();
  42. leader_succeed = true;
  43. } else
  44. SEQ_TWO_KEYS(KC_T, KC_R) {
  45. // tmux: Switch pane and repeat last action
  46. tmux_pane_switch_repeat();
  47. leader_succeed = true;
  48. } else
  49. SEQ_TWO_KEYS(KC_V, KC_Z){
  50. // vim: Zoom pane
  51. tap_code16(LCTL(KC_W));
  52. tap_code16(LSFT(KC_BSLS));
  53. leader_succeed = true;
  54. } else
  55. SEQ_TWO_KEYS(KC_V, KC_R) {
  56. // vim: Substitute and place cursor
  57. SEND_STRING(":%s///g" SS_TAP(X_LEFT));
  58. tap_code(KC_LEFT);
  59. tap_code(KC_LEFT);
  60. leader_succeed = true;
  61. } else
  62. SEQ_TWO_KEYS(KC_V, KC_T) {
  63. // vim: move current pane to new tab
  64. tap_code16(LCTL(KC_W));
  65. tap_code16(LSFT(KC_T));
  66. leader_succeed = true;
  67. } else
  68. SEQ_ONE_KEY(KC_R){
  69. // Toggle RGB Layer indicator
  70. tap_code16(KC_RGB_T);
  71. leader_succeed = true;
  72. } else
  73. SEQ_ONE_KEY(KC_SPC){
  74. // One Shot Unicode layer
  75. //TODO tap_code16(OS_UNI);
  76. leader_succeed = true;
  77. } else
  78. SEQ_TWO_KEYS(KC_SPC, KC_SPC){
  79. // Toggle _MODS
  80. tap_code16(TG_MODS);
  81. leader_succeed = true;
  82. } else
  83. SEQ_THREE_KEYS(KC_BSPC, KC_BSPC, KC_BSPC){
  84. // Reset the keyboard
  85. reset_keyboard();
  86. leader_succeed = true;
  87. }
  88. leader_end();
  89. }
  90. // matrix_scan_keymap();
  91. }
  92. void leader_start(void) {
  93. #ifdef RGBLIGHT_ENABLE
  94. rgblight_savebase();
  95. rgblight_mode_noeeprom(1);
  96. rgblight_sethsv_noeeprom(HSV_GOLDENROD);
  97. #endif
  98. }
  99. void leader_end(void) {
  100. // pick color depending of success /fail
  101. // fade leader_start from 100 to 0
  102. // fade new color from 0 to 100 to 0
  103. // fade old color from 0 to 100
  104. #ifdef RGBLIGHT_ENABLE
  105. if (leader_succeed) {
  106. fadeflash_leds(HSV_GREEN);
  107. } else {
  108. fadeflash_leds(HSV_RED);
  109. }
  110. #endif
  111. }