1 /* See LICENSE for license details. */
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 || \
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)))
20 #define TRUECOLOR(r,g,b) (1 << 24 | (r) << 16 | (g) << 8 | (b))
21 #define IS_TRUECOL(x) (1 << 24 & (x))
23 enum glyph_attribute
{
28 ATTR_UNDERLINE
= 1 << 3,
30 ATTR_REVERSE
= 1 << 5,
31 ATTR_INVISIBLE
= 1 << 6,
35 ATTR_WDUMMY
= 1 << 10,
36 ATTR_BOLD_FAINT
= ATTR_BOLD
| ATTR_FAINT
,
42 MODE_APPKEYPAD
= 1 << 2,
43 MODE_ALTSCREEN
= 1 << 3,
45 MODE_MOUSEBTN
= 1 << 5,
46 MODE_MOUSEMOTION
= 1 << 6,
47 MODE_REVERSE
= 1 << 7,
48 MODE_KBDLOCK
= 1 << 8,
51 MODE_APPCURSOR
= 1 << 11,
52 MODE_MOUSESGR
= 1 << 12,
55 MODE_FBLINK
= 1 << 15,
57 MODE_MOUSEX10
= 1 << 17,
58 MODE_MOUSEMANY
= 1 << 18,
59 MODE_BRCKTPASTE
= 1 << 19,
63 MODE_MOUSE
= MODE_MOUSEBTN
|MODE_MOUSEMOTION
|MODE_MOUSEX10\
88 typedef unsigned char uchar
;
89 typedef unsigned int uint
;
90 typedef unsigned long ulong
;
91 typedef unsigned short ushort
;
93 typedef uint_least32_t Rune
;
96 Rune u
; /* character code */
97 ushort mode
; /* attribute flags */
98 uint32_t fg
; /* foreground */
99 uint32_t bg
; /* background */
103 typedef XftGlyphFontSpec GlyphFontSpec
;
106 Glyph attr
; /* current char attributes */
112 /* Internal representation of the screen */
114 int row
; /* nb row */
115 int col
; /* nb col */
116 Line
*line
; /* screen */
117 Line
*alt
; /* alternate screen */
118 int *dirty
; /* dirtyness of lines */
119 GlyphFontSpec
*specbuf
; /* font spec buffer used for rendering */
120 TCursor c
; /* cursor */
121 int top
; /* top scroll limit */
122 int bot
; /* bottom scroll limit */
123 int mode
; /* terminal mode flags */
124 int esc
; /* escape state flags */
125 char trantbl
[4]; /* charset table translation */
126 int charset
; /* current charset */
127 int icharset
; /* selected charset for sequence */
128 int numlock
; /* lock numbers in keyboard */
132 /* Purely graphic info */
134 int tw
, th
; /* tty width and height */
135 int w
, h
; /* window width and height */
136 int ch
; /* char height */
137 int cw
; /* char width */
138 char state
; /* focus, redraw, visible */
139 int cursor
; /* cursor style */
153 * Selection variables:
154 * nb – normalized coordinates of the beginning of the selection
155 * ne – normalized coordinates of the end of the selection
156 * ob – original coordinates of the beginning of the selection
157 * oe – original coordinates of the end of the selection
163 char *primary
, *clipboard
;
165 struct timespec tclick1
;
166 struct timespec tclick2
;
181 void (*func
)(const Arg
*);
185 void die(const char *, ...);
190 void tsetdirt(int, int);
191 void tsetdirtattr(int);
192 int match(uint
, uint
);
194 size_t ttyread(void);
195 void ttyresize(void);
196 void ttysend(char *, size_t);
197 void ttywrite(const char *, size_t);
199 void resettitle(void);
201 char *kmap(KeySym
, uint
);
202 void cresize(int, int);
206 void selnormalize(void);
207 int selected(int, int);
212 size_t utf8decode(char *, Rune
*, size_t);
213 size_t utf8encode(Rune
, char *);
215 void *xmalloc(size_t);
216 char *xstrdup(char *);
219 extern TermWindow win
;
221 extern Selection sel
;
224 extern char **opt_cmd
;
225 extern char *opt_class
;
226 extern char *opt_embed
;
227 extern char *opt_font
;
229 extern char *opt_line
;
230 extern char *opt_name
;
231 extern char *opt_title
;
232 extern int oldbutton
;
234 extern char *usedfont
;
235 extern double usedfontsize
;
236 extern double defaultfontsize
;
238 /* config.h globals */
241 extern float cwscale
;
242 extern float chscale
;
243 extern unsigned int doubleclicktimeout
;
244 extern unsigned int tripleclicktimeout
;
245 extern int allowaltscreen
;
246 extern unsigned int xfps
;
247 extern unsigned int actionfps
;
248 extern unsigned int cursorthickness
;
249 extern unsigned int blinktimeout
;
250 extern char termname
[];
251 extern const char *colorname
[];
252 extern size_t colornamelen
;
253 extern unsigned int defaultfg
;
254 extern unsigned int defaultbg
;
255 extern unsigned int defaultcs
;
256 extern unsigned int defaultrcs
;
257 extern unsigned int cursorshape
;
258 extern unsigned int cols
;
259 extern unsigned int rows
;
260 extern unsigned int mouseshape
;
261 extern unsigned int mousefg
;
262 extern unsigned int mousebg
;
263 extern unsigned int defaultattr
;
264 extern MouseShortcut mshortcuts
[];
265 extern size_t mshortcutslen
;
266 extern Shortcut shortcuts
[];
267 extern size_t shortcutslen
;
268 extern uint forceselmod
;
269 extern uint selmasks
[];
270 extern size_t selmaskslen
;
271 extern char ascii_printable
[];