encoder.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* Copyright 2020 Sergi Meseguer <zigotica@gmail.com>
  2. This program is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation, either version 2 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. #include "zigotica.h"
  14. bool encoder_update_user(uint8_t index, bool clockwise) {
  15. switch(get_highest_layer(layer_state)){
  16. case _VIM:
  17. if (index == 0) { // LEFT
  18. // Cycle through buffers
  19. if (clockwise) {
  20. register_code(KC_ESC);
  21. SEND_STRING(":bprevious");
  22. register_code(KC_ENT);
  23. unregister_code(KC_ESC);
  24. unregister_code(KC_ENT);
  25. } else {
  26. register_code(KC_ESC);
  27. SEND_STRING(":bnext");
  28. register_code(KC_ENT);
  29. unregister_code(KC_ESC);
  30. unregister_code(KC_ENT);
  31. }
  32. } else { // RIGHT
  33. // Scroll
  34. if (clockwise) {
  35. tap_code(KC_PGDN);
  36. } else {
  37. tap_code(KC_PGUP);
  38. }
  39. }
  40. break;
  41. case _BROWSER:
  42. if (index == 0) { // LEFT
  43. // Cycle through Tabs
  44. if (clockwise) {
  45. tap_code16(C(KC_TAB));
  46. } else {
  47. tap_code16(S(C(KC_TAB)));
  48. }
  49. } else { // RIGHT
  50. // Scroll up/down
  51. if (clockwise) {
  52. register_code(KC_WH_U);
  53. unregister_code(KC_WH_U);
  54. } else {
  55. register_code(KC_WH_D);
  56. unregister_code(KC_WH_D);
  57. }
  58. }
  59. break;
  60. case _FIGMA:
  61. if (index == 0) { // LEFT
  62. // Cycle through Tabs
  63. if (clockwise) {
  64. tap_code16(C(KC_TAB));
  65. } else {
  66. tap_code16(S(C(KC_TAB)));
  67. }
  68. } else { // RIGHT
  69. // Zoom in/out
  70. if (clockwise) {
  71. register_code(KC_LGUI);
  72. register_code(KC_WH_D);
  73. unregister_code(KC_WH_D);
  74. unregister_code(KC_LGUI);
  75. } else {
  76. register_code(KC_LGUI);
  77. register_code(KC_WH_U);
  78. unregister_code(KC_WH_U);
  79. unregister_code(KC_LGUI);
  80. }
  81. }
  82. break;
  83. case _BASE:
  84. default:
  85. if (index == 0) { // LEFT
  86. // Volume control.
  87. if (clockwise) {
  88. tap_code(KC_VOLU);
  89. } else {
  90. tap_code(KC_VOLD);
  91. }
  92. } else { // RIGHT
  93. // Scroll
  94. if (clockwise) {
  95. tap_code(KC_PGDN);
  96. } else {
  97. tap_code(KC_PGUP);
  98. }
  99. }
  100. break;
  101. }
  102. return false;
  103. }