keymap.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /**
  2. * Copyright 2021 Quentin LEBASTARD <qlebastard@gmail.com>
  3. * Copyright 2022 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 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 DILEMMA_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 SPC_MBO LT(LAYER_MBO, KC_SPC)
  37. #define MOUSE(KC) LT(LAYER_MOUSE, KC)
  38. #define USR_RDO KC_AGAIN
  39. #define USR_PST S(KC_INS)
  40. #define USR_CPY C(KC_INS)
  41. #define USR_CUT S(KC_DEL)
  42. #define USR_UND KC_UNDO
  43. #define MS_L KC_MS_LEFT
  44. #define MS_R KC_MS_RIGHT
  45. #define MS_D KC_MS_DOWN
  46. #define MS_U KC_MS_UP
  47. #define WH_L KC_MS_WH_LEFT
  48. #define WH_R KC_MS_WH_RIGHT
  49. #define WH_D KC_MS_WH_DOWN
  50. #define WH_U KC_MS_WH_UP
  51. // clang-format off
  52. /** Convenience macro. */
  53. #define _KC_LAYOUT_wrapper( \
  54. k00, k01, k02, k03, k04, k05, k06, k07, k08, k09, \
  55. k10, k11, k12, k13, k14, k15, k16, k17, k18, k19, \
  56. k20, k21, k22, k23, k24, k25, k26, k27, k28, k29, \
  57. ...) \
  58. KC_##k00, KC_##k01, KC_##k02, KC_##k03, KC_##k04, KC_##k05, KC_##k06, KC_##k07, KC_##k08, KC_##k09, \
  59. KC_##k10, KC_##k11, KC_##k12, KC_##k13, KC_##k14, KC_##k15, KC_##k16, KC_##k17, KC_##k18, KC_##k19, \
  60. KC_##k20, KC_##k21, KC_##k22, KC_##k23, KC_##k24, KC_##k25, KC_##k26, KC_##k27, KC_##k28, KC_##k29, \
  61. __VA_ARGS__
  62. #define KC_LAYOUT_wrapper(...) _KC_LAYOUT_wrapper(__VA_ARGS__)
  63. /** Base layer with BÉPO layout. */
  64. #define LAYOUT_LAYER_BASE_BEPO KC_LAYOUT_wrapper( \
  65. B, W, P, O, QUOT, DOT, V, D, L, J, \
  66. A, U, I, E, COMM, C, T, S, R, N, \
  67. Z, Y, X, SLSH, K, M, Q, G, H, F, \
  68. KC_A, SPC_MBO, TAB_MED, ESC_SYM, SPC_NUM, KC_A)
  69. /** Convenience key shorthands. */
  70. #define U_NA KC_NO // Present but not available for use.
  71. #define U_NU KC_NO // Available but not used.
  72. /** Convenience row shorthands. */
  73. #define ________________HOME_ROW_NA________________ U_NA, U_NA, U_NA, U_NA, U_NA
  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. ________________HOME_ROW_NA________________, USR_RDO, USR_PST, USR_CPY, USR_CUT, USR_UND, \
  82. ______________HOME_ROW_GASC_L______________, KC_BSPC, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, \
  83. KC_BTN3, KC_ALGR, KC_BTN2, KC_BTN1, U_NA, KC_DEL, KC_HOME, KC_PGDN, KC_PGUP, KC_END, \
  84. U_NA, U_NA, U_NA, KC_ENT, KC_ENT, KC_ENT
  85. // Media.
  86. #define LAYOUT_LAYER_MEDIA \
  87. ________________HOME_ROW_NA________________, 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, KC_BTN2
  91. // Navigation.
  92. #define LAYOUT_LAYER_NAV \
  93. ________________HOME_ROW_NA________________, 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, U_NA
  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, DRGSCRL, _______, U_NU, MS_L, MS_D, MS_U, MS_R, \
  101. USR_RDO, USR_PST, USR_CPY, KC_BTN3, USR_UND, U_NU, WH_L, WH_D, WH_U, WH_R, \
  102. KC_BTN3, KC_BTN1, KC_BTN2, KC_BTN1, KC_BTN3, KC_BTN2
  103. // Symbols.
  104. #define LAYOUT_LAYER_SYM \
  105. KC_LCBR, KC_AMPR, KC_ASTR, KC_LPRN, KC_RCBR, ________________HOME_ROW_NA________________, \
  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_MINS, ______________HOME_ROW_ALGR_R______________, \
  108. U_NA, KC_RPRN, KC_LPRN, U_NA, U_NA, U_NA
  109. // Numerals.
  110. #define LAYOUT_LAYER_NUM \
  111. KC_LBRC, KC_7, KC_8, KC_9, KC_RBRC, ________________HOME_ROW_NA________________, \
  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_UNDS, ______________HOME_ROW_ALGR_R______________, \
  114. U_NA, KC_0, KC_MINS, U_NA, U_NA, U_NA
  115. // Function keys.
  116. #define LAYOUT_LAYER_FUN \
  117. KC_F12, KC_F7, KC_F8, KC_F9, KC_PSCR, ________________HOME_ROW_NA________________, \
  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. U_NA, KC_APP, KC_TAB, U_NA, 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. L20, MOUSE(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_split_3x5_3(__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(DILEMMA_AUTO_SNIPING_ON_LAYER)
  179. layer_state_t layer_state_set_user(layer_state_t state) {
  180. dilemma_set_pointer_sniping_enabled(layer_state_cmp(state, DILEMMA_AUTO_SNIPING_ON_LAYER));
  181. return state;
  182. }
  183. #endif // POINTING_DEVICE_ENABLE && DILEMMA_AUTO_SNIPING_ON_LAYER
  184. #ifdef RGB_MATRIX_ENABLE
  185. // Forward-declare this helper function since it is defined in rgb_matrix.c.
  186. void rgb_matrix_update_pwm_buffers(void);
  187. #endif
  188. void shutdown_user(void) {
  189. #ifdef RGBLIGHT_ENABLE
  190. rgblight_enable_noeeprom();
  191. rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT);
  192. rgblight_setrgb_red();
  193. #endif // RGBLIGHT_ENABLE
  194. #ifdef RGB_MATRIX_ENABLE
  195. rgb_matrix_set_color_all(RGB_RED);
  196. rgb_matrix_update_pwm_buffers();
  197. #endif // RGB_MATRIX_ENABLE
  198. }