Xinqi Bao's Git
8637d358123ea1d5cdcc850bcc571bb698eb6b15
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 DEFAULT(a, b) (a) = (a) ? (a) : (b)
13 #define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x)
14 #define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || \
16 #define IS_SET(flag) ((term.mode & (flag)) != 0)
17 #define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + \
18 (t1.tv_nsec-t2.tv_nsec)/1E6)
19 #define MODBIT(x, set, bit) ((set) ? ((x) |= (bit)) : ((x) &= ~(bit)))
21 #define TRUECOLOR(r,g,b) (1 << 24 | (r) << 16 | (g) << 8 | (b))
22 #define IS_TRUECOL(x) (1 << 24 & (x))
24 enum glyph_attribute
{
29 ATTR_UNDERLINE
= 1 << 3,
31 ATTR_REVERSE
= 1 << 5,
32 ATTR_INVISIBLE
= 1 << 6,
36 ATTR_WDUMMY
= 1 << 10,
37 ATTR_BOLD_FAINT
= ATTR_BOLD
| ATTR_FAINT
,
43 MODE_APPKEYPAD
= 1 << 2,
44 MODE_ALTSCREEN
= 1 << 3,
46 MODE_MOUSEBTN
= 1 << 5,
47 MODE_MOUSEMOTION
= 1 << 6,
48 MODE_REVERSE
= 1 << 7,
49 MODE_KBDLOCK
= 1 << 8,
52 MODE_APPCURSOR
= 1 << 11,
53 MODE_MOUSESGR
= 1 << 12,
56 MODE_FBLINK
= 1 << 15,
58 MODE_MOUSEX10
= 1 << 17,
59 MODE_MOUSEMANY
= 1 << 18,
60 MODE_BRCKTPASTE
= 1 << 19,
64 MODE_MOUSE
= MODE_MOUSEBTN
|MODE_MOUSEMOTION
|MODE_MOUSEX10\
84 typedef unsigned char uchar
;
85 typedef unsigned int uint
;
86 typedef unsigned long ulong
;
87 typedef unsigned short ushort
;
89 typedef uint_least32_t Rune
;
93 Rune u
; /* character code */
94 ushort mode
; /* attribute flags */
95 uint32_t fg
; /* foreground */
96 uint32_t bg
; /* background */
102 Glyph attr
; /* current char attributes */
108 /* Internal representation of the screen */
110 int row
; /* nb row */
111 int col
; /* nb col */
112 Line
*line
; /* screen */
113 Line
*alt
; /* alternate screen */
114 int *dirty
; /* dirtyness of lines */
115 TCursor c
; /* cursor */
116 int top
; /* top scroll limit */
117 int bot
; /* bottom scroll limit */
118 int mode
; /* terminal mode flags */
119 int esc
; /* escape state flags */
120 char trantbl
[4]; /* charset table translation */
121 int charset
; /* current charset */
122 int icharset
; /* selected charset for sequence */
123 int numlock
; /* lock numbers in keyboard */
127 /* Purely graphic info */
129 int tw
, th
; /* tty width and height */
130 int w
, h
; /* window width and height */
131 int ch
; /* char height */
132 int cw
; /* char width */
133 char state
; /* focus, redraw, visible */
134 int cursor
; /* cursor style */
142 * Selection variables:
143 * nb – normalized coordinates of the beginning of the selection
144 * ne – normalized coordinates of the end of the selection
145 * ob – original coordinates of the beginning of the selection
146 * oe – original coordinates of the end of the selection
152 char *primary
, *clipboard
;
154 struct timespec tclick1
;
155 struct timespec tclick2
;
167 void die(const char *, ...);
170 void iso14755(const Arg
*);
171 void numlock(const Arg
*);
172 void printscreen(const Arg
*);
173 void printsel(const Arg
*);
174 void sendbreak(const Arg
*);
175 void toggleprinter(const Arg
*);
179 void tresize(int, int);
180 void tsetdirt(int, int);
181 void tsetdirtattr(int);
182 void ttynew(char *, char *, char **);
183 size_t ttyread(void);
184 void ttyresize(int, int);
185 void ttysend(char *, size_t);
186 void ttywrite(const char *, size_t);
188 void resettitle(void);
192 void selnormalize(void);
193 int selected(int, int);
196 size_t utf8decode(const char *, Rune
*, size_t);
197 size_t utf8encode(Rune
, char *);
199 void *xmalloc(size_t);
200 void *xrealloc(void *, size_t);
201 char *xstrdup(char *);
205 extern Selection sel
;
208 extern int oldbutton
;
210 /* config.h globals */
213 extern char *stty_args
;
215 extern char *worddelimiters
;
216 extern int allowaltscreen
;
217 extern char *termname
;
218 extern unsigned int tabspaces
;
219 extern unsigned int defaultfg
;
220 extern unsigned int defaultbg
;