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.

188 lines
9.8 KiB

  1. /*
  2. Copyright 2019-2021 Adrian L Lange <legal@p3lim.net>
  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. #define LAYOUT_p3lim(\
  16. K04, K14, K24, K34, K44, K54, K16, KB6, KB7, K17, KA4, KB4, KC4, KE4, \
  17. K03, K13, K23, K33, K43, K53, K26, KC6, KC7, K27, KA3, KB3, KC3, \
  18. K02, K12, K22, K32, K42, K52, K36, KD6, KD7, K37, KA2, KB2, KC2, KD2, \
  19. K01, K11, K21, K31, K41, K51, K46, KE6, KE7, K47, KA1, KB1, KC1, \
  20. K00, K10, K20, K56, K57, KB0, KC0 \
  21. ){ \
  22. { K00, K10, K20, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KB0, KC0, KC_NO, KC_NO }, \
  23. { K01, K11, K21, K31, K41, K51, KC_NO, KC_NO, KC_NO, KC_NO, KA1, KB1, KC1, KC_NO, KC_NO }, \
  24. { K02, K12, K22, K32, K42, K52, KC_NO, KC_NO, KC_NO, KC_NO, KA2, KB2, KC2, KD2, KC_NO }, \
  25. { K03, K13, K23, K33, K43, K53, KC_NO, KC_NO, KC_NO, KC_NO, KA3, KB3, KC3, KC_NO, KC_NO }, \
  26. { K04, K14, K24, K34, K44, K54, KC_NO, KC_NO, KC_NO, KC_NO, KA4, KB4, KC4, KC_NO, KE4 }, \
  27. { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \
  28. { KC_NO, K16, K26, K36, K46, K56, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KB6, KC6, KD6, KE6 }, \
  29. { KC_NO, K17, K27, K37, K47, K57, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KB7, KC7, KD7, KE7 } \
  30. }
  31. enum my_keycodes {
  32. C_ESC0 = SAFE_RANGE, // layer 0 esc
  33. C_ESC1, // layer 1 esc
  34. C_NO1, // æ, requires RCTL to be a compose key in software
  35. C_NO2, // ø, requires RCTL to be a compose key in software
  36. C_NO3 // å, requires RCTL to be a compose key in software
  37. };
  38. // use compiler macros for simpler stuff
  39. #define C_KVM1 LCA(KC_1)
  40. #define C_KVM2 LCA(KC_2)
  41. #define C_KVM3 LCA(KC_3)
  42. #define C_KVM4 LCA(KC_4)
  43. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  44. /* QWERTY
  45. * ,-----------------------------------------------------------------------------------------.
  46. * | Esc | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - | = | Bkspc |
  47. * |-----------------------------------------------------------------------------------------+
  48. * | Tab | Q | W | E | R | T | Y | U | I | O | P | [ | ] | |
  49. * |---------------------------------------------------------------------------------| Enter |
  50. * | Ctrl | A | S | D | F | G | H | J | K | L | ; | ' | \ | |
  51. * |-----------------------------------------------------------------------------------------+
  52. * | Shift | Z | X | C | V | B | N | M | , | . | / | Shift | Del |
  53. * |-----------------------------------------------------------------------------------------+
  54. * | FN1 | Alt | GUI | Space | FN2 | Alt | Ctrl |
  55. * `-----------------------------------------------------------------------------------------'
  56. */
  57. [0] = LAYOUT_p3lim(
  58. C_ESC0, 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,
  59. 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,
  60. KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_BSLS, KC_ENT,
  61. 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_DEL,
  62. MO(1), KC_LALT, KC_LGUI, KC_SPC, MO(2), KC_RGUI, KC_RCTL
  63. ),
  64. /* FN1
  65. * ,-----------------------------------------------------------------------------------------.
  66. * | ` | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 | |
  67. * |-----------------------------------------------------------------------------------------+
  68. * | Caps | Home| Up | End | PgUp| | | | | | | | | |
  69. * |---------------------------------------------------------------------------------| |
  70. * | | Left| Down|Right| PgDn|PrtSc| | | | | | | | |
  71. * |-----------------------------------------------------------------------------------------+
  72. * | | KVM1| KVM2| KVM3| KVM4| | | | | | | | |
  73. * |-----------------------------------------------------------------------------------------+
  74. * | | | | | | | |
  75. * `-----------------------------------------------------------------------------------------'
  76. */
  77. [1] = LAYOUT_p3lim(
  78. C_ESC1, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______,
  79. KC_CAPS, KC_HOME, KC_UP, KC_END, KC_PGUP, _______, _______, _______, _______, _______, _______, _______, _______,
  80. _______, KC_LEFT, KC_DOWN, KC_RGHT, KC_PGDN, KC_PSCR, _______, _______, _______, _______, _______, _______, _______, _______,
  81. _______, C_KVM1, C_KVM2, C_KVM3, C_KVM4, _______, _______, _______, _______, _______, _______, _______, _______,
  82. _______, _______, _______, _______, KC_NO, _______, _______
  83. ),
  84. /* FN2
  85. * ,-----------------------------------------------------------------------------------------.
  86. * | | | | | | | | | | | | | | |
  87. * |-----------------------------------------------------------------------------------------+
  88. * | | | | | | | | | | | | Å | | |
  89. * |---------------------------------------------------------------------------------| |
  90. * | | | | | | | | | | | Ø | Æ | | |
  91. * |-----------------------------------------------------------------------------------------+
  92. * | | | | | | | | | | | | | |
  93. * |-----------------------------------------------------------------------------------------+
  94. * | | | | | | | |
  95. * `-----------------------------------------------------------------------------------------'
  96. */
  97. [2] = LAYOUT_p3lim(
  98. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  99. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, C_NO3, _______,
  100. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, C_NO2, C_NO1, _______, _______,
  101. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  102. KC_NO, _______, _______, _______, _______, _______, _______
  103. ),
  104. /*
  105. [n] = LAYOUT_p3lim(
  106. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  107. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  108. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  109. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  110. _______, _______, _______, _______, _______, _______, _______
  111. ),
  112. */
  113. };
  114. static bool grave_esc_shifted = false;
  115. bool process_record_user(uint16_t keycode, keyrecord_t *record){
  116. const uint8_t mods = get_mods();
  117. uint8_t shifted = mods & MOD_MASK_SHIFT;
  118. switch(keycode){
  119. case C_ESC0: // layer 0
  120. if(record->event.pressed){
  121. grave_esc_shifted = shifted;
  122. register_code(shifted ? KC_GRAVE : KC_ESCAPE);
  123. } else
  124. unregister_code(grave_esc_shifted ? KC_GRAVE : KC_ESCAPE);
  125. return false;
  126. case C_ESC1: // layer 1
  127. if(record->event.pressed){
  128. grave_esc_shifted = shifted;
  129. register_code(shifted ? KC_ESCAPE : KC_GRAVE);
  130. } else
  131. unregister_code(grave_esc_shifted ? KC_ESCAPE : KC_GRAVE);
  132. return false;
  133. case C_NO1: // æ
  134. if(record->event.pressed){
  135. // we use shift for A and E to make it capitalized, no need to handle it here
  136. tap_code(KC_RCTL);
  137. tap_code(KC_A);
  138. tap_code(KC_E);
  139. }
  140. return false;
  141. case C_NO2: // ø
  142. // the "/" symbol can't be shifted, so we have to deal with that
  143. if(record->event.pressed){
  144. if(shifted){
  145. unregister_code(KC_LSFT); // reset the shift state, I always use LSFT personally
  146. tap_code(KC_RCTL);
  147. tap_code(KC_SLSH);
  148. tap_code16(S(KC_O));
  149. register_code(KC_LSFT); // enable the shift state again to keep state consistent
  150. } else {
  151. tap_code(KC_RCTL);
  152. tap_code(KC_SLSH);
  153. tap_code(KC_O);
  154. }
  155. }
  156. return false;
  157. case C_NO3: // å
  158. // the "o" symbol can't be shifted, so we have to deal with that
  159. if(record->event.pressed){
  160. if(shifted){
  161. unregister_code(KC_LSFT); // reset the shift state, I always use LSFT personally
  162. tap_code(KC_RCTL);
  163. tap_code(KC_O);
  164. tap_code16(S(KC_A));
  165. register_code(KC_LSFT); // enable the shift state again to keep state consistent
  166. } else {
  167. tap_code(KC_RCTL);
  168. tap_code(KC_O);
  169. tap_code(KC_A);
  170. }
  171. }
  172. return false;
  173. }
  174. return true;
  175. }