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.

221 lines
5.2 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. int mode;
  123. int type;
  124. int snap;
  125. /*
  126. * Selection variables:
  127. * nb normalized coordinates of the beginning of the selection
  128. * ne normalized coordinates of the end of the selection
  129. * ob original coordinates of the beginning of the selection
  130. * oe original coordinates of the end of the selection
  131. */
  132. struct {
  133. int x, y;
  134. } nb, ne, ob, oe;
  135. char *primary, *clipboard;
  136. int alt;
  137. struct timespec tclick1;
  138. struct timespec tclick2;
  139. //Atom xtarget;
  140. } Selection;
  141. typedef union {
  142. int i;
  143. uint ui;
  144. float f;
  145. const void *v;
  146. } Arg;
  147. void die(const char *, ...);
  148. void redraw(void);
  149. void iso14755(const Arg *);
  150. void numlock(const Arg *);
  151. void printscreen(const Arg *);
  152. void printsel(const Arg *);
  153. void sendbreak(const Arg *);
  154. void toggleprinter(const Arg *);
  155. int tattrset(int);
  156. void tnew(int, int);
  157. void tresize(int, int);
  158. void tsetdirt(int, int);
  159. void tsetdirtattr(int);
  160. void ttynew(char *, char *, char **);
  161. size_t ttyread(void);
  162. void ttyresize(int, int);
  163. void ttysend(char *, size_t);
  164. void ttywrite(const char *, size_t);
  165. void resettitle(void);
  166. void selclear(void);
  167. void selinit(void);
  168. void selnormalize(void);
  169. int selected(int, int);
  170. char *getsel(void);
  171. size_t utf8decode(const char *, Rune *, size_t);
  172. size_t utf8encode(Rune, char *);
  173. void *xmalloc(size_t);
  174. void *xrealloc(void *, size_t);
  175. char *xstrdup(char *);
  176. /* Globals */
  177. extern TermWindow win;
  178. extern Term term;
  179. extern Selection sel;
  180. extern int cmdfd;
  181. extern pid_t pid;
  182. extern int oldbutton;
  183. /* config.h globals */
  184. extern char *shell;
  185. extern char *utmp;
  186. extern char *stty_args;
  187. extern char *vtiden;
  188. extern char *worddelimiters;
  189. extern int allowaltscreen;
  190. extern char *termname;
  191. extern unsigned int tabspaces;
  192. extern unsigned int defaultfg;
  193. extern unsigned int defaultbg;