logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

keymap.c (6212B)


  1. /* Copyright 2022 schwarzer-geiger
  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 QMK_KEYBOARD_H
  17. enum layer_names {
  18. _BASE,
  19. _LOWER,
  20. _RAISE,
  21. _ADJUST
  22. };
  23. #define LOWER MO(_LOWER)
  24. #define RAISE MO(_RAISE)
  25. #define ADJUST MO(_ADJUST)
  26. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  27. [_BASE] = LAYOUT(
  28. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
  29. KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
  30. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, RSFT_T(KC_ENT),
  31. KC_LALT, LOWER, KC_SPC, RAISE, KC_RGUI
  32. ),
  33. [_LOWER] = LAYOUT(
  34. _______, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_DEL,
  35. _______, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, KC_GRV, KC_TILD,
  36. _______, KC_ESC, KC_LGUI, KC_LALT, KC_CAPS, KC_DQUO, KC_HOME, KC_END, KC_PGUP, KC_PGDN, KC_PSCR, RSFT_T(KC_SPC),
  37. _______, _______, KC_ENT, _______, _______
  38. ),
  39. [_RAISE] = LAYOUT(
  40. _______, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL,
  41. _______, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6,
  42. _______, KC_ESC, KC_RGUI, KC_RALT, KC_CAPS, KC_QUOT, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12,
  43. _______, _______, KC_BSPC, _______, _______
  44. ),
  45. [_ADJUST] = LAYOUT(
  46. UG_VALU, UG_SATU, UG_HUEU, UG_NEXT, XXXXXXX, UG_TOGG, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
  47. UG_VALD, UG_SATD, UG_HUED, UG_PREV, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
  48. XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, QK_BOOT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
  49. _______, _______, XXXXXXX, _______, _______
  50. ),
  51. };
  52. // Thumbstick keymap, change KC_XXX to whatever you need
  53. #define THUMBSTICK_RIGHT_TAP KC_RIGHT
  54. #define THUMBSTICK_LEFT_TAP KC_LEFT
  55. #define THUMBSTICK_UP_TAP KC_UP
  56. #define THUMBSTICK_DOWN_TAP KC_DOWN
  57. // Thumbstick code, no customisation needed
  58. bool cursor_mode = false;
  59. bool scrolling_mode = false;
  60. bool tapping_mode = false;
  61. // tracks if thumbstick was released
  62. bool returned_to_zero = true;
  63. // tracks how many times mouse_report.x/y have been read zero in succession
  64. uint16_t zero_reads = 0;
  65. // set mode depending on layer
  66. layer_state_t layer_state_set_user(layer_state_t state) {
  67. state = update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST);
  68. switch (get_highest_layer(state)) {
  69. case SCROLLING_LAYER:
  70. if (scrolling_mode == false) {
  71. scrolling_mode = true;
  72. }
  73. if (tapping_mode) {
  74. tapping_mode = false;
  75. }
  76. if (cursor_mode) {
  77. cursor_mode = false;
  78. }
  79. break;
  80. case TAPPING_LAYER:
  81. if (tapping_mode == false) {
  82. tapping_mode = true;
  83. }
  84. if (cursor_mode) {
  85. cursor_mode = false;
  86. }
  87. if (scrolling_mode) {
  88. scrolling_mode = false;
  89. }
  90. break;
  91. default:
  92. if (scrolling_mode) {
  93. scrolling_mode = false;
  94. }
  95. if (tapping_mode) {
  96. tapping_mode = false;
  97. }
  98. if (cursor_mode == false) {
  99. cursor_mode = true;
  100. }
  101. break;
  102. }
  103. return state;
  104. }
  105. // manipulate mouse report based on current mode
  106. report_mouse_t pointing_device_task_user(report_mouse_t mouse_report) {
  107. if (cursor_mode) {
  108. mouse_report.x = CURSOR_SPEED * mouse_report.x/100;
  109. mouse_report.y = CURSOR_SPEED * mouse_report.y/100;
  110. }
  111. if (scrolling_mode) {
  112. mouse_report.h = SCROLL_SPEED * mouse_report.x/100;
  113. mouse_report.v = SCROLL_SPEED * mouse_report.y/100;
  114. mouse_report.x = 0;
  115. mouse_report.y = 0;
  116. if ((mouse_report.h != 0) | (mouse_report.v != 0)) {
  117. _delay_ms(SCROLL_DELAY_MS);
  118. }
  119. } else if (tapping_mode) {
  120. if ((mouse_report.x || mouse_report.y) != 0) {
  121. if (returned_to_zero) {
  122. if (mouse_report.x > 0) {
  123. tap_code16(THUMBSTICK_RIGHT_TAP);
  124. }
  125. if (mouse_report.x < 0) {
  126. tap_code16(THUMBSTICK_LEFT_TAP);
  127. }
  128. if (mouse_report.y > 0) {
  129. tap_code16(THUMBSTICK_DOWN_TAP);
  130. }
  131. if (mouse_report.y < 0) {
  132. tap_code16(THUMBSTICK_UP_TAP);
  133. }
  134. returned_to_zero = false;
  135. }
  136. zero_reads = 0;
  137. } else if (zero_reads < 20) {
  138. zero_reads++;
  139. }
  140. if (zero_reads >= 20) {
  141. if (returned_to_zero == false) {
  142. returned_to_zero = true;
  143. }
  144. }
  145. mouse_report.x = 0;
  146. mouse_report.y = 0;
  147. }
  148. return mouse_report;
  149. }