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.

557 lines
15 KiB

  1. #include "romus.h"
  2. /*---------------*\
  3. |*-----MOUSE-----*|
  4. \*---------------*/
  5. #ifdef MOUSEKEY_ENABLE
  6. #include "mousekey.h"
  7. #endif
  8. /*-------------*\
  9. |*-----RGB-----*|
  10. \*-------------*/
  11. #ifdef RGBLIGHT_ENABLE
  12. #include "rgblight.h"
  13. #endif
  14. /*-------------*\
  15. |*---UNICODE---*|
  16. \*-------------*/
  17. #ifdef UNICODE_ENABLE
  18. #endif
  19. /*-----------------*\
  20. |*-----SECRETS-----*|
  21. \*-----------------*/
  22. // Enabled by adding a non-tracked secrets.h to this dir.
  23. #if (__has_include("secrets.h"))
  24. #include "secrets.h"
  25. #endif
  26. /*---------------*\
  27. |*-----MUSIC-----*|
  28. \*---------------*/
  29. #ifdef AUDIO_ENABLE
  30. float tone_game[][2] = SONG(ZELDA_PUZZLE);
  31. float tone_return[][2] = SONG(ZELDA_TREASURE);
  32. float tone_linux[][2] = SONG(UNICODE_LINUX);
  33. float tone_windows[][2] = SONG(UNICODE_WINDOWS);
  34. #endif
  35. /*-------------------*\
  36. |*-----TAP-DANCE-----*|
  37. \*-------------------*/
  38. #ifdef TAP_DANCE_ENABLE
  39. qk_tap_dance_action_t tap_dance_actions[] = {
  40. // Shift on double tap of semicolon
  41. [SCL] = ACTION_TAP_DANCE_DOUBLE( KC_SCLN, KC_COLN )
  42. };
  43. #endif
  44. /* In keymaps, instead of writing _user functions, write _keymap functions
  45. * The __attribute__((weak)) allows for empty definitions here, and during
  46. * compilation, if these functions are defined elsewhere, they are written
  47. * over. This allows to include custom code from keymaps in the generic code
  48. * in this file.
  49. */
  50. __attribute__ ((weak)) void matrix_init_keymap(void) { }
  51. __attribute__ ((weak)) void matrix_scan_keymap(void) { }
  52. __attribute__ ((weak)) bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
  53. return true;
  54. }
  55. __attribute__ ((weak)) uint32_t layer_state_set_keymap (uint32_t state) {
  56. return state;
  57. }
  58. __attribute__ ((weak)) void led_set_keymap(uint8_t usb_led) { }
  59. /* ----------------------- *\
  60. * -----RGB Functions----- *
  61. \* ----------------------- */
  62. #ifdef RGBLIGHT_ENABLE
  63. // Set RGBLIGHT state depending on layer
  64. void rgblight_change( uint8_t this_layer ) {
  65. // Enable RGB light; will not work without this
  66. //rgblight_enable_noeeprom();
  67. // Change RGB light
  68. switch ( this_layer ) {
  69. case _DV:
  70. // Load base layer
  71. rgblight_disable_noeeprom();
  72. break;
  73. case _AL:
  74. // Do yellow for alternate
  75. rgblight_enable_noeeprom();
  76. rgblight_sethsv_noeeprom( 60,255,255);
  77. break;
  78. case _GA:
  79. // Do purple for game
  80. rgblight_enable_noeeprom();
  81. rgblight_sethsv_noeeprom(285,255,255);
  82. break;
  83. case _NU:
  84. // Do azure for number
  85. rgblight_enable_noeeprom();
  86. rgblight_sethsv_noeeprom(186,200,255);
  87. break;
  88. case _SE:
  89. // Do red for settings
  90. rgblight_enable_noeeprom();
  91. rgblight_sethsv_noeeprom( 16,255,255);
  92. break;
  93. case _MO:
  94. // Do green for mouse
  95. rgblight_enable_noeeprom();
  96. rgblight_sethsv_noeeprom(120,255,255);
  97. break;
  98. case _MU:
  99. // Do orange for music
  100. rgblight_enable_noeeprom();
  101. rgblight_sethsv_noeeprom( 39,255,255);
  102. break;
  103. default:
  104. // Something went wrong
  105. rgblight_enable_noeeprom();
  106. rgblight_sethsv_noeeprom( 0,255,255);
  107. break;
  108. }
  109. }
  110. #endif
  111. /*---------------------*\
  112. |*-----MATRIX INIT-----*|
  113. \*---------------------*/
  114. void matrix_init_user (void) {
  115. // Keymap specific things, do it first thing to allow for delays etc
  116. matrix_init_keymap();
  117. // Correct unicode
  118. #ifdef UNICODE_ENABLE
  119. set_unicode_input_mode(UC_LNX);
  120. #endif
  121. // Make beginning layer DVORAK
  122. set_single_persistent_default_layer(_DV);
  123. }
  124. /*---------------------*\
  125. |*-----MATRIX SCAN-----*|
  126. \*---------------------*/
  127. void matrix_scan_user (void) {
  128. // Keymap specific, do it first
  129. matrix_scan_keymap();
  130. }
  131. /*------------------*\
  132. |*-----KEYCODES-----*|
  133. \*------------------*/
  134. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  135. // Shift check
  136. bool is_capital = ( keyboard_report->mods & (MOD_BIT(KC_LSFT)|MOD_BIT(KC_RSFT)) );
  137. static bool lock_flag = false;
  138. uint8_t layer = biton32 (layer_state);
  139. switch (keycode) {
  140. // Secrets implementation
  141. #if (__has_include("secrets.h"))
  142. case SECRET1:
  143. if( !record->event.pressed ) {
  144. send_string_P( secret[ keycode - SECRET1 ] );
  145. }
  146. return false;
  147. break;
  148. case SECRET2:
  149. if( !record->event.pressed ) {
  150. send_string_P( secret[ keycode - SECRET2 ] );
  151. }
  152. return false;
  153. break;
  154. case SECRET3:
  155. if( !record->event.pressed ) {
  156. send_string_P( secret[ keycode - SECRET3 ] );
  157. }
  158. return false;
  159. break;
  160. #endif
  161. // Lock functionality: These layers are locked if the LOCKED buttons are
  162. // pressed. Otherwise, they are momentary toggles
  163. case K_LOCK:
  164. if (record->event.pressed) {
  165. lock_flag = !lock_flag;
  166. }
  167. return false;
  168. break;
  169. case K_MOUSE:
  170. if (record->event.pressed) {
  171. layer_on(_MO);
  172. lock_flag = false;
  173. } else {
  174. if ( lock_flag ) {
  175. lock_flag = false;
  176. } else {
  177. layer_off(_MO);
  178. }
  179. }
  180. return false;
  181. break;
  182. case K_NUMBR:
  183. if (record->event.pressed) {
  184. layer_on(_NU);
  185. lock_flag = false;
  186. } else {
  187. if ( lock_flag ) {
  188. lock_flag = false;
  189. } else {
  190. layer_off(_NU);
  191. }
  192. }
  193. return false;
  194. break;
  195. // Layer switches with sound
  196. case K_GAMES:
  197. if (record->event.pressed) {
  198. // On press, turn off layer if active
  199. if ( layer == _GA ) {
  200. #ifdef AUDIO_ENABLE
  201. stop_all_notes();
  202. PLAY_SONG(tone_return);
  203. #endif
  204. layer_off(_GA);
  205. }
  206. } else {
  207. // After click, turn on layer if accessed from setting
  208. if ( layer == _SE ) {
  209. #ifdef AUDIO_ENABLE
  210. stop_all_notes();
  211. PLAY_SONG(tone_game);
  212. #endif
  213. layer_on(_GA);
  214. layer_off(_SE);
  215. }
  216. }
  217. return false;
  218. break;
  219. case MU_TOG:
  220. if (record->event.pressed) {
  221. // On press, turn off layer if active
  222. if ( layer == _SE ) {
  223. layer_off(_SE);
  224. layer_on(_MU);
  225. } else {
  226. layer_off(_MU);
  227. }
  228. }
  229. return true;
  230. break;
  231. //------UNICODE
  232. // Unicode switches with sound
  233. #ifdef UNICODE_ENABLE
  234. case UNI_LI:
  235. if (record->event.pressed) {
  236. #ifdef AUDIO_ENABLE
  237. stop_all_notes();
  238. PLAY_SONG(tone_linux);
  239. #endif
  240. set_unicode_input_mode(UC_LNX);
  241. }
  242. return false;
  243. break;
  244. case UNI_WN:
  245. if (record->event.pressed) {
  246. #ifdef AUDIO_ENABLE
  247. stop_all_notes();
  248. PLAY_SONG(tone_windows);
  249. #endif
  250. set_unicode_input_mode(UC_WIN);
  251. }
  252. return false;
  253. break;
  254. // Turkish letters, with capital functionality
  255. case TUR_A:
  256. if (record->event.pressed) {
  257. if ( is_capital ) {
  258. unicode_input_start();
  259. register_hex(0x00c2);
  260. unicode_input_finish();
  261. } else {
  262. unicode_input_start();
  263. register_hex(0x00e2);
  264. unicode_input_finish();
  265. }
  266. }
  267. return false;
  268. break;
  269. case TUR_O:
  270. if (record->event.pressed) {
  271. if ( is_capital ) {
  272. unicode_input_start();
  273. register_hex(0x00d6);
  274. unicode_input_finish();
  275. } else {
  276. unicode_input_start();
  277. register_hex(0x00f6);
  278. unicode_input_finish();
  279. }
  280. }
  281. return false;
  282. break;
  283. case TUR_U:
  284. if (record->event.pressed) {
  285. if ( is_capital ) {
  286. unicode_input_start();
  287. register_hex(0x00dc);
  288. unicode_input_finish();
  289. } else {
  290. unicode_input_start();
  291. register_hex(0x00fc);
  292. unicode_input_finish();
  293. }
  294. }
  295. return false;
  296. break;
  297. case TUR_I:
  298. if (record->event.pressed) {
  299. if ( is_capital ) {
  300. unicode_input_start();
  301. register_hex(0x0130);
  302. unicode_input_finish();
  303. } else {
  304. unicode_input_start();
  305. register_hex(0x0131);
  306. unicode_input_finish();
  307. }
  308. }
  309. return false;
  310. break;
  311. case TUR_G:
  312. if (record->event.pressed) {
  313. if ( is_capital ) {
  314. unicode_input_start();
  315. register_hex(0x011e);
  316. unicode_input_finish();
  317. } else {
  318. unicode_input_start();
  319. register_hex(0x011f);
  320. unicode_input_finish();
  321. }
  322. }
  323. return false;
  324. break;
  325. case TUR_C:
  326. if (record->event.pressed) {
  327. if ( is_capital ) {
  328. unicode_input_start();
  329. register_hex(0x00c7);
  330. unicode_input_finish();
  331. } else {
  332. unicode_input_start();
  333. register_hex(0x00e7);
  334. unicode_input_finish();
  335. }
  336. }
  337. return false;
  338. break;
  339. case TUR_S:
  340. if (record->event.pressed) {
  341. if ( is_capital ) {
  342. unicode_input_start();
  343. register_hex(0x015e);
  344. unicode_input_finish();
  345. } else {
  346. unicode_input_start();
  347. register_hex(0x015f);
  348. unicode_input_finish();
  349. }
  350. }
  351. return false;
  352. break;
  353. #endif
  354. //-------Diagonal mouse movements
  355. #ifdef MOUSEKEY_ENABLE
  356. case MO_NE:
  357. if( record->event.pressed ) {
  358. mousekey_on(MO_N);
  359. mousekey_on(MO_E);
  360. mousekey_send();
  361. } else {
  362. mousekey_off(MO_N);
  363. mousekey_off(MO_E);
  364. mousekey_send();
  365. }
  366. return false;
  367. break;
  368. case MO_NW:
  369. if( record->event.pressed ) {
  370. mousekey_on(MO_N);
  371. mousekey_on(MO_W);
  372. mousekey_send();
  373. } else {
  374. mousekey_off(MO_N);
  375. mousekey_off(MO_W);
  376. mousekey_send();
  377. }
  378. return false;
  379. break;
  380. case MO_SE:
  381. if( record->event.pressed ) {
  382. mousekey_on(MO_S);
  383. mousekey_on(MO_E);
  384. mousekey_send();
  385. } else {
  386. mousekey_off(MO_S);
  387. mousekey_off(MO_E);
  388. mousekey_send();
  389. }
  390. return false;
  391. break;
  392. case MO_SW:
  393. if( record->event.pressed ) {
  394. mousekey_on(MO_S);
  395. mousekey_on(MO_W);
  396. mousekey_send();
  397. } else {
  398. mousekey_off(MO_S);
  399. mousekey_off(MO_W);
  400. mousekey_send();
  401. }
  402. return false;
  403. break;
  404. case MO_S_NE:
  405. if( record->event.pressed ) {
  406. mousekey_on(MO_S_N);
  407. mousekey_on(MO_S_E);
  408. mousekey_send();
  409. } else {
  410. mousekey_off(MO_S_N);
  411. mousekey_off(MO_S_E);
  412. mousekey_send();
  413. }
  414. return false;
  415. break;
  416. case MO_S_NW:
  417. if( record->event.pressed ) {
  418. mousekey_on(MO_S_N);
  419. mousekey_on(MO_S_W);
  420. mousekey_send();
  421. } else {
  422. mousekey_off(MO_S_N);
  423. mousekey_off(MO_S_W);
  424. mousekey_send();
  425. }
  426. return false;
  427. break;
  428. case MO_S_SE:
  429. if( record->event.pressed ) {
  430. mousekey_on(MO_S_S);
  431. mousekey_on(MO_S_E);
  432. mousekey_send();
  433. } else {
  434. mousekey_off(MO_S_S);
  435. mousekey_off(MO_S_E);
  436. mousekey_send();
  437. }
  438. return false;
  439. break;
  440. case MO_S_SW:
  441. if( record->event.pressed ) {
  442. mousekey_on(MO_S_S);
  443. mousekey_on(MO_S_W);
  444. mousekey_send();
  445. } else {
  446. mousekey_off(MO_S_S);
  447. mousekey_off(MO_S_W);
  448. mousekey_send();
  449. }
  450. return false;
  451. break;
  452. #endif
  453. //------DOUBLE PRESS, with added left navigation
  454. case DBL_SPC:
  455. if( record->event.pressed ) {
  456. SEND_STRING(" "SS_TAP(X_LEFT));
  457. }
  458. return false;
  459. break;
  460. case DBL_ANG:
  461. if( record->event.pressed ) {
  462. SEND_STRING("<>"SS_TAP(X_LEFT));
  463. }
  464. return false;
  465. break;
  466. case DBL_PAR:
  467. if( record->event.pressed ) {
  468. SEND_STRING("()"SS_TAP(X_LEFT));
  469. }
  470. return false;
  471. break;
  472. case DBL_SQR:
  473. if( record->event.pressed ) {
  474. SEND_STRING("[]"SS_TAP(X_LEFT));
  475. }
  476. return false;
  477. break;
  478. case DBL_BRC:
  479. if( record->event.pressed ) {
  480. SEND_STRING("{}"SS_TAP(X_LEFT));
  481. }
  482. return false;
  483. break;
  484. case DBL_QUO:
  485. if( record->event.pressed ) {
  486. SEND_STRING("\'\'"SS_TAP(X_LEFT));
  487. }
  488. return false;
  489. break;
  490. case DBL_DQT:
  491. if( record->event.pressed ) {
  492. SEND_STRING("\"\""SS_TAP(X_LEFT));
  493. }
  494. return false;
  495. break;
  496. case DBL_GRV:
  497. if( record->event.pressed ) {
  498. SEND_STRING("``"SS_TAP(X_LEFT));
  499. }
  500. return false;
  501. break;
  502. // END OF KEYCODES
  503. }
  504. return process_record_keymap(keycode, record);
  505. }
  506. /*----------------------*\
  507. |*-----LAYER CHANGE-----*|
  508. \*----------------------*/
  509. layer_state_t layer_state_set_user(layer_state_t state) {
  510. state = layer_state_set_keymap (state);
  511. #ifdef RGBLIGHT_ENABLE
  512. // Change RGB lighting depending on the last layer activated
  513. rgblight_change( biton32(state) );
  514. #endif
  515. return state;
  516. }