keymap.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /* Copyright 2021 Jay Greco
  2. *
  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. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include QMK_KEYBOARD_H
  17. enum layer_names {
  18. _BASE,
  19. _VIA1,
  20. _VIA2,
  21. _VIA3
  22. };
  23. #define KC_DISC_MUTE KC_F23
  24. #define KC_DISC_DEAF KC_F24
  25. enum custom_keycodes {
  26. PROG = QK_KB_0,
  27. DISC_MUTE,
  28. DISC_DEAF,
  29. SUPER_ALT_TAB,
  30. _NUM_CUST_KCS,
  31. };
  32. // Macro variables
  33. bool is_alt_tab_active = false;
  34. uint16_t alt_tab_timer = 0;
  35. bool muted = false;
  36. bool deafened = false;
  37. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  38. [_BASE] = LAYOUT_all(
  39. QK_GESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_HOME,
  40. KC_F13, KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_DEL,
  41. KC_F14, KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_PGUP,
  42. KC_F15, KC_LSFT, KC_NUBS, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_PGDN,
  43. KC_F16, KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, MO(_VIA1), KC_RALT, KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT
  44. ),
  45. [_VIA1] = LAYOUT_all(
  46. QK_BOOT, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, KC_END,
  47. RGB_TOG, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  48. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  49. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  50. _______, _______, _______, _______, _______, _______, _______, _______, KC_MPRV, KC_MPLY, KC_MNXT
  51. ),
  52. [_VIA2] = LAYOUT_all(
  53. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  54. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  55. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  56. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  57. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  58. ),
  59. [_VIA3] = LAYOUT_all(
  60. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  61. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  62. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  63. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  64. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  65. ),
  66. };
  67. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  68. // Send keystrokes to host keyboard, if connected (see readme)
  69. process_record_remote_kb(keycode, record);
  70. switch(keycode) {
  71. case PROG:
  72. if (record->event.pressed) {
  73. rgblight_disable_noeeprom();
  74. bootloader_jump();
  75. }
  76. break;
  77. case DISC_MUTE:
  78. if (record->event.pressed) {
  79. tap_code(KC_DISC_MUTE);
  80. if (!rgblight_is_enabled()) break;
  81. if (muted) {
  82. rgblight_enable_noeeprom();
  83. } else {
  84. rgblight_timer_disable();
  85. uint8_t val = rgblight_get_val();
  86. rgblight_sethsv_range(255, 255, val, 0, 1);
  87. }
  88. muted = !muted;
  89. }
  90. break;
  91. case DISC_DEAF:
  92. if (record->event.pressed) {
  93. tap_code(KC_DISC_DEAF);
  94. if (!rgblight_is_enabled()) break;
  95. if (deafened) {
  96. rgblight_enable_noeeprom();
  97. } else {
  98. rgblight_timer_disable();
  99. uint8_t val = rgblight_get_val();
  100. rgblight_sethsv_range(255, 255, val, 0, RGBLIGHT_LED_COUNT-1);
  101. }
  102. deafened = !deafened;
  103. }
  104. break;
  105. case SUPER_ALT_TAB:
  106. if (record->event.pressed) {
  107. if (!is_alt_tab_active) {
  108. is_alt_tab_active = true;
  109. register_code(KC_LALT);
  110. }
  111. alt_tab_timer = timer_read();
  112. register_code(KC_TAB);
  113. } else {
  114. unregister_code(KC_TAB);
  115. }
  116. break;
  117. default:
  118. break;
  119. }
  120. return true;
  121. }
  122. bool encoder_update_user(uint8_t index, bool clockwise) {
  123. // Encoder is mapped to volume functions by default
  124. if (clockwise) {
  125. tap_code(KC_VOLU);
  126. } else {
  127. tap_code(KC_VOLD);
  128. }
  129. return true;
  130. }
  131. void matrix_init_user(void) {
  132. // Initialize remote keyboard, if connected (see readme)
  133. matrix_init_remote_kb();
  134. }
  135. void matrix_scan_user(void) {
  136. // Scan and parse keystrokes from remote keyboard, if connected (see readme)
  137. matrix_scan_remote_kb();
  138. if (is_alt_tab_active) {
  139. if (timer_elapsed(alt_tab_timer) > 1000) {
  140. unregister_code(KC_LALT);
  141. is_alt_tab_active = false;
  142. }
  143. }
  144. }