My build of suckless st terminal
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.

261 lines
6.1 KiB

  1. /* See LICENSE for license details. */
  2. /* Arbitrary sizes */
  3. #define UTF_SIZ 4
  4. /* macros */
  5. #define MIN(a, b) ((a) < (b) ? (a) : (b))
  6. #define MAX(a, b) ((a) < (b) ? (b) : (a))
  7. #define LEN(a) (sizeof(a) / sizeof(a)[0])
  8. #define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b))
  9. #define DIVCEIL(n, d) (((n) + ((d) - 1)) / (d))
  10. #define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x)
  11. #define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || \
  12. (a).bg != (b).bg)
  13. #define IS_SET(flag) ((term.mode & (flag)) != 0)
  14. #define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + \
  15. (t1.tv_nsec-t2.tv_nsec)/1E6)
  16. #define MODBIT(x, set, bit) ((set) ? ((x) |= (bit)) : ((x) &= ~(bit)))
  17. #define TRUECOLOR(r,g,b) (1 << 24 | (r) << 16 | (g) << 8 | (b))
  18. #define IS_TRUECOL(x) (1 << 24 & (x))
  19. enum glyph_attribute {
  20. ATTR_NULL = 0,
  21. ATTR_BOLD = 1 << 0,
  22. ATTR_FAINT = 1 << 1,
  23. ATTR_ITALIC = 1 << 2,
  24. ATTR_UNDERLINE = 1 << 3,
  25. ATTR_BLINK = 1 << 4,
  26. ATTR_REVERSE = 1 << 5,
  27. ATTR_INVISIBLE = 1 << 6,
  28. ATTR_STRUCK = 1 << 7,
  29. ATTR_WRAP = 1 << 8,
  30. ATTR_WIDE = 1 << 9,
  31. ATTR_WDUMMY = 1 << 10,
  32. ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
  33. };
  34. enum term_mode {
  35. MODE_WRAP = 1 << 0,
  36. MODE_INSERT = 1 << 1,
  37. MODE_APPKEYPAD = 1 << 2,
  38. MODE_ALTSCREEN = 1 << 3,
  39. MODE_CRLF = 1 << 4,
  40. MODE_MOUSEBTN = 1 << 5,
  41. MODE_MOUSEMOTION = 1 << 6,
  42. MODE_REVERSE = 1 << 7,
  43. MODE_KBDLOCK = 1 << 8,
  44. MODE_HIDE = 1 << 9,
  45. MODE_ECHO = 1 << 10,
  46. MODE_APPCURSOR = 1 << 11,
  47. MODE_MOUSESGR = 1 << 12,
  48. MODE_8BIT = 1 << 13,
  49. MODE_BLINK = 1 << 14,
  50. MODE_FBLINK = 1 << 15,
  51. MODE_FOCUS = 1 << 16,
  52. MODE_MOUSEX10 = 1 << 17,
  53. MODE_MOUSEMANY = 1 << 18,
  54. MODE_BRCKTPASTE = 1 << 19,
  55. MODE_PRINT = 1 << 20,
  56. MODE_UTF8 = 1 << 21,
  57. MODE_SIXEL = 1 << 22,
  58. MODE_MOUSE = MODE_MOUSEBTN|MODE_MOUSEMOTION|MODE_MOUSEX10\
  59. |MODE_MOUSEMANY,
  60. };
  61. enum selection_mode {
  62. SEL_IDLE = 0,
  63. SEL_EMPTY = 1,
  64. SEL_READY = 2
  65. };
  66. enum selection_type {
  67. SEL_REGULAR = 1,
  68. SEL_RECTANGULAR = 2
  69. };
  70. enum selection_snap {
  71. SNAP_WORD = 1,
  72. SNAP_LINE = 2
  73. };
  74. typedef unsigned char uchar;
  75. typedef unsigned int uint;
  76. typedef unsigned long ulong;
  77. typedef unsigned short ushort;
  78. typedef uint_least32_t Rune;
  79. #define Glyph Glyph_
  80. typedef struct {
  81. Rune u; /* character code */
  82. ushort mode; /* attribute flags */
  83. uint32_t fg; /* foreground */
  84. uint32_t bg; /* background */
  85. } Glyph;
  86. typedef Glyph *Line;
  87. typedef struct {
  88. Glyph attr; /* current char attributes */
  89. int x;
  90. int y;
  91. char state;
  92. } TCursor;
  93. /* Internal representation of the screen */
  94. typedef struct {
  95. int row; /* nb row */
  96. int col; /* nb col */
  97. Line *line; /* screen */
  98. Line *alt; /* alternate screen */
  99. int *dirty; /* dirtyness of lines */
  100. TCursor c; /* cursor */
  101. int top; /* top scroll limit */
  102. int bot; /* bottom scroll limit */
  103. int mode; /* terminal mode flags */
  104. int esc; /* escape state flags */
  105. char trantbl[4]; /* charset table translation */
  106. int charset; /* current charset */
  107. int icharset; /* selected charset for sequence */
  108. int numlock; /* lock numbers in keyboard */
  109. int *tabs;
  110. } Term;
  111. /* Purely graphic info */
  112. typedef struct {
  113. int tw, th; /* tty width and height */
  114. int w, h; /* window width and height */
  115. int ch; /* char height */
  116. int cw; /* char width */
  117. char state; /* focus, redraw, visible */
  118. int cursor; /* cursor style */
  119. } TermWindow;
  120. typedef struct {
  121. uint b;
  122. uint mask;
  123. char *s;
  124. } MouseShortcut;
  125. typedef struct {
  126. int mode;
  127. int type;
  128. int snap;
  129. /*
  130. * Selection variables:
  131. * nb normalized coordinates of the beginning of the selection
  132. * ne normalized coordinates of the end of the selection
  133. * ob original coordinates of the beginning of the selection
  134. * oe original coordinates of the end of the selection
  135. */
  136. struct {
  137. int x, y;
  138. } nb, ne, ob, oe;
  139. char *primary, *clipboard;
  140. int alt;
  141. struct timespec tclick1;
  142. struct timespec tclick2;
  143. //Atom xtarget;
  144. } Selection;
  145. typedef union {
  146. int i;
  147. uint ui;
  148. float f;
  149. const void *v;
  150. } Arg;
  151. typedef struct {
  152. uint mod;
  153. KeySym keysym;
  154. void (*func)(const Arg *);
  155. const Arg arg;
  156. } Shortcut;
  157. void die(const char *, ...);
  158. void redraw(void);
  159. int tattrset(int);
  160. void tnew(int, int);
  161. void tresize(int, int);
  162. void tsetdirt(int, int);
  163. void tsetdirtattr(int);
  164. int match(uint, uint);
  165. void ttynew(void);
  166. size_t ttyread(void);
  167. void ttyresize(void);
  168. void ttysend(char *, size_t);
  169. void ttywrite(const char *, size_t);
  170. void resettitle(void);
  171. char *kmap(KeySym, uint);
  172. void selclear(void);
  173. void selinit(void);
  174. void selnormalize(void);
  175. int selected(int, int);
  176. char *getsel(void);
  177. size_t utf8decode(char *, Rune *, size_t);
  178. size_t utf8encode(Rune, char *);
  179. void *xmalloc(size_t);
  180. void *xrealloc(void *, size_t);
  181. char *xstrdup(char *);
  182. /* Globals */
  183. extern TermWindow win;
  184. extern Term term;
  185. extern Selection sel;
  186. extern int cmdfd;
  187. extern pid_t pid;
  188. extern char **opt_cmd;
  189. extern char *opt_class;
  190. extern char *opt_embed;
  191. extern char *opt_font;
  192. extern char *opt_io;
  193. extern char *opt_line;
  194. extern char *opt_name;
  195. extern char *opt_title;
  196. extern int oldbutton;
  197. /* config.h globals */
  198. extern char font[];
  199. extern int borderpx;
  200. extern float cwscale;
  201. extern float chscale;
  202. extern unsigned int doubleclicktimeout;
  203. extern unsigned int tripleclicktimeout;
  204. extern int allowaltscreen;
  205. extern unsigned int xfps;
  206. extern unsigned int actionfps;
  207. extern unsigned int cursorthickness;
  208. extern int bellvolume;
  209. extern unsigned int blinktimeout;
  210. extern char termname[];
  211. extern const char *colorname[];
  212. extern size_t colornamelen;
  213. extern unsigned int defaultfg;
  214. extern unsigned int defaultbg;
  215. extern unsigned int defaultcs;
  216. extern unsigned int defaultrcs;
  217. extern unsigned int cursorshape;
  218. extern unsigned int cols;
  219. extern unsigned int rows;
  220. extern unsigned int mouseshape;
  221. extern unsigned int mousefg;
  222. extern unsigned int mousebg;
  223. extern unsigned int defaultattr;
  224. extern MouseShortcut mshortcuts[];
  225. extern size_t mshortcutslen;
  226. extern Shortcut shortcuts[];
  227. extern size_t shortcutslen;
  228. extern uint forceselmod;
  229. extern uint selmasks[];
  230. extern size_t selmaskslen;
  231. extern char ascii_printable[];