pdl.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. Copyright 2018-2021 Daniel Perrett
  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 "pdl.h"
  15. // unshifted
  16. //
  17. // regardless of current mods, send this character in an unshifted state
  18. __attribute__ ((weak))
  19. bool unshifted (uint16_t keycode, keyrecord_t *record) {
  20. uint8_t mods;
  21. if (record->event.pressed) {
  22. mods = keyboard_report->mods & EITHER_SHIFT;
  23. if (mods) {
  24. unregister_mods(mods);
  25. register_code(keycode);
  26. register_mods(mods);
  27. } else {
  28. register_code(keycode);
  29. }
  30. return false;
  31. } else {
  32. return true;
  33. }
  34. }
  35. /*
  36. * update_punctn_coding_layer_state
  37. *
  38. * Check NAVIGN and NUMBRS layers. If one is activated, also activate PUNCTN. If both are activated, also activate CODING.
  39. */
  40. __attribute__ ((weak))
  41. uint32_t update_punctn_coding_layer_state(uint32_t state) {
  42. uint32_t maskEither = (1UL << _NAVIGN) | (1UL << _NUMBRS);
  43. uint32_t maskPunctn = 1UL << _PUNCTN;
  44. uint32_t maskCoding = 1UL << _CODING;
  45. #ifdef COMBO_PDL
  46. return (
  47. (state & maskEither)
  48. ? (state | maskPunctn) & ~maskCoding // either => punctn
  49. : (state & ~maskCoding) & ~maskPunctn // neither => neither
  50. );
  51. #endif
  52. return (
  53. (state & maskEither)
  54. ? (state & maskEither) == maskEither
  55. ? (state & ~maskPunctn) | maskCoding // both => coding
  56. : (state | maskPunctn) & ~maskCoding // either => punctn
  57. : (state & ~maskCoding) & ~maskPunctn // neither => neither
  58. );
  59. }
  60. __attribute__ ((weak))
  61. uint32_t layer_state_set_user(uint32_t state) {
  62. return update_punctn_coding_layer_state(state);
  63. }
  64. __attribute__ ((weak))
  65. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  66. switch (keycode) {
  67. case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:
  68. if (record->event.pressed) {
  69. // ensure that the toggled layer is switched off by a single tap
  70. layer_off(keycode & 0xFF);
  71. }
  72. break;
  73. case QWERTY:
  74. if (record->event.pressed) {
  75. set_single_persistent_default_layer(_QWERTY);
  76. }
  77. return false;
  78. break;
  79. case PROXIM:
  80. if (record->event.pressed) {
  81. set_single_persistent_default_layer(_PROXIM);
  82. }
  83. return false;
  84. break;
  85. // KC_LBRC, KC_NUHS, KC_GRV, KC_RBRC [#`]
  86. // These four keys are unshifted in the UK layout and should be sent as such.
  87. case KU_LBRC:
  88. return unshifted(KC_LBRC, record);
  89. case KU_NUHS:
  90. return unshifted(KC_NUHS, record);
  91. case KU_GRV:
  92. return unshifted(KC_GRV, record);
  93. case KU_RBRC:
  94. return unshifted(KC_RBRC, record);
  95. case KC_ESC:
  96. if (!record->event.pressed) {
  97. layer_off(_NUMBRS);
  98. layer_off(_NAVIGN);
  99. layer_off(_PUNCTN);
  100. layer_off(_CODING);
  101. }
  102. return true;
  103. }
  104. return true;
  105. }
  106. #ifdef COMBO_PDL
  107. enum combos {
  108. VCOMBO_PU,
  109. VCOMBO_NU,
  110. VCOMBO_EU,
  111. VCOMBO_IU,
  112. VCOMBO_LU,
  113. VCOMBO_PD,
  114. VCOMBO_ND,
  115. VCOMBO_ED,
  116. VCOMBO_ID,
  117. VCOMBO_LD,
  118. HCOMBO_JR,
  119. HCOMBO_UR,
  120. HCOMBO_PR,
  121. HCOMBO_MR,
  122. HCOMBO_HR,
  123. XCOMBO_LEFT,
  124. XCOMBO_RIGHT,
  125. XCOMBO_UP,
  126. XCOMBO_DOWN,
  127. XCOMBO_ENTER,
  128. XCOMBO_DEL,
  129. XCOMBO_BKSP,
  130. XCOMBO_MINS,
  131. XCOMBO_TAB,
  132. XCOMBO_UNDO,
  133. XCOMBO_REDO,
  134. XCOMBO_PGUP,
  135. XCOMBO_PGDN
  136. };
  137. const uint16_t PROGMEM vcombo_pu[] = {KC_J, KC_P, COMBO_END};
  138. const uint16_t PROGMEM vcombo_nu[] = {KC_Y, KC_N, COMBO_END};
  139. const uint16_t PROGMEM vcombo_eu[] = {KC_O, KC_E, COMBO_END};
  140. const uint16_t PROGMEM vcombo_iu[] = {KC_U, KC_I, COMBO_END};
  141. const uint16_t PROGMEM vcombo_lu[] = {KC_QUOT, KC_L, COMBO_END};
  142. const uint16_t PROGMEM vcombo_pd[] = {KC_M, KC_P, COMBO_END};
  143. const uint16_t PROGMEM vcombo_nd[] = {KC_H, KC_N, COMBO_END};
  144. const uint16_t PROGMEM vcombo_ed[] = {KC_COMM, KC_E, COMBO_END};
  145. const uint16_t PROGMEM vcombo_id[] = {KC_DOT, KC_I, COMBO_END};
  146. const uint16_t PROGMEM vcombo_ld[] = {KC_SLSH, KC_L, COMBO_END};
  147. const uint16_t PROGMEM hcombo_jr[] = {KC_J, KC_Y, COMBO_END};
  148. const uint16_t PROGMEM hcombo_ur[] = {KC_QUOT, KC_U, COMBO_END};
  149. const uint16_t PROGMEM hcombo_pr[] = {KC_P, KC_N, COMBO_END};
  150. const uint16_t PROGMEM hcombo_mr[] = {KC_M, KC_H, COMBO_END};
  151. const uint16_t PROGMEM hcombo_hr[] = {KC_COMM, KC_H, COMBO_END};
  152. const uint16_t PROGMEM xcombo_left[] = {KC_K, KC_P, COMBO_END};
  153. const uint16_t PROGMEM xcombo_right[] = {KC_M, KC_G, COMBO_END};
  154. const uint16_t PROGMEM xcombo_up[] = {KC_B, KC_J, COMBO_END};
  155. const uint16_t PROGMEM xcombo_down[] = {KC_K, KC_M, COMBO_END};
  156. const uint16_t PROGMEM xcombo_enter[] = {KC_G, KC_P, COMBO_END};
  157. const uint16_t PROGMEM xcombo_del[] = {KC_M, KC_B, COMBO_END};
  158. const uint16_t PROGMEM xcombo_bksp[] = {KC_K, KC_J, COMBO_END};
  159. const uint16_t PROGMEM xcombo_mins[] = {KC_V, KC_H, COMBO_END};
  160. const uint16_t PROGMEM xcombo_tab[] = {KC_V, KC_K, COMBO_END};
  161. const uint16_t PROGMEM xcombo_undo[] = {KC_V, KC_J, COMBO_END};
  162. const uint16_t PROGMEM xcombo_redo[] = {KC_B, KC_H, COMBO_END};
  163. const uint16_t PROGMEM xcombo_pgup[] = {KC_G, KC_B, COMBO_END};
  164. const uint16_t PROGMEM xcombo_pgdn[] = {KC_G, KC_K, COMBO_END};
  165. combo_t key_combos[COMBO_COUNT] = {
  166. [VCOMBO_PU] = COMBO(vcombo_pu, KC_CIRC),
  167. [VCOMBO_NU] = COMBO(vcombo_nu, KC_LBRC),
  168. [VCOMBO_EU] = COMBO(vcombo_eu, LSFT(KC_9)),
  169. [VCOMBO_IU] = COMBO(vcombo_iu, LSFT(KC_0)),
  170. [VCOMBO_LU] = COMBO(vcombo_lu, KC_RBRC),
  171. [VCOMBO_PD] = COMBO(vcombo_pd, LSFT(KC_7)),
  172. [VCOMBO_ND] = COMBO(vcombo_nd, KC_EQL),
  173. [VCOMBO_ED] = COMBO(vcombo_ed, KC_MINS),
  174. [VCOMBO_ID] = COMBO(vcombo_id, LSFT(KC_1)),
  175. [VCOMBO_LD] = COMBO(vcombo_ld, LSFT(KC_5)),
  176. [HCOMBO_JR] = COMBO(hcombo_jr, KC_GRV),
  177. [HCOMBO_UR] = COMBO(hcombo_ur, LSFT(KC_2)),
  178. [HCOMBO_PR] = COMBO(hcombo_pr, LSFT(KC_8)),
  179. [HCOMBO_MR] = COMBO(hcombo_mr, KC_NUHS),
  180. [HCOMBO_HR] = COMBO(hcombo_hr, KC_NUBS),
  181. [XCOMBO_LEFT] = COMBO(xcombo_left, KC_LEFT),
  182. [XCOMBO_RIGHT] = COMBO(xcombo_right, KC_RGHT),
  183. [XCOMBO_UP] = COMBO(xcombo_up, KC_UP),
  184. [XCOMBO_DOWN] = COMBO(xcombo_down, KC_DOWN),
  185. [XCOMBO_ENTER] = COMBO(xcombo_enter, KC_ENT),
  186. [XCOMBO_DEL] = COMBO(xcombo_del, KC_DEL),
  187. [XCOMBO_BKSP] = COMBO(xcombo_bksp, KC_BSPC),
  188. [XCOMBO_MINS] = COMBO(xcombo_mins, KC_MINS),
  189. [XCOMBO_TAB] = COMBO(xcombo_tab, KC_TAB),
  190. [XCOMBO_UNDO] = COMBO(xcombo_undo, LCTL(KC_Y)),
  191. [XCOMBO_REDO] = COMBO(xcombo_redo, LCTL(KC_Z)),
  192. [XCOMBO_PGUP] = COMBO(xcombo_pgup, KC_PGUP),
  193. [XCOMBO_PGDN] = COMBO(xcombo_pgdn, KC_PGDN)
  194. };
  195. #endif