st.h
1/* See LICENSE for license details. */
2
3#include <stdint.h>
4#include <time.h>
5#include <sys/types.h>
6#include <X11/Xatom.h>
7#include <X11/Xlib.h>
8#include <X11/cursorfont.h>
9#include <X11/keysym.h>
10#include <X11/Xft/Xft.h>
11#include <X11/XKBlib.h>
12
13/* macros */
14#define MIN(a, b) ((a) < (b) ? (a) : (b))
15#define MAX(a, b) ((a) < (b) ? (b) : (a))
16#define LEN(a) (sizeof(a) / sizeof(a)[0])
17#define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b))
18#define DIVCEIL(n, d) (((n) + ((d) - 1)) / (d))
19#define DEFAULT(a, b) (a) = (a) ? (a) : (b)
20#define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x)
21#define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || \
22 (a).bg != (b).bg)
23#define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + \
24 (t1.tv_nsec-t2.tv_nsec)/1E6)
25#define MODBIT(x, set, bit) ((set) ? ((x) |= (bit)) : ((x) &= ~(bit)))
26
27#define TRUECOLOR(r,g,b) (1 << 24 | (r) << 16 | (g) << 8 | (b))
28#define IS_TRUECOL(x) (1 << 24 & (x))
29
30enum glyph_attribute {
31 ATTR_NULL = 0,
32 ATTR_BOLD = 1 << 0,
33 ATTR_FAINT = 1 << 1,
34 ATTR_ITALIC = 1 << 2,
35 ATTR_UNDERLINE = 1 << 3,
36 ATTR_BLINK = 1 << 4,
37 ATTR_REVERSE = 1 << 5,
38 ATTR_INVISIBLE = 1 << 6,
39 ATTR_STRUCK = 1 << 7,
40 ATTR_WRAP = 1 << 8,
41 ATTR_WIDE = 1 << 9,
42 ATTR_WDUMMY = 1 << 10,
43 ATTR_BOXDRAW = 1 << 11,
44 ATTR_SIXEL = 1 << 12,
45 ATTR_DIRTYUNDERLINE = 1 << 13,
46 ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
47};
48
49typedef struct _ImageList {
50 struct _ImageList *next, *prev;
51 unsigned char *pixels;
52 void *pixmap;
53 void *clipmask;
54 int width;
55 int height;
56 int x;
57 int y;
58 int cols;
59 int cw;
60 int ch;
61 int transparent;
62} ImageList;
63
64enum drawing_mode {
65 DRAW_NONE = 0,
66 DRAW_BG = 1 << 0,
67 DRAW_FG = 1 << 1,
68};
69
70enum selection_mode {
71 SEL_IDLE = 0,
72 SEL_EMPTY = 1,
73 SEL_READY = 2
74};
75
76enum selection_type {
77 SEL_REGULAR = 1,
78 SEL_RECTANGULAR = 2
79};
80
81enum selection_snap {
82 SNAP_WORD = 1,
83 SNAP_LINE = 2
84};
85
86typedef unsigned char uchar;
87typedef unsigned int uint;
88typedef unsigned long ulong;
89typedef unsigned short ushort;
90
91typedef uint_least32_t Rune;
92
93typedef XftDraw *Draw;
94typedef XftColor Color;
95typedef XftGlyphFontSpec GlyphFontSpec;
96
97#define Glyph Glyph_
98typedef struct {
99 Rune u; /* character code */
100 ushort mode; /* attribute flags */
101 uint32_t fg; /* foreground */
102 uint32_t bg; /* background */
103 int ustyle; /* underline style */
104 int ucolor[3]; /* underline color */
105} Glyph;
106
107typedef Glyph *Line;
108
109typedef struct {
110 Glyph attr; /* current char attributes */
111 int x;
112 int y;
113 char state;
114} TCursor;
115
116typedef struct {
117 int mode;
118 int type;
119 int snap;
120 /*
121 * Selection variables:
122 * nb – normalized coordinates of the beginning of the selection
123 * ne – normalized coordinates of the end of the selection
124 * ob – original coordinates of the beginning of the selection
125 * oe – original coordinates of the end of the selection
126 */
127 struct {
128 int x, y;
129 } nb, ne, ob, oe;
130
131 int alt;
132} Selection;
133
134
135typedef union {
136 int i;
137 uint ui;
138 float f;
139 const void *v;
140 const char *s;
141} Arg;
142
143typedef struct {
144 Display *dpy;
145 Colormap cmap;
146 Window win;
147 Drawable buf;
148 GlyphFontSpec *specbuf; /* font spec buffer used for rendering */
149 Atom xembed, wmdeletewin, netwmname, netwmiconname, netwmpid;
150 struct {
151 XIM xim;
152 XIC xic;
153 XPoint spot;
154 XVaNestedList spotlist;
155 } ime;
156 Draw draw;
157 Visual *vis;
158 XSetWindowAttributes attrs;
159 int scr;
160 int isfixed; /* is fixed geometry? */
161 int l, t; /* left and top offset */
162 int gm; /* geometry mask */
163} XWindow;
164
165typedef struct {
166 Atom xtarget;
167 char *primary, *clipboard;
168 struct timespec tclick1;
169 struct timespec tclick2;
170} XSelection;
171
172/* Font structure */
173#define Font Font_
174typedef struct {
175 int height;
176 int width;
177 int ascent;
178 int descent;
179 int badslant;
180 int badweight;
181 short lbearing;
182 short rbearing;
183 XftFont *match;
184 FcFontSet *set;
185 FcPattern *pattern;
186} Font;
187
188/* Internal representation of the screen */
189typedef struct {
190 int row; /* nb row */
191 int col; /* nb col */
192 Line *line; /* screen */
193 Line *alt; /* alternate screen */
194 int *dirty; /* dirtyness of lines */
195 TCursor c; /* cursor */
196 int ocx; /* old cursor col */
197 int ocy; /* old cursor row */
198 int top; /* top scroll limit */
199 int bot; /* bottom scroll limit */
200 int mode; /* terminal mode flags */
201 int esc; /* escape state flags */
202 char trantbl[4]; /* charset table translation */
203 int charset; /* current charset */
204 int icharset; /* selected charset for sequence */
205 int *tabs;
206 ImageList *images; /* sixel images */
207 ImageList *images_alt; /* sixel images for alternate screen */
208 Rune lastc; /* last printed char outside of sequence, 0 if control */
209} Term;
210
211/* Purely graphic info */
212typedef struct {
213 int tw, th; /* tty width and height */
214 int w, h; /* window width and height */
215 int ch; /* char height */
216 int cw; /* char width */
217 int cyo; /* char y offset */
218 int mode; /* window state/mode flags */
219 int cursor; /* cursor style */
220} TermWindow;
221
222/* Drawing Context */
223typedef struct {
224 Color *col;
225 size_t collen;
226 Font font, bfont, ifont, ibfont;
227 GC gc;
228} DC;
229
230void die(const char *, ...);
231void redraw(void);
232void draw(void);
233void tfulldirt(void);
234
235void printscreen(const Arg *);
236void printsel(const Arg *);
237void sendbreak(const Arg *);
238void toggleprinter(const Arg *);
239
240int tattrset(int);
241void tnew(int, int);
242void tresize(int, int);
243void tsetdirtattr(int);
244void ttyhangup(void);
245int ttynew(const char *, char *, const char *, char **);
246size_t ttyread(void);
247void ttyresize(int, int);
248void ttywrite(const char *, size_t, int);
249
250void resettitle(void);
251
252void selclear(void);
253void selinit(void);
254void selstart(int, int, int);
255void selextend(int, int, int, int);
256int selected(int, int);
257char *getsel(void);
258
259size_t utf8encode(Rune, char *);
260
261void *xmalloc(size_t);
262void *xrealloc(void *, size_t);
263char *xstrdup(const char *);
264
265int isboxdraw(Rune);
266ushort boxdrawindex(const Glyph *);
267#ifdef XFT_VERSION
268/* only exposed to x.c, otherwise we'll need Xft.h for the types */
269void boxdraw_xinit(Display *, Colormap, XftDraw *, Visual *);
270void drawboxes(int, int, int, int, XftColor *, XftColor *, const XftGlyphFontSpec *, int);
271#endif
272
273/* config.h globals */
274extern char *utmp;
275extern char *scroll;
276extern char *stty_args;
277extern char *vtiden;
278extern wchar_t *worddelimiters;
279extern int allowaltscreen;
280extern int allowwindowops;
281extern char *termname;
282extern unsigned int tabspaces;
283extern unsigned int defaultfg;
284extern unsigned int defaultbg;
285extern unsigned int defaultcs;
286extern const int boxdraw, boxdraw_bold, boxdraw_braille;
287
288extern DC dc;
289extern XWindow xw;
290extern XSelection xsel;
291extern TermWindow win;
292extern Term term;