babblePaste.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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 bable_mode 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 jeebak & algernon's keymap
  7. */
  8. #pragma once
  9. #include "quantum.h"
  10. #ifdef USE_BABBLEPASTE
  11. void set_babble_mode(uint8_t id);
  12. void babble_mode_increment(void);
  13. void babble_mode_decrement(void);
  14. void babble_led_user(void);
  15. // manually re-order these if you want to set the order or default.
  16. enum babble_modes {
  17. # ifdef BABL_MAC
  18. BABL_MAC_MODE,
  19. # endif
  20. # ifdef BABL_READMUX
  21. BABL_READMUX_MODE,
  22. # endif
  23. # ifdef BABL_WINDOWS
  24. BABL_WINDOWS_MODE,
  25. # endif
  26. # ifdef BABL_VI
  27. BABL_VI_MODE,
  28. # endif
  29. # ifdef BABL_LINUX
  30. BABL_LINUX_MODE,
  31. # endif
  32. # ifdef BABL_EMACS
  33. BABL_EMACS_MODE,
  34. # endif
  35. # ifdef BABL_CHROMEOS
  36. BABL_CHROMEOS_MODE,
  37. # endif
  38. BABL_MODEMAX
  39. };
  40. // void babble_led_user( uint8_t id)
  41. /// Hacks to make it easier to create sendstring macros
  42. //"outer" versions wrap text
  43. # define OMCTL(arg) SS_DOWN(X_LCTRL) arg SS_UP(X_LCTRL)
  44. # define OMGUI(arg) SS_DOWN(X_LGUI) arg SS_UP(X_LGUI)
  45. # define OMALT(arg) SS_DOWN(X_LALT) arg SS_UP(X_LALT)
  46. # define OMSFT(...) SS_DOWN(X_LSHIFT) __VA_ARGS__ SS_UP(X_LSHIFT)
  47. //"inner" versions wrap a key tap
  48. # define IMCTL(arg) SS_DOWN(X_LCTRL) SS_TAP(arg) SS_UP(X_LCTRL)
  49. # define IMGUI(arg) SS_DOWN(X_LGUI) SS_TAP(arg) SS_UP(X_LGUI)
  50. # define IMALT(arg) SS_DOWN(X_LALT) SS_TAP(arg) SS_UP(X_LALT)
  51. # define IMSFT(arg) SS_DOWN(X_LSHIFT) SS_TAP(arg) SS_UP(X_LSHIFT)
  52. # define BABLM(ent, ...) \
  53. if (ent == keycode) { \
  54. SEND_STRING(__VA_ARGS__); \
  55. return true; \
  56. }
  57. // BabblePaste should be loaded first (header in userspace .h file, before all else)
  58. // if not,we'll do our best.
  59. # if defined(NEW_SAFE_RANGE)
  60. # define BABBLE_START NEW_SAFE_RANGE
  61. # else
  62. # if defined(KEYMAP_SAFE_RANGE)
  63. # define BABBLE_START KEYMAP_SAFE_RANGE
  64. # else
  65. # define BABBLE_START SAFE_RANGE
  66. # endif
  67. # endif
  68. enum babble_keycodes {
  69. FIRST = BABBLE_START,
  70. # ifdef BABL_MOVE
  71. // Movement macros
  72. // left & right
  73. BABL_GO_LEFT_1C,
  74. BABL_GO_RIGHT_1C,
  75. BABL_GO_LEFT_WORD,
  76. BABL_GO_RIGHT_WORD,
  77. BABL_GO_START_LINE,
  78. BABL_GO_END_LINE,
  79. // now up & down
  80. BABL_GO_START_DOC,
  81. BABL_GO_END_DOC,
  82. BABL_GO_NEXT_LINE,
  83. BABL_GO_PREV_LINE,
  84. BABL_GO_PARA_START,
  85. BABL_GO_PARA_END,
  86. BABL_PGDN,
  87. BABL_PGUP,
  88. // And the delete options
  89. BABL_DEL_LEFT_1C, // == backspace, so why bother?
  90. BABL_DEL_RIGHT_1C, // usually = Del
  91. BABL_DEL_LEFT_WORD,
  92. BABL_DEL_RIGHT_WORD,
  93. BABL_DEL_TO_LINE_END, // delete from cursor to end of line
  94. BABL_DEL_TO_LINE_START, // delete from cursor to begining line
  95. BABL_MODE, // print out string saying what mode we're in.
  96. # endif
  97. # ifdef BABL_OSKEYS
  98. BABL_UNDO,
  99. BABL_REDO,
  100. BABL_CUT,
  101. BABL_COPY,
  102. BABL_PASTE,
  103. BABL_SELECT_ALL,
  104. /* not yet implemented
  105. BABL_SWAP_LAST2C, // swap last characters before the cursor
  106. BABL_SWAP_LAST2W, // Swap the last two words before the cursor
  107. */
  108. // find & replace
  109. BABL_FIND,
  110. BABL_FIND_NEXT,
  111. BABL_FIND_PREV,
  112. BABL_FIND_REPLACE,
  113. // GUI or app
  114. BABL_RUNAPP,
  115. BABL_SWITCH_APP_NEXT,
  116. BABL_SWITCH_APP_LAST, // previous
  117. BABL_WINDOW_NEXT,
  118. BABL_WINDOW_PREV,
  119. BABL_WINDOW_NEW,
  120. BABL_CLOSE_APP,
  121. BABL_HELP,
  122. BABL_LOCK,
  123. BABL_SCREENCAPTURE,
  124. BABL_SWITCH_KEYBOARD_LAYOUT,
  125. # endif
  126. # ifdef BABL_BROWSER
  127. BABL_BROWSER_NEW_TAB,
  128. BABL_BROWSER_CLOSE_TAB,
  129. BABL_BROWSER_REOPEN_LAST_TAB,
  130. BABL_BROWSER_NEXT_TAB,
  131. BABL_BROWSER_PREV_TAB,
  132. BABL_BROWSER_URL_BAR,
  133. BABL_BROWSER_FORWARD,
  134. BABL_BROWSER_BACK,
  135. BABL_BROWSER_FIND,
  136. BABL_BROWSER_BOOKMARK,
  137. BABL_BROWSER_DEV_TOOLS, // hard one to remember
  138. BABL_BROWSER_RELOAD,
  139. BABL_BROWSER_FULLSCREEN,
  140. BABL_BROWSER_ZOOM_IN,
  141. BABL_BROWSER_ZOOM_OUT,
  142. BABL_BROWSER_VIEWSRC,
  143. # endif
  144. # ifdef BABL_APP
  145. BABL_APP_SAVE, // save file blurs app & os. Move?
  146. BABL_APP_PASTE_VALUES, // paste only values, or with some special formatting. ctrl shift v chrome, // Ctrl+Alt+V, excel
  147. // App hotkeys will be flawed, since you may use different spreadsheets across OSes.
  148. # ifdef BABL_APP_CELLS // spreadsheets and tables
  149. BABL_APP_CENTER_ALIGN, // Center align contents of a cell in table or spreadsheet.
  150. BABL_APP_CLEAR_FORMATTING, //
  151. BABL_APP_SCROLL_ACTIVE_CELL, // scroll to active cell.
  152. BABL_NEWLINE_IN_CELL, // newline inside cell of table,
  153. BABL_INSERT_COMMENT, // insert comment
  154. BABL_INSERT_COL_LEFT, // insert columns to the left
  155. BABL_INSERT_ROW, // insert row
  156. BABL_DELETE_ROW, // delete row // excel ctrl minus // chrome ctrl alt minus
  157. BABL_SELECT_COL, // select column - ctrl space //same in both
  158. BABL_SELECT_ROW, // select row shift spaced // same in both.
  159. # endif // BABL_APP_CELLS
  160. # ifdef BABL_APP_EDITOR
  161. BABL_APP_MULTI_SELECT, /* www.sublimetext.com/docs/2/multiple_selection_with_the_keyboard.html */
  162. # endif // BABL_APP_EDITOR
  163. # ifdef BABL_APP_WINDOWSPLITTING
  164. // These aren't useful on most oses.
  165. BABL_SPLIT_FRAME_VERT,
  166. BABL_UNSPLIT_FRAME_VERT,
  167. BABL_SPLIT_FRAME_HORIZONTAL,
  168. BABL_UNSPLIT_FRAME_HORIZONTAL,
  169. BABL_NEXT_FRAME,
  170. BABL_PREV_FRAME,
  171. # endif
  172. # endif
  173. // Macros for mode switching
  174. # ifdef BABL_WINDOWS
  175. BABL_DO_WINDOWS,
  176. # endif
  177. # ifdef BABL_MAC
  178. BABL_DO_MAC,
  179. # endif
  180. # ifdef BABL_LINUX
  181. BABL_DO_LINUX,
  182. # endif
  183. # ifdef BABL_EMACS
  184. BABL_DO_EMACS,
  185. # endif
  186. # ifdef BABL_VI
  187. BABL_DO_VI,
  188. # endif
  189. # ifdef BABL_READMUX
  190. BABL_DO_READMUX,
  191. # endif
  192. # ifdef BABL_CHROMEOS
  193. BABL_DO_CHROMEOS,
  194. # endif
  195. BABBLE_END_RANGE
  196. };
  197. // primary function.
  198. bool babblePaste(uint16_t keycode);
  199. /****************************************************/
  200. /* All per-os includes and short mode switch macros*/
  201. # ifdef BABL_WINDOWS
  202. # define B_WIN BABL_DO_WINDOWS
  203. bool babblePaste_win(uint16_t keycode);
  204. # endif
  205. # ifdef BABL_MAC
  206. # define B_MAC BABL_DO_MAC
  207. bool babblePaste_mac(uint16_t keycode);
  208. # endif
  209. # ifdef BABL_LINUX
  210. # define B_LINUX BABL_DO_LINUX
  211. bool babblePaste_linux(uint16_t keycode);
  212. # endif
  213. # ifdef BABL_EMACS
  214. # define B_EMACS BABL_DO_EMACS
  215. bool babblePaste_emacs(uint16_t keycode);
  216. # endif
  217. # ifdef BABL_VI
  218. # define B_VI BABL_DO_VI
  219. bool babblePaste_vi(uint16_t keycode);
  220. # endif
  221. # ifdef BABL_READMUX
  222. # define B_READ BABL_DO_READMUX
  223. bool babblePaste_readmux(uint16_t keycode);
  224. # endif
  225. # ifdef BABL_CHROMEOS
  226. # define B_CROM BABL_DO_CHROMEOS
  227. bool babblePaste_chromeos(uint16_t keycode);
  228. # endif
  229. # define BABL_INC babble_mode_increment();
  230. # define BABL_DEC babble_mode_decrement();
  231. /****************************************************
  232. ** All keyboard macros for Babble Actions
  233. *****************************************************/
  234. # ifdef BABL_MOVE
  235. # define B_L1C BABL_GO_LEFT_1C
  236. # define B_R1C BABL_GO_RIGHT_1C
  237. # define B_L1W BABL_GO_LEFT_WORD
  238. # define B_R1W BABL_GO_RIGHT_WORD
  239. # define B_GSOL BABL_GO_START_LINE
  240. # define B_GEOL BABL_GO_END_LINE
  241. # define B_GTOP BABL_GO_START_DOC
  242. # define B_GEND BABL_GO_END_DOC
  243. # define B_DOWN BABL_GO_NEXT_LINE
  244. # define B_UP BABL_GO_PREV_LINE
  245. # define B_PTOP BABL_GO_PARA_START
  246. # define B_PEND BABL_GO_PARA_END
  247. # define B_PGDN BABL_PGDN
  248. # define B_PGUP BABL_PGUP
  249. //#define B_BKSP BABL_DEL_LEFT_1C == backspace so why bother.
  250. # define B_DEL BABL_DEL_RIGHT_1C // usually = Del
  251. # define B_DLW BABL_DEL_LEFT_WORD
  252. # define B_DRW BABL_DEL_RIGHT_WORD
  253. # define B_DEOL BABL_DEL_TO_LINE_END // delete from cursor to end of line
  254. # define B_DSOL BABL_DEL_TO_LINE_START // delete from cursor to begining line
  255. # define B_MODE BABL_MODE // type out name of current mode.
  256. # endif
  257. # ifdef BABL_OSKEYS
  258. # define B_UNDO BABL_UNDO
  259. # define B_REDO BABL_REDO
  260. # define B_CUT BABL_CUT
  261. # define B_COPY BABL_COPY
  262. # define B_PASTE BABL_PASTE
  263. # define B_SELALL BABL_SELECT_ALL
  264. # define B_SELA BABL_SELECT_ALL
  265. # define B_FIND BABL_FIND
  266. # define B_FINDN BABL_FIND_NEXT
  267. # define B_FINDP BABL_FIND_PREV
  268. # define B_RPLACE BABL_FIND_REPLACE
  269. # define B_RUNAPP BABL_RUNAPP
  270. # define B_NAPP BABL_SWITCH_APP_NEXT
  271. # define B_PAPP BABL_SWITCH_APP_LAST // previous
  272. # define B_NWIN BABL_WINDOW_NEXT
  273. # define B_PWIN BABL_WINDOW_PREV
  274. # define B_WINN BABL_WINDOW_NEW
  275. # define B_CAPP BABL_CLOSE_APP
  276. # define B_HELP BABL_HELP
  277. # define B_LOCK BABL_LOCK
  278. # define B_SCAP BABL_SCREENCAPTURE
  279. # define B_KEYB BABL_SWITCH_KEYBOARD_LAYOUT
  280. # endif
  281. # ifdef BABL_BROWSER
  282. # define B_NTAB BABL_BROWSER_NEW_TAB
  283. # define B_CTAB BABL_BROWSER_CLOSE_TAB
  284. # define B_ROTB BABL_BROWSER_REOPEN_LAST_TAB
  285. # define B_NXTB BABL_BROWSER_NEXT_TAB
  286. # define B_PTAB BABL_BROWSER_PREV_TAB
  287. # define B_NURL BABL_BROWSER_URL_BAR
  288. # define B_BFWD BABL_BROWSER_FORWARD
  289. # define B_BBAK BABL_BROWSER_BACK
  290. # define B_BFND BABL_BROWSER_FIND
  291. # define B_BOOK BABL_BROWSER_BOOKMARK
  292. # define B_BDEV BABL_BROWSER_DEV_TOOLS // hard one to remember
  293. # define B_BRLD BABL_BROWSER_RELOAD
  294. # define B_BFULL BABL_BROWSER_FULLSCREEN
  295. # define B_ZIN BABL_BROWSER_ZOOM_IN
  296. # define B_ZOUT BABL_BROWSER_ZOOM_OUT
  297. # endif
  298. # ifdef BABL_APP
  299. # define B_SAVE BABL_APP_SAVE
  300. # ifdef BABL_APP_CELLS // spreadsheets and tables
  301. # define B_PASTV BABL_APP_PASTE_VALUES
  302. # define B_CALN BABL_APP_CENTER_ALIGN
  303. # define B_CFMT BABL_APP_CLEAR_FORMATTING
  304. # define B_SCLA BABL_APP_SCROLL_ACTIVE_CELL
  305. # define B_NCEL BABL_NEWLINE_IN_CELL
  306. # define B_IPRW BABL_INSERT_ROW_ABOVE
  307. # define B_ICOL BABL_INSERT_COL_LEFT
  308. # define B_IROW BABL_INSERT_ROW
  309. # define B_DROW BABL_DELETE_ROW
  310. # define B_SELC BABL_SELECT_COL
  311. # define B_SELR BABL_SELECT_ROW
  312. # endif // BABL_APP_CELLS
  313. # ifdef BABL_APP_EDITOR
  314. # define B_MSEL BABL_APP_MULTI_SELECT
  315. /* www.sublimetext.com/docs/2/multiple_selection_with_the_keyboard.html */
  316. # endif // BABL_APP_EDITOR
  317. # ifdef BABL_APP_WINDOWSPLITTING
  318. # define B_VSPLIT BABL_SPLIT_FRAME_VERT
  319. # define B_VUNSPT BABL_UNSPLIT_FRAME_VERT
  320. # define B_HSPLIT BABL_SPLIT_FRAME_HORIZONTAL
  321. # define B_HUNSPT BABL_UNSPLIT_FRAME_HORIZONTAL
  322. # define B_NXTFM BABL_NEXT_FRAME
  323. # define B_PRVFM BABL_PREV_FRAME
  324. # endif // BABL_APP_WINDOWSPLITTING
  325. # endif // BABL_APP
  326. #endif