babblePaste.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* A library to output the right key shortcut in any common app.
  2. Given a global variable babble_mode to show the environment and a
  3. key that calls the paste macro, do the right type of paste.
  4. Setting the context is done by another macro, or TBD interaction with the host.
  5. Huge thanks to https://en.wikipedia.org/wiki/Table_of_keyboard_shortcuts
  6. and https://github.com/qmk/qmk_firmware/blob/master/keyboards/planck/keymaps/jeebak/keymap.c
  7. */
  8. #include QMK_KEYBOARD_H
  9. #ifdef USE_BABBLEPASTE
  10. # include "babblePaste.h"
  11. // small function that we might also want to call from a keymap.
  12. // GLOBAL variable to determine mode. Sets startup default if no eeppom
  13. uint8_t babble_mode = 0;
  14. // function to tell the user that the mode has changed
  15. __attribute__((weak)) void babble_led_user(void) {}
  16. void set_babble_mode(uint8_t id) { babble_mode = id; }
  17. void babble_mode_increment() {
  18. babble_mode += 1;
  19. if (babble_mode >= BABL_MODEMAX) {
  20. babble_mode = 0;
  21. }
  22. }
  23. void babble_mode_decrement() {
  24. if (babble_mode >= 1) {
  25. babble_mode -= 1;
  26. } else {
  27. babble_mode = BABL_MODEMAX - 1;
  28. }
  29. }
  30. /* this function runs the appropriate babblepaste macro, given
  31. the global babble_mode and a keycode defined in the babble_keycodes enum.
  32. This could be made faster by splitting into two functions sorted by keycode range
  33. But that makes for a *lot* of ifdefs.
  34. */
  35. bool babblePaste(uint16_t keycode) {
  36. // handle the OS/mode switching first
  37. # ifdef BABL_MAC
  38. if (keycode == BABL_DO_MAC) {
  39. set_babble_mode(BABL_MAC_MODE);
  40. babble_led_user();
  41. return true;
  42. }
  43. if (babble_mode == BABL_MAC_MODE) {
  44. babblePaste_mac(keycode);
  45. }
  46. # endif
  47. # ifdef BABL_VI
  48. if (keycode == BABL_DO_VI) {
  49. set_babble_mode(BABL_VI_MODE);
  50. babble_led_user();
  51. return true;
  52. }
  53. if (babble_mode == BABL_VI_MODE) {
  54. babblePaste_vi(keycode);
  55. }
  56. # endif
  57. # ifdef BABL_WINDOWS
  58. if (keycode == BABL_DO_WINDOWS) {
  59. set_babble_mode(BABL_WINDOWS_MODE);
  60. babble_led_user();
  61. return true;
  62. }
  63. if (babble_mode == BABL_WINDOWS_MODE) {
  64. babblePaste_win(keycode);
  65. }
  66. # endif
  67. # ifdef BABL_LINUX
  68. if (keycode == BABL_DO_LINUX) {
  69. set_babble_mode(BABL_LINUX_MODE);
  70. babble_led_user();
  71. return true;
  72. }
  73. if (babble_mode == BABL_LINUX_MODE) {
  74. babblePaste_linux(keycode);
  75. }
  76. # endif
  77. # ifdef BABL_EMACS
  78. if (keycode == BABL_DO_EMACS) {
  79. set_babble_mode(BABL_EMACS_MODE);
  80. babble_led_user();
  81. return true;
  82. }
  83. if (babble_mode == BABL_EMACS_MODE) {
  84. babblePaste_emacs(keycode);
  85. }
  86. # endif
  87. # ifdef BABL_CHROME
  88. if (keycode == BABL_DO_CHROMEOS) {
  89. set_babble_mode(BABL_CHROMEOS_MODE);
  90. babble_led_user();
  91. return true;
  92. }
  93. if (babble_mode == BABL_CHROMEOS_MODE) {
  94. babblePaste_readmux(keycode);
  95. }
  96. # endif
  97. # ifdef BABL_READMUX
  98. if (keycode == BABL_DO_READMUX) {
  99. set_babble_mode(BABL_READMUX_MODE);
  100. babble_led_user();
  101. return true;
  102. }
  103. if (babble_mode == BABL_READMUX_MODE) {
  104. babblePaste_readmux(keycode);
  105. }
  106. # endif
  107. return false;
  108. }
  109. #endif // USE_BABBLEPASTE