diff options
Diffstat (limited to 'users/miles2go/babblePaste.c')
| -rw-r--r-- | users/miles2go/babblePaste.c | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/users/miles2go/babblePaste.c b/users/miles2go/babblePaste.c new file mode 100644 index 000000000..2a32024cd --- /dev/null +++ b/users/miles2go/babblePaste.c | |||
| @@ -0,0 +1,125 @@ | |||
| 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 | |||
| 6 | Huge thanks to https://en.wikipedia.org/wiki/Table_of_keyboard_shortcuts | ||
| 7 | and https://github.com/qmk/qmk_firmware/blob/master/keyboards/planck/keymaps/jeebak/keymap.c | ||
| 8 | */ | ||
| 9 | |||
| 10 | #include QMK_KEYBOARD_H | ||
| 11 | |||
| 12 | #ifdef USE_BABBLEPASTE | ||
| 13 | # include "babblePaste.h" | ||
| 14 | |||
| 15 | // small function that we might also want to call from a keymap. | ||
| 16 | |||
| 17 | // GLOBAL variable to determine mode. Sets startup default if no eeppom | ||
| 18 | uint8_t babble_mode = 0; | ||
| 19 | |||
| 20 | // function to tell the user that the mode has changed | ||
| 21 | __attribute__((weak)) void babble_led_user(void) {} | ||
| 22 | |||
| 23 | void set_babble_mode(uint8_t id) { babble_mode = id; } | ||
| 24 | |||
| 25 | void babble_mode_increment() { | ||
| 26 | babble_mode += 1; | ||
| 27 | if (babble_mode >= BABL_MODEMAX) { | ||
| 28 | babble_mode = 0; | ||
| 29 | } | ||
| 30 | } | ||
| 31 | |||
| 32 | void babble_mode_decrement() { | ||
| 33 | if (babble_mode >= 1) { | ||
| 34 | babble_mode -= 1; | ||
| 35 | } else { | ||
| 36 | babble_mode = BABL_MODEMAX - 1; | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 40 | /* this function runs the appropriate babblepaste macro, given | ||
| 41 | the global babble_mode and a keycode defined in the babble_keycodes enum. | ||
| 42 | |||
| 43 | This could be made faster by splitting into two functions sorted by keycode range | ||
| 44 | But that makes for a *lot* of ifdefs. | ||
| 45 | */ | ||
| 46 | bool babblePaste(uint16_t keycode) { | ||
| 47 | // handle the OS/mode switching first | ||
| 48 | |||
| 49 | # ifdef BABL_MAC | ||
| 50 | if (keycode == BABL_DO_MAC) { | ||
| 51 | set_babble_mode(BABL_MAC_MODE); | ||
| 52 | babble_led_user(); | ||
| 53 | return true; | ||
| 54 | } | ||
| 55 | |||
| 56 | if (babble_mode == BABL_MAC_MODE) { | ||
| 57 | babblePaste_mac(keycode); | ||
| 58 | } | ||
| 59 | # endif | ||
| 60 | |||
| 61 | # ifdef BABL_VI | ||
| 62 | if (keycode == BABL_DO_VI) { | ||
| 63 | set_babble_mode(BABL_VI_MODE); | ||
| 64 | babble_led_user(); | ||
| 65 | return true; | ||
| 66 | } | ||
| 67 | if (babble_mode == BABL_VI_MODE) { | ||
| 68 | babblePaste_vi(keycode); | ||
| 69 | } | ||
| 70 | # endif | ||
| 71 | # ifdef BABL_WINDOWS | ||
| 72 | if (keycode == BABL_DO_WINDOWS) { | ||
| 73 | set_babble_mode(BABL_WINDOWS_MODE); | ||
| 74 | babble_led_user(); | ||
| 75 | return true; | ||
| 76 | } | ||
| 77 | if (babble_mode == BABL_WINDOWS_MODE) { | ||
| 78 | babblePaste_win(keycode); | ||
| 79 | } | ||
| 80 | # endif | ||
| 81 | # ifdef BABL_LINUX | ||
| 82 | if (keycode == BABL_DO_LINUX) { | ||
| 83 | set_babble_mode(BABL_LINUX_MODE); | ||
| 84 | babble_led_user(); | ||
| 85 | return true; | ||
| 86 | } | ||
| 87 | if (babble_mode == BABL_LINUX_MODE) { | ||
| 88 | babblePaste_linux(keycode); | ||
| 89 | } | ||
| 90 | # endif | ||
| 91 | # ifdef BABL_EMACS | ||
| 92 | if (keycode == BABL_DO_EMACS) { | ||
| 93 | set_babble_mode(BABL_EMACS_MODE); | ||
| 94 | babble_led_user(); | ||
| 95 | return true; | ||
| 96 | } | ||
| 97 | if (babble_mode == BABL_EMACS_MODE) { | ||
| 98 | babblePaste_emacs(keycode); | ||
| 99 | } | ||
| 100 | # endif | ||
| 101 | # ifdef BABL_CHROME | ||
| 102 | if (keycode == BABL_DO_CHROMEOS) { | ||
| 103 | set_babble_mode(BABL_CHROMEOS_MODE); | ||
| 104 | babble_led_user(); | ||
| 105 | return true; | ||
| 106 | } | ||
| 107 | if (babble_mode == BABL_CHROMEOS_MODE) { | ||
| 108 | babblePaste_readmux(keycode); | ||
| 109 | } | ||
| 110 | # endif | ||
| 111 | # ifdef BABL_READMUX | ||
| 112 | if (keycode == BABL_DO_READMUX) { | ||
| 113 | set_babble_mode(BABL_READMUX_MODE); | ||
| 114 | babble_led_user(); | ||
| 115 | return true; | ||
| 116 | } | ||
| 117 | if (babble_mode == BABL_READMUX_MODE) { | ||
| 118 | babblePaste_readmux(keycode); | ||
| 119 | } | ||
| 120 | # endif | ||
| 121 | |||
| 122 | return false; | ||
| 123 | } | ||
| 124 | |||
| 125 | #endif // USE_BABBLEPASTE | ||
