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.

144 lines
6.0 KiB

  1. /*
  2. Copyright 2020 Andy Jack
  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 QMK_KEYBOARD_H
  15. enum layers {
  16. _QWERTY,
  17. _L1,
  18. _L2
  19. };
  20. #define CTL_ESC LCTL_T(KC_ESC)
  21. /* these key combos are mapped to shell commands in my .keylaunchrc */
  22. #define MUT_IN LALT(KC_F10)
  23. #define MUT_OUT LALT(KC_F11)
  24. #define MUT_MIC LALT(KC_F12)
  25. #define SCN_LCK LCTL(KC_SCRL)
  26. extern keymap_config_t keymap_config;
  27. enum custom_keycodes {
  28. AJ_FN = SAFE_RANGE,
  29. AJ_RCTL,
  30. AJ_MSWP,
  31. AJ_MLCK,
  32. };
  33. // clang-format off
  34. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  35. [_QWERTY] = LAYOUT_68_ansi(
  36. KC_GRV, 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_INS, KC_PGUP,
  37. 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, KC_PGDN,
  38. CTL_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT,
  39. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP,
  40. KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, AJ_FN, AJ_RCTL, KC_LEFT, KC_DOWN, KC_RGHT
  41. ),
  42. [_L1] = LAYOUT_68_ansi(
  43. KC_ESC, 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_BSPC, KC_VOLU, KC_HOME,
  44. _______, _______, KC_HOME, KC_UP, KC_END, _______, _______, MUT_IN , MUT_OUT, MUT_MIC, _______, _______, BL_STEP, _______, KC_VOLD, KC_END,
  45. _______, _______, KC_LEFT, KC_DOWN, KC_RGHT, _______, _______, _______, _______, SCN_LCK, _______, _______, _______,
  46. _______, _______, _______, _______, KC_BTN3, _______, _______, KC_MUTE, _______, _______, _______, _______, KC_MUTE,
  47. _______, AJ_MLCK, AJ_MSWP, _______, _______, _______, _______, KC_MPRV, KC_MPLY, KC_MNXT
  48. ),
  49. [_L2] = LAYOUT_68_ansi(
  50. KC_GRV, 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_BSPC, KC_VOLU, KC_HOME,
  51. _______, _______, _______, KC_UP, _______, _______, _______, KC_7, KC_8, KC_9, _______, _______, _______, _______, KC_VOLD, KC_END,
  52. _______, _______, KC_LEFT, KC_DOWN, KC_RGHT, _______, _______, KC_4, KC_5, KC_6, _______, _______, _______,
  53. _______, _______, _______, _______, _______, _______, KC_0, KC_1, KC_2, KC_3, _______, _______, KC_MUTE,
  54. _______, _______, _______, _______, _______, _______, _______, KC_MPRV, KC_MPLY, KC_MNXT
  55. )
  56. };
  57. // clang-format on
  58. static bool aj_fn_down = false;
  59. static bool aj_rctl_down = false;
  60. static uint8_t keycode_for_aj_rctl;
  61. /* My version of:
  62. https://www.reddit.com/r/olkb/comments/8eticz/how_to_activate_a_layer_with_a_combination/dxygw0f/
  63. * AJ_FN by itself turns on layer 1
  64. * AJ_RCTL by itself acts as a control key
  65. * pressing FN and RCTL together, in any order, turns on layer 2
  66. */
  67. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  68. switch (keycode) {
  69. case AJ_FN:
  70. if (record->event.pressed) {
  71. if (aj_rctl_down) {
  72. layer_on(_L2);
  73. } else {
  74. layer_on(_L1);
  75. }
  76. aj_fn_down = true;
  77. } else {
  78. layer_off(_L1);
  79. layer_off(_L2);
  80. aj_fn_down = false;
  81. }
  82. return false;
  83. break;
  84. case AJ_RCTL:
  85. if (record->event.pressed) {
  86. if (aj_fn_down) {
  87. layer_on(_L2);
  88. } else {
  89. register_code(keycode_for_aj_rctl);
  90. }
  91. aj_rctl_down = true;
  92. } else {
  93. layer_off(_L2);
  94. unregister_code(keycode_for_aj_rctl);
  95. aj_rctl_down = false;
  96. }
  97. return false;
  98. break;
  99. case AJ_MSWP:
  100. case AJ_MLCK:
  101. if (record->event.pressed) {
  102. if (!eeconfig_is_enabled()) {
  103. eeconfig_init();
  104. }
  105. keymap_config.raw = eeconfig_read_keymap();
  106. switch (keycode) {
  107. case AJ_MSWP:
  108. keymap_config.swap_lalt_lgui = !keymap_config.swap_lalt_lgui;
  109. keymap_config.swap_ralt_rgui = keymap_config.swap_lalt_lgui;
  110. keycode_for_aj_rctl = keymap_config.swap_lalt_lgui ? KC_RALT : KC_RCTL;
  111. break;
  112. case AJ_MLCK:
  113. keymap_config.no_gui = !keymap_config.no_gui;
  114. break;
  115. }
  116. eeconfig_update_keymap(keymap_config.raw);
  117. clear_keyboard(); // clear to prevent stuck keys
  118. }
  119. return false;
  120. break;
  121. }
  122. return true;
  123. }
  124. void keyboard_post_init_user(void) {
  125. if (!eeconfig_is_enabled()) {
  126. eeconfig_init();
  127. }
  128. keymap_config.raw = eeconfig_read_keymap();
  129. keycode_for_aj_rctl = keymap_config.swap_lalt_lgui ? KC_RALT : KC_RCTL;
  130. eeconfig_update_keymap(keymap_config.raw);
  131. clear_keyboard(); // clear to prevent stuck keys
  132. }