aboutsummaryrefslogtreecommitdiff
path: root/users/miles2go/babblePaste.c
diff options
context:
space:
mode:
Diffstat (limited to 'users/miles2go/babblePaste.c')
-rw-r--r--users/miles2go/babblePaste.c125
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.
2Given a global variable babble_mode to show the environment and a
3key that calls the paste macro, do the right type of paste.
4Setting the context is done by another macro, or TBD interaction with the host.
5
6Huge thanks to https://en.wikipedia.org/wiki/Table_of_keyboard_shortcuts
7and 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
18uint8_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
23void set_babble_mode(uint8_t id) { babble_mode = id; }
24
25void babble_mode_increment() {
26 babble_mode += 1;
27 if (babble_mode >= BABL_MODEMAX) {
28 babble_mode = 0;
29 }
30}
31
32void 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
41the global babble_mode and a keycode defined in the babble_keycodes enum.
42
43This could be made faster by splitting into two functions sorted by keycode range
44But that makes for a *lot* of ifdefs.
45*/
46bool 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