keymap.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /**
  2. * Copyright 2021 Quentin LEBASTARD <qlebastard@gmail.com>
  3. * Copyright 2021 Charly Delay <charly@codesink.dev> (@0xcharly)
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include QMK_KEYBOARD_H
  19. enum charybdis_keymap_bstiq_layers {
  20. LAYER_BASE = 0,
  21. LAYER_MBO,
  22. LAYER_MEDIA,
  23. LAYER_NAV,
  24. LAYER_MOUSE,
  25. LAYER_SYM,
  26. LAYER_NUM,
  27. LAYER_FUN,
  28. };
  29. // Automatically enable sniping when the mouse layer is on.
  30. #define CHARYBDIS_AUTO_SNIPING_ON_LAYER LAYER_MOUSE
  31. #define BSP_NAV LT(LAYER_NAV, KC_BSPC)
  32. #define ENT_MBO LT(LAYER_MBO, KC_ENT)
  33. #define TAB_MED LT(LAYER_MEDIA, KC_TAB)
  34. #define ESC_SYM LT(LAYER_SYM, KC_ESC)
  35. #define SPC_NUM LT(LAYER_NUM, KC_SPC)
  36. #define MOUSE(KC) LT(LAYER_MOUSE, KC)
  37. #define USR_RDO KC_AGAIN
  38. #define USR_PST S(KC_INS)
  39. #define USR_CPY C(KC_INS)
  40. #define USR_CUT S(KC_DEL)
  41. #define USR_UND KC_UNDO
  42. #define MS_L KC_MS_LEFT
  43. #define MS_R KC_MS_RIGHT
  44. #define MS_D KC_MS_DOWN
  45. #define MS_U KC_MS_UP
  46. #define WH_L KC_MS_WH_LEFT
  47. #define WH_R KC_MS_WH_RIGHT
  48. #define WH_D KC_MS_WH_DOWN
  49. #define WH_U KC_MS_WH_UP
  50. // clang-format off
  51. /** Convenience macro. */
  52. #define _KC_LAYOUT_wrapper( \
  53. k00, k01, k02, k03, k04, k05, k06, k07, k08, k09, \
  54. k10, k11, k12, k13, k14, k15, k16, k17, k18, k19, \
  55. k20, k21, k22, k23, k24, k25, k26, k27, k28, k29, \
  56. ...) \
  57. KC_##k00, KC_##k01, KC_##k02, KC_##k03, KC_##k04, KC_##k05, KC_##k06, KC_##k07, KC_##k08, KC_##k09, \
  58. KC_##k10, KC_##k11, KC_##k12, KC_##k13, KC_##k14, KC_##k15, KC_##k16, KC_##k17, KC_##k18, KC_##k19, \
  59. KC_##k20, KC_##k21, KC_##k22, KC_##k23, KC_##k24, KC_##k25, KC_##k26, KC_##k27, KC_##k28, KC_##k29, \
  60. __VA_ARGS__
  61. #define KC_LAYOUT_wrapper(...) _KC_LAYOUT_wrapper(__VA_ARGS__)
  62. /** Base layer with BÉPO layout. */
  63. #define LAYOUT_LAYER_BASE_BEPO KC_LAYOUT_wrapper( \
  64. B, Z, P, O, QUOT, DOT, V, D, L, J, \
  65. A, U, I, E, COMM, C, T, S, R, N, \
  66. W, Y, X, SLSH, K, M, Q, G, H, F, \
  67. BSP_NAV, ENT_MBO, TAB_MED, ESC_SYM, SPC_NUM)
  68. /** Convenience key shorthands. */
  69. #define U_NA KC_NO // Present but not available for use.
  70. #define U_NU KC_NO // Available but not used.
  71. /** Convenience row shorthands. */
  72. #define __________________RESET_L__________________ QK_BOOT, U_NA, U_NA, U_NA, U_NA
  73. #define __________________RESET_R__________________ U_NA, U_NA, U_NA, U_NA, QK_BOOT
  74. #define ______________HOME_ROW_GASC_L______________ KC_LGUI, KC_LALT, KC_LSFT, KC_LCTL, U_NA
  75. #define ______________HOME_ROW_ALGR_L______________ U_NA, KC_ALGR, U_NA, U_NA, U_NA
  76. #define ______________HOME_ROW_GASC_R______________ U_NA, KC_LCTL, KC_LSFT, KC_LALT, KC_LGUI
  77. #define ______________HOME_ROW_ALGR_R______________ U_NA, U_NA, U_NA, KC_ALGR, U_NA
  78. /** Layers. */
  79. // Buttons.
  80. #define LAYOUT_LAYER_MBO \
  81. __________________RESET_L__________________, USR_RDO, USR_PST, USR_CPY, USR_CUT, USR_UND, \
  82. ______________HOME_ROW_GASC_L______________, KC_CAPS, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, \
  83. KC_BTN3, KC_ALGR, KC_BTN2, KC_BTN1, U_NA, KC_INS, KC_HOME, KC_PGDN, KC_PGUP, KC_END, \
  84. U_NA, U_NA, U_NA, KC_ENT, KC_DEL
  85. // Media.
  86. #define LAYOUT_LAYER_MEDIA \
  87. __________________RESET_L__________________, USR_RDO, USR_PST, USR_CPY, USR_CUT, USR_UND, \
  88. ______________HOME_ROW_GASC_L______________, U_NU, MS_L, MS_D, MS_U, MS_R, \
  89. ______________HOME_ROW_ALGR_L______________, U_NU, WH_L, WH_D, WH_U, WH_R, \
  90. U_NA, U_NA, U_NA, KC_BTN1, KC_BTN3
  91. // Navigation.
  92. #define LAYOUT_LAYER_NAV \
  93. __________________RESET_L__________________, RGB_TOG, RGB_MOD, RGB_HUI, RGB_SAI, RGB_VAI, \
  94. ______________HOME_ROW_GASC_L______________, U_NU, KC_MPRV, KC_VOLD, KC_VOLU, KC_MNXT, \
  95. ______________HOME_ROW_ALGR_L______________, U_NU, U_NU, U_NU, U_NU, U_NU, \
  96. U_NA, U_NA, U_NA, KC_MSTP, KC_MPLY
  97. // Mouse.
  98. #define LAYOUT_LAYER_MOUSE \
  99. S_D_MOD, USR_PST, USR_CPY, USR_CUT, USR_UND, USR_RDO, USR_PST, USR_CPY, USR_CUT, USR_UND, \
  100. DPI_MOD, DRGSCRL, KC_LSFT, KC_LCTL, _______, U_NU, MS_L, MS_D, MS_U, MS_R, \
  101. USR_RDO, USR_PST, USR_CPY, USR_CUT, USR_UND, U_NU, WH_L, WH_D, WH_U, WH_R, \
  102. KC_BTN2, KC_BTN1, KC_BTN3, KC_BTN1, KC_BTN3
  103. // Symbols.
  104. #define LAYOUT_LAYER_SYM \
  105. KC_LCBR, KC_AMPR, KC_ASTR, KC_LPRN, KC_RCBR, __________________RESET_R__________________, \
  106. KC_COLN, KC_DLR, KC_PERC, KC_CIRC, KC_PLUS, ______________HOME_ROW_GASC_R______________, \
  107. KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_PIPE, ______________HOME_ROW_ALGR_R______________, \
  108. KC_LPRN, KC_RPRN, KC_UNDS, U_NA, U_NA
  109. // Numerals.
  110. #define LAYOUT_LAYER_NUM \
  111. KC_LBRC, KC_7, KC_8, KC_9, KC_RBRC, __________________RESET_R__________________, \
  112. KC_SCLN, KC_4, KC_5, KC_6, KC_EQL, ______________HOME_ROW_GASC_R______________, \
  113. KC_GRV, KC_1, KC_2, KC_3, KC_BSLS, ______________HOME_ROW_ALGR_R______________, \
  114. KC_DOT, KC_0, KC_MINS, U_NA, U_NA
  115. // Function keys.
  116. #define LAYOUT_LAYER_FUN \
  117. KC_F12, KC_F7, KC_F8, KC_F9, KC_PSCR, __________________RESET_R__________________, \
  118. KC_F11, KC_F4, KC_F5, KC_F6, KC_SCRL, ______________HOME_ROW_GASC_R______________, \
  119. KC_F10, KC_F1, KC_F2, KC_F3, KC_PAUS, ______________HOME_ROW_ALGR_R______________,\
  120. KC_APP, KC_SPC, KC_TAB, U_NA, U_NA
  121. /**
  122. * Add Home Row mod to a layout.
  123. *
  124. * Expects a 10-key per row layout. Adds support for GASC (Gui, Alt, Shift, Ctl)
  125. * home row. The layout passed in parameter must contain at least 20 keycodes.
  126. *
  127. * This is meant to be used with `LAYOUT_LAYER_BASE_BEPO` defined above, eg.:
  128. *
  129. * HOME_ROW_MOD_GASC(LAYOUT_LAYER_BASE_BEPO)
  130. */
  131. #define _HOME_ROW_MOD_GASC( \
  132. L00, L01, L02, L03, L04, R05, R06, R07, R08, R09, \
  133. L10, L11, L12, L13, L14, R15, R16, R17, R18, R19, \
  134. ...) \
  135. L00, L01, L02, L03, L04, \
  136. R05, R06, R07, R08, R09, \
  137. LGUI_T(L10), LALT_T(L11), LSFT_T(L12), LCTL_T(L13), L14, \
  138. R15, RCTL_T(R16), RSFT_T(R17), LALT_T(R18), RGUI_T(R19), \
  139. __VA_ARGS__
  140. #define HOME_ROW_MOD_GASC(...) _HOME_ROW_MOD_GASC(__VA_ARGS__)
  141. /**
  142. * Add mouse layer keys to a layout.
  143. *
  144. * Expects a 10-key per row layout. The layout passed in parameter must contain
  145. * at least 30 keycodes.
  146. *
  147. * This is meant to be used with `LAYOUT_LAYER_BASE_BEPO` defined above, eg.:
  148. *
  149. * MOUSE_MOD(LAYOUT_LAYER_BASE_BEPO)
  150. */
  151. #define _MOUSE_MOD( \
  152. L00, L01, L02, L03, L04, R05, R06, R07, R08, R09, \
  153. L10, L11, L12, L13, L14, R15, R16, R17, R18, R19, \
  154. L20, L21, L22, L23, L24, R25, R26, R27, R28, R29, \
  155. ...) \
  156. L00, L01, L02, L03, L04, \
  157. R05, R06, R07, R08, R09, \
  158. L10, L11, L12, L13, L14, \
  159. R15, R16, R17, R18, R19, \
  160. MOUSE(L20), L21, L22, L23, L24, \
  161. R25, R26, R27, R28, MOUSE(R29), \
  162. __VA_ARGS__
  163. #define MOUSE_MOD(...) _MOUSE_MOD(__VA_ARGS__)
  164. #define LAYOUT_wrapper(...) LAYOUT_charybdis_3x5(__VA_ARGS__)
  165. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  166. [LAYER_BASE] = LAYOUT_wrapper(
  167. MOUSE_MOD(HOME_ROW_MOD_GASC(LAYOUT_LAYER_BASE_BEPO))
  168. ),
  169. [LAYER_MBO] = LAYOUT_wrapper(LAYOUT_LAYER_MBO),
  170. [LAYER_MEDIA] = LAYOUT_wrapper(LAYOUT_LAYER_MEDIA),
  171. [LAYER_NAV] = LAYOUT_wrapper(LAYOUT_LAYER_NAV),
  172. [LAYER_MOUSE] = LAYOUT_wrapper(LAYOUT_LAYER_MOUSE),
  173. [LAYER_SYM] = LAYOUT_wrapper(LAYOUT_LAYER_SYM),
  174. [LAYER_NUM] = LAYOUT_wrapper(LAYOUT_LAYER_NUM),
  175. [LAYER_FUN] = LAYOUT_wrapper(LAYOUT_LAYER_FUN),
  176. };
  177. // clang-format on
  178. #if defined(POINTING_DEVICE_ENABLE) && defined(CHARYBDIS_AUTO_SNIPING_ON_LAYER)
  179. layer_state_t layer_state_set_kb(layer_state_t state) {
  180. state = layer_state_set_user(state);
  181. charybdis_set_pointer_sniping_enabled(layer_state_cmp(state, CHARYBDIS_AUTO_SNIPING_ON_LAYER));
  182. return state;
  183. }
  184. #endif // POINTING_DEVICE_ENABLE && CHARYBDIS_AUTO_SNIPING_ON_LAYER
  185. #ifdef RGB_MATRIX_ENABLE
  186. // Forward-declare this helper function since it is defined in rgb_matrix.c.
  187. void rgb_matrix_update_pwm_buffers(void);
  188. #endif
  189. void shutdown_user(void) {
  190. #ifdef RGBLIGHT_ENABLE
  191. rgblight_enable_noeeprom();
  192. rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT);
  193. rgblight_setrgb(RGB_RED);
  194. #endif // RGBLIGHT_ENABLE
  195. #ifdef RGB_MATRIX_ENABLE
  196. rgb_matrix_set_color_all(RGB_RED);
  197. rgb_matrix_update_pwm_buffers();
  198. #endif // RGB_MATRIX_ENABLE
  199. }