diff options
author | Michael Forney <mforney@mforney.org> | 2017-01-20 00:06:39 -0800 |
---|---|---|
committer | Michael Forney <mforney@mforney.org> | 2017-01-20 19:42:26 -0800 |
commit | e2ee5ee6114eb74bb08cb9abe5a3020203e92688 (patch) | |
tree | 7fa47c27df85b1803f8e35860ad6ed2603138acb /st.h | |
parent | c63a87cd936c1eeef14c4c21572e5b782d3df4bc (diff) | |
download | st-patched-e2ee5ee6114eb74bb08cb9abe5a3020203e92688.tar.bz2 st-patched-e2ee5ee6114eb74bb08cb9abe5a3020203e92688.tar.xz st-patched-e2ee5ee6114eb74bb08cb9abe5a3020203e92688.zip |
Split X-specific code into x.c
Diffstat (limited to 'st.h')
-rw-r--r-- | st.h | 272 |
1 files changed, 272 insertions, 0 deletions
@@ -0,0 +1,272 @@ | |||
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 | enum window_state { | ||
84 | WIN_VISIBLE = 1, | ||
85 | WIN_FOCUSED = 2 | ||
86 | }; | ||
87 | |||
88 | typedef unsigned char uchar; | ||
89 | typedef unsigned int uint; | ||
90 | typedef unsigned long ulong; | ||
91 | typedef unsigned short ushort; | ||
92 | |||
93 | typedef uint_least32_t Rune; | ||
94 | |||
95 | typedef struct { | ||
96 | Rune u; /* character code */ | ||
97 | ushort mode; /* attribute flags */ | ||
98 | uint32_t fg; /* foreground */ | ||
99 | uint32_t bg; /* background */ | ||
100 | } Glyph; | ||
101 | |||
102 | typedef Glyph *Line; | ||
103 | |||
104 | typedef struct { | ||
105 | Glyph attr; /* current char attributes */ | ||
106 | int x; | ||
107 | int y; | ||
108 | char state; | ||
109 | } TCursor; | ||
110 | |||
111 | /* Internal representation of the screen */ | ||
112 | typedef struct { | ||
113 | int row; /* nb row */ | ||
114 | int col; /* nb col */ | ||
115 | Line *line; /* screen */ | ||
116 | Line *alt; /* alternate screen */ | ||
117 | int *dirty; /* dirtyness of lines */ | ||
118 | GlyphFontSpec *specbuf; /* font spec buffer used for rendering */ | ||
119 | TCursor c; /* cursor */ | ||
120 | int top; /* top scroll limit */ | ||
121 | int bot; /* bottom scroll limit */ | ||
122 | int mode; /* terminal mode flags */ | ||
123 | int esc; /* escape state flags */ | ||
124 | char trantbl[4]; /* charset table translation */ | ||
125 | int charset; /* current charset */ | ||
126 | int icharset; /* selected charset for sequence */ | ||
127 | int numlock; /* lock numbers in keyboard */ | ||
128 | int *tabs; | ||
129 | } Term; | ||
130 | |||
131 | /* Purely graphic info */ | ||
132 | typedef struct { | ||
133 | int tw, th; /* tty width and height */ | ||
134 | int w, h; /* window width and height */ | ||
135 | int ch; /* char height */ | ||
136 | int cw; /* char width */ | ||
137 | char state; /* focus, redraw, visible */ | ||
138 | int cursor; /* cursor style */ | ||
139 | } TermWindow; | ||
140 | |||
141 | typedef struct { | ||
142 | uint b; | ||
143 | uint mask; | ||
144 | char *s; | ||
145 | } MouseShortcut; | ||
146 | |||
147 | typedef struct { | ||
148 | int mode; | ||
149 | int type; | ||
150 | int snap; | ||
151 | /* | ||
152 | * Selection variables: | ||
153 | * nb – normalized coordinates of the beginning of the selection | ||
154 | * ne – normalized coordinates of the end of the selection | ||
155 | * ob – original coordinates of the beginning of the selection | ||
156 | * oe – original coordinates of the end of the selection | ||
157 | */ | ||
158 | struct { | ||
159 | int x, y; | ||
160 | } nb, ne, ob, oe; | ||
161 | |||
162 | char *primary, *clipboard; | ||
163 | int alt; | ||
164 | struct timespec tclick1; | ||
165 | struct timespec tclick2; | ||
166 | |||
167 | //Atom xtarget; | ||
168 | } Selection; | ||
169 | |||
170 | typedef union { | ||
171 | int i; | ||
172 | uint ui; | ||
173 | float f; | ||
174 | const void *v; | ||
175 | } Arg; | ||
176 | |||
177 | typedef struct { | ||
178 | uint mod; | ||
179 | KeySym keysym; | ||
180 | void (*func)(const Arg *); | ||
181 | const Arg arg; | ||
182 | } Shortcut; | ||
183 | |||
184 | void die(const char *, ...); | ||
185 | void redraw(void); | ||
186 | |||
187 | int tattrset(int); | ||
188 | void tnew(int, int); | ||
189 | void tsetdirt(int, int); | ||
190 | void tsetdirtattr(int); | ||
191 | int match(uint, uint); | ||
192 | void ttynew(void); | ||
193 | size_t ttyread(void); | ||
194 | void ttyresize(void); | ||
195 | void ttysend(char *, size_t); | ||
196 | void ttywrite(const char *, size_t); | ||
197 | |||
198 | void resettitle(void); | ||
199 | |||
200 | char *kmap(KeySym, uint); | ||
201 | void cresize(int, int); | ||
202 | void selclear(void); | ||
203 | |||
204 | void selinit(void); | ||
205 | void selnormalize(void); | ||
206 | int selected(int, int); | ||
207 | char *getsel(void); | ||
208 | int x2col(int); | ||
209 | int y2row(int); | ||
210 | |||
211 | size_t utf8decode(char *, Rune *, size_t); | ||
212 | size_t utf8encode(Rune, char *); | ||
213 | |||
214 | void *xmalloc(size_t); | ||
215 | char *xstrdup(char *); | ||
216 | |||
217 | void usage(void); | ||
218 | |||
219 | /* Globals */ | ||
220 | extern TermWindow win; | ||
221 | extern Term term; | ||
222 | extern Selection sel; | ||
223 | extern int cmdfd; | ||
224 | extern pid_t pid; | ||
225 | extern char **opt_cmd; | ||
226 | extern char *opt_class; | ||
227 | extern char *opt_embed; | ||
228 | extern char *opt_font; | ||
229 | extern char *opt_io; | ||
230 | extern char *opt_line; | ||
231 | extern char *opt_name; | ||
232 | extern char *opt_title; | ||
233 | extern int oldbutton; | ||
234 | |||
235 | extern char *usedfont; | ||
236 | extern double usedfontsize; | ||
237 | extern double defaultfontsize; | ||
238 | |||
239 | /* config.h globals */ | ||
240 | extern char font[]; | ||
241 | extern int borderpx; | ||
242 | extern float cwscale; | ||
243 | extern float chscale; | ||
244 | extern unsigned int doubleclicktimeout; | ||
245 | extern unsigned int tripleclicktimeout; | ||
246 | extern int allowaltscreen; | ||
247 | extern unsigned int xfps; | ||
248 | extern unsigned int actionfps; | ||
249 | extern unsigned int cursorthickness; | ||
250 | extern unsigned int blinktimeout; | ||
251 | extern char termname[]; | ||
252 | extern const char *colorname[]; | ||
253 | extern size_t colornamelen; | ||
254 | extern unsigned int defaultfg; | ||
255 | extern unsigned int defaultbg; | ||
256 | extern unsigned int defaultcs; | ||
257 | extern unsigned int defaultrcs; | ||
258 | extern unsigned int cursorshape; | ||
259 | extern unsigned int cols; | ||
260 | extern unsigned int rows; | ||
261 | extern unsigned int mouseshape; | ||
262 | extern unsigned int mousefg; | ||
263 | extern unsigned int mousebg; | ||
264 | extern unsigned int defaultattr; | ||
265 | extern MouseShortcut mshortcuts[]; | ||
266 | extern size_t mshortcutslen; | ||
267 | extern Shortcut shortcuts[]; | ||
268 | extern size_t shortcutslen; | ||
269 | extern uint forceselmod; | ||
270 | extern uint selmasks[]; | ||
271 | extern size_t selmaskslen; | ||
272 | extern char ascii_printable[]; | ||