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.

153 lines
4.3 KiB

  1. /* Copyright 2022 Olly Hayes (@ollyhayes)
  2. *
  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. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "ollyhayes.h"
  17. #ifdef VIRTSER_ENABLE
  18. # include "virtser.h"
  19. #endif
  20. layer_state_t default_layer_state_set_kb(layer_state_t state) {
  21. if (layer_state_cmp(state, BASE)) {
  22. rgb_matrix_mode(3);
  23. } else if (layer_state_cmp(state, GAMES)) {
  24. rgb_matrix_mode(1);
  25. }
  26. return state;
  27. }
  28. uint16_t key_presses = 0;
  29. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  30. // for tab/number layer switch
  31. static bool key_pressed_since_switch = false;
  32. static uint16_t switch_down_time = 0;
  33. // for alt-tab on punc layer
  34. static bool alt_tab_used = false;
  35. // for capital umlauts
  36. static bool shift_held = false;
  37. #ifdef VIRTSER_ENABLE
  38. if (record->event.pressed) {
  39. uint8_t key_index = 40 + record->event.key.col + record->event.key.row * 6;
  40. virtser_send(key_index);
  41. } else {
  42. uint8_t key_index = 90 + record->event.key.col + record->event.key.row * 6;
  43. virtser_send(key_index);
  44. }
  45. #endif
  46. if (record->event.pressed) {
  47. key_pressed_since_switch = true;
  48. key_presses++;
  49. }
  50. switch (keycode) {
  51. case UP4:
  52. if (record->event.pressed) {
  53. tap_code(KC_UP);
  54. tap_code(KC_UP);
  55. tap_code(KC_UP);
  56. tap_code(KC_UP);
  57. return false;
  58. }
  59. break;
  60. case DOWN4:
  61. if (record->event.pressed) {
  62. tap_code(KC_DOWN);
  63. tap_code(KC_DOWN);
  64. tap_code(KC_DOWN);
  65. tap_code(KC_DOWN);
  66. return false;
  67. }
  68. break;
  69. case NUM_SWITCH:
  70. if (record->event.pressed) {
  71. layer_on(NUM);
  72. key_pressed_since_switch = false;
  73. switch_down_time = timer_read();
  74. } else {
  75. layer_off(NUM);
  76. if (!key_pressed_since_switch && timer_elapsed(switch_down_time) < 200) {
  77. tap_code(KC_TAB);
  78. }
  79. }
  80. return false;
  81. case MO(PUNC):
  82. if (!record->event.pressed) {
  83. if (alt_tab_used) {
  84. unregister_code(KC_LALT);
  85. alt_tab_used = false;
  86. }
  87. }
  88. return true;
  89. case MO(FUNCTIONS):
  90. if (!record->event.pressed) {
  91. // if NUM_SWITCH has been lifted first, toggle to that layer
  92. // (4 = 2^NUM)
  93. if ((layer_state & 4) != 0) {
  94. layer_on(FUNCTIONS);
  95. return false;
  96. }
  97. }
  98. return true;
  99. case ALTTAB:
  100. if (record->event.pressed) {
  101. alt_tab_used = true;
  102. register_code(KC_LALT);
  103. tap_code(KC_TAB);
  104. }
  105. return false;
  106. case KC_LSFT:
  107. case KC_RSFT:
  108. shift_held = record->event.pressed;
  109. break;
  110. case A_UMLAUT:
  111. if (record->event.pressed) {
  112. if (shift_held)
  113. register_unicode(0x00c4);
  114. else
  115. register_unicode(0x00e4);
  116. }
  117. break;
  118. case O_UMLAUT:
  119. if (record->event.pressed) {
  120. if (shift_held)
  121. register_unicode(0x00d6);
  122. else
  123. register_unicode(0x00f6);
  124. }
  125. break;
  126. case U_UMLAUT:
  127. if (record->event.pressed) {
  128. if (shift_held)
  129. register_unicode(0x00dc);
  130. else
  131. register_unicode(0x00fc);
  132. }
  133. break;
  134. }
  135. return true;
  136. }