You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

383 lines
12 KiB

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