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.

326 lines
12 KiB

  1. #include "ergotravel.h"
  2. #include "action_layer.h"
  3. #include "eeconfig.h"
  4. #include "mousekey.h"
  5. #include "process_unicode.h"
  6. extern keymap_config_t keymap_config;
  7. #define _QWERTY 0
  8. #define _NUMBERS 1
  9. #define _SYMBOLS 2
  10. #define _CODING 3
  11. #define _NAVIGATION 4
  12. #define _ADJUST 16
  13. enum custom_keycodes {
  14. QWERTY = SAFE_RANGE,
  15. ADJUST,
  16. CODING_SPACE,
  17. NUMBERS_SPACE,
  18. SYMBOLS_SPACE,
  19. NAVIGATE_SPACE,
  20. TABLE_FLIP,
  21. RESET_TABLE,
  22. SHRUG,
  23. LOOK_OF_DISAPPROVAL
  24. };
  25. #define KC_ KC_TRNS
  26. #define KC_ADJT MO(_ADJUST)
  27. #define KC_RST RESET
  28. #define KC_BL_S BL_STEP
  29. #define KC_DBUG DEBUG
  30. #define KC_RTOG RGB_TOG
  31. #define KC_RMOD RGB_MOD
  32. #define KC_RHUI RGB_HUI
  33. #define KC_RHUD RGB_HUD
  34. #define KC_RSAI RGB_SAI
  35. #define KC_RSAD RGB_SAD
  36. #define KC_RVAI RGB_VAI
  37. #define KC_RVAD RGB_VAD
  38. #define KC_RSEN MT(MOD_RSFT, KC_ENT) // Tap for enter, hold for right shift
  39. #define KC_LCCA MT(MOD_LCTL, KC_CAPS) // Tap for caps lock, hold for left control
  40. #define KC_SHDE MT(MOD_LSFT, KC_DEL) // Tap for delete, hold for left shift
  41. #define KC_NAVI MO(_NAVIGATION)
  42. #define KC_COSP CODING_SPACE
  43. #define KC_NUSP NUMBERS_SPACE
  44. #define KC_SYSP SYMBOLS_SPACE
  45. #define KC_NASP NAVIGATE_SPACE
  46. #define KC_FLIP TABLE_FLIP
  47. #define KC_TSET RESET_TABLE
  48. #define KC_SRUG SHRUG
  49. #define KC_DISA LOOK_OF_DISAPPROVAL
  50. #define KC_RST RESET
  51. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  52. [_QWERTY] = LAYOUT_kc(
  53. //,----+----+----+----+----+----+----. ,----+----+----+----+----+----+----.
  54. TAB , Q , W , E , R , T ,HOME, PGUP, Y , U , I , O , P ,BSPC,
  55. //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----|
  56. LCCA, A , S , D , F , G ,END , PGDN, H , J , K , L ,SCLN,QUOT,
  57. //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----|
  58. SHDE, Z , X , C , V , B ,LGUI, RALT, N , M ,COMM,DOT ,SLSH,RSEN,
  59. //|----+----+----+----+----+----+----. .----+----+----+----+----+----+----|
  60. ESC ,ADJT,LALT,ENT ,NUSP,NASP, SYSP,COSP,RCTL,NAVI,ADJT,DEL
  61. //`----+----+----+--+-+----/----/ \----\----+----+----+----+----'
  62. ),
  63. [_NUMBERS] = LAYOUT_kc(
  64. //,----+----+----+----+----+----+----. ,----+----+----+----+----+----+----.
  65. GRAVE, 1 , 2 , 3 , 4 , 5 ,MPLY, VOLU, 6 , 7 , 8 , 9 , 0 , ,
  66. //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----|
  67. , , , , , ,MNXT, VOLD,FLIP,TSET,SRUG,DISA, , ,
  68. //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----|
  69. , , , , , , , , , , , , , ,
  70. //|----+----+----+----+----+----+----. .----+----+----+----+----+----+----|
  71. , , , , , , , , , , ,
  72. //`----+----+----+--+-+----/----/ \----\----+----+----+----+----'
  73. ),
  74. [_SYMBOLS] = LAYOUT_kc(
  75. //,----+----+----+----+----+----+----. ,----+----+----+----+----+----+----.
  76. GRAVE,EXLM, AT ,HASH,DLR ,PERC,MPLY, VOLU,CIRC,AMPR,ASTR,LPRN,RPRN,BSLS,
  77. //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----|
  78. , , , , , ,MNXT, VOLD, , , , , , ,
  79. //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----|
  80. , , , , , , , , , , , , , ,
  81. //|----+----+----+----+----+----+----. .----+----+----+----+----+----+----|
  82. , , , , , , , , , , ,
  83. //`----+----+----+--+-+----/----/ \----\----+----+----+----+----'
  84. ),
  85. [_CODING] = LAYOUT_kc(
  86. //,----+----+----+----+----+----+----. ,----+----+----+----+----+----+----.
  87. , , ,LCBR,RCBR, ,MPLY, VOLU, ,AMPR,PIPE,DLR , , ,
  88. //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----|
  89. , , ,LPRN,RPRN, ,MNXT, VOLD, ,UNDS,MINS,ASTR, , ,
  90. //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----|
  91. , , ,LBRC,RBRC, , , , ,PLUS,EQL , , , ,
  92. //|----+----+----+----+----+----+----. .----+----+----+----+----+----+----|
  93. , , , , , , , , , , ,
  94. //`----+----+----+--+-+----/----/ \----\----+----+----+----+----'
  95. ),
  96. [_NAVIGATION] = LAYOUT_kc(
  97. //,----+----+----+----+----+----+----. ,----+----+----+----+----+----+----.
  98. , , , UP , , ,MPLY, VOLU,WH_U,BTN1,MS_U,BTN1, , ,
  99. //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----|
  100. , ,LEFT,DOWN,RGHT, ,MNXT, VOLD,WH_D,MS_L,MS_D,MS_R, , ,
  101. //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----|
  102. , , , , , , , , , , , , , ,
  103. //|----+----+----+----+----+----+----. .----+----+----+----+----+----+----|
  104. , , , , , , , , , , ,
  105. //`----+----+----+--+-+----/----/ \----\----+----+----+----+----'
  106. ),
  107. [_ADJUST] = LAYOUT_kc(
  108. //,----+----+----+----+----+----+----. ,----+----+----+----+----+----+----.
  109. F1 ,F2 ,F3 ,F4 ,F5 ,F6 , , ,F7 ,F8 ,F9 ,F10 ,F11 ,F12 ,
  110. //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----|
  111. ,RTOG,RVAI,RHUI,RSAI, , , , , , , , , ,
  112. //|----+----+----+----+----+----+----| |----+----+----+----+----+----+----|
  113. ,RMOD,RVAD,RHUD,RSAD, , , ,RST , , , , , ,
  114. //|----+----+----+----+----+----+----. .----+----+----+----+----+----+----|
  115. , , , , , , , , , , ,
  116. //`----+----+----+--+-+----/----/ \----\----+----+----+----+----'
  117. )
  118. };
  119. #ifdef AUDIO_ENABLE
  120. float tone_qwerty[][2] = SONG(QWERTY_SOUND);
  121. #endif
  122. void persistent_default_layer_set(uint16_t default_layer) {
  123. eeconfig_update_default_layer(default_layer);
  124. default_layer_set(default_layer);
  125. }
  126. uint16_t custom_lt_timer;
  127. keypos_t prv_key_pressed;
  128. // Runs just one time when the keyboard initializes.
  129. void matrix_init_user(void) {
  130. // set_unicode_input_mode(UC_LNX); // Linux
  131. set_unicode_input_mode(UC_OSX); // Mac OSX
  132. // set_unicode_input_mode(UC_WIN); // Windows (with registry key, see wiki)
  133. //set_unicode_input_mode(UC_WINC); // Windows (with WinCompose, see wiki)
  134. };
  135. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  136. if(record->event.pressed) prv_key_pressed = record->event.key;
  137. #define IS_KEYPOS_SAME(keyone,keytwo) ((keyone.col==keytwo.col)&&(keyone.row==keytwo.row))
  138. #define ANOTHER_KEY_PRESSED (!IS_KEYPOS_SAME(prv_key_pressed, record->event.key))
  139. inline void tap(uint16_t keycode) {
  140. register_code(keycode);
  141. unregister_code(keycode);
  142. };
  143. inline void swapInput(void) {
  144. register_code(KC_LGUI);
  145. tap(KC_SPC);
  146. unregister_code(KC_LGUI);
  147. };
  148. switch (keycode) {
  149. case QWERTY:
  150. if (record->event.pressed) {
  151. #ifdef AUDIO_ENABLE
  152. PLAY_SONG(tone_qwerty);
  153. #endif
  154. persistent_default_layer_set(1UL<<_QWERTY);
  155. }
  156. return false;
  157. break;
  158. case CODING_SPACE:
  159. if (record->event.pressed) {
  160. custom_lt_timer = timer_read();
  161. layer_on(_CODING);
  162. } else {
  163. layer_off(_CODING);
  164. if (timer_elapsed(custom_lt_timer)<150 && (!ANOTHER_KEY_PRESSED)) {
  165. register_code(KC_SPC);
  166. unregister_code(KC_SPC);
  167. }
  168. }
  169. return false;
  170. break;
  171. case NUMBERS_SPACE:
  172. if (record->event.pressed) {
  173. custom_lt_timer = timer_read();
  174. layer_on(_NUMBERS);
  175. } else {
  176. layer_off(_NUMBERS);
  177. if (timer_elapsed(custom_lt_timer)<150 && (!ANOTHER_KEY_PRESSED)) {
  178. register_code(KC_SPC);
  179. unregister_code(KC_SPC);
  180. }
  181. }
  182. return false;
  183. break;
  184. case SYMBOLS_SPACE:
  185. if (record->event.pressed) {
  186. custom_lt_timer = timer_read();
  187. layer_on(_SYMBOLS);
  188. } else {
  189. layer_off(_SYMBOLS);
  190. if (timer_elapsed(custom_lt_timer)<150 && (!ANOTHER_KEY_PRESSED)) {
  191. register_code(KC_SPC);
  192. unregister_code(KC_SPC);
  193. }
  194. }
  195. return false;
  196. break;
  197. case NAVIGATE_SPACE:
  198. if (record->event.pressed) {
  199. custom_lt_timer = timer_read();
  200. layer_on(_NAVIGATION);
  201. } else {
  202. layer_off(_NAVIGATION);
  203. if (timer_elapsed(custom_lt_timer)<150 && (!ANOTHER_KEY_PRESSED)) {
  204. register_code(KC_SPC);
  205. unregister_code(KC_SPC);
  206. }
  207. }
  208. return false;
  209. break;
  210. case TABLE_FLIP:
  211. if (record->event.pressed) {
  212. swapInput();
  213. register_code(KC_RSFT);
  214. tap(KC_9);
  215. unregister_code(KC_RSFT);
  216. process_unicode((0x256F|QK_UNICODE), record); // Arm
  217. process_unicode((0x00B0|QK_UNICODE), record); // Eye
  218. process_unicode((0x25A1|QK_UNICODE), record); // Mouth
  219. process_unicode((0x00B0|QK_UNICODE), record); // Eye
  220. register_code(KC_RSFT);
  221. tap(KC_0);
  222. unregister_code(KC_RSFT);
  223. process_unicode((0x256F|QK_UNICODE), record); // Arm
  224. tap(KC_SPC);
  225. process_unicode((0x0361|QK_UNICODE), record); // Flippy
  226. tap(KC_SPC);
  227. process_unicode((0x253B|QK_UNICODE), record); // Table
  228. process_unicode((0x2501|QK_UNICODE), record); // Table
  229. process_unicode((0x253B|QK_UNICODE), record); // Table
  230. swapInput();
  231. }
  232. return false;
  233. break;
  234. case RESET_TABLE: // ┬──┬ ノ( ゜-゜ノ)
  235. if (record->event.pressed) {
  236. swapInput();
  237. process_unicode((0x252C|QK_UNICODE), record); // Table
  238. process_unicode((0x2500|QK_UNICODE), record); // Table
  239. process_unicode((0x2500|QK_UNICODE), record); // Table
  240. process_unicode((0x252C|QK_UNICODE), record); // Table
  241. tap(KC_SPC);
  242. process_unicode((0x30CE|QK_UNICODE), record); // Arm
  243. register_code(KC_RSFT);
  244. tap(KC_9);
  245. unregister_code(KC_RSFT);
  246. tap(KC_SPC);
  247. process_unicode((0x309C|QK_UNICODE), record); // Eye
  248. tap(KC_MINS);
  249. process_unicode((0x309C|QK_UNICODE), record); // Eye
  250. process_unicode((0x30CE|QK_UNICODE), record); // Arm
  251. register_code(KC_RSFT);
  252. tap(KC_0);
  253. unregister_code(KC_RSFT);
  254. swapInput();
  255. }
  256. return false;
  257. break;
  258. case SHRUG: // ¯\_(ツ)_/¯
  259. if (record->event.pressed) {
  260. swapInput();
  261. process_unicode((0x00AF|QK_UNICODE), record); // Hand
  262. tap(KC_BSLS); // Arm
  263. register_code(KC_RSFT);
  264. tap(KC_UNDS); // Arm
  265. tap(KC_LPRN); // Head
  266. unregister_code(KC_RSFT);
  267. process_unicode((0x30C4|QK_UNICODE), record); // Face
  268. register_code(KC_RSFT);
  269. tap(KC_RPRN); // Head
  270. tap(KC_UNDS); // Arm
  271. unregister_code(KC_RSFT);
  272. tap(KC_SLSH); // Arm
  273. process_unicode((0x00AF|QK_UNICODE), record); // Hand
  274. swapInput();
  275. }
  276. return false;
  277. break;
  278. case LOOK_OF_DISAPPROVAL: // ಠ_ಠ
  279. if(record->event.pressed){
  280. swapInput();
  281. process_unicode((0x0CA0|QK_UNICODE), record); // Eye
  282. register_code(KC_RSFT);
  283. tap(KC_MINS);
  284. unregister_code(KC_RSFT);
  285. process_unicode((0x0CA0|QK_UNICODE), record); // Eye
  286. swapInput();
  287. }
  288. return false;
  289. break;
  290. }
  291. return true;
  292. }