Xinqi Bao's Git

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