babblePaste.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. #ifndef _babblePaste_h_included__
  9. #define _babblePaste_h_included__
  10. #include "../MS_sculpt_mobile/config.h"
  11. #include "action_layer.h"
  12. #include "quantum_keycodes.h"
  13. #ifdef USE_BABLPASTE
  14. /* ***************************
  15. // Uncomment any modes you want. Whatever mode = 0 will be the default on boot
  16. // Expect to get errors if you comment a feature out and leave it in your keymap.
  17. #define USE_BABLPASTE
  18. //#define MS_MODE 0 // Windows.
  19. //#define MAC_MODE 1
  20. //#define LINUX_MODE 2 //aka gnome+KDE
  21. //#define EMACS_MODE 3
  22. //#define VI_MODE 4
  23. //#define WORDSTAR_MODE 5
  24. //#define READMUX 6 // Readline and tmux
  25. // This removes everything but cursor movement
  26. //#define BABL_MOVEMENTONLY
  27. // and this just removes browser shortcuts
  28. //#define BABL_NOBROWSER
  29. ****************************/
  30. // Uncomment if you need more free flash space
  31. // It removes everything but cursor movement
  32. //#define BABL_MOVEMENTONLY
  33. // Define starting number for BABL macros in the macro range.
  34. // Probably can start the default even lower
  35. #define BABL_START_NUM 50
  36. /* Macros handled by babblepaste. Most should be available for all platforms.
  37. Whatever isn't defined will NOP */
  38. enum {
  39. // Movement macros
  40. // left & right
  41. BABL_GO_LEFT_1C= BABL_START_NUM,
  42. BABL_GO_RIGHT_1C,
  43. BABL_GO_LEFT_WORD,
  44. BABL_GO_RIGHT_WORD,
  45. BABL_GO_START_LINE,
  46. BABL_GO_END_LINE,
  47. // now up & down
  48. BABL_GO_START_DOC,
  49. BABL_GO_END_DOC,
  50. BABL_GO_NEXT_LINE,
  51. BABL_GO_PREV_LINE,
  52. BABL_PGDN,
  53. BABL_PGUP,
  54. // And the delete options
  55. //BABL_DEL_LEFT_1C == backspace, so why bother.
  56. BABL_DEL_RIGHT_1C, // usually = Del
  57. BABL_DEL_LEFT_WORD,
  58. BABL_DEL_RIGHT_WORD,
  59. BABL_DEL_TO_LINE_END, // delete from cursor to end of line
  60. BABL_DEL_TO_LINE_START, // delete from cursor to begining line
  61. #ifndef BABL_MOVEMENTONLY
  62. // Cut & Paste
  63. BABL_UNDO,
  64. BABL_REDO,
  65. BABL_CUT,
  66. BABL_COPY,
  67. BABL_PASTE,
  68. BABL_SELECT_ALL,
  69. /* not yet implemented
  70. BABL_SWAP_LAST2C // swap last characters before the cursor
  71. BABL_SWAP_LAST2W // Swap the last two words before the cursor
  72. */
  73. // find & replace
  74. BABL_FIND,
  75. BABL_FIND_NEXT,
  76. BABL_FIND_REPLACE,
  77. // GUI or app
  78. BABL_RUNAPP,
  79. BABL_SWITCH_APP_NEXT,
  80. BABL_SWITCH_APP_LAST, // previous
  81. BABL_CLOSE_APP,
  82. BABL_HELP,
  83. #ifndef BABL_NOBROWSER
  84. BABL_BROWSER_NEW_TAB,
  85. BABL_BROWSER_CLOSE_TAB,
  86. BABL_BROWSER_REOPEN_LAST_TAB,
  87. BABL_BROWSER_NEXT_TAB,
  88. BABL_BROWSER_PREV_TAB,
  89. BABL_BROWSER_URL_BAR,
  90. BABL_BROWSER_FORWARD,
  91. BABL_BROWSER_BACK,
  92. BABL_BROWSER_FIND,
  93. BABL_BROWSER_BOOKMARK,
  94. BABL_BROWSER_DEV_TOOLS, // hard one to remember
  95. BABL_BROWSER_RELOAD,
  96. BABL_BROWSER_FULLSCREEN,
  97. BABL_BROWSER_ZOOM_IN,
  98. BABL_BROWSER_ZOOM_OUT,
  99. #endif
  100. #endif
  101. // Macros for mode switching
  102. #ifdef MS_MODE
  103. BABL_WINDOWS,
  104. #endif
  105. #ifdef MAC_MODE
  106. BABL_MAC,
  107. #endif
  108. #ifdef LINUX_MODE
  109. BABL_LINUX,
  110. #endif
  111. #ifdef EMACS_MODE
  112. BABL_EMACS,
  113. #endif
  114. #ifdef VI_MODE
  115. BABL_VI,
  116. #endif
  117. #ifdef READMUX_MODE
  118. BABL_READLINE,
  119. #endif
  120. };
  121. // BUG, used to jump to babble functiion. Surely there is a way to calculate size of enum?
  122. #define BABL_NUM_MACROS 48+4 // 48 + # of defined modes.
  123. /* And all the shorthand keymap ready versions */
  124. // First the mode switching macros
  125. #ifdef MS_MODE
  126. #define B_WIN M(BABL_WINDOWS)
  127. #endif
  128. #ifdef MAC_MODE
  129. #define B_MAC M(BABL_MAC)
  130. #endif
  131. #ifdef LINUX_MODE
  132. #define B_LNX M(BABL_LINUX)
  133. #endif
  134. #ifdef EMACS_MODE
  135. #define B_EMAX M(BABL_EMACS)
  136. #endif
  137. #ifdef VI_MODE
  138. #define B_VI M(BABL_VI)
  139. #endif
  140. #ifdef READMUX_MODE
  141. #define B_READ M(BABL_READLINE)
  142. #endif
  143. // and all the movement & action.
  144. #define B_L1C M(BABL_GO_LEFT_1C)
  145. #define B_R1C M(BABL_GO_RIGHT_1C)
  146. #define B_L1W M(BABL_GO_LEFT_WORD)
  147. #define B_R1W M(BABL_GO_RIGHT_WORD)
  148. #define B_GSOL M(BABL_GO_START_LINE)
  149. #define B_GEOL M(BABL_GO_END_LINE)
  150. #define B_GTOP M(BABL_GO_START_DOC)
  151. #define B_GEND M(BABL_GO_END_DOC)
  152. #define B_DOWN M(BABL_GO_NEXT_LINE)
  153. #define B_UP M(BABL_GO_PREV_LINE)
  154. #define B_PGDN M(BABL_PGDN)
  155. #define B_PGUP M(BABL_PGUP)
  156. //#define B_BKSP M(BABL_DEL_LEFT_1C) == backspace so why bother.
  157. #define B_DEL M(BABL_DEL_RIGHT_1C) // usually = Del
  158. #define B_DLW M(BABL_DEL_LEFT_WORD)
  159. #define B_DRW M(BABL_DEL_RIGHT_WORD)
  160. #define B_DEOL M(BABL_DEL_TO_LINE_END) // delete from cursor to end of line
  161. #define B_DSOL M(BABL_DEL_TO_LINE_START) // delete from cursor to begining line
  162. #define B_UNDO M(BABL_UNDO)
  163. #define B_REDO M(BABL_REDO)
  164. #define B_CUT M(BABL_CUT)
  165. #define B_COPY M(BABL_COPY)
  166. #define B_PAST M(BABL_PASTE)
  167. #define B_SELA M(BABL_SELECT_ALL)
  168. #define B_FIND M(BABL_FIND)
  169. #define B_FINDN M(BABL_FIND_NEXT)
  170. #define B_FINDR M(BABL_FIND_REPLACE)
  171. #define B_RAPP M(BABL_RUNAPP)
  172. #define B_NAPP M(BABL_SWITCH_APP_NEXT)
  173. #define B_PAPP M(BABL_SWITCH_APP_LAST) // previous
  174. #define B_CAPP M(BABL_CLOSE_APP)
  175. #define B_HELP M(BABL_HELP)
  176. #define B_NTAB M(BABL_BROWSER_NEW_TAB)
  177. #define B_CTAB M(BABL_BROWSER_CLOSE_TAB)
  178. #define B_ROTB M(BABL_BROWSER_REOPEN_LAST_TAB)
  179. #define B_NXTB M(BABL_BROWSER_NEXT_TAB)
  180. #define B_PTAB M(BABL_BROWSER_PREV_TAB)
  181. #define B_NURL M(BABL_BROWSER_URL_BAR)
  182. #define B_BFWD M(BABL_BROWSER_FORWARD)
  183. #define B_BBAK M(BABL_BROWSER_BACK)
  184. #define B_BFND M(BABL_BROWSER_FIND)
  185. #define B_BOOK M(BABL_BROWSER_BOOKMARK)
  186. #define B_BDEV M(BABL_BROWSER_DEV_TOOLS) // hard one to remember
  187. #define B_BRLD M(BABL_BROWSER_RELOAD)
  188. #define B_BFUlL M(BABL_BROWSER_FULLSCREEN)
  189. #define B_ZMIN M(BABL_BROWSER_ZOOM_IN)
  190. #define B_ZMOT M(BABL_BROWSER_ZOOM_OUT)
  191. /* from action_macro.h
  192. typedef uint8_t macro_t;
  193. #define MACRO_NONE (macro_t*)0
  194. #define MACRO(...) ({ static const macro_t __m[] PROGMEM = { __VA_ARGS__ }; &__m[0]; })
  195. #define MACRO_GET(p) pgm_read_byte(p)
  196. #define BABL_MSTART (entry, os, macro...) ( const macro_t bablDict[entry][os] PROGMEM = { macro... }; )
  197. */
  198. const macro_t *babblePaste(keyrecord_t *record, uint8_t shortcut);
  199. macro_t* switch_babble_mode( uint8_t id);
  200. #endif
  201. #endif