gourdo1.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. /* Copyright 2021 Jonavin Eng @Jonavin
  2. Copyright 2022 gourdo1 <gourdo1@outlook.com>
  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. #include "gourdo1.h"
  16. #include "custom_double_taps.h"
  17. #include "autocorrect/autocorrection.h"
  18. // RGB NIGHT MODE
  19. #ifdef RGB_MATRIX_ENABLE
  20. static bool rgb_nightmode = false;
  21. // Turn on/off NUM LOCK if current state is different
  22. void activate_rgb_nightmode(bool turn_on) {
  23. if (rgb_nightmode != turn_on) {
  24. rgb_nightmode = !rgb_nightmode;
  25. }
  26. }
  27. bool get_rgb_nightmode(void) {
  28. return rgb_nightmode;
  29. }
  30. #endif // RGB_MATRIX_ENABLE
  31. // TIMEOUTS
  32. #ifdef IDLE_TIMEOUT_ENABLE
  33. static uint16_t timeout_timer = 0;
  34. static uint16_t timeout_counter = 0; //in minute intervals
  35. static uint16_t timeout_threshold = TIMEOUT_THRESHOLD_DEFAULT;
  36. uint16_t get_timeout_threshold(void) {
  37. return timeout_threshold;
  38. }
  39. void timeout_reset_timer(void) {
  40. timeout_timer = timer_read();
  41. timeout_counter = 0;
  42. };
  43. void timeout_update_threshold(bool increase) {
  44. if (increase && timeout_threshold < TIMEOUT_THRESHOLD_MAX) timeout_threshold++;
  45. if (!increase && timeout_threshold > 0) timeout_threshold--;
  46. };
  47. void timeout_tick_timer(void) {
  48. if (timeout_threshold > 0) {
  49. if (timer_elapsed(timeout_timer) >= 60000) { // 1 minute tick
  50. timeout_counter++;
  51. timeout_timer = timer_read();
  52. }
  53. #ifdef RGB_MATRIX_ENABLE
  54. if (timeout_threshold > 0 && timeout_counter >= timeout_threshold) {
  55. rgb_matrix_disable_noeeprom();
  56. }
  57. #endif
  58. } // timeout_threshold = 0 will disable timeout
  59. }
  60. #endif // IDLE_TIMEOUT_ENABLE
  61. #if defined(ALTTAB_SCROLL_ENABLE) || defined(IDLE_TIMEOUT_ENABLE) // timer features
  62. __attribute__((weak)) void matrix_scan_keymap(void) {}
  63. void matrix_scan_user(void) {
  64. #ifdef ALTTAB_SCROLL_ENABLE
  65. encoder_tick_alttabscroll();
  66. #endif
  67. #ifdef IDLE_TIMEOUT_ENABLE
  68. timeout_tick_timer();
  69. #endif
  70. matrix_scan_keymap();
  71. }
  72. #endif // ALTTAB_SCROLL_ENABLE or IDLE_TIMEOUT_ENABLE
  73. // Initialize variable holding the binary representation of active modifiers.
  74. uint8_t mod_state;
  75. // ============================================= PROCESS KEY CODES =============================================
  76. __attribute__((weak)) bool process_record_keymap(uint16_t keycode, keyrecord_t * record) {
  77. return true;
  78. }
  79. bool process_record_user(uint16_t keycode, keyrecord_t * record) {
  80. mod_state = get_mods();
  81. if (!process_record_keymap(keycode, record)) { return false; }
  82. if (!process_capsnum(keycode, record)) { return false; }
  83. if (!process_esc_to_base(keycode, record)) { return false; }
  84. if (!process_lsft_for_caps(keycode, record)) { return false; }
  85. if (!process_autocorrection(keycode, record)) { return false; }
  86. // Key macros ...
  87. switch (keycode) {
  88. // User configuration toggles
  89. case PRNCONF: // Print verbose status of all user_config toggles (open a text editor before engaging!!)
  90. if (record->event.pressed) {
  91. send_string("\n"SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)"#########");
  92. send_string(" gourdo1" SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_3)SS_TAP(X_KP_9))"s GMMK Pro User Settings ");
  93. send_string("#########"SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)"\n");
  94. send_string("Hold "SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_1))"Fn"SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_3))" and the number corresponding to a setting below to toggle.\n");
  95. send_string("Re"SS_TAP(X_KP_MINUS)"print this screen with "SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_1))"Fn" SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_3)) SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_1))"`" SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_3))" to see your changes reflected.\n");
  96. send_string("Config also visible as RGB under number keys by holding "SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_1))"Fn" SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_3))".\n");
  97. send_string(SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS));
  98. send_string(SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS));
  99. send_string(SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS));
  100. send_string(SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)SS_TAP(X_KP_MINUS)"\n");
  101. send_string("1. CapsLock RGB highlight alpha keys................ ");
  102. if (user_config.rgb_hilite_caps) {
  103. send_string(SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_1))"ON" SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_3))"\n");
  104. } else {
  105. send_string(SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_1))"OFF" SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_3))"\n");
  106. }
  107. send_string("2. Numpad RGB highlight layer keys.................. ");
  108. if (user_config.rgb_hilite_numpad) {
  109. send_string(SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_1))"ON" SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_3))"\n");
  110. } else {
  111. send_string(SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_1))"OFF" SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_3))"\n");
  112. }
  113. send_string("3. Double tap ESC to revert to BASE layer........... ");
  114. if (user_config.esc_double_tap_to_baselyr) {
  115. send_string(SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_1))"ON" SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_3))"\n");
  116. } else {
  117. send_string(SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_1))"OFF" SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_3))"\n");
  118. }
  119. send_string("4. DEL "SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_3)SS_TAP(X_KP_8))" HOME key locations......................... ");
  120. if (user_config.del_right_home_top) {
  121. send_string(SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_1))"HOME on F13"SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_5)SS_TAP(X_KP_9))" DEL right of BKSPC" SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_3))"\n");
  122. } else {
  123. send_string(SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_1))"DEL on F13"SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_5)SS_TAP(X_KP_9))" HOME right of BKSPC" SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_3))"\n");
  124. }
  125. send_string("5. Numpad on CapsLock"SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_5)SS_TAP(X_KP_9))" double tap LSHIFT for Caps... ");
  126. if (user_config.double_tap_shift_for_capslock) {
  127. send_string(SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_1))"ON" SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_3))"\n");
  128. } else {
  129. send_string(SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_1))"OFF" SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_3))"\n");
  130. }
  131. send_string("6. Encoder button function.......................... ");
  132. if (user_config.encoder_press_mute_or_media) {
  133. send_string(SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_1))"MUTE" SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_3))"\n");
  134. } else {
  135. send_string(SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_1))"MEDIA PLAY"SS_TAP(X_KP_SLASH) "PAUSE" SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_3))"\n");
  136. }
  137. send_string("7. Insert function accessed with.................... ");
  138. if (user_config.ins_on_shft_bkspc_or_del) {
  139. send_string(SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_1))"SHIFT"SS_TAP(X_KP_MINUS)"BKSPC"SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_3))"\n");
  140. } else {
  141. send_string(SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_1))"SHIFT"SS_TAP(X_KP_MINUS)"DEL"SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_3))"\n");
  142. }
  143. send_string("8. Force SHIFT "SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_3)SS_TAP(X_KP_8))" CTRL"SS_TAP(X_KP_MINUS)"SPACE to function like SPACE.. ");
  144. if (user_config.disable_space_mods) {
  145. send_string(SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_1))"ON"SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_3))"\n");
  146. } else {
  147. send_string(SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_1))"OFF"SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_3))"\n");
  148. }
  149. send_string("9. AutoCorrect...................................... ");
  150. if (user_config.autocorrect) {
  151. send_string(SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_1))"ON"SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_3))"\n");
  152. } else {
  153. send_string(SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_1))"OFF"SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_3))"\n");
  154. }
  155. send_string("0. CapsLock highlights extended alphas "SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_4)SS_TAP(X_KP_0))"ISO"SS_TAP(X_KP_MINUS)"only"SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_4)SS_TAP(X_KP_1))"... ");
  156. if (user_config.rgb_english_caps) {
  157. send_string(SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_1))"OFF"SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_3))"\n");
  158. } else {
  159. send_string(SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_1))"ON"SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_9)SS_TAP(X_KP_3))"\n");
  160. }
  161. send_string("\nThe latest firmware updates are always here"SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_5)SS_TAP(X_KP_8))" https" SS_LALT(SS_TAP(X_KP_0)SS_TAP(X_KP_0)SS_TAP(X_KP_5)SS_TAP(X_KP_8))SS_TAP(X_KP_SLASH)SS_TAP(X_KP_SLASH) "github.com"SS_TAP(X_KP_SLASH) "gourdo1"SS_TAP(X_KP_SLASH)"gmmkpro"SS_TAP(X_KP_MINUS)"media\n");
  162. }
  163. break;
  164. case TG_CAPS: // Toggle RGB highlighting of Capslock state
  165. if (record->event.pressed) {
  166. user_config.rgb_hilite_caps ^= 1; // Toggles the status
  167. eeconfig_update_user(user_config.raw); // Writes the new status to EEPROM
  168. }
  169. break;
  170. case TG_PAD: // Toggle RGB highlighting of Numpad state
  171. if (record->event.pressed) {
  172. user_config.rgb_hilite_numpad ^= 1; // Toggles the status
  173. eeconfig_update_user(user_config.raw); // Writes the new status to EEPROM
  174. }
  175. break;
  176. case TG_ESC: // Toggle alternate ESC functionality
  177. if (record->event.pressed) {
  178. user_config.esc_double_tap_to_baselyr ^= 1; // Toggles the status
  179. eeconfig_update_user(user_config.raw); // Writes the new status to EEPROM
  180. }
  181. break;
  182. case TG_DEL: // Toggle alternate placement of DEL and HOME keys
  183. if (record->event.pressed) {
  184. user_config.del_right_home_top ^= 1; // Toggles the status
  185. eeconfig_update_user(user_config.raw); // Writes the new status to EEPROM
  186. }
  187. break;
  188. case TG_TDCAP: // Toggle alternate Capslock/Numpad functionality
  189. if (record->event.pressed) {
  190. user_config.double_tap_shift_for_capslock ^= 1; // Toggles the status
  191. eeconfig_update_user(user_config.raw); // Writes the new status to EEPROM
  192. }
  193. break;
  194. case TG_ENC: // Toggle Encoder function
  195. if (record->event.pressed) {
  196. user_config.encoder_press_mute_or_media ^= 1; // Toggles the status
  197. eeconfig_update_user(user_config.raw); // Writes the new status to EEPROM
  198. }
  199. break;
  200. case TG_INS: // Toggle Encoder function
  201. if (record->event.pressed) {
  202. user_config.ins_on_shft_bkspc_or_del ^= 1; // Toggles the status
  203. eeconfig_update_user(user_config.raw); // Writes the new status to EEPROM
  204. }
  205. break;
  206. case TG_SPCMOD: // Toggle forcing SHIFT&CTRL-SPACE to function like SPACE
  207. if (record->event.pressed) {
  208. user_config.disable_space_mods ^= 1; // Toggles the status
  209. eeconfig_update_user(user_config.raw); // Writes the new status to EEPROM
  210. }
  211. break;
  212. case TG_AUTOCR: // Toggle AutoCorrect
  213. if (record->event.pressed) {
  214. user_config.autocorrect ^= 1; // Toggles the status
  215. eeconfig_update_user(user_config.raw); // Writes the new status to EEPROM
  216. }
  217. break;
  218. case TG_ENGCAP: // Toggle highlighting Non-English letters during CAPSLOCK
  219. if (record->event.pressed) {
  220. user_config.rgb_english_caps ^= 1; // Toggles the status
  221. eeconfig_update_user(user_config.raw); // Writes the new status to EEPROM
  222. }
  223. break;
  224. //return false;
  225. // Key to the left of encoder function (default HOME)
  226. case LEFTOFENC:
  227. if (!(user_config.del_right_home_top)) {
  228. if (!(user_config.ins_on_shft_bkspc_or_del)) {
  229. static bool inskey_registered;
  230. if (record -> event.pressed) {
  231. // Detect the activation of either shift keys
  232. if (mod_state & MOD_MASK_SHIFT) {
  233. // First temporarily canceling both shifts so that
  234. // shift isn't applied to the KC_INS keycode
  235. del_mods(MOD_MASK_SHIFT);
  236. register_code(KC_INS);
  237. // Update the boolean variable to reflect the status of KC_INS
  238. inskey_registered = true;
  239. // Reapplying modifier state so that the held shift key(s)
  240. // still work even after having tapped the key.
  241. set_mods(mod_state);
  242. return false;
  243. } else {
  244. register_code(KC_DEL);
  245. return false;
  246. }
  247. } else { // on release of KC_DEL
  248. // In case KC_INS is still being sent even after the release of KC_DEL
  249. if (inskey_registered) {
  250. unregister_code(KC_INS);
  251. inskey_registered = false;
  252. return false;
  253. } else {
  254. unregister_code(KC_DEL);
  255. return false;
  256. }
  257. }
  258. } else {
  259. if (record -> event.pressed) {
  260. register_code(KC_DEL);
  261. return false;
  262. } else {
  263. unregister_code(KC_DEL);
  264. return false;
  265. }
  266. }
  267. } else {
  268. if (record -> event.pressed) {
  269. register_code(KC_HOME);
  270. return false;
  271. } else {
  272. unregister_code(KC_HOME);
  273. return false;
  274. }
  275. }
  276. break;
  277. // Key below encoder function (default DEL)
  278. case BELOWENC:
  279. if (user_config.del_right_home_top) {
  280. if (!(user_config.ins_on_shft_bkspc_or_del)) {
  281. static bool inskey_registered;
  282. if (record -> event.pressed) {
  283. // Detect the activation of either shift keys
  284. if (mod_state & MOD_MASK_SHIFT) {
  285. // First temporarily canceling both shifts so that
  286. // shift isn't applied to the KC_INS keycode
  287. del_mods(MOD_MASK_SHIFT);
  288. register_code(KC_INS);
  289. // Update the boolean variable to reflect the status of KC_INS
  290. inskey_registered = true;
  291. // Reapplying modifier state so that the held shift key(s)
  292. // still work even after having tapped the key.
  293. set_mods(mod_state);
  294. return false;
  295. } else {
  296. register_code(KC_DEL);
  297. return false;
  298. }
  299. } else { // on release of KC_DEL
  300. // In case KC_INS is still being sent even after the release of KC_DEL
  301. if (inskey_registered) {
  302. unregister_code(KC_INS);
  303. inskey_registered = false;
  304. return false;
  305. } else {
  306. unregister_code(KC_DEL);
  307. return false;
  308. }
  309. }
  310. } else {
  311. if (record -> event.pressed) {
  312. register_code(KC_DEL);
  313. return false;
  314. } else {
  315. unregister_code(KC_DEL);
  316. return false;
  317. }
  318. }
  319. } else {
  320. if (record -> event.pressed) {
  321. register_code(KC_HOME);
  322. return false;
  323. } else {
  324. unregister_code(KC_HOME);
  325. return false;
  326. }
  327. }
  328. break;
  329. // Encoder button function
  330. case ENCFUNC:
  331. if (user_config.encoder_press_mute_or_media) {
  332. if (record -> event.pressed) {
  333. register_code(KC_MUTE);
  334. } else unregister_code16(keycode);
  335. }
  336. else {
  337. if (record -> event.pressed) {
  338. register_code(KC_MPLY);
  339. } else unregister_code16(keycode);
  340. }
  341. break;
  342. // DotCom domain macros
  343. case DOTCOM:
  344. if (record -> event.pressed) {
  345. send_string(".com");
  346. } else {
  347. // when keycode is released
  348. }
  349. break;
  350. case YAHOO:
  351. if (record -> event.pressed) {
  352. send_string("yahoo.com");
  353. } else {
  354. // when keycode is released
  355. }
  356. break;
  357. case OUTLOOK:
  358. if (record -> event.pressed) {
  359. send_string("outlook.com");
  360. } else {
  361. // when keycode is released
  362. }
  363. break;
  364. case GMAIL:
  365. if (record -> event.pressed) {
  366. send_string("gmail.com");
  367. } else {
  368. // when keycode is released
  369. }
  370. break;
  371. case HOTMAIL:
  372. if (record -> event.pressed) {
  373. send_string("hotmail.com");
  374. } else {
  375. // when keycode is released
  376. }
  377. break;
  378. // Windows Key lockout
  379. case WINLOCK:
  380. if (record -> event.pressed) {
  381. keymap_config.no_gui = !keymap_config.no_gui; //toggle status
  382. } else unregister_code16(keycode);
  383. break;
  384. // Double Zero
  385. case KC_00:
  386. if (record -> event.pressed) {
  387. // when keycode KC_00 is pressed
  388. send_string(SS_TAP(X_KP_0)SS_TAP(X_KP_0));
  389. } else unregister_code16(keycode);
  390. break;
  391. // Treat Control & Shift-Space as if regular Space
  392. case KC_SPC:
  393. if (user_config.disable_space_mods) {
  394. // Initialize a boolean variable that keeps track of the space key status: registered or not?
  395. static bool spckey_registered;
  396. if (record -> event.pressed) {
  397. // Detect the activation of either ctrl keys
  398. if (mod_state & MOD_MASK_CTRL) {
  399. // First temporarily canceling both ctrls so that
  400. // ctrl isn't applied to the KC_SPC keycode
  401. del_mods(MOD_MASK_CTRL);
  402. register_code(KC_SPC);
  403. // Update the boolean variable to reflect the status of KC_SPC
  404. spckey_registered = true;
  405. // Reapplying modifier state so that the held ctrl key(s)
  406. // still work even after having tapped the Space key.
  407. set_mods(mod_state);
  408. return false;
  409. }
  410. else if (mod_state & MOD_MASK_SHIFT) {
  411. // First temporarily canceling both shifts so that
  412. // shift isn't applied to the KC_SPC keycode
  413. del_mods(MOD_MASK_SHIFT);
  414. register_code(KC_SPC);
  415. // Update the boolean variable to reflect the status of KC_SPC
  416. spckey_registered = true;
  417. // Reapplying modifier state so that the held shift key(s)
  418. // still work even after having tapped the Space key.
  419. set_mods(mod_state);
  420. return false;
  421. }
  422. } else { // on release of KC_SPC
  423. // In case KC_SPC is still being sent even after the release of KC_SPC
  424. if (spckey_registered) {
  425. unregister_code(KC_SPC);
  426. spckey_registered = false;
  427. return false;
  428. }
  429. }
  430. }
  431. break;
  432. // INS as SHIFT-modified BackSpace key
  433. case KC_BSPC: {
  434. if (user_config.ins_on_shft_bkspc_or_del) {
  435. // Initialize a boolean variable that keeps track of the ins key status: registered or not?
  436. static bool inskey_registered;
  437. if (record -> event.pressed) {
  438. // Detect the activation of either shift keys
  439. if (mod_state & MOD_MASK_SHIFT) {
  440. // First temporarily canceling both shifts so that
  441. // shift isn't applied to the KC_INS keycode
  442. del_mods(MOD_MASK_SHIFT);
  443. register_code(KC_INS);
  444. // Update the boolean variable to reflect the status of KC_INS
  445. inskey_registered = true;
  446. // Reapplying modifier state so that the held shift key(s)
  447. // still work even after having tapped the key.
  448. set_mods(mod_state);
  449. return false;
  450. }
  451. } else { // on release of KC_BSPC
  452. // In case KC_INS is still being sent even after the release of KC_BSPC
  453. if (inskey_registered) {
  454. unregister_code(KC_INS);
  455. inskey_registered = false;
  456. return false;
  457. }
  458. }
  459. }
  460. }
  461. break;
  462. #ifdef IDLE_TIMEOUT_ENABLE
  463. case RGB_TOI:
  464. if (record -> event.pressed) {
  465. timeout_update_threshold(true);
  466. } else unregister_code16(keycode);
  467. break;
  468. case RGB_TOD:
  469. if (record -> event.pressed) {
  470. timeout_update_threshold(false); //decrease timeout
  471. } else unregister_code16(keycode);
  472. break;
  473. #endif // IDLE_TIMEOUT_ENABLE
  474. #ifdef RGB_MATRIX_ENABLE
  475. case RGB_NITE:
  476. if (record -> event.pressed) {
  477. rgb_nightmode = !rgb_nightmode;
  478. } else unregister_code16(keycode);
  479. break;
  480. #endif // RGB_MATRIX_ENABLE
  481. #ifdef EMOTICON_ENABLE
  482. case EMO_SHRUG:
  483. if (record -> event.pressed) send_string("`\\_(\"/)_/`");
  484. else unregister_code16(keycode);
  485. break;
  486. case EMO_CONFUSE:
  487. if (record -> event.pressed) send_string("(*_*)");
  488. else unregister_code16(keycode);
  489. break;
  490. case EMO_TEARS:
  491. if (record -> event.pressed) send_string("(T_T)");
  492. else unregister_code16(keycode);
  493. break;
  494. case EMO_NERVOUS:
  495. if (record -> event.pressed) send_string("(~_~;)");
  496. else unregister_code16(keycode);
  497. break;
  498. case EMO_JOY:
  499. if (record -> event.pressed) send_string("(^o^)");
  500. else unregister_code16(keycode);
  501. break;
  502. case EMO_SAD:
  503. if (record -> event.pressed) send_string(":'-(");
  504. else unregister_code16(keycode);
  505. break;
  506. #endif // EMOTICON_ENABLE
  507. #ifdef ALTTAB_SCROLL_ENABLE
  508. case KC_TSTOG:
  509. if (record -> event.pressed) encoder_toggle_alttabscroll();
  510. else unregister_code16(keycode);
  511. break;
  512. #endif // ALTTAB_SCROLL_ENABLE
  513. default:
  514. if (record -> event.pressed) {
  515. #ifdef RGB_MATRIX_ENABLE
  516. rgb_matrix_enable();
  517. #endif
  518. #ifdef IDLE_TIMEOUT_ENABLE
  519. timeout_reset_timer(); //reset activity timer
  520. #endif
  521. }
  522. break;
  523. }
  524. return true;
  525. };
  526. // Define custom Caps Word continuity characters
  527. bool caps_word_press_user(uint16_t keycode) {
  528. switch (keycode) {
  529. // Keycodes that continue Caps Word, with shift applied.
  530. case KC_A ... KC_Z:
  531. case KC_TILD:
  532. case KC_UNDS:
  533. case KC_DQT:
  534. case KC_COLN:
  535. case KC_RSFT:
  536. case KC_LSFT:
  537. add_weak_mods(MOD_BIT(KC_LSFT)); // Apply shift to next key.
  538. return true;
  539. // Keycodes that continue Caps Word, without shifting.
  540. case KC_1 ... KC_0:
  541. case KC_GRV:
  542. case KC_MINS:
  543. case KC_QUOT:
  544. case KC_SCLN:
  545. case KC_BSPC:
  546. case KC_DEL:
  547. return true;
  548. default:
  549. return false; // Deactivate Caps Word.
  550. }
  551. }
  552. // Turn on/off NUM LOCK if current state is different
  553. void activate_numlock(bool turn_on) {
  554. if (IS_HOST_LED_ON(USB_LED_NUM_LOCK) != turn_on) {
  555. tap_code(KC_NUM_LOCK);
  556. }
  557. }
  558. // INITIAL STARTUP
  559. __attribute__((weak)) void keyboard_post_init_keymap(void) {
  560. }
  561. void keyboard_post_init_user(void) {
  562. // Read the user config from EEPROM
  563. user_config.raw = eeconfig_read_user();
  564. keyboard_post_init_keymap();
  565. #ifdef STARTUP_NUMLOCK_ON
  566. activate_numlock(true); // turn on Num lock by default so that the numpad layer always has predictable results
  567. #endif // STARTUP_NUMLOCK_ON
  568. #ifdef IDLE_TIMEOUT_ENABLE
  569. timeout_timer = timer_read(); // set initial time for idle timeout
  570. #endif
  571. }
  572. /* Set defaults for EEPROM user configuration variables */
  573. void eeconfig_init_user(void) {
  574. user_config.raw = 0;
  575. user_config.rgb_hilite_caps = true;
  576. user_config.rgb_hilite_numpad = true;
  577. user_config.double_tap_shift_for_capslock = true;
  578. user_config.del_right_home_top = true;
  579. user_config.encoder_press_mute_or_media = true;
  580. user_config.esc_double_tap_to_baselyr = true;
  581. user_config.ins_on_shft_bkspc_or_del = true;
  582. user_config.disable_space_mods = true;
  583. user_config.autocorrect = true;
  584. user_config.rgb_english_caps = true;
  585. eeconfig_update_user(user_config.raw);
  586. }