2
0

keymap.c 12 KB

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