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.

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