xref: /openbsd-src/usr.bin/tmux/tmux.h (revision 4e1ee0786f11cc571bd0be17d38e46f635c719fc)
1 /* $OpenBSD: tmux.h,v 1.1148 2021/10/20 09:50:40 nicm Exp $ */
2 
3 /*
4  * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef TMUX_H
20 #define TMUX_H
21 
22 #include <sys/time.h>
23 #include <sys/queue.h>
24 #include <sys/tree.h>
25 
26 #include <bitstring.h>
27 #include <event.h>
28 #include <limits.h>
29 #include <stdarg.h>
30 #include <stdint.h>
31 #include <stdio.h>
32 #include <termios.h>
33 
34 #include "tmux-protocol.h"
35 #include "xmalloc.h"
36 
37 extern char   **environ;
38 
39 struct args;
40 struct args_command_state;
41 struct client;
42 struct cmd;
43 struct cmd_find_state;
44 struct cmdq_item;
45 struct cmdq_list;
46 struct cmdq_state;
47 struct cmds;
48 struct control_state;
49 struct environ;
50 struct format_job_tree;
51 struct format_tree;
52 struct input_ctx;
53 struct job;
54 struct menu_data;
55 struct mode_tree_data;
56 struct mouse_event;
57 struct options;
58 struct options_array_item;
59 struct options_entry;
60 struct screen_write_citem;
61 struct screen_write_cline;
62 struct screen_write_ctx;
63 struct session;
64 struct tty_ctx;
65 struct tty_code;
66 struct tty_key;
67 struct tmuxpeer;
68 struct tmuxproc;
69 struct winlink;
70 
71 /* Default configuration files and socket paths. */
72 #ifndef TMUX_CONF
73 #define TMUX_CONF "/etc/tmux.conf:~/.tmux.conf"
74 #endif
75 #ifndef TMUX_SOCK
76 #define TMUX_SOCK "$TMUX_TMPDIR:" _PATH_TMP
77 #endif
78 #ifndef TMUX_TERM
79 #define TMUX_TERM "screen"
80 #endif
81 
82 /* Minimum layout cell size, NOT including border lines. */
83 #define PANE_MINIMUM 1
84 
85 /* Minimum and maximum window size. */
86 #define WINDOW_MINIMUM PANE_MINIMUM
87 #define WINDOW_MAXIMUM 10000
88 
89 /* Automatic name refresh interval, in microseconds. Must be < 1 second. */
90 #define NAME_INTERVAL 500000
91 
92 /* Default pixel cell sizes. */
93 #define DEFAULT_XPIXEL 16
94 #define DEFAULT_YPIXEL 32
95 
96 /* Attribute to make GCC check printf-like arguments. */
97 #define printflike(a, b) __attribute__ ((format (printf, a, b)))
98 
99 /* Number of items in array. */
100 #ifndef nitems
101 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
102 #endif
103 
104 /* Alert option values. */
105 #define ALERT_NONE 0
106 #define ALERT_ANY 1
107 #define ALERT_CURRENT 2
108 #define ALERT_OTHER 3
109 
110 /* Visual option values. */
111 #define VISUAL_OFF 0
112 #define VISUAL_ON 1
113 #define VISUAL_BOTH 2
114 
115 /* No key or unknown key. */
116 #define KEYC_NONE            0x000ff000000000ULL
117 #define KEYC_UNKNOWN         0x000fe000000000ULL
118 
119 /*
120  * Base for special (that is, not Unicode) keys. An enum must be at most a
121  * signed int, so these are based in the highest Unicode PUA.
122  */
123 #define KEYC_BASE            0x0000000010e000ULL
124 #define KEYC_USER            0x0000000010f000ULL
125 
126 /* Key modifier bits. */
127 #define KEYC_META            0x00100000000000ULL
128 #define KEYC_CTRL            0x00200000000000ULL
129 #define KEYC_SHIFT           0x00400000000000ULL
130 
131 /* Key flag bits. */
132 #define KEYC_LITERAL         0x01000000000000ULL
133 #define KEYC_KEYPAD          0x02000000000000ULL
134 #define KEYC_CURSOR          0x04000000000000ULL
135 #define KEYC_IMPLIED_META    0x08000000000000ULL
136 #define KEYC_BUILD_MODIFIERS 0x10000000000000ULL
137 #define KEYC_VI              0x20000000000000ULL
138 
139 /* Masks for key bits. */
140 #define KEYC_MASK_MODIFIERS  0x00f00000000000ULL
141 #define KEYC_MASK_FLAGS      0xff000000000000ULL
142 #define KEYC_MASK_KEY        0x000fffffffffffULL
143 
144 /* Available user keys. */
145 #define KEYC_NUSER 1000
146 
147 /* Is this a mouse key? */
148 #define KEYC_IS_MOUSE(key) \
149 	(((key) & KEYC_MASK_KEY) >= KEYC_MOUSE && \
150 	 ((key) & KEYC_MASK_KEY) < KEYC_BSPACE)
151 
152 /* Is this a Unicode key? */
153 #define KEYC_IS_UNICODE(key) \
154 	(((key) & KEYC_MASK_KEY) > 0x7f && \
155 	 (((key) & KEYC_MASK_KEY) < KEYC_BASE || \
156 	  ((key) & KEYC_MASK_KEY) >= KEYC_BASE_END))
157 
158 /* Multiple click timeout. */
159 #define KEYC_CLICK_TIMEOUT 300
160 
161 /* Mouse key codes. */
162 #define KEYC_MOUSE_KEY(name)					\
163 	KEYC_ ## name ## _PANE,					\
164 	KEYC_ ## name ## _STATUS,				\
165 	KEYC_ ## name ## _STATUS_LEFT,				\
166 	KEYC_ ## name ## _STATUS_RIGHT,				\
167 	KEYC_ ## name ## _STATUS_DEFAULT,			\
168 	KEYC_ ## name ## _BORDER
169 #define KEYC_MOUSE_STRING(name, s)				\
170 	{ #s "Pane", KEYC_ ## name ## _PANE },			\
171 	{ #s "Status", KEYC_ ## name ## _STATUS },		\
172 	{ #s "StatusLeft", KEYC_ ## name ## _STATUS_LEFT },	\
173 	{ #s "StatusRight", KEYC_ ## name ## _STATUS_RIGHT },	\
174 	{ #s "StatusDefault", KEYC_ ## name ## _STATUS_DEFAULT }, \
175 	{ #s "Border", KEYC_ ## name ## _BORDER }
176 
177 /*
178  * A single key. This can be ASCII or Unicode or one of the keys between
179  * KEYC_BASE and KEYC_BASE_END.
180  */
181 typedef unsigned long long key_code;
182 
183 /* Special key codes. */
184 enum {
185 	/* Focus events. */
186 	KEYC_FOCUS_IN = KEYC_BASE,
187 	KEYC_FOCUS_OUT,
188 
189 	/* "Any" key, used if not found in key table. */
190 	KEYC_ANY,
191 
192 	/* Paste brackets. */
193 	KEYC_PASTE_START,
194 	KEYC_PASTE_END,
195 
196 	/* Mouse keys. */
197 	KEYC_MOUSE, /* unclassified mouse event */
198 	KEYC_DRAGGING, /* dragging in progress */
199 	KEYC_DOUBLECLICK, /* double click complete */
200 	KEYC_MOUSE_KEY(MOUSEMOVE),
201 	KEYC_MOUSE_KEY(MOUSEDOWN1),
202 	KEYC_MOUSE_KEY(MOUSEDOWN2),
203 	KEYC_MOUSE_KEY(MOUSEDOWN3),
204 	KEYC_MOUSE_KEY(MOUSEUP1),
205 	KEYC_MOUSE_KEY(MOUSEUP2),
206 	KEYC_MOUSE_KEY(MOUSEUP3),
207 	KEYC_MOUSE_KEY(MOUSEDRAG1),
208 	KEYC_MOUSE_KEY(MOUSEDRAG2),
209 	KEYC_MOUSE_KEY(MOUSEDRAG3),
210 	KEYC_MOUSE_KEY(MOUSEDRAGEND1),
211 	KEYC_MOUSE_KEY(MOUSEDRAGEND2),
212 	KEYC_MOUSE_KEY(MOUSEDRAGEND3),
213 	KEYC_MOUSE_KEY(WHEELUP),
214 	KEYC_MOUSE_KEY(WHEELDOWN),
215 	KEYC_MOUSE_KEY(SECONDCLICK1),
216 	KEYC_MOUSE_KEY(SECONDCLICK2),
217 	KEYC_MOUSE_KEY(SECONDCLICK3),
218 	KEYC_MOUSE_KEY(DOUBLECLICK1),
219 	KEYC_MOUSE_KEY(DOUBLECLICK2),
220 	KEYC_MOUSE_KEY(DOUBLECLICK3),
221 	KEYC_MOUSE_KEY(TRIPLECLICK1),
222 	KEYC_MOUSE_KEY(TRIPLECLICK2),
223 	KEYC_MOUSE_KEY(TRIPLECLICK3),
224 
225 	/* Backspace key. */
226 	KEYC_BSPACE,
227 
228 	/* Function keys. */
229 	KEYC_F1,
230 	KEYC_F2,
231 	KEYC_F3,
232 	KEYC_F4,
233 	KEYC_F5,
234 	KEYC_F6,
235 	KEYC_F7,
236 	KEYC_F8,
237 	KEYC_F9,
238 	KEYC_F10,
239 	KEYC_F11,
240 	KEYC_F12,
241 	KEYC_IC,
242 	KEYC_DC,
243 	KEYC_HOME,
244 	KEYC_END,
245 	KEYC_NPAGE,
246 	KEYC_PPAGE,
247 	KEYC_BTAB,
248 
249 	/* Arrow keys. */
250 	KEYC_UP,
251 	KEYC_DOWN,
252 	KEYC_LEFT,
253 	KEYC_RIGHT,
254 
255 	/* Numeric keypad. */
256 	KEYC_KP_SLASH,
257 	KEYC_KP_STAR,
258 	KEYC_KP_MINUS,
259 	KEYC_KP_SEVEN,
260 	KEYC_KP_EIGHT,
261 	KEYC_KP_NINE,
262 	KEYC_KP_PLUS,
263 	KEYC_KP_FOUR,
264 	KEYC_KP_FIVE,
265 	KEYC_KP_SIX,
266 	KEYC_KP_ONE,
267 	KEYC_KP_TWO,
268 	KEYC_KP_THREE,
269 	KEYC_KP_ENTER,
270 	KEYC_KP_ZERO,
271 	KEYC_KP_PERIOD,
272 
273 	/* End of special keys. */
274 	KEYC_BASE_END
275 };
276 
277 /* Termcap codes. */
278 enum tty_code_code {
279 	TTYC_ACSC,
280 	TTYC_AM,
281 	TTYC_AX,
282 	TTYC_BCE,
283 	TTYC_BEL,
284 	TTYC_BIDI,
285 	TTYC_BLINK,
286 	TTYC_BOLD,
287 	TTYC_CIVIS,
288 	TTYC_CLEAR,
289 	TTYC_CLMG,
290 	TTYC_CMG,
291 	TTYC_CNORM,
292 	TTYC_COLORS,
293 	TTYC_CR,
294 	TTYC_CS,
295 	TTYC_CSR,
296 	TTYC_CUB,
297 	TTYC_CUB1,
298 	TTYC_CUD,
299 	TTYC_CUD1,
300 	TTYC_CUF,
301 	TTYC_CUF1,
302 	TTYC_CUP,
303 	TTYC_CUU,
304 	TTYC_CUU1,
305 	TTYC_CVVIS,
306 	TTYC_DCH,
307 	TTYC_DCH1,
308 	TTYC_DIM,
309 	TTYC_DL,
310 	TTYC_DL1,
311 	TTYC_DSBP,
312 	TTYC_DSEKS,
313 	TTYC_DSFCS,
314 	TTYC_DSMG,
315 	TTYC_E3,
316 	TTYC_ECH,
317 	TTYC_ED,
318 	TTYC_EL,
319 	TTYC_EL1,
320 	TTYC_ENACS,
321 	TTYC_ENBP,
322 	TTYC_ENEKS,
323 	TTYC_ENFCS,
324 	TTYC_ENMG,
325 	TTYC_FSL,
326 	TTYC_HOME,
327 	TTYC_HPA,
328 	TTYC_ICH,
329 	TTYC_ICH1,
330 	TTYC_IL,
331 	TTYC_IL1,
332 	TTYC_INDN,
333 	TTYC_INVIS,
334 	TTYC_KCBT,
335 	TTYC_KCUB1,
336 	TTYC_KCUD1,
337 	TTYC_KCUF1,
338 	TTYC_KCUU1,
339 	TTYC_KDC2,
340 	TTYC_KDC3,
341 	TTYC_KDC4,
342 	TTYC_KDC5,
343 	TTYC_KDC6,
344 	TTYC_KDC7,
345 	TTYC_KDCH1,
346 	TTYC_KDN2,
347 	TTYC_KDN3,
348 	TTYC_KDN4,
349 	TTYC_KDN5,
350 	TTYC_KDN6,
351 	TTYC_KDN7,
352 	TTYC_KEND,
353 	TTYC_KEND2,
354 	TTYC_KEND3,
355 	TTYC_KEND4,
356 	TTYC_KEND5,
357 	TTYC_KEND6,
358 	TTYC_KEND7,
359 	TTYC_KF1,
360 	TTYC_KF10,
361 	TTYC_KF11,
362 	TTYC_KF12,
363 	TTYC_KF13,
364 	TTYC_KF14,
365 	TTYC_KF15,
366 	TTYC_KF16,
367 	TTYC_KF17,
368 	TTYC_KF18,
369 	TTYC_KF19,
370 	TTYC_KF2,
371 	TTYC_KF20,
372 	TTYC_KF21,
373 	TTYC_KF22,
374 	TTYC_KF23,
375 	TTYC_KF24,
376 	TTYC_KF25,
377 	TTYC_KF26,
378 	TTYC_KF27,
379 	TTYC_KF28,
380 	TTYC_KF29,
381 	TTYC_KF3,
382 	TTYC_KF30,
383 	TTYC_KF31,
384 	TTYC_KF32,
385 	TTYC_KF33,
386 	TTYC_KF34,
387 	TTYC_KF35,
388 	TTYC_KF36,
389 	TTYC_KF37,
390 	TTYC_KF38,
391 	TTYC_KF39,
392 	TTYC_KF4,
393 	TTYC_KF40,
394 	TTYC_KF41,
395 	TTYC_KF42,
396 	TTYC_KF43,
397 	TTYC_KF44,
398 	TTYC_KF45,
399 	TTYC_KF46,
400 	TTYC_KF47,
401 	TTYC_KF48,
402 	TTYC_KF49,
403 	TTYC_KF5,
404 	TTYC_KF50,
405 	TTYC_KF51,
406 	TTYC_KF52,
407 	TTYC_KF53,
408 	TTYC_KF54,
409 	TTYC_KF55,
410 	TTYC_KF56,
411 	TTYC_KF57,
412 	TTYC_KF58,
413 	TTYC_KF59,
414 	TTYC_KF6,
415 	TTYC_KF60,
416 	TTYC_KF61,
417 	TTYC_KF62,
418 	TTYC_KF63,
419 	TTYC_KF7,
420 	TTYC_KF8,
421 	TTYC_KF9,
422 	TTYC_KHOM2,
423 	TTYC_KHOM3,
424 	TTYC_KHOM4,
425 	TTYC_KHOM5,
426 	TTYC_KHOM6,
427 	TTYC_KHOM7,
428 	TTYC_KHOME,
429 	TTYC_KIC2,
430 	TTYC_KIC3,
431 	TTYC_KIC4,
432 	TTYC_KIC5,
433 	TTYC_KIC6,
434 	TTYC_KIC7,
435 	TTYC_KICH1,
436 	TTYC_KIND,
437 	TTYC_KLFT2,
438 	TTYC_KLFT3,
439 	TTYC_KLFT4,
440 	TTYC_KLFT5,
441 	TTYC_KLFT6,
442 	TTYC_KLFT7,
443 	TTYC_KMOUS,
444 	TTYC_KNP,
445 	TTYC_KNXT2,
446 	TTYC_KNXT3,
447 	TTYC_KNXT4,
448 	TTYC_KNXT5,
449 	TTYC_KNXT6,
450 	TTYC_KNXT7,
451 	TTYC_KPP,
452 	TTYC_KPRV2,
453 	TTYC_KPRV3,
454 	TTYC_KPRV4,
455 	TTYC_KPRV5,
456 	TTYC_KPRV6,
457 	TTYC_KPRV7,
458 	TTYC_KRI,
459 	TTYC_KRIT2,
460 	TTYC_KRIT3,
461 	TTYC_KRIT4,
462 	TTYC_KRIT5,
463 	TTYC_KRIT6,
464 	TTYC_KRIT7,
465 	TTYC_KUP2,
466 	TTYC_KUP3,
467 	TTYC_KUP4,
468 	TTYC_KUP5,
469 	TTYC_KUP6,
470 	TTYC_KUP7,
471 	TTYC_MS,
472 	TTYC_OL,
473 	TTYC_OP,
474 	TTYC_RECT,
475 	TTYC_REV,
476 	TTYC_RGB,
477 	TTYC_RI,
478 	TTYC_RIN,
479 	TTYC_RMACS,
480 	TTYC_RMCUP,
481 	TTYC_RMKX,
482 	TTYC_SE,
483 	TTYC_SETAB,
484 	TTYC_SETAF,
485 	TTYC_SETAL,
486 	TTYC_SETRGBB,
487 	TTYC_SETRGBF,
488 	TTYC_SETULC,
489 	TTYC_SGR0,
490 	TTYC_SITM,
491 	TTYC_SMACS,
492 	TTYC_SMCUP,
493 	TTYC_SMKX,
494 	TTYC_SMOL,
495 	TTYC_SMSO,
496 	TTYC_SMUL,
497 	TTYC_SMULX,
498 	TTYC_SMXX,
499 	TTYC_SS,
500 	TTYC_SYNC,
501 	TTYC_TC,
502 	TTYC_TSL,
503 	TTYC_U8,
504 	TTYC_VPA,
505 	TTYC_XT
506 };
507 
508 /* Character classes. */
509 #define WHITESPACE " "
510 
511 /* Mode keys. */
512 #define MODEKEY_EMACS 0
513 #define MODEKEY_VI 1
514 
515 /* Modes. */
516 #define MODE_CURSOR 0x1
517 #define MODE_INSERT 0x2
518 #define MODE_KCURSOR 0x4
519 #define MODE_KKEYPAD 0x8
520 #define MODE_WRAP 0x10
521 #define MODE_MOUSE_STANDARD 0x20
522 #define MODE_MOUSE_BUTTON 0x40
523 #define MODE_CURSOR_BLINKING 0x80
524 #define MODE_MOUSE_UTF8 0x100
525 #define MODE_MOUSE_SGR 0x200
526 #define MODE_BRACKETPASTE 0x400
527 #define MODE_FOCUSON 0x800
528 #define MODE_MOUSE_ALL 0x1000
529 #define MODE_ORIGIN 0x2000
530 #define MODE_CRLF 0x4000
531 #define MODE_KEXTENDED 0x8000
532 #define MODE_CURSOR_VERY_VISIBLE 0x10000
533 
534 #define ALL_MODES 0xffffff
535 #define ALL_MOUSE_MODES (MODE_MOUSE_STANDARD|MODE_MOUSE_BUTTON|MODE_MOUSE_ALL)
536 #define MOTION_MOUSE_MODES (MODE_MOUSE_BUTTON|MODE_MOUSE_ALL)
537 #define CURSOR_MODES (MODE_CURSOR|MODE_CURSOR_BLINKING|MODE_CURSOR_VERY_VISIBLE)
538 
539 /* A single UTF-8 character. */
540 typedef u_int utf8_char;
541 
542 /*
543  * An expanded UTF-8 character. UTF8_SIZE must be big enough to hold combining
544  * characters as well. It can't be more than 32 bytes without changes to how
545  * characters are stored.
546  */
547 #define UTF8_SIZE 21
548 struct utf8_data {
549 	u_char	data[UTF8_SIZE];
550 
551 	u_char	have;
552 	u_char	size;
553 
554 	u_char	width;	/* 0xff if invalid */
555 };
556 enum utf8_state {
557 	UTF8_MORE,
558 	UTF8_DONE,
559 	UTF8_ERROR
560 };
561 
562 /* Colour flags. */
563 #define COLOUR_FLAG_256 0x01000000
564 #define COLOUR_FLAG_RGB 0x02000000
565 
566 /* Special colours. */
567 #define COLOUR_DEFAULT(c) ((c) == 8 || (c) == 9)
568 
569 /* Replacement palette. */
570 struct colour_palette {
571 	int	 fg;
572 	int	 bg;
573 
574 	int	*palette;
575 	int	*default_palette;
576 };
577 
578 /* Grid attributes. Anything above 0xff is stored in an extended cell. */
579 #define GRID_ATTR_BRIGHT 0x1
580 #define GRID_ATTR_DIM 0x2
581 #define GRID_ATTR_UNDERSCORE 0x4
582 #define GRID_ATTR_BLINK 0x8
583 #define GRID_ATTR_REVERSE 0x10
584 #define GRID_ATTR_HIDDEN 0x20
585 #define GRID_ATTR_ITALICS 0x40
586 #define GRID_ATTR_CHARSET 0x80	/* alternative character set */
587 #define GRID_ATTR_STRIKETHROUGH 0x100
588 #define GRID_ATTR_UNDERSCORE_2 0x200
589 #define GRID_ATTR_UNDERSCORE_3 0x400
590 #define GRID_ATTR_UNDERSCORE_4 0x800
591 #define GRID_ATTR_UNDERSCORE_5 0x1000
592 #define GRID_ATTR_OVERLINE 0x2000
593 
594 /* All underscore attributes. */
595 #define GRID_ATTR_ALL_UNDERSCORE \
596 	(GRID_ATTR_UNDERSCORE|	 \
597 	 GRID_ATTR_UNDERSCORE_2| \
598 	 GRID_ATTR_UNDERSCORE_3| \
599 	 GRID_ATTR_UNDERSCORE_4| \
600 	 GRID_ATTR_UNDERSCORE_5)
601 
602 /* Grid flags. */
603 #define GRID_FLAG_FG256 0x1
604 #define GRID_FLAG_BG256 0x2
605 #define GRID_FLAG_PADDING 0x4
606 #define GRID_FLAG_EXTENDED 0x8
607 #define GRID_FLAG_SELECTED 0x10
608 #define GRID_FLAG_NOPALETTE 0x20
609 #define GRID_FLAG_CLEARED 0x40
610 
611 /* Grid line flags. */
612 #define GRID_LINE_WRAPPED 0x1
613 #define GRID_LINE_EXTENDED 0x2
614 #define GRID_LINE_DEAD 0x4
615 
616 #define CELL_INSIDE 0
617 #define CELL_TOPBOTTOM 1
618 #define CELL_LEFTRIGHT 2
619 #define CELL_TOPLEFT 3
620 #define CELL_TOPRIGHT 4
621 #define CELL_BOTTOMLEFT 5
622 #define CELL_BOTTOMRIGHT 6
623 #define CELL_TOPJOIN 7
624 #define CELL_BOTTOMJOIN 8
625 #define CELL_LEFTJOIN 9
626 #define CELL_RIGHTJOIN 10
627 #define CELL_JOIN 11
628 #define CELL_OUTSIDE 12
629 
630 #define CELL_BORDERS " xqlkmjwvtun~"
631 #define SIMPLE_BORDERS " |-+++++++++."
632 #define PADDED_BORDERS "             "
633 
634 /* Grid cell data. */
635 struct grid_cell {
636 	struct utf8_data	data;
637 	u_short			attr;
638 	u_char			flags;
639 	int			fg;
640 	int			bg;
641 	int			us;
642 };
643 
644 /* Grid extended cell entry. */
645 struct grid_extd_entry {
646 	utf8_char		data;
647 	u_short			attr;
648 	u_char			flags;
649 	int			fg;
650 	int			bg;
651 	int			us;
652 } __packed;
653 
654 /* Grid cell entry. */
655 struct grid_cell_entry {
656 	u_char			flags;
657 	union {
658 		u_int		offset;
659 		struct {
660 			u_char	attr;
661 			u_char	fg;
662 			u_char	bg;
663 			u_char	data;
664 		} data;
665 	};
666 } __packed;
667 
668 /* Grid line. */
669 struct grid_line {
670 	u_int			 cellused;
671 	u_int			 cellsize;
672 	struct grid_cell_entry	*celldata;
673 
674 	u_int			 extdsize;
675 	struct grid_extd_entry	*extddata;
676 
677 	int			 flags;
678 } __packed;
679 
680 /* Entire grid of cells. */
681 struct grid {
682 	int			 flags;
683 #define GRID_HISTORY 0x1 /* scroll lines into history */
684 
685 	u_int			 sx;
686 	u_int			 sy;
687 
688 	u_int			 hscrolled;
689 	u_int			 hsize;
690 	u_int			 hlimit;
691 
692 	struct grid_line	*linedata;
693 };
694 
695 /* Virtual cursor in a grid. */
696 struct grid_reader {
697 	struct grid	*gd;
698 	u_int		 cx;
699 	u_int		 cy;
700 };
701 
702 /* Style alignment. */
703 enum style_align {
704 	STYLE_ALIGN_DEFAULT,
705 	STYLE_ALIGN_LEFT,
706 	STYLE_ALIGN_CENTRE,
707 	STYLE_ALIGN_RIGHT,
708 	STYLE_ALIGN_ABSOLUTE_CENTRE
709 };
710 
711 /* Style list. */
712 enum style_list {
713 	STYLE_LIST_OFF,
714 	STYLE_LIST_ON,
715 	STYLE_LIST_FOCUS,
716 	STYLE_LIST_LEFT_MARKER,
717 	STYLE_LIST_RIGHT_MARKER,
718 };
719 
720 /* Style range. */
721 enum style_range_type {
722 	STYLE_RANGE_NONE,
723 	STYLE_RANGE_LEFT,
724 	STYLE_RANGE_RIGHT,
725 	STYLE_RANGE_WINDOW
726 };
727 struct style_range {
728 	enum style_range_type	 type;
729 	u_int			 argument;
730 
731 	u_int			 start;
732 	u_int			 end; /* not included */
733 
734 	TAILQ_ENTRY(style_range) entry;
735 };
736 TAILQ_HEAD(style_ranges, style_range);
737 
738 /* Style default. */
739 enum style_default_type {
740 	STYLE_DEFAULT_BASE,
741 	STYLE_DEFAULT_PUSH,
742 	STYLE_DEFAULT_POP
743 };
744 
745 /* Style option. */
746 struct style {
747 	struct grid_cell	gc;
748 	int			ignore;
749 
750 	int			fill;
751 	enum style_align	align;
752 	enum style_list		list;
753 
754 	enum style_range_type	range_type;
755 	u_int			range_argument;
756 
757 	enum style_default_type	default_type;
758 };
759 
760 /* Cursor style. */
761 enum screen_cursor_style {
762 	SCREEN_CURSOR_DEFAULT,
763 	SCREEN_CURSOR_BLOCK,
764 	SCREEN_CURSOR_UNDERLINE,
765 	SCREEN_CURSOR_BAR
766 };
767 
768 /* Virtual screen. */
769 struct screen_sel;
770 struct screen_titles;
771 struct screen {
772 	char				*title;
773 	char				*path;
774 	struct screen_titles		*titles;
775 
776 	struct grid			*grid;	  /* grid data */
777 
778 	u_int				 cx;	  /* cursor x */
779 	u_int				 cy;	  /* cursor y */
780 
781 	enum screen_cursor_style	 cstyle;  /* cursor style */
782 	char				*ccolour; /* cursor colour */
783 
784 	u_int				 rupper;  /* scroll region top */
785 	u_int				 rlower;  /* scroll region bottom */
786 
787 	int				 mode;
788 
789 	u_int				 saved_cx;
790 	u_int				 saved_cy;
791 	struct grid			*saved_grid;
792 	struct grid_cell		 saved_cell;
793 	int				 saved_flags;
794 
795 	bitstr_t			*tabs;
796 	struct screen_sel		*sel;
797 
798 	struct screen_write_cline	*write_list;
799 };
800 
801 /* Screen write context. */
802 typedef void (*screen_write_init_ctx_cb)(struct screen_write_ctx *,
803     struct tty_ctx *);
804 struct screen_write_ctx {
805 	struct window_pane		*wp;
806 	struct screen			*s;
807 
808 	int				 flags;
809 #define SCREEN_WRITE_SYNC 0x1
810 #define SCREEN_WRITE_ZWJ 0x2
811 
812 	screen_write_init_ctx_cb	 init_ctx_cb;
813 	void				*arg;
814 
815 	struct screen_write_citem	*item;
816 	u_int				 scrolled;
817 	u_int				 bg;
818 };
819 
820 /* Box border lines option. */
821 enum box_lines {
822 	BOX_LINES_DEFAULT = -1,
823 	BOX_LINES_SINGLE,
824 	BOX_LINES_DOUBLE,
825 	BOX_LINES_HEAVY,
826 	BOX_LINES_SIMPLE,
827 	BOX_LINES_ROUNDED,
828 	BOX_LINES_PADDED,
829 	BOX_LINES_NONE
830 };
831 
832 /* Pane border lines option. */
833 enum pane_lines {
834 	PANE_LINES_SINGLE,
835 	PANE_LINES_DOUBLE,
836 	PANE_LINES_HEAVY,
837 	PANE_LINES_SIMPLE,
838 	PANE_LINES_NUMBER
839 };
840 
841 /* Screen redraw context. */
842 struct screen_redraw_ctx {
843 	struct client	*c;
844 
845 	u_int		 statuslines;
846 	int		 statustop;
847 
848 	int		 pane_status;
849 	enum pane_lines	 pane_lines;
850 
851 	struct grid_cell no_pane_gc;
852 	int		 no_pane_gc_set;
853 
854 	u_int		 sx;
855 	u_int		 sy;
856 	u_int		 ox;
857 	u_int		 oy;
858 };
859 
860 /* Screen size. */
861 #define screen_size_x(s) ((s)->grid->sx)
862 #define screen_size_y(s) ((s)->grid->sy)
863 #define screen_hsize(s) ((s)->grid->hsize)
864 #define screen_hlimit(s) ((s)->grid->hlimit)
865 
866 /* Menu. */
867 struct menu_item {
868 	const char	*name;
869 	key_code	 key;
870 	const char	*command;
871 };
872 struct menu {
873 	const char		*title;
874 	struct menu_item	*items;
875 	u_int			 count;
876 	u_int			 width;
877 };
878 typedef void (*menu_choice_cb)(struct menu *, u_int, key_code, void *);
879 
880 /*
881  * Window mode. Windows can be in several modes and this is used to call the
882  * right function to handle input and output.
883  */
884 struct window_mode_entry;
885 struct window_mode {
886 	const char	*name;
887 	const char	*default_format;
888 
889 	struct screen	*(*init)(struct window_mode_entry *,
890 			     struct cmd_find_state *, struct args *);
891 	void		 (*free)(struct window_mode_entry *);
892 	void		 (*resize)(struct window_mode_entry *, u_int, u_int);
893 	void		 (*update)(struct window_mode_entry *);
894 	void		 (*key)(struct window_mode_entry *, struct client *,
895 			     struct session *, struct winlink *, key_code,
896 			     struct mouse_event *);
897 
898 	const char	*(*key_table)(struct window_mode_entry *);
899 	void		 (*command)(struct window_mode_entry *, struct client *,
900 			     struct session *, struct winlink *, struct args *,
901 			     struct mouse_event *);
902 	void		 (*formats)(struct window_mode_entry *,
903 			     struct format_tree *);
904 };
905 
906 /* Active window mode. */
907 struct window_mode_entry {
908 	struct window_pane		*wp;
909 	struct window_pane		*swp;
910 
911 	const struct window_mode	*mode;
912 	void				*data;
913 
914 	struct screen			*screen;
915 	u_int				 prefix;
916 
917 	TAILQ_ENTRY(window_mode_entry)	 entry;
918 };
919 
920 /* Offsets into pane buffer. */
921 struct window_pane_offset {
922 	size_t	used;
923 };
924 
925 /* Queued pane resize. */
926 struct window_pane_resize {
927 	u_int				sx;
928 	u_int				sy;
929 
930 	u_int				osx;
931 	u_int				osy;
932 
933 	TAILQ_ENTRY(window_pane_resize)	entry;
934 };
935 TAILQ_HEAD(window_pane_resizes, window_pane_resize);
936 
937 /* Child window structure. */
938 struct window_pane {
939 	u_int		 id;
940 	u_int		 active_point;
941 
942 	struct window	*window;
943 	struct options	*options;
944 
945 	struct layout_cell *layout_cell;
946 	struct layout_cell *saved_layout_cell;
947 
948 	u_int		 sx;
949 	u_int		 sy;
950 
951 	u_int		 xoff;
952 	u_int		 yoff;
953 
954 	int		 flags;
955 #define PANE_REDRAW 0x1
956 #define PANE_DROP 0x2
957 #define PANE_FOCUSED 0x4
958 /* 0x8 unused */
959 /* 0x10 unused */
960 /* 0x20 unused */
961 #define PANE_INPUTOFF 0x40
962 #define PANE_CHANGED 0x80
963 #define PANE_EXITED 0x100
964 #define PANE_STATUSREADY 0x200
965 #define PANE_STATUSDRAWN 0x400
966 #define PANE_EMPTY 0x800
967 #define PANE_STYLECHANGED 0x1000
968 
969 	int		 argc;
970 	char	       **argv;
971 	char		*shell;
972 	char		*cwd;
973 
974 	pid_t		 pid;
975 	char		 tty[TTY_NAME_MAX];
976 	int		 status;
977 
978 	int		 fd;
979 	struct bufferevent *event;
980 
981 	struct window_pane_offset offset;
982 	size_t		 base_offset;
983 
984 	struct window_pane_resizes resize_queue;
985 	struct event	 resize_timer;
986 
987 	struct input_ctx *ictx;
988 
989 	struct grid_cell cached_gc;
990 	struct grid_cell cached_active_gc;
991 	struct colour_palette palette;
992 
993 	int		 pipe_fd;
994 	struct bufferevent *pipe_event;
995 	struct window_pane_offset pipe_offset;
996 
997 	struct screen	*screen;
998 	struct screen	 base;
999 
1000 	struct screen	 status_screen;
1001 	size_t		 status_size;
1002 
1003 	TAILQ_HEAD(, window_mode_entry) modes;
1004 
1005 	char		*searchstr;
1006 	int		 searchregex;
1007 
1008 	int		 border_gc_set;
1009 	struct grid_cell border_gc;
1010 
1011 	TAILQ_ENTRY(window_pane) entry;
1012 	RB_ENTRY(window_pane) tree_entry;
1013 };
1014 TAILQ_HEAD(window_panes, window_pane);
1015 RB_HEAD(window_pane_tree, window_pane);
1016 
1017 /* Window structure. */
1018 struct window {
1019 	u_int		 id;
1020 	void		*latest;
1021 
1022 	char		*name;
1023 	struct event	 name_event;
1024 	struct timeval	 name_time;
1025 
1026 	struct event	 alerts_timer;
1027 	struct event	 offset_timer;
1028 
1029 	struct timeval	 activity_time;
1030 
1031 	struct window_pane *active;
1032 	struct window_pane *last;
1033 	struct window_panes panes;
1034 
1035 	int		 lastlayout;
1036 	struct layout_cell *layout_root;
1037 	struct layout_cell *saved_layout_root;
1038 	char		*old_layout;
1039 
1040 	u_int		 sx;
1041 	u_int		 sy;
1042 	u_int		 manual_sx;
1043 	u_int		 manual_sy;
1044 	u_int		 xpixel;
1045 	u_int		 ypixel;
1046 
1047 	u_int		 new_sx;
1048 	u_int		 new_sy;
1049 	u_int		 new_xpixel;
1050 	u_int		 new_ypixel;
1051 
1052 	int		 flags;
1053 #define WINDOW_BELL 0x1
1054 #define WINDOW_ACTIVITY 0x2
1055 #define WINDOW_SILENCE 0x4
1056 #define WINDOW_ZOOMED 0x8
1057 #define WINDOW_WASZOOMED 0x10
1058 #define WINDOW_RESIZE 0x20
1059 #define WINDOW_ALERTFLAGS (WINDOW_BELL|WINDOW_ACTIVITY|WINDOW_SILENCE)
1060 
1061 	int		 alerts_queued;
1062 	TAILQ_ENTRY(window) alerts_entry;
1063 
1064 	struct options	*options;
1065 
1066 	u_int		 references;
1067 	TAILQ_HEAD(, winlink) winlinks;
1068 
1069 	RB_ENTRY(window) entry;
1070 };
1071 RB_HEAD(windows, window);
1072 
1073 /* Entry on local window list. */
1074 struct winlink {
1075 	int		 idx;
1076 	struct session	*session;
1077 	struct window	*window;
1078 
1079 	int		 flags;
1080 #define WINLINK_BELL 0x1
1081 #define WINLINK_ACTIVITY 0x2
1082 #define WINLINK_SILENCE 0x4
1083 #define WINLINK_ALERTFLAGS (WINLINK_BELL|WINLINK_ACTIVITY|WINLINK_SILENCE)
1084 
1085 	RB_ENTRY(winlink) entry;
1086 	TAILQ_ENTRY(winlink) wentry;
1087 	TAILQ_ENTRY(winlink) sentry;
1088 };
1089 RB_HEAD(winlinks, winlink);
1090 TAILQ_HEAD(winlink_stack, winlink);
1091 
1092 /* Window size option. */
1093 #define WINDOW_SIZE_LARGEST 0
1094 #define WINDOW_SIZE_SMALLEST 1
1095 #define WINDOW_SIZE_MANUAL 2
1096 #define WINDOW_SIZE_LATEST 3
1097 
1098 /* Pane border status option. */
1099 #define PANE_STATUS_OFF 0
1100 #define PANE_STATUS_TOP 1
1101 #define PANE_STATUS_BOTTOM 2
1102 
1103 /* Layout direction. */
1104 enum layout_type {
1105 	LAYOUT_LEFTRIGHT,
1106 	LAYOUT_TOPBOTTOM,
1107 	LAYOUT_WINDOWPANE
1108 };
1109 
1110 /* Layout cells queue. */
1111 TAILQ_HEAD(layout_cells, layout_cell);
1112 
1113 /* Layout cell. */
1114 struct layout_cell {
1115 	enum layout_type type;
1116 
1117 	struct layout_cell *parent;
1118 
1119 	u_int		 sx;
1120 	u_int		 sy;
1121 
1122 	u_int		 xoff;
1123 	u_int		 yoff;
1124 
1125 	struct window_pane *wp;
1126 	struct layout_cells cells;
1127 
1128 	TAILQ_ENTRY(layout_cell) entry;
1129 };
1130 
1131 /* Environment variable. */
1132 struct environ_entry {
1133 	char		*name;
1134 	char		*value;
1135 
1136 	int		 flags;
1137 #define ENVIRON_HIDDEN 0x1
1138 
1139 	RB_ENTRY(environ_entry) entry;
1140 };
1141 
1142 /* Client session. */
1143 struct session_group {
1144 	const char		*name;
1145 	TAILQ_HEAD(, session)	 sessions;
1146 
1147 	RB_ENTRY(session_group)	 entry;
1148 };
1149 RB_HEAD(session_groups, session_group);
1150 
1151 struct session {
1152 	u_int		 id;
1153 
1154 	char		*name;
1155 	const char	*cwd;
1156 
1157 	struct timeval	 creation_time;
1158 	struct timeval	 last_attached_time;
1159 	struct timeval	 activity_time;
1160 	struct timeval	 last_activity_time;
1161 
1162 	struct event	 lock_timer;
1163 
1164 	struct winlink	*curw;
1165 	struct winlink_stack lastw;
1166 	struct winlinks	 windows;
1167 
1168 	int		 statusat;
1169 	u_int		 statuslines;
1170 
1171 	struct options	*options;
1172 
1173 #define SESSION_PASTING 0x1
1174 #define SESSION_ALERTED 0x2
1175 	int		 flags;
1176 
1177 	u_int		 attached;
1178 
1179 	struct termios	*tio;
1180 
1181 	struct environ	*environ;
1182 
1183 	int		 references;
1184 
1185 	TAILQ_ENTRY(session) gentry;
1186 	RB_ENTRY(session)    entry;
1187 };
1188 RB_HEAD(sessions, session);
1189 
1190 /* Mouse button masks. */
1191 #define MOUSE_MASK_BUTTONS 3
1192 #define MOUSE_MASK_SHIFT 4
1193 #define MOUSE_MASK_META 8
1194 #define MOUSE_MASK_CTRL 16
1195 #define MOUSE_MASK_DRAG 32
1196 #define MOUSE_MASK_WHEEL 64
1197 #define MOUSE_MASK_MODIFIERS (MOUSE_MASK_SHIFT|MOUSE_MASK_META|MOUSE_MASK_CTRL)
1198 
1199 /* Mouse wheel states. */
1200 #define MOUSE_WHEEL_UP 0
1201 #define MOUSE_WHEEL_DOWN 1
1202 
1203 /* Mouse helpers. */
1204 #define MOUSE_BUTTONS(b) ((b) & MOUSE_MASK_BUTTONS)
1205 #define MOUSE_WHEEL(b) ((b) & MOUSE_MASK_WHEEL)
1206 #define MOUSE_DRAG(b) ((b) & MOUSE_MASK_DRAG)
1207 #define MOUSE_RELEASE(b) (((b) & MOUSE_MASK_BUTTONS) == 3)
1208 
1209 /* Mouse input. */
1210 struct mouse_event {
1211 	int		valid;
1212 	int		ignore;
1213 
1214 	key_code	key;
1215 
1216 	int		statusat;
1217 	u_int		statuslines;
1218 
1219 	u_int		x;
1220 	u_int		y;
1221 	u_int		b;
1222 
1223 	u_int		lx;
1224 	u_int		ly;
1225 	u_int		lb;
1226 
1227 	u_int		ox;
1228 	u_int		oy;
1229 
1230 	int		s;
1231 	int		w;
1232 	int		wp;
1233 
1234 	u_int		sgr_type;
1235 	u_int		sgr_b;
1236 };
1237 
1238 /* Key event. */
1239 struct key_event {
1240 	key_code		key;
1241 	struct mouse_event	m;
1242 };
1243 
1244 /* Terminal definition. */
1245 struct tty_term {
1246 	char		*name;
1247 	struct tty	*tty;
1248 	int		 features;
1249 
1250 	char		 acs[UCHAR_MAX + 1][2];
1251 
1252 	struct tty_code	*codes;
1253 
1254 #define TERM_256COLOURS 0x1
1255 #define TERM_NOAM 0x2
1256 #define TERM_DECSLRM 0x4
1257 #define TERM_DECFRA 0x8
1258 #define TERM_RGBCOLOURS 0x10
1259 #define TERM_VT100LIKE 0x20
1260 	int		 flags;
1261 
1262 	LIST_ENTRY(tty_term) entry;
1263 };
1264 LIST_HEAD(tty_terms, tty_term);
1265 
1266 /* Client terminal. */
1267 struct tty {
1268 	struct client	*client;
1269 	struct event	 start_timer;
1270 
1271 	u_int		 sx;
1272 	u_int		 sy;
1273 	u_int		 xpixel;
1274 	u_int		 ypixel;
1275 
1276 	u_int		 cx;
1277 	u_int		 cy;
1278 	enum screen_cursor_style cstyle;
1279 	char		*ccolour;
1280 
1281 	int		 oflag;
1282 	u_int		 oox;
1283 	u_int		 ooy;
1284 	u_int		 osx;
1285 	u_int		 osy;
1286 
1287 	int		 mode;
1288 
1289 	u_int		 rlower;
1290 	u_int		 rupper;
1291 
1292 	u_int		 rleft;
1293 	u_int		 rright;
1294 
1295 	struct event	 event_in;
1296 	struct evbuffer	*in;
1297 	struct event	 event_out;
1298 	struct evbuffer	*out;
1299 	struct event	 timer;
1300 	size_t		 discarded;
1301 
1302 	struct termios	 tio;
1303 
1304 	struct grid_cell cell;
1305 	struct grid_cell last_cell;
1306 
1307 #define TTY_NOCURSOR 0x1
1308 #define TTY_FREEZE 0x2
1309 #define TTY_TIMER 0x4
1310 /* 0x8 unused */
1311 #define TTY_STARTED 0x10
1312 #define TTY_OPENED 0x20
1313 /* 0x40 unused */
1314 #define TTY_BLOCK 0x80
1315 #define TTY_HAVEDA 0x100
1316 #define TTY_HAVEXDA 0x200
1317 #define TTY_SYNCING 0x400
1318 	int		 flags;
1319 
1320 	struct tty_term	*term;
1321 
1322 	u_int		 mouse_last_x;
1323 	u_int		 mouse_last_y;
1324 	u_int		 mouse_last_b;
1325 	int		 mouse_drag_flag;
1326 	void		(*mouse_drag_update)(struct client *,
1327 			    struct mouse_event *);
1328 	void		(*mouse_drag_release)(struct client *,
1329 			    struct mouse_event *);
1330 
1331 	struct event	 key_timer;
1332 	struct tty_key	*key_tree;
1333 };
1334 
1335 /* Terminal command context. */
1336 typedef void (*tty_ctx_redraw_cb)(const struct tty_ctx *);
1337 typedef int (*tty_ctx_set_client_cb)(struct tty_ctx *, struct client *);
1338 struct tty_ctx {
1339 	struct screen		*s;
1340 
1341 	tty_ctx_redraw_cb	 redraw_cb;
1342 	tty_ctx_set_client_cb	 set_client_cb;
1343 	void			*arg;
1344 
1345 	const struct grid_cell	*cell;
1346 	int			 wrapped;
1347 
1348 	u_int			 num;
1349 	void			*ptr;
1350 
1351 	/*
1352 	 * Cursor and region position before the screen was updated - this is
1353 	 * where the command should be applied; the values in the screen have
1354 	 * already been updated.
1355 	 */
1356 	u_int		 ocx;
1357 	u_int		 ocy;
1358 
1359 	u_int		 orupper;
1360 	u_int		 orlower;
1361 
1362 	/* Target region (usually pane) offset and size. */
1363 	u_int		 xoff;
1364 	u_int		 yoff;
1365 	u_int		 rxoff;
1366 	u_int		 ryoff;
1367 	u_int		 sx;
1368 	u_int		 sy;
1369 
1370 	/* The background colour used for clearing (erasing). */
1371 	u_int		 bg;
1372 
1373 	/* The default colours and palette. */
1374 	struct grid_cell defaults;
1375 	struct colour_palette *palette;
1376 
1377 	/* Containing region (usually window) offset and size. */
1378 	int		 bigger;
1379 	u_int		 wox;
1380 	u_int		 woy;
1381 	u_int		 wsx;
1382 	u_int		 wsy;
1383 };
1384 
1385 /* Saved message entry. */
1386 struct message_entry {
1387 	char				*msg;
1388 	u_int				 msg_num;
1389 	struct timeval			 msg_time;
1390 
1391 	TAILQ_ENTRY(message_entry)	 entry;
1392 };
1393 TAILQ_HEAD(message_list, message_entry);
1394 
1395 /* Argument type. */
1396 enum args_type {
1397 	ARGS_NONE,
1398 	ARGS_STRING,
1399 	ARGS_COMMANDS
1400 };
1401 
1402 /* Argument value. */
1403 struct args_value {
1404 	enum args_type		 type;
1405 	union {
1406 		char		*string;
1407 		struct cmd_list	*cmdlist;
1408 	};
1409 	char			*cached;
1410 	TAILQ_ENTRY(args_value)	 entry;
1411 };
1412 
1413 /* Arguments set. */
1414 struct args_entry;
1415 RB_HEAD(args_tree, args_entry);
1416 
1417 /* Arguments parsing type. */
1418 enum args_parse_type {
1419 	ARGS_PARSE_INVALID,
1420 	ARGS_PARSE_STRING,
1421 	ARGS_PARSE_COMMANDS_OR_STRING,
1422 	ARGS_PARSE_COMMANDS
1423 };
1424 
1425 /* Arguments parsing state. */
1426 typedef enum args_parse_type (*args_parse_cb)(struct args *, u_int, char **);
1427 struct args_parse {
1428 	const char	*template;
1429 	int		 lower;
1430 	int		 upper;
1431 	args_parse_cb	 cb;
1432 };
1433 
1434 /* Command find structures. */
1435 enum cmd_find_type {
1436 	CMD_FIND_PANE,
1437 	CMD_FIND_WINDOW,
1438 	CMD_FIND_SESSION,
1439 };
1440 struct cmd_find_state {
1441 	int			 flags;
1442 	struct cmd_find_state	*current;
1443 
1444 	struct session		*s;
1445 	struct winlink		*wl;
1446 	struct window		*w;
1447 	struct window_pane	*wp;
1448 	int			 idx;
1449 };
1450 
1451 /* Command find flags. */
1452 #define CMD_FIND_PREFER_UNATTACHED 0x1
1453 #define CMD_FIND_QUIET 0x2
1454 #define CMD_FIND_WINDOW_INDEX 0x4
1455 #define CMD_FIND_DEFAULT_MARKED 0x8
1456 #define CMD_FIND_EXACT_SESSION 0x10
1457 #define CMD_FIND_EXACT_WINDOW 0x20
1458 #define CMD_FIND_CANFAIL 0x40
1459 
1460 /* List of commands. */
1461 struct cmd_list {
1462 	int		 references;
1463 	u_int		 group;
1464 	struct cmds	*list;
1465 };
1466 
1467 /* Command return values. */
1468 enum cmd_retval {
1469 	CMD_RETURN_ERROR = -1,
1470 	CMD_RETURN_NORMAL = 0,
1471 	CMD_RETURN_WAIT,
1472 	CMD_RETURN_STOP
1473 };
1474 
1475 /* Command parse result. */
1476 enum cmd_parse_status {
1477 	CMD_PARSE_ERROR,
1478 	CMD_PARSE_SUCCESS
1479 };
1480 struct cmd_parse_result {
1481 	enum cmd_parse_status	 status;
1482 	struct cmd_list		*cmdlist;
1483 	char			*error;
1484 };
1485 struct cmd_parse_input {
1486 	int			 flags;
1487 #define CMD_PARSE_QUIET 0x1
1488 #define CMD_PARSE_PARSEONLY 0x2
1489 #define CMD_PARSE_NOALIAS 0x4
1490 #define CMD_PARSE_VERBOSE 0x8
1491 #define CMD_PARSE_ONEGROUP 0x10
1492 
1493 	const char		*file;
1494 	u_int			 line;
1495 
1496 	struct cmdq_item	*item;
1497 	struct client		*c;
1498 	struct cmd_find_state	 fs;
1499 };
1500 
1501 /* Command queue flags. */
1502 #define CMDQ_STATE_REPEAT 0x1
1503 #define CMDQ_STATE_CONTROL 0x2
1504 #define CMDQ_STATE_NOHOOKS 0x4
1505 
1506 /* Command queue callback. */
1507 typedef enum cmd_retval (*cmdq_cb) (struct cmdq_item *, void *);
1508 
1509 /* Command definition flag. */
1510 struct cmd_entry_flag {
1511 	char			 flag;
1512 	enum cmd_find_type	 type;
1513 	int			 flags;
1514 };
1515 
1516 /* Command definition. */
1517 struct cmd_entry {
1518 	const char		*name;
1519 	const char		*alias;
1520 
1521 	struct args_parse	 args;
1522 	const char		*usage;
1523 
1524 	struct cmd_entry_flag	 source;
1525 	struct cmd_entry_flag	 target;
1526 
1527 #define CMD_STARTSERVER 0x1
1528 #define CMD_READONLY 0x2
1529 #define CMD_AFTERHOOK 0x4
1530 #define CMD_CLIENT_CFLAG 0x8
1531 #define CMD_CLIENT_TFLAG 0x10
1532 #define CMD_CLIENT_CANFAIL 0x20
1533 	int		 flags;
1534 
1535 	enum cmd_retval	 (*exec)(struct cmd *, struct cmdq_item *);
1536 };
1537 
1538 /* Status line. */
1539 #define STATUS_LINES_LIMIT 5
1540 struct status_line_entry {
1541 	char			*expanded;
1542 	struct style_ranges	 ranges;
1543 };
1544 struct status_line {
1545 	struct event		 timer;
1546 
1547 	struct screen		 screen;
1548 	struct screen		*active;
1549 	int			 references;
1550 
1551 	struct grid_cell	 style;
1552 	struct status_line_entry entries[STATUS_LINES_LIMIT];
1553 };
1554 
1555 /* Prompt type. */
1556 #define PROMPT_NTYPES 4
1557 enum prompt_type {
1558 	PROMPT_TYPE_COMMAND,
1559 	PROMPT_TYPE_SEARCH,
1560 	PROMPT_TYPE_TARGET,
1561 	PROMPT_TYPE_WINDOW_TARGET,
1562 	PROMPT_TYPE_INVALID = 0xff
1563 };
1564 
1565 /* File in client. */
1566 typedef void (*client_file_cb) (struct client *, const char *, int, int,
1567     struct evbuffer *, void *);
1568 struct client_file {
1569 	struct client			*c;
1570 	struct tmuxpeer			*peer;
1571 	struct client_files		*tree;
1572 	int				 references;
1573 	int				 stream;
1574 
1575 	char				*path;
1576 	struct evbuffer			*buffer;
1577 	struct bufferevent		*event;
1578 
1579 	int				 fd;
1580 	int				 error;
1581 	int				 closed;
1582 
1583 	client_file_cb			 cb;
1584 	void				*data;
1585 
1586 	RB_ENTRY(client_file)		 entry;
1587 };
1588 RB_HEAD(client_files, client_file);
1589 
1590 /* Client window. */
1591 struct client_window {
1592 	u_int			 window;
1593 	struct window_pane	*pane;
1594 
1595 	u_int			 sx;
1596 	u_int			 sy;
1597 
1598 	RB_ENTRY(client_window)	 entry;
1599 };
1600 RB_HEAD(client_windows, client_window);
1601 
1602 /* Visible areas not obstructed by overlays. */
1603 #define OVERLAY_MAX_RANGES 3
1604 struct overlay_ranges {
1605 	u_int	px[OVERLAY_MAX_RANGES];
1606 	u_int	nx[OVERLAY_MAX_RANGES];
1607 };
1608 
1609 /* Client connection. */
1610 typedef int (*prompt_input_cb)(struct client *, void *, const char *, int);
1611 typedef void (*prompt_free_cb)(void *);
1612 typedef void (*overlay_check_cb)(struct client*, void *, u_int, u_int, u_int,
1613 	    struct overlay_ranges *);
1614 typedef struct screen *(*overlay_mode_cb)(struct client *, void *, u_int *,
1615 	    u_int *);
1616 typedef void (*overlay_draw_cb)(struct client *, void *,
1617 	    struct screen_redraw_ctx *);
1618 typedef int (*overlay_key_cb)(struct client *, void *, struct key_event *);
1619 typedef void (*overlay_free_cb)(struct client *, void *);
1620 typedef void (*overlay_resize_cb)(struct client *, void *);
1621 struct client {
1622 	const char	*name;
1623 	struct tmuxpeer	*peer;
1624 	struct cmdq_list *queue;
1625 
1626 	struct client_windows windows;
1627 
1628 	struct control_state *control_state;
1629 	u_int		 pause_age;
1630 
1631 	pid_t		 pid;
1632 	int		 fd;
1633 	int		 out_fd;
1634 	struct event	 event;
1635 	int		 retval;
1636 
1637 	struct timeval	 creation_time;
1638 	struct timeval	 activity_time;
1639 
1640 	struct environ	*environ;
1641 	struct format_job_tree	*jobs;
1642 
1643 	char		*title;
1644 	const char	*cwd;
1645 
1646 	char		*term_name;
1647 	int		 term_features;
1648 	char		*term_type;
1649 	char	       **term_caps;
1650 	u_int		 term_ncaps;
1651 
1652 	char		*ttyname;
1653 	struct tty	 tty;
1654 
1655 	size_t		 written;
1656 	size_t		 discarded;
1657 	size_t		 redraw;
1658 
1659 	struct event	 repeat_timer;
1660 
1661 	struct event	 click_timer;
1662 	u_int		 click_button;
1663 	struct mouse_event click_event;
1664 
1665 	struct status_line status;
1666 
1667 #define CLIENT_TERMINAL 0x1
1668 #define CLIENT_LOGIN 0x2
1669 #define CLIENT_EXIT 0x4
1670 #define CLIENT_REDRAWWINDOW 0x8
1671 #define CLIENT_REDRAWSTATUS 0x10
1672 #define CLIENT_REPEAT 0x20
1673 #define CLIENT_SUSPENDED 0x40
1674 #define CLIENT_ATTACHED 0x80
1675 #define CLIENT_EXITED 0x100
1676 #define CLIENT_DEAD 0x200
1677 #define CLIENT_REDRAWBORDERS 0x400
1678 #define CLIENT_READONLY 0x800
1679 #define CLIENT_NOSTARTSERVER 0x1000
1680 #define CLIENT_CONTROL 0x2000
1681 #define CLIENT_CONTROLCONTROL 0x4000
1682 #define CLIENT_FOCUSED 0x8000
1683 #define CLIENT_UTF8 0x10000
1684 #define CLIENT_IGNORESIZE 0x20000
1685 #define CLIENT_IDENTIFIED 0x40000
1686 #define CLIENT_STATUSFORCE 0x80000
1687 #define CLIENT_DOUBLECLICK 0x100000
1688 #define CLIENT_TRIPLECLICK 0x200000
1689 #define CLIENT_SIZECHANGED 0x400000
1690 #define CLIENT_STATUSOFF 0x800000
1691 #define CLIENT_REDRAWSTATUSALWAYS 0x1000000
1692 #define CLIENT_REDRAWOVERLAY 0x2000000
1693 #define CLIENT_CONTROL_NOOUTPUT 0x4000000
1694 #define CLIENT_DEFAULTSOCKET 0x8000000
1695 #define CLIENT_STARTSERVER 0x10000000
1696 #define CLIENT_REDRAWPANES 0x20000000
1697 #define CLIENT_NOFORK 0x40000000
1698 #define CLIENT_ACTIVEPANE 0x80000000ULL
1699 #define CLIENT_CONTROL_PAUSEAFTER 0x100000000ULL
1700 #define CLIENT_CONTROL_WAITEXIT 0x200000000ULL
1701 #define CLIENT_WINDOWSIZECHANGED 0x400000000ULL
1702 #define CLIENT_ALLREDRAWFLAGS		\
1703 	(CLIENT_REDRAWWINDOW|		\
1704 	 CLIENT_REDRAWSTATUS|		\
1705 	 CLIENT_REDRAWSTATUSALWAYS|	\
1706 	 CLIENT_REDRAWBORDERS|		\
1707 	 CLIENT_REDRAWOVERLAY|		\
1708 	 CLIENT_REDRAWPANES)
1709 #define CLIENT_UNATTACHEDFLAGS	\
1710 	(CLIENT_DEAD|		\
1711 	 CLIENT_SUSPENDED|	\
1712 	 CLIENT_EXIT)
1713 #define CLIENT_NOSIZEFLAGS	\
1714 	(CLIENT_DEAD|		\
1715 	 CLIENT_SUSPENDED|	\
1716 	 CLIENT_EXIT)
1717 	uint64_t	 flags;
1718 
1719 	enum {
1720 		CLIENT_EXIT_RETURN,
1721 		CLIENT_EXIT_SHUTDOWN,
1722 		CLIENT_EXIT_DETACH
1723 	}		 exit_type;
1724 	enum msgtype	 exit_msgtype;
1725 	char		*exit_session;
1726 	char		*exit_message;
1727 
1728 	struct key_table *keytable;
1729 
1730 	uint64_t	 redraw_panes;
1731 
1732 	int		 message_ignore_keys;
1733 	int		 message_ignore_styles;
1734 	char		*message_string;
1735 	struct event	 message_timer;
1736 
1737 	char		*prompt_string;
1738 	struct utf8_data *prompt_buffer;
1739 	char		*prompt_last;
1740 	size_t		 prompt_index;
1741 	prompt_input_cb	 prompt_inputcb;
1742 	prompt_free_cb	 prompt_freecb;
1743 	void		*prompt_data;
1744 	u_int		 prompt_hindex[PROMPT_NTYPES];
1745 	enum { PROMPT_ENTRY, PROMPT_COMMAND } prompt_mode;
1746 	struct utf8_data *prompt_saved;
1747 #define PROMPT_SINGLE 0x1
1748 #define PROMPT_NUMERIC 0x2
1749 #define PROMPT_INCREMENTAL 0x4
1750 #define PROMPT_NOFORMAT 0x8
1751 #define PROMPT_KEY 0x10
1752 	int		 prompt_flags;
1753 	enum prompt_type prompt_type;
1754 
1755 	struct session	*session;
1756 	struct session	*last_session;
1757 
1758 	int		 references;
1759 
1760 	void		*pan_window;
1761 	u_int		 pan_ox;
1762 	u_int		 pan_oy;
1763 
1764 	overlay_check_cb overlay_check;
1765 	overlay_mode_cb	 overlay_mode;
1766 	overlay_draw_cb	 overlay_draw;
1767 	overlay_key_cb	 overlay_key;
1768 	overlay_free_cb	 overlay_free;
1769 	overlay_resize_cb overlay_resize;
1770 	void		*overlay_data;
1771 	struct event	 overlay_timer;
1772 
1773 	struct client_files files;
1774 
1775 	TAILQ_ENTRY(client) entry;
1776 };
1777 TAILQ_HEAD(clients, client);
1778 
1779 /* Control mode subscription type. */
1780 enum control_sub_type {
1781 	CONTROL_SUB_SESSION,
1782 	CONTROL_SUB_PANE,
1783 	CONTROL_SUB_ALL_PANES,
1784 	CONTROL_SUB_WINDOW,
1785 	CONTROL_SUB_ALL_WINDOWS
1786 };
1787 
1788 /* Key binding and key table. */
1789 struct key_binding {
1790 	key_code		 key;
1791 	struct cmd_list		*cmdlist;
1792 	const char		*note;
1793 
1794 	int			 flags;
1795 #define KEY_BINDING_REPEAT 0x1
1796 
1797 	RB_ENTRY(key_binding)	 entry;
1798 };
1799 RB_HEAD(key_bindings, key_binding);
1800 
1801 struct key_table {
1802 	const char		*name;
1803 	struct key_bindings	 key_bindings;
1804 	struct key_bindings	 default_key_bindings;
1805 
1806 	u_int			 references;
1807 
1808 	RB_ENTRY(key_table)	 entry;
1809 };
1810 RB_HEAD(key_tables, key_table);
1811 
1812 /* Option data. */
1813 RB_HEAD(options_array, options_array_item);
1814 union options_value {
1815 	char			*string;
1816 	long long		 number;
1817 	struct style		 style;
1818 	struct options_array	 array;
1819 	struct cmd_list		*cmdlist;
1820 };
1821 
1822 /* Option table entries. */
1823 enum options_table_type {
1824 	OPTIONS_TABLE_STRING,
1825 	OPTIONS_TABLE_NUMBER,
1826 	OPTIONS_TABLE_KEY,
1827 	OPTIONS_TABLE_COLOUR,
1828 	OPTIONS_TABLE_FLAG,
1829 	OPTIONS_TABLE_CHOICE,
1830 	OPTIONS_TABLE_COMMAND
1831 };
1832 
1833 #define OPTIONS_TABLE_NONE 0
1834 #define OPTIONS_TABLE_SERVER 0x1
1835 #define OPTIONS_TABLE_SESSION 0x2
1836 #define OPTIONS_TABLE_WINDOW 0x4
1837 #define OPTIONS_TABLE_PANE 0x8
1838 
1839 #define OPTIONS_TABLE_IS_ARRAY 0x1
1840 #define OPTIONS_TABLE_IS_HOOK 0x2
1841 #define OPTIONS_TABLE_IS_STYLE 0x4
1842 
1843 struct options_table_entry {
1844 	const char		 *name;
1845 	const char		 *alternative_name;
1846 	enum options_table_type	  type;
1847 	int			  scope;
1848 	int			  flags;
1849 
1850 	u_int			  minimum;
1851 	u_int			  maximum;
1852 	const char		**choices;
1853 
1854 	const char		 *default_str;
1855 	long long		  default_num;
1856 	const char		**default_arr;
1857 
1858 	const char		 *separator;
1859 	const char		 *pattern;
1860 
1861 	const char		 *text;
1862 	const char		 *unit;
1863 };
1864 
1865 struct options_name_map {
1866 	const char		*from;
1867 	const char		*to;
1868 };
1869 
1870 /* Common command usages. */
1871 #define CMD_TARGET_PANE_USAGE "[-t target-pane]"
1872 #define CMD_TARGET_WINDOW_USAGE "[-t target-window]"
1873 #define CMD_TARGET_SESSION_USAGE "[-t target-session]"
1874 #define CMD_TARGET_CLIENT_USAGE "[-t target-client]"
1875 #define CMD_SRCDST_PANE_USAGE "[-s src-pane] [-t dst-pane]"
1876 #define CMD_SRCDST_WINDOW_USAGE "[-s src-window] [-t dst-window]"
1877 #define CMD_SRCDST_SESSION_USAGE "[-s src-session] [-t dst-session]"
1878 #define CMD_SRCDST_CLIENT_USAGE "[-s src-client] [-t dst-client]"
1879 #define CMD_BUFFER_USAGE "[-b buffer-name]"
1880 
1881 /* Spawn common context. */
1882 struct spawn_context {
1883 	struct cmdq_item	 *item;
1884 
1885 	struct session		 *s;
1886 	struct winlink		 *wl;
1887 	struct client		 *tc;
1888 
1889 	struct window_pane	 *wp0;
1890 	struct layout_cell	 *lc;
1891 
1892 	const char		 *name;
1893 	char			**argv;
1894 	int			  argc;
1895 	struct environ		 *environ;
1896 
1897 	int			  idx;
1898 	const char		 *cwd;
1899 
1900 	int			  flags;
1901 #define SPAWN_KILL 0x1
1902 #define SPAWN_DETACHED 0x2
1903 #define SPAWN_RESPAWN 0x4
1904 #define SPAWN_BEFORE 0x8
1905 #define SPAWN_NONOTIFY 0x10
1906 #define SPAWN_FULLSIZE 0x20
1907 #define SPAWN_EMPTY 0x40
1908 #define SPAWN_ZOOM 0x80
1909 };
1910 
1911 /* Mode tree sort order. */
1912 struct mode_tree_sort_criteria {
1913 	u_int	field;
1914 	int	reversed;
1915 };
1916 
1917 /* tmux.c */
1918 extern struct options	*global_options;
1919 extern struct options	*global_s_options;
1920 extern struct options	*global_w_options;
1921 extern struct environ	*global_environ;
1922 extern struct timeval	 start_time;
1923 extern const char	*socket_path;
1924 extern const char	*shell_command;
1925 extern int		 ptm_fd;
1926 extern const char	*shell_command;
1927 int		 checkshell(const char *);
1928 void		 setblocking(int, int);
1929 uint64_t	 get_timer(void);
1930 const char	*sig2name(int);
1931 const char	*find_cwd(void);
1932 const char	*find_home(void);
1933 const char	*getversion(void);
1934 
1935 /* proc.c */
1936 struct imsg;
1937 int	proc_send(struct tmuxpeer *, enum msgtype, int, const void *, size_t);
1938 struct tmuxproc *proc_start(const char *);
1939 void	proc_loop(struct tmuxproc *, int (*)(void));
1940 void	proc_exit(struct tmuxproc *);
1941 void	proc_set_signals(struct tmuxproc *, void(*)(int));
1942 void	proc_clear_signals(struct tmuxproc *, int);
1943 struct tmuxpeer *proc_add_peer(struct tmuxproc *, int,
1944 	    void (*)(struct imsg *, void *), void *);
1945 void	proc_remove_peer(struct tmuxpeer *);
1946 void	proc_kill_peer(struct tmuxpeer *);
1947 void	proc_toggle_log(struct tmuxproc *);
1948 pid_t	proc_fork_and_daemon(int *);
1949 
1950 /* cfg.c */
1951 extern int cfg_finished;
1952 extern struct client *cfg_client;
1953 extern char **cfg_files;
1954 extern u_int cfg_nfiles;
1955 extern int cfg_quiet;
1956 void	start_cfg(void);
1957 int	load_cfg(const char *, struct client *, struct cmdq_item *, int,
1958 	    struct cmdq_item **);
1959 int	load_cfg_from_buffer(const void *, size_t, const char *,
1960 	    struct client *, struct cmdq_item *, int, struct cmdq_item **);
1961 void printflike(1, 2) cfg_add_cause(const char *, ...);
1962 void	cfg_print_causes(struct cmdq_item *);
1963 void	cfg_show_causes(struct session *);
1964 
1965 /* paste.c */
1966 struct paste_buffer;
1967 const char	*paste_buffer_name(struct paste_buffer *);
1968 u_int		 paste_buffer_order(struct paste_buffer *);
1969 time_t		 paste_buffer_created(struct paste_buffer *);
1970 const char	*paste_buffer_data(struct paste_buffer *, size_t *);
1971 struct paste_buffer *paste_walk(struct paste_buffer *);
1972 struct paste_buffer *paste_get_top(const char **);
1973 struct paste_buffer *paste_get_name(const char *);
1974 void		 paste_free(struct paste_buffer *);
1975 void		 paste_add(const char *, char *, size_t);
1976 int		 paste_rename(const char *, const char *, char **);
1977 int		 paste_set(char *, size_t, const char *, char **);
1978 void		 paste_replace(struct paste_buffer *, char *, size_t);
1979 char		*paste_make_sample(struct paste_buffer *);
1980 
1981 /* format.c */
1982 #define FORMAT_STATUS 0x1
1983 #define FORMAT_FORCE 0x2
1984 #define FORMAT_NOJOBS 0x4
1985 #define FORMAT_VERBOSE 0x8
1986 #define FORMAT_NONE 0
1987 #define FORMAT_PANE 0x80000000U
1988 #define FORMAT_WINDOW 0x40000000U
1989 struct format_tree;
1990 struct format_modifier;
1991 typedef void *(*format_cb)(struct format_tree *);
1992 void		 format_tidy_jobs(void);
1993 const char	*format_skip(const char *, const char *);
1994 int		 format_true(const char *);
1995 struct format_tree *format_create(struct client *, struct cmdq_item *, int,
1996 		     int);
1997 void		 format_free(struct format_tree *);
1998 void		 format_merge(struct format_tree *, struct format_tree *);
1999 struct window_pane *format_get_pane(struct format_tree *);
2000 void printflike(3, 4) format_add(struct format_tree *, const char *,
2001 		     const char *, ...);
2002 void		 format_add_tv(struct format_tree *, const char *,
2003 		     struct timeval *);
2004 void		 format_add_cb(struct format_tree *, const char *, format_cb);
2005 void		 format_log_debug(struct format_tree *, const char *);
2006 void		 format_each(struct format_tree *, void (*)(const char *,
2007 		     const char *, void *), void *);
2008 char		*format_expand_time(struct format_tree *, const char *);
2009 char		*format_expand(struct format_tree *, const char *);
2010 char		*format_single(struct cmdq_item *, const char *,
2011 		     struct client *, struct session *, struct winlink *,
2012 		     struct window_pane *);
2013 char		*format_single_from_state(struct cmdq_item *, const char *,
2014 		    struct client *, struct cmd_find_state *);
2015 char		*format_single_from_target(struct cmdq_item *, const char *);
2016 struct format_tree *format_create_defaults(struct cmdq_item *, struct client *,
2017 		     struct session *, struct winlink *, struct window_pane *);
2018 struct format_tree *format_create_from_state(struct cmdq_item *,
2019 		     struct client *, struct cmd_find_state *);
2020 struct format_tree *format_create_from_target(struct cmdq_item *);
2021 void		 format_defaults(struct format_tree *, struct client *,
2022 		     struct session *, struct winlink *, struct window_pane *);
2023 void		 format_defaults_window(struct format_tree *, struct window *);
2024 void		 format_defaults_pane(struct format_tree *,
2025 		     struct window_pane *);
2026 void		 format_defaults_paste_buffer(struct format_tree *,
2027 		     struct paste_buffer *);
2028 void		 format_lost_client(struct client *);
2029 char		*format_grid_word(struct grid *, u_int, u_int);
2030 char		*format_grid_line(struct grid *, u_int);
2031 
2032 /* format-draw.c */
2033 void		 format_draw(struct screen_write_ctx *,
2034 		     const struct grid_cell *, u_int, const char *,
2035 		     struct style_ranges *);
2036 u_int		 format_width(const char *);
2037 char		*format_trim_left(const char *, u_int);
2038 char		*format_trim_right(const char *, u_int);
2039 
2040 /* notify.c */
2041 void	notify_hook(struct cmdq_item *, const char *);
2042 void	notify_client(const char *, struct client *);
2043 void	notify_session(const char *, struct session *);
2044 void	notify_winlink(const char *, struct winlink *);
2045 void	notify_session_window(const char *, struct session *, struct window *);
2046 void	notify_window(const char *, struct window *);
2047 void	notify_pane(const char *, struct window_pane *);
2048 
2049 /* options.c */
2050 struct options	*options_create(struct options *);
2051 void		 options_free(struct options *);
2052 struct options	*options_get_parent(struct options *);
2053 void		 options_set_parent(struct options *, struct options *);
2054 struct options_entry *options_first(struct options *);
2055 struct options_entry *options_next(struct options_entry *);
2056 struct options_entry *options_empty(struct options *,
2057 		     const struct options_table_entry *);
2058 struct options_entry *options_default(struct options *,
2059 		     const struct options_table_entry *);
2060 char		*options_default_to_string(const struct options_table_entry *);
2061 const char	*options_name(struct options_entry *);
2062 struct options	*options_owner(struct options_entry *);
2063 const struct options_table_entry *options_table_entry(struct options_entry *);
2064 struct options_entry *options_get_only(struct options *, const char *);
2065 struct options_entry *options_get(struct options *, const char *);
2066 void		 options_array_clear(struct options_entry *);
2067 union options_value *options_array_get(struct options_entry *, u_int);
2068 int		 options_array_set(struct options_entry *, u_int, const char *,
2069 		     int, char **);
2070 int		 options_array_assign(struct options_entry *, const char *,
2071 		     char **);
2072 struct options_array_item *options_array_first(struct options_entry *);
2073 struct options_array_item *options_array_next(struct options_array_item *);
2074 u_int		 options_array_item_index(struct options_array_item *);
2075 union options_value *options_array_item_value(struct options_array_item *);
2076 int		 options_is_array(struct options_entry *);
2077 int		 options_is_string(struct options_entry *);
2078 char		*options_to_string(struct options_entry *, int, int);
2079 char		*options_parse(const char *, int *);
2080 struct options_entry *options_parse_get(struct options *, const char *, int *,
2081 		     int);
2082 char		*options_match(const char *, int *, int *);
2083 struct options_entry *options_match_get(struct options *, const char *, int *,
2084 		     int, int *);
2085 const char	*options_get_string(struct options *, const char *);
2086 long long	 options_get_number(struct options *, const char *);
2087 struct options_entry * printflike(4, 5) options_set_string(struct options *,
2088 		     const char *, int, const char *, ...);
2089 struct options_entry *options_set_number(struct options *, const char *,
2090 		     long long);
2091 int		 options_scope_from_name(struct args *, int,
2092 		     const char *, struct cmd_find_state *, struct options **,
2093 		     char **);
2094 int		 options_scope_from_flags(struct args *, int,
2095 		     struct cmd_find_state *, struct options **, char **);
2096 struct style	*options_string_to_style(struct options *, const char *,
2097 		     struct format_tree *);
2098 int		 options_from_string(struct options *,
2099 		     const struct options_table_entry *, const char *,
2100 		     const char *, int, char **);
2101 int	 	 options_find_choice(const struct options_table_entry *,
2102 		     const char *, char **);
2103 void		 options_push_changes(const char *);
2104 int		 options_remove_or_default(struct options_entry *, int,
2105 		     char **);
2106 
2107 /* options-table.c */
2108 extern const struct options_table_entry	options_table[];
2109 extern const struct options_name_map	options_other_names[];
2110 
2111 /* job.c */
2112 typedef void (*job_update_cb) (struct job *);
2113 typedef void (*job_complete_cb) (struct job *);
2114 typedef void (*job_free_cb) (void *);
2115 #define JOB_NOWAIT 0x1
2116 #define JOB_KEEPWRITE 0x2
2117 #define JOB_PTY 0x4
2118 struct job	*job_run(const char *, int, char **, struct environ *,
2119 		     struct session *, const char *, job_update_cb,
2120 		     job_complete_cb, job_free_cb, void *, int, int, int);
2121 void		 job_free(struct job *);
2122 int		 job_transfer(struct job *, pid_t *, char *, size_t);
2123 void		 job_resize(struct job *, u_int, u_int);
2124 void		 job_check_died(pid_t, int);
2125 int		 job_get_status(struct job *);
2126 void		*job_get_data(struct job *);
2127 struct bufferevent *job_get_event(struct job *);
2128 void		 job_kill_all(void);
2129 int		 job_still_running(void);
2130 void		 job_print_summary(struct cmdq_item *, int);
2131 
2132 /* environ.c */
2133 struct environ *environ_create(void);
2134 void	environ_free(struct environ *);
2135 struct environ_entry *environ_first(struct environ *);
2136 struct environ_entry *environ_next(struct environ_entry *);
2137 void	environ_copy(struct environ *, struct environ *);
2138 struct environ_entry *environ_find(struct environ *, const char *);
2139 void printflike(4, 5) environ_set(struct environ *, const char *, int,
2140 	    const char *, ...);
2141 void	environ_clear(struct environ *, const char *);
2142 void	environ_put(struct environ *, const char *, int);
2143 void	environ_unset(struct environ *, const char *);
2144 void	environ_update(struct options *, struct environ *, struct environ *);
2145 void	environ_push(struct environ *);
2146 void printflike(2, 3) environ_log(struct environ *, const char *, ...);
2147 struct environ *environ_for_session(struct session *, int);
2148 
2149 /* tty.c */
2150 void	tty_create_log(void);
2151 int	tty_window_bigger(struct tty *);
2152 int	tty_window_offset(struct tty *, u_int *, u_int *, u_int *, u_int *);
2153 void	tty_update_window_offset(struct window *);
2154 void	tty_update_client_offset(struct client *);
2155 void	tty_raw(struct tty *, const char *);
2156 void	tty_attributes(struct tty *, const struct grid_cell *,
2157 	    const struct grid_cell *, struct colour_palette *);
2158 void	tty_reset(struct tty *);
2159 void	tty_region_off(struct tty *);
2160 void	tty_margin_off(struct tty *);
2161 void	tty_cursor(struct tty *, u_int, u_int);
2162 void	tty_putcode(struct tty *, enum tty_code_code);
2163 void	tty_putcode1(struct tty *, enum tty_code_code, int);
2164 void	tty_putcode2(struct tty *, enum tty_code_code, int, int);
2165 void	tty_putcode3(struct tty *, enum tty_code_code, int, int, int);
2166 void	tty_putcode_ptr1(struct tty *, enum tty_code_code, const void *);
2167 void	tty_putcode_ptr2(struct tty *, enum tty_code_code, const void *,
2168 	    const void *);
2169 void	tty_puts(struct tty *, const char *);
2170 void	tty_putc(struct tty *, u_char);
2171 void	tty_putn(struct tty *, const void *, size_t, u_int);
2172 void	tty_cell(struct tty *, const struct grid_cell *,
2173 	    const struct grid_cell *, struct colour_palette *);
2174 int	tty_init(struct tty *, struct client *);
2175 void	tty_resize(struct tty *);
2176 void	tty_set_size(struct tty *, u_int, u_int, u_int, u_int);
2177 void	tty_start_tty(struct tty *);
2178 void	tty_send_requests(struct tty *);
2179 void	tty_stop_tty(struct tty *);
2180 void	tty_set_title(struct tty *, const char *);
2181 void	tty_update_mode(struct tty *, int, struct screen *);
2182 void	tty_draw_line(struct tty *, struct screen *, u_int, u_int, u_int,
2183 	    u_int, u_int, const struct grid_cell *, struct colour_palette *);
2184 void	tty_sync_start(struct tty *);
2185 void	tty_sync_end(struct tty *);
2186 int	tty_open(struct tty *, char **);
2187 void	tty_close(struct tty *);
2188 void	tty_free(struct tty *);
2189 void	tty_update_features(struct tty *);
2190 void	tty_set_selection(struct tty *, const char *, size_t);
2191 void	tty_write(void (*)(struct tty *, const struct tty_ctx *),
2192 	    struct tty_ctx *);
2193 void	tty_cmd_alignmenttest(struct tty *, const struct tty_ctx *);
2194 void	tty_cmd_cell(struct tty *, const struct tty_ctx *);
2195 void	tty_cmd_cells(struct tty *, const struct tty_ctx *);
2196 void	tty_cmd_clearendofline(struct tty *, const struct tty_ctx *);
2197 void	tty_cmd_clearendofscreen(struct tty *, const struct tty_ctx *);
2198 void	tty_cmd_clearline(struct tty *, const struct tty_ctx *);
2199 void	tty_cmd_clearscreen(struct tty *, const struct tty_ctx *);
2200 void	tty_cmd_clearstartofline(struct tty *, const struct tty_ctx *);
2201 void	tty_cmd_clearstartofscreen(struct tty *, const struct tty_ctx *);
2202 void	tty_cmd_deletecharacter(struct tty *, const struct tty_ctx *);
2203 void	tty_cmd_clearcharacter(struct tty *, const struct tty_ctx *);
2204 void	tty_cmd_deleteline(struct tty *, const struct tty_ctx *);
2205 void	tty_cmd_erasecharacter(struct tty *, const struct tty_ctx *);
2206 void	tty_cmd_insertcharacter(struct tty *, const struct tty_ctx *);
2207 void	tty_cmd_insertline(struct tty *, const struct tty_ctx *);
2208 void	tty_cmd_linefeed(struct tty *, const struct tty_ctx *);
2209 void	tty_cmd_scrollup(struct tty *, const struct tty_ctx *);
2210 void	tty_cmd_scrolldown(struct tty *, const struct tty_ctx *);
2211 void	tty_cmd_reverseindex(struct tty *, const struct tty_ctx *);
2212 void	tty_cmd_setselection(struct tty *, const struct tty_ctx *);
2213 void	tty_cmd_rawstring(struct tty *, const struct tty_ctx *);
2214 void	tty_cmd_syncstart(struct tty *, const struct tty_ctx *);
2215 void	tty_default_colours(struct grid_cell *, struct window_pane *);
2216 
2217 /* tty-term.c */
2218 extern struct tty_terms tty_terms;
2219 u_int		 tty_term_ncodes(void);
2220 void		 tty_term_apply(struct tty_term *, const char *, int);
2221 void		 tty_term_apply_overrides(struct tty_term *);
2222 struct tty_term *tty_term_create(struct tty *, char *, char **, u_int, int *,
2223 		     char **);
2224 void		 tty_term_free(struct tty_term *);
2225 int		 tty_term_read_list(const char *, int, char ***, u_int *,
2226 		     char **);
2227 void		 tty_term_free_list(char **, u_int);
2228 int		 tty_term_has(struct tty_term *, enum tty_code_code);
2229 const char	*tty_term_string(struct tty_term *, enum tty_code_code);
2230 const char	*tty_term_string1(struct tty_term *, enum tty_code_code, int);
2231 const char	*tty_term_string2(struct tty_term *, enum tty_code_code, int,
2232 		     int);
2233 const char	*tty_term_string3(struct tty_term *, enum tty_code_code, int,
2234 		     int, int);
2235 const char	*tty_term_ptr1(struct tty_term *, enum tty_code_code,
2236 		     const void *);
2237 const char	*tty_term_ptr2(struct tty_term *, enum tty_code_code,
2238 		     const void *, const void *);
2239 int		 tty_term_number(struct tty_term *, enum tty_code_code);
2240 int		 tty_term_flag(struct tty_term *, enum tty_code_code);
2241 const char	*tty_term_describe(struct tty_term *, enum tty_code_code);
2242 
2243 /* tty-features.c */
2244 void		 tty_add_features(int *, const char *, const char *);
2245 const char	*tty_get_features(int);
2246 int		 tty_apply_features(struct tty_term *, int);
2247 void		 tty_default_features(int *, const char *, u_int);
2248 
2249 /* tty-acs.c */
2250 int		 tty_acs_needed(struct tty *);
2251 const char	*tty_acs_get(struct tty *, u_char);
2252 int		 tty_acs_reverse_get(struct tty *, const char *, size_t);
2253 const struct utf8_data *tty_acs_double_borders(int);
2254 const struct utf8_data *tty_acs_heavy_borders(int);
2255 const struct utf8_data *tty_acs_rounded_borders(int);
2256 
2257 /* tty-keys.c */
2258 void		tty_keys_build(struct tty *);
2259 void		tty_keys_free(struct tty *);
2260 int		tty_keys_next(struct tty *);
2261 
2262 /* arguments.c */
2263 void		 args_set(struct args *, u_char, struct args_value *);
2264 struct args 	*args_create(void);
2265 struct args	*args_parse(const struct args_parse *, struct args_value *,
2266 		     u_int, char **);
2267 struct args	*args_copy(struct args *, int, char **);
2268 void		 args_to_vector(struct args *, int *, char ***);
2269 struct args_value *args_from_vector(int, char **);
2270 void		 args_free_value(struct args_value *);
2271 void		 args_free_values(struct args_value *, u_int);
2272 void		 args_free(struct args *);
2273 char		*args_print(struct args *);
2274 char		*args_escape(const char *);
2275 int		 args_has(struct args *, u_char);
2276 const char	*args_get(struct args *, u_char);
2277 u_char		 args_first(struct args *, struct args_entry **);
2278 u_char		 args_next(struct args_entry **);
2279 u_int		 args_count(struct args *);
2280 struct args_value *args_values(struct args *);
2281 struct args_value *args_value(struct args *, u_int);
2282 const char	*args_string(struct args *, u_int);
2283 struct cmd_list	*args_make_commands_now(struct cmd *, struct cmdq_item *,
2284 		     u_int, int);
2285 struct args_command_state *args_make_commands_prepare(struct cmd *,
2286 		     struct cmdq_item *, u_int, const char *, int, int);
2287 struct cmd_list *args_make_commands(struct args_command_state *, int, char **,
2288 		     char **);
2289 void		 args_make_commands_free(struct args_command_state *);
2290 char		*args_make_commands_get_command(struct args_command_state *);
2291 struct args_value *args_first_value(struct args *, u_char);
2292 struct args_value *args_next_value(struct args_value *);
2293 long long	 args_strtonum(struct args *, u_char, long long, long long,
2294 		     char **);
2295 long long	 args_percentage(struct args *, u_char, long long,
2296 		     long long, long long, char **);
2297 long long	 args_string_percentage(const char *, long long, long long,
2298 		     long long, char **);
2299 
2300 /* cmd-find.c */
2301 int		 cmd_find_target(struct cmd_find_state *, struct cmdq_item *,
2302 		     const char *, enum cmd_find_type, int);
2303 struct client	*cmd_find_best_client(struct session *);
2304 struct client	*cmd_find_client(struct cmdq_item *, const char *, int);
2305 void		 cmd_find_clear_state(struct cmd_find_state *, int);
2306 int		 cmd_find_empty_state(struct cmd_find_state *);
2307 int		 cmd_find_valid_state(struct cmd_find_state *);
2308 void		 cmd_find_copy_state(struct cmd_find_state *,
2309 		     struct cmd_find_state *);
2310 void		 cmd_find_from_session(struct cmd_find_state *,
2311 		     struct session *, int);
2312 void		 cmd_find_from_winlink(struct cmd_find_state *,
2313 		     struct winlink *, int);
2314 int		 cmd_find_from_session_window(struct cmd_find_state *,
2315 		     struct session *, struct window *, int);
2316 int		 cmd_find_from_window(struct cmd_find_state *, struct window *,
2317 		     int);
2318 void		 cmd_find_from_winlink_pane(struct cmd_find_state *,
2319 		     struct winlink *, struct window_pane *, int);
2320 int		 cmd_find_from_pane(struct cmd_find_state *,
2321 		     struct window_pane *, int);
2322 int		 cmd_find_from_client(struct cmd_find_state *, struct client *,
2323 		     int);
2324 int		 cmd_find_from_mouse(struct cmd_find_state *,
2325 		     struct mouse_event *, int);
2326 int		 cmd_find_from_nothing(struct cmd_find_state *, int);
2327 
2328 /* cmd.c */
2329 extern const struct cmd_entry *cmd_table[];
2330 void printflike(3, 4) cmd_log_argv(int, char **, const char *, ...);
2331 void		 cmd_prepend_argv(int *, char ***, const char *);
2332 void		 cmd_append_argv(int *, char ***, const char *);
2333 int		 cmd_pack_argv(int, char **, char *, size_t);
2334 int		 cmd_unpack_argv(char *, size_t, int, char ***);
2335 char	       **cmd_copy_argv(int, char **);
2336 void		 cmd_free_argv(int, char **);
2337 char		*cmd_stringify_argv(int, char **);
2338 char		*cmd_get_alias(const char *);
2339 const struct cmd_entry *cmd_get_entry(struct cmd *);
2340 struct args	*cmd_get_args(struct cmd *);
2341 u_int		 cmd_get_group(struct cmd *);
2342 void		 cmd_get_source(struct cmd *, const char **, u_int *);
2343 struct cmd	*cmd_parse(struct args_value *, u_int, const char *, u_int,
2344 		     char **);
2345 struct cmd	*cmd_copy(struct cmd *, int, char **);
2346 void		 cmd_free(struct cmd *);
2347 char		*cmd_print(struct cmd *);
2348 struct cmd_list	*cmd_list_new(void);
2349 struct cmd_list	*cmd_list_copy(struct cmd_list *, int, char **);
2350 void		 cmd_list_append(struct cmd_list *, struct cmd *);
2351 void		 cmd_list_append_all(struct cmd_list *, struct cmd_list *);
2352 void		 cmd_list_move(struct cmd_list *, struct cmd_list *);
2353 void		 cmd_list_free(struct cmd_list *);
2354 char		*cmd_list_print(struct cmd_list *, int);
2355 struct cmd	*cmd_list_first(struct cmd_list *);
2356 struct cmd	*cmd_list_next(struct cmd *);
2357 int		 cmd_list_all_have(struct cmd_list *, int);
2358 int		 cmd_list_any_have(struct cmd_list *, int);
2359 int		 cmd_mouse_at(struct window_pane *, struct mouse_event *,
2360 		     u_int *, u_int *, int);
2361 struct winlink	*cmd_mouse_window(struct mouse_event *, struct session **);
2362 struct window_pane *cmd_mouse_pane(struct mouse_event *, struct session **,
2363 		     struct winlink **);
2364 char		*cmd_template_replace(const char *, const char *, int);
2365 
2366 /* cmd-attach-session.c */
2367 enum cmd_retval	 cmd_attach_session(struct cmdq_item *, const char *, int, int,
2368 		     int, const char *, int, const char *);
2369 
2370 /* cmd-parse.c */
2371 void		 cmd_parse_empty(struct cmd_parse_input *);
2372 struct cmd_parse_result *cmd_parse_from_file(FILE *, struct cmd_parse_input *);
2373 struct cmd_parse_result *cmd_parse_from_string(const char *,
2374 		     struct cmd_parse_input *);
2375 enum cmd_parse_status cmd_parse_and_insert(const char *,
2376 		     struct cmd_parse_input *, struct cmdq_item *,
2377 		     struct cmdq_state *, char **);
2378 enum cmd_parse_status cmd_parse_and_append(const char *,
2379 		     struct cmd_parse_input *, struct client *,
2380 		     struct cmdq_state *, char **);
2381 struct cmd_parse_result *cmd_parse_from_buffer(const void *, size_t,
2382 		     struct cmd_parse_input *);
2383 struct cmd_parse_result *cmd_parse_from_arguments(struct args_value *, u_int,
2384 		     struct cmd_parse_input *);
2385 
2386 /* cmd-queue.c */
2387 struct cmdq_state *cmdq_new_state(struct cmd_find_state *, struct key_event *,
2388 		     int);
2389 struct cmdq_state *cmdq_link_state(struct cmdq_state *);
2390 struct cmdq_state *cmdq_copy_state(struct cmdq_state *);
2391 void		  cmdq_free_state(struct cmdq_state *);
2392 void printflike(3, 4) cmdq_add_format(struct cmdq_state *, const char *,
2393 		     const char *, ...);
2394 void		  cmdq_add_formats(struct cmdq_state *, struct format_tree *);
2395 void		  cmdq_merge_formats(struct cmdq_item *, struct format_tree *);
2396 struct cmdq_list *cmdq_new(void);
2397 void cmdq_free(struct cmdq_list *);
2398 const char	 *cmdq_get_name(struct cmdq_item *);
2399 struct client	 *cmdq_get_client(struct cmdq_item *);
2400 struct client	 *cmdq_get_target_client(struct cmdq_item *);
2401 struct cmdq_state *cmdq_get_state(struct cmdq_item *);
2402 struct cmd_find_state *cmdq_get_target(struct cmdq_item *);
2403 struct cmd_find_state *cmdq_get_source(struct cmdq_item *);
2404 struct key_event *cmdq_get_event(struct cmdq_item *);
2405 struct cmd_find_state *cmdq_get_current(struct cmdq_item *);
2406 int		  cmdq_get_flags(struct cmdq_item *);
2407 struct cmdq_item *cmdq_get_command(struct cmd_list *, struct cmdq_state *);
2408 #define cmdq_get_callback(cb, data) cmdq_get_callback1(#cb, cb, data)
2409 struct cmdq_item *cmdq_get_callback1(const char *, cmdq_cb, void *);
2410 struct cmdq_item *cmdq_get_error(const char *);
2411 struct cmdq_item *cmdq_insert_after(struct cmdq_item *, struct cmdq_item *);
2412 struct cmdq_item *cmdq_append(struct client *, struct cmdq_item *);
2413 void printflike(4, 5) cmdq_insert_hook(struct session *, struct cmdq_item *,
2414 		     struct cmd_find_state *, const char *, ...);
2415 void		 cmdq_continue(struct cmdq_item *);
2416 u_int		 cmdq_next(struct client *);
2417 struct cmdq_item *cmdq_running(struct client *);
2418 void		 cmdq_guard(struct cmdq_item *, const char *, int);
2419 void printflike(2, 3) cmdq_print(struct cmdq_item *, const char *, ...);
2420 void printflike(2, 3) cmdq_error(struct cmdq_item *, const char *, ...);
2421 
2422 /* cmd-wait-for.c */
2423 void	cmd_wait_for_flush(void);
2424 
2425 /* client.c */
2426 int	client_main(struct event_base *, int, char **, uint64_t, int);
2427 
2428 /* key-bindings.c */
2429 struct key_table *key_bindings_get_table(const char *, int);
2430 struct key_table *key_bindings_first_table(void);
2431 struct key_table *key_bindings_next_table(struct key_table *);
2432 void	 key_bindings_unref_table(struct key_table *);
2433 struct key_binding *key_bindings_get(struct key_table *, key_code);
2434 struct key_binding *key_bindings_get_default(struct key_table *, key_code);
2435 struct key_binding *key_bindings_first(struct key_table *);
2436 struct key_binding *key_bindings_next(struct key_table *, struct key_binding *);
2437 void	 key_bindings_add(const char *, key_code, const char *, int,
2438 	     struct cmd_list *);
2439 void	 key_bindings_remove(const char *, key_code);
2440 void	 key_bindings_reset(const char *, key_code);
2441 void	 key_bindings_remove_table(const char *);
2442 void	 key_bindings_reset_table(const char *);
2443 void	 key_bindings_init(void);
2444 struct cmdq_item *key_bindings_dispatch(struct key_binding *,
2445 	     struct cmdq_item *, struct client *, struct key_event *,
2446 	     struct cmd_find_state *);
2447 
2448 /* key-string.c */
2449 key_code	 key_string_lookup_string(const char *);
2450 const char	*key_string_lookup_key(key_code, int);
2451 
2452 /* alerts.c */
2453 void	alerts_reset_all(void);
2454 void	alerts_queue(struct window *, int);
2455 void	alerts_check_session(struct session *);
2456 
2457 /* file.c */
2458 int	 file_cmp(struct client_file *, struct client_file *);
2459 RB_PROTOTYPE(client_files, client_file, entry, file_cmp);
2460 struct client_file *file_create_with_peer(struct tmuxpeer *,
2461 	    struct client_files *, int, client_file_cb, void *);
2462 struct client_file *file_create_with_client(struct client *, int,
2463 	    client_file_cb, void *);
2464 void	 file_free(struct client_file *);
2465 void	 file_fire_done(struct client_file *);
2466 void	 file_fire_read(struct client_file *);
2467 int	 file_can_print(struct client *);
2468 void printflike(2, 3) file_print(struct client *, const char *, ...);
2469 void printflike(2, 0) file_vprint(struct client *, const char *, va_list);
2470 void	 file_print_buffer(struct client *, void *, size_t);
2471 void printflike(2, 3) file_error(struct client *, const char *, ...);
2472 void	 file_write(struct client *, const char *, int, const void *, size_t,
2473 	     client_file_cb, void *);
2474 void	 file_read(struct client *, const char *, client_file_cb, void *);
2475 void	 file_push(struct client_file *);
2476 int	 file_write_left(struct client_files *);
2477 void	 file_write_open(struct client_files *, struct tmuxpeer *,
2478 	     struct imsg *, int, int, client_file_cb, void *);
2479 void	 file_write_data(struct client_files *, struct imsg *);
2480 void	 file_write_close(struct client_files *, struct imsg *);
2481 void	 file_read_open(struct client_files *, struct tmuxpeer *, struct imsg *,
2482 	     int, int, client_file_cb, void *);
2483 void	 file_write_ready(struct client_files *, struct imsg *);
2484 void	 file_read_data(struct client_files *, struct imsg *);
2485 void	 file_read_done(struct client_files *, struct imsg *);
2486 
2487 /* server.c */
2488 extern struct tmuxproc *server_proc;
2489 extern struct clients clients;
2490 extern struct cmd_find_state marked_pane;
2491 extern struct message_list message_log;
2492 void	 server_set_marked(struct session *, struct winlink *,
2493 	     struct window_pane *);
2494 void	 server_clear_marked(void);
2495 int	 server_is_marked(struct session *, struct winlink *,
2496 	     struct window_pane *);
2497 int	 server_check_marked(void);
2498 int	 server_start(struct tmuxproc *, int, struct event_base *, int, char *);
2499 void	 server_update_socket(void);
2500 void	 server_add_accept(int);
2501 void printflike(1, 2) server_add_message(const char *, ...);
2502 
2503 /* server-client.c */
2504 RB_PROTOTYPE(client_windows, client_window, entry, server_client_window_cmp);
2505 u_int	 server_client_how_many(void);
2506 void	 server_client_set_overlay(struct client *, u_int, overlay_check_cb,
2507 	     overlay_mode_cb, overlay_draw_cb, overlay_key_cb,
2508 	     overlay_free_cb, overlay_resize_cb, void *);
2509 void	 server_client_clear_overlay(struct client *);
2510 void	 server_client_overlay_range(u_int, u_int, u_int, u_int, u_int, u_int,
2511 	     u_int, struct overlay_ranges *);
2512 void	 server_client_set_key_table(struct client *, const char *);
2513 const char *server_client_get_key_table(struct client *);
2514 int	 server_client_check_nested(struct client *);
2515 int	 server_client_handle_key(struct client *, struct key_event *);
2516 struct client *server_client_create(int);
2517 int	 server_client_open(struct client *, char **);
2518 void	 server_client_unref(struct client *);
2519 void	 server_client_set_session(struct client *, struct session *);
2520 void	 server_client_lost(struct client *);
2521 void	 server_client_suspend(struct client *);
2522 void	 server_client_detach(struct client *, enum msgtype);
2523 void	 server_client_exec(struct client *, const char *);
2524 void	 server_client_loop(void);
2525 void	 server_client_push_stdout(struct client *);
2526 void	 server_client_push_stderr(struct client *);
2527 const char *server_client_get_cwd(struct client *, struct session *);
2528 void	 server_client_set_flags(struct client *, const char *);
2529 const char *server_client_get_flags(struct client *);
2530 struct client_window *server_client_get_client_window(struct client *, u_int);
2531 struct client_window *server_client_add_client_window(struct client *, u_int);
2532 struct window_pane *server_client_get_pane(struct client *);
2533 void	 server_client_set_pane(struct client *, struct window_pane *);
2534 void	 server_client_remove_pane(struct window_pane *);
2535 
2536 /* server-fn.c */
2537 void	 server_redraw_client(struct client *);
2538 void	 server_status_client(struct client *);
2539 void	 server_redraw_session(struct session *);
2540 void	 server_redraw_session_group(struct session *);
2541 void	 server_status_session(struct session *);
2542 void	 server_status_session_group(struct session *);
2543 void	 server_redraw_window(struct window *);
2544 void	 server_redraw_window_borders(struct window *);
2545 void	 server_status_window(struct window *);
2546 void	 server_lock(void);
2547 void	 server_lock_session(struct session *);
2548 void	 server_lock_client(struct client *);
2549 void	 server_kill_pane(struct window_pane *);
2550 void	 server_kill_window(struct window *, int);
2551 void	 server_renumber_session(struct session *);
2552 void	 server_renumber_all(void);
2553 int	 server_link_window(struct session *,
2554 	     struct winlink *, struct session *, int, int, int, char **);
2555 void	 server_unlink_window(struct session *, struct winlink *);
2556 void	 server_destroy_pane(struct window_pane *, int);
2557 void	 server_destroy_session(struct session *);
2558 void	 server_check_unattached(void);
2559 void	 server_unzoom_window(struct window *);
2560 
2561 /* status.c */
2562 extern char	**status_prompt_hlist[];
2563 extern u_int	  status_prompt_hsize[];
2564 void	 status_timer_start(struct client *);
2565 void	 status_timer_start_all(void);
2566 void	 status_update_cache(struct session *);
2567 int	 status_at_line(struct client *);
2568 u_int	 status_line_size(struct client *);
2569 struct style_range *status_get_range(struct client *, u_int, u_int);
2570 void	 status_init(struct client *);
2571 void	 status_free(struct client *);
2572 int	 status_redraw(struct client *);
2573 void printflike(5, 6) status_message_set(struct client *, int, int, int,
2574 	     const char *, ...);
2575 void	 status_message_clear(struct client *);
2576 int	 status_message_redraw(struct client *);
2577 void	 status_prompt_set(struct client *, struct cmd_find_state *,
2578 	     const char *, const char *, prompt_input_cb, prompt_free_cb,
2579 	     void *, int, enum prompt_type);
2580 void	 status_prompt_clear(struct client *);
2581 int	 status_prompt_redraw(struct client *);
2582 int	 status_prompt_key(struct client *, key_code);
2583 void	 status_prompt_update(struct client *, const char *, const char *);
2584 void	 status_prompt_load_history(void);
2585 void	 status_prompt_save_history(void);
2586 const char *status_prompt_type_string(u_int);
2587 enum prompt_type status_prompt_type(const char *type);
2588 
2589 /* resize.c */
2590 void	 resize_window(struct window *, u_int, u_int, int, int);
2591 void	 default_window_size(struct client *, struct session *, struct window *,
2592 	     u_int *, u_int *, u_int *, u_int *, int);
2593 void	 recalculate_size(struct window *, int);
2594 void	 recalculate_sizes(void);
2595 void	 recalculate_sizes_now(int);
2596 
2597 /* input.c */
2598 struct input_ctx *input_init(struct window_pane *, struct bufferevent *,
2599 	     struct colour_palette *);
2600 void	 input_free(struct input_ctx *);
2601 void	 input_reset(struct input_ctx *, int);
2602 struct evbuffer *input_pending(struct input_ctx *);
2603 void	 input_parse_pane(struct window_pane *);
2604 void	 input_parse_buffer(struct window_pane *, u_char *, size_t);
2605 void	 input_parse_screen(struct input_ctx *, struct screen *,
2606 	     screen_write_init_ctx_cb, void *, u_char *, size_t);
2607 
2608 /* input-key.c */
2609 void	 input_key_build(void);
2610 int	 input_key_pane(struct window_pane *, key_code, struct mouse_event *);
2611 int	 input_key(struct screen *, struct bufferevent *, key_code);
2612 int	 input_key_get_mouse(struct screen *, struct mouse_event *, u_int,
2613 	     u_int, const char **, size_t *);
2614 
2615 /* colour.c */
2616 int	 colour_find_rgb(u_char, u_char, u_char);
2617 int	 colour_join_rgb(u_char, u_char, u_char);
2618 void	 colour_split_rgb(int, u_char *, u_char *, u_char *);
2619 const char *colour_tostring(int);
2620 int	 colour_fromstring(const char *s);
2621 int	 colour_256toRGB(int);
2622 int	 colour_256to16(int);
2623 int	 colour_byname(const char *);
2624 void	 colour_palette_init(struct colour_palette *);
2625 void	 colour_palette_clear(struct colour_palette *);
2626 void	 colour_palette_free(struct colour_palette *);
2627 int	 colour_palette_get(struct colour_palette *, int);
2628 int	 colour_palette_set(struct colour_palette *, int, int);
2629 void	 colour_palette_from_option(struct colour_palette *, struct options *);
2630 
2631 /* attributes.c */
2632 const char *attributes_tostring(int);
2633 int	 attributes_fromstring(const char *);
2634 
2635 /* grid.c */
2636 extern const struct grid_cell grid_default_cell;
2637 void	 grid_empty_line(struct grid *, u_int, u_int);
2638 int	 grid_cells_equal(const struct grid_cell *, const struct grid_cell *);
2639 int	 grid_cells_look_equal(const struct grid_cell *,
2640 	     const struct grid_cell *);
2641 struct grid *grid_create(u_int, u_int, u_int);
2642 void	 grid_destroy(struct grid *);
2643 int	 grid_compare(struct grid *, struct grid *);
2644 void	 grid_collect_history(struct grid *);
2645 void	 grid_remove_history(struct grid *, u_int );
2646 void	 grid_scroll_history(struct grid *, u_int);
2647 void	 grid_scroll_history_region(struct grid *, u_int, u_int, u_int);
2648 void	 grid_clear_history(struct grid *);
2649 const struct grid_line *grid_peek_line(struct grid *, u_int);
2650 void	 grid_get_cell(struct grid *, u_int, u_int, struct grid_cell *);
2651 void	 grid_set_cell(struct grid *, u_int, u_int, const struct grid_cell *);
2652 void	 grid_set_padding(struct grid *, u_int, u_int);
2653 void	 grid_set_cells(struct grid *, u_int, u_int, const struct grid_cell *,
2654 	     const char *, size_t);
2655 struct grid_line *grid_get_line(struct grid *, u_int);
2656 void	 grid_adjust_lines(struct grid *, u_int);
2657 void	 grid_clear(struct grid *, u_int, u_int, u_int, u_int, u_int);
2658 void	 grid_clear_lines(struct grid *, u_int, u_int, u_int);
2659 void	 grid_move_lines(struct grid *, u_int, u_int, u_int, u_int);
2660 void	 grid_move_cells(struct grid *, u_int, u_int, u_int, u_int, u_int);
2661 char	*grid_string_cells(struct grid *, u_int, u_int, u_int,
2662 	     struct grid_cell **, int, int, int);
2663 void	 grid_duplicate_lines(struct grid *, u_int, struct grid *, u_int,
2664 	     u_int);
2665 void	 grid_reflow(struct grid *, u_int);
2666 void	 grid_wrap_position(struct grid *, u_int, u_int, u_int *, u_int *);
2667 void	 grid_unwrap_position(struct grid *, u_int *, u_int *, u_int, u_int);
2668 u_int	 grid_line_length(struct grid *, u_int);
2669 
2670 /* grid-reader.c */
2671 void	 grid_reader_start(struct grid_reader *, struct grid *, u_int, u_int);
2672 void	 grid_reader_get_cursor(struct grid_reader *, u_int *, u_int *);
2673 u_int	 grid_reader_line_length(struct grid_reader *);
2674 int	 grid_reader_in_set(struct grid_reader *, const char *);
2675 void	 grid_reader_cursor_right(struct grid_reader *, int, int);
2676 void	 grid_reader_cursor_left(struct grid_reader *, int);
2677 void	 grid_reader_cursor_down(struct grid_reader *);
2678 void	 grid_reader_cursor_up(struct grid_reader *);
2679 void	 grid_reader_cursor_start_of_line(struct grid_reader *, int);
2680 void	 grid_reader_cursor_end_of_line(struct grid_reader *, int, int);
2681 void	 grid_reader_cursor_next_word(struct grid_reader *, const char *);
2682 void	 grid_reader_cursor_next_word_end(struct grid_reader *, const char *);
2683 void	 grid_reader_cursor_previous_word(struct grid_reader *, const char *,
2684 	     int, int);
2685 int	 grid_reader_cursor_jump(struct grid_reader *,
2686 	     const struct utf8_data *);
2687 int	 grid_reader_cursor_jump_back(struct grid_reader *,
2688 	     const struct utf8_data *);
2689 void	 grid_reader_cursor_back_to_indentation(struct grid_reader *);
2690 
2691 /* grid-view.c */
2692 void	 grid_view_get_cell(struct grid *, u_int, u_int, struct grid_cell *);
2693 void	 grid_view_set_cell(struct grid *, u_int, u_int,
2694 	     const struct grid_cell *);
2695 void	 grid_view_set_padding(struct grid *, u_int, u_int);
2696 void	 grid_view_set_cells(struct grid *, u_int, u_int,
2697 	     const struct grid_cell *, const char *, size_t);
2698 void	 grid_view_clear_history(struct grid *, u_int);
2699 void	 grid_view_clear(struct grid *, u_int, u_int, u_int, u_int, u_int);
2700 void	 grid_view_scroll_region_up(struct grid *, u_int, u_int, u_int);
2701 void	 grid_view_scroll_region_down(struct grid *, u_int, u_int, u_int);
2702 void	 grid_view_insert_lines(struct grid *, u_int, u_int, u_int);
2703 void	 grid_view_insert_lines_region(struct grid *, u_int, u_int, u_int,
2704 	     u_int);
2705 void	 grid_view_delete_lines(struct grid *, u_int, u_int, u_int);
2706 void	 grid_view_delete_lines_region(struct grid *, u_int, u_int, u_int,
2707 	     u_int);
2708 void	 grid_view_insert_cells(struct grid *, u_int, u_int, u_int, u_int);
2709 void	 grid_view_delete_cells(struct grid *, u_int, u_int, u_int, u_int);
2710 char	*grid_view_string_cells(struct grid *, u_int, u_int, u_int);
2711 
2712 /* screen-write.c */
2713 void	 screen_write_make_list(struct screen *);
2714 void	 screen_write_free_list(struct screen *);
2715 void	 screen_write_start_pane(struct screen_write_ctx *,
2716 	     struct window_pane *, struct screen *);
2717 void	 screen_write_start(struct screen_write_ctx *, struct screen *);
2718 void	 screen_write_start_callback(struct screen_write_ctx *, struct screen *,
2719 	     screen_write_init_ctx_cb, void *);
2720 void	 screen_write_stop(struct screen_write_ctx *);
2721 void	 screen_write_reset(struct screen_write_ctx *);
2722 size_t printflike(1, 2) screen_write_strlen(const char *, ...);
2723 int printflike(7, 8) screen_write_text(struct screen_write_ctx *, u_int, u_int,
2724 	     u_int, int, const struct grid_cell *, const char *, ...);
2725 void printflike(3, 4) screen_write_puts(struct screen_write_ctx *,
2726 	     const struct grid_cell *, const char *, ...);
2727 void printflike(4, 5) screen_write_nputs(struct screen_write_ctx *,
2728 	     ssize_t, const struct grid_cell *, const char *, ...);
2729 void printflike(4, 0) screen_write_vnputs(struct screen_write_ctx *, ssize_t,
2730 	     const struct grid_cell *, const char *, va_list);
2731 void	 screen_write_putc(struct screen_write_ctx *, const struct grid_cell *,
2732 	     u_char);
2733 void	 screen_write_fast_copy(struct screen_write_ctx *, struct screen *,
2734 	     u_int, u_int, u_int, u_int);
2735 void	 screen_write_hline(struct screen_write_ctx *, u_int, int, int);
2736 void	 screen_write_vline(struct screen_write_ctx *, u_int, int, int);
2737 void	 screen_write_menu(struct screen_write_ctx *, struct menu *, int,
2738 	     const struct grid_cell *);
2739 void	 screen_write_box(struct screen_write_ctx *, u_int, u_int, int,
2740 	     const struct grid_cell *, const char *);
2741 void	 screen_write_preview(struct screen_write_ctx *, struct screen *, u_int,
2742 	     u_int);
2743 void	 screen_write_backspace(struct screen_write_ctx *);
2744 void	 screen_write_mode_set(struct screen_write_ctx *, int);
2745 void	 screen_write_mode_clear(struct screen_write_ctx *, int);
2746 void	 screen_write_cursorup(struct screen_write_ctx *, u_int);
2747 void	 screen_write_cursordown(struct screen_write_ctx *, u_int);
2748 void	 screen_write_cursorright(struct screen_write_ctx *, u_int);
2749 void	 screen_write_cursorleft(struct screen_write_ctx *, u_int);
2750 void	 screen_write_alignmenttest(struct screen_write_ctx *);
2751 void	 screen_write_insertcharacter(struct screen_write_ctx *, u_int, u_int);
2752 void	 screen_write_deletecharacter(struct screen_write_ctx *, u_int, u_int);
2753 void	 screen_write_clearcharacter(struct screen_write_ctx *, u_int, u_int);
2754 void	 screen_write_insertline(struct screen_write_ctx *, u_int, u_int);
2755 void	 screen_write_deleteline(struct screen_write_ctx *, u_int, u_int);
2756 void	 screen_write_clearline(struct screen_write_ctx *, u_int);
2757 void	 screen_write_clearendofline(struct screen_write_ctx *, u_int);
2758 void	 screen_write_clearstartofline(struct screen_write_ctx *, u_int);
2759 void	 screen_write_cursormove(struct screen_write_ctx *, int, int, int);
2760 void	 screen_write_reverseindex(struct screen_write_ctx *, u_int);
2761 void	 screen_write_scrollregion(struct screen_write_ctx *, u_int, u_int);
2762 void	 screen_write_linefeed(struct screen_write_ctx *, int, u_int);
2763 void	 screen_write_scrollup(struct screen_write_ctx *, u_int, u_int);
2764 void	 screen_write_scrolldown(struct screen_write_ctx *, u_int, u_int);
2765 void	 screen_write_carriagereturn(struct screen_write_ctx *);
2766 void	 screen_write_clearendofscreen(struct screen_write_ctx *, u_int);
2767 void	 screen_write_clearstartofscreen(struct screen_write_ctx *, u_int);
2768 void	 screen_write_clearscreen(struct screen_write_ctx *, u_int);
2769 void	 screen_write_clearhistory(struct screen_write_ctx *);
2770 void	 screen_write_fullredraw(struct screen_write_ctx *);
2771 void	 screen_write_collect_end(struct screen_write_ctx *);
2772 void	 screen_write_collect_add(struct screen_write_ctx *,
2773 	     const struct grid_cell *);
2774 void	 screen_write_cell(struct screen_write_ctx *, const struct grid_cell *);
2775 void	 screen_write_setselection(struct screen_write_ctx *, u_char *, u_int);
2776 void	 screen_write_rawstring(struct screen_write_ctx *, u_char *, u_int);
2777 void	 screen_write_alternateon(struct screen_write_ctx *,
2778 	     struct grid_cell *, int);
2779 void	 screen_write_alternateoff(struct screen_write_ctx *,
2780 	     struct grid_cell *, int);
2781 
2782 /* screen-redraw.c */
2783 void	 screen_redraw_screen(struct client *);
2784 void	 screen_redraw_pane(struct client *, struct window_pane *);
2785 
2786 /* screen.c */
2787 void	 screen_init(struct screen *, u_int, u_int, u_int);
2788 void	 screen_reinit(struct screen *);
2789 void	 screen_free(struct screen *);
2790 void	 screen_reset_tabs(struct screen *);
2791 void	 screen_set_cursor_style(struct screen *, u_int);
2792 void	 screen_set_cursor_colour(struct screen *, const char *);
2793 int	 screen_set_title(struct screen *, const char *);
2794 void	 screen_set_path(struct screen *, const char *);
2795 void	 screen_push_title(struct screen *);
2796 void	 screen_pop_title(struct screen *);
2797 void	 screen_resize(struct screen *, u_int, u_int, int);
2798 void	 screen_resize_cursor(struct screen *, u_int, u_int, int, int, int);
2799 void	 screen_set_selection(struct screen *, u_int, u_int, u_int, u_int,
2800 	     u_int, int, struct grid_cell *);
2801 void	 screen_clear_selection(struct screen *);
2802 void	 screen_hide_selection(struct screen *);
2803 int	 screen_check_selection(struct screen *, u_int, u_int);
2804 void	 screen_select_cell(struct screen *, struct grid_cell *,
2805 	     const struct grid_cell *);
2806 void	 screen_alternate_on(struct screen *, struct grid_cell *, int);
2807 void	 screen_alternate_off(struct screen *, struct grid_cell *, int);
2808 const char *screen_mode_to_string(int);
2809 
2810 /* window.c */
2811 extern struct windows windows;
2812 extern struct window_pane_tree all_window_panes;
2813 int		 window_cmp(struct window *, struct window *);
2814 RB_PROTOTYPE(windows, window, entry, window_cmp);
2815 int		 winlink_cmp(struct winlink *, struct winlink *);
2816 RB_PROTOTYPE(winlinks, winlink, entry, winlink_cmp);
2817 int		 window_pane_cmp(struct window_pane *, struct window_pane *);
2818 RB_PROTOTYPE(window_pane_tree, window_pane, tree_entry, window_pane_cmp);
2819 struct winlink	*winlink_find_by_index(struct winlinks *, int);
2820 struct winlink	*winlink_find_by_window(struct winlinks *, struct window *);
2821 struct winlink	*winlink_find_by_window_id(struct winlinks *, u_int);
2822 u_int		 winlink_count(struct winlinks *);
2823 struct winlink	*winlink_add(struct winlinks *, int);
2824 void		 winlink_set_window(struct winlink *, struct window *);
2825 void		 winlink_remove(struct winlinks *, struct winlink *);
2826 struct winlink	*winlink_next(struct winlink *);
2827 struct winlink	*winlink_previous(struct winlink *);
2828 struct winlink	*winlink_next_by_number(struct winlink *, struct session *,
2829 		     int);
2830 struct winlink	*winlink_previous_by_number(struct winlink *, struct session *,
2831 		     int);
2832 void		 winlink_stack_push(struct winlink_stack *, struct winlink *);
2833 void		 winlink_stack_remove(struct winlink_stack *, struct winlink *);
2834 struct window	*window_find_by_id_str(const char *);
2835 struct window	*window_find_by_id(u_int);
2836 void		 window_update_activity(struct window *);
2837 struct window	*window_create(u_int, u_int, u_int, u_int);
2838 void		 window_pane_set_event(struct window_pane *);
2839 struct window_pane *window_get_active_at(struct window *, u_int, u_int);
2840 struct window_pane *window_find_string(struct window *, const char *);
2841 int		 window_has_pane(struct window *, struct window_pane *);
2842 int		 window_set_active_pane(struct window *, struct window_pane *,
2843 		     int);
2844 void		 window_update_focus(struct window *);
2845 void		 window_pane_update_focus(struct window_pane *);
2846 void		 window_redraw_active_switch(struct window *,
2847 		     struct window_pane *);
2848 struct window_pane *window_add_pane(struct window *, struct window_pane *,
2849 		     u_int, int);
2850 void		 window_resize(struct window *, u_int, u_int, int, int);
2851 void		 window_pane_send_resize(struct window_pane *, u_int, u_int);
2852 int		 window_zoom(struct window_pane *);
2853 int		 window_unzoom(struct window *);
2854 int		 window_push_zoom(struct window *, int, int);
2855 int		 window_pop_zoom(struct window *);
2856 void		 window_lost_pane(struct window *, struct window_pane *);
2857 void		 window_remove_pane(struct window *, struct window_pane *);
2858 struct window_pane *window_pane_at_index(struct window *, u_int);
2859 struct window_pane *window_pane_next_by_number(struct window *,
2860 			struct window_pane *, u_int);
2861 struct window_pane *window_pane_previous_by_number(struct window *,
2862 			struct window_pane *, u_int);
2863 int		 window_pane_index(struct window_pane *, u_int *);
2864 u_int		 window_count_panes(struct window *);
2865 void		 window_destroy_panes(struct window *);
2866 struct window_pane *window_pane_find_by_id_str(const char *);
2867 struct window_pane *window_pane_find_by_id(u_int);
2868 int		 window_pane_destroy_ready(struct window_pane *);
2869 void		 window_pane_resize(struct window_pane *, u_int, u_int);
2870 int		 window_pane_set_mode(struct window_pane *,
2871 		     struct window_pane *, const struct window_mode *,
2872 		     struct cmd_find_state *, struct args *);
2873 void		 window_pane_reset_mode(struct window_pane *);
2874 void		 window_pane_reset_mode_all(struct window_pane *);
2875 int		 window_pane_key(struct window_pane *, struct client *,
2876 		     struct session *, struct winlink *, key_code,
2877 		     struct mouse_event *);
2878 int		 window_pane_visible(struct window_pane *);
2879 u_int		 window_pane_search(struct window_pane *, const char *, int,
2880 		     int);
2881 const char	*window_printable_flags(struct winlink *, int);
2882 struct window_pane *window_pane_find_up(struct window_pane *);
2883 struct window_pane *window_pane_find_down(struct window_pane *);
2884 struct window_pane *window_pane_find_left(struct window_pane *);
2885 struct window_pane *window_pane_find_right(struct window_pane *);
2886 void		 window_set_name(struct window *, const char *);
2887 void		 window_add_ref(struct window *, const char *);
2888 void		 window_remove_ref(struct window *, const char *);
2889 void		 winlink_clear_flags(struct winlink *);
2890 int		 winlink_shuffle_up(struct session *, struct winlink *, int);
2891 int		 window_pane_start_input(struct window_pane *,
2892 		     struct cmdq_item *, char **);
2893 void		*window_pane_get_new_data(struct window_pane *,
2894 		     struct window_pane_offset *, size_t *);
2895 void		 window_pane_update_used_data(struct window_pane *,
2896 		     struct window_pane_offset *, size_t);
2897 
2898 /* layout.c */
2899 u_int		 layout_count_cells(struct layout_cell *);
2900 struct layout_cell *layout_create_cell(struct layout_cell *);
2901 void		 layout_free_cell(struct layout_cell *);
2902 void		 layout_print_cell(struct layout_cell *, const char *, u_int);
2903 void		 layout_destroy_cell(struct window *, struct layout_cell *,
2904 		     struct layout_cell **);
2905 void		 layout_resize_layout(struct window *, struct layout_cell *,
2906 		     enum layout_type, int, int);
2907 struct layout_cell *layout_search_by_border(struct layout_cell *, u_int, u_int);
2908 void		 layout_set_size(struct layout_cell *, u_int, u_int, u_int,
2909 		     u_int);
2910 void		 layout_make_leaf(struct layout_cell *, struct window_pane *);
2911 void		 layout_make_node(struct layout_cell *, enum layout_type);
2912 void		 layout_fix_offsets(struct window *);
2913 void		 layout_fix_panes(struct window *, struct window_pane *);
2914 void		 layout_resize_adjust(struct window *, struct layout_cell *,
2915 		     enum layout_type, int);
2916 void		 layout_init(struct window *, struct window_pane *);
2917 void		 layout_free(struct window *);
2918 void		 layout_resize(struct window *, u_int, u_int);
2919 void		 layout_resize_pane(struct window_pane *, enum layout_type,
2920 		     int, int);
2921 void		 layout_resize_pane_to(struct window_pane *, enum layout_type,
2922 		     u_int);
2923 void		 layout_assign_pane(struct layout_cell *, struct window_pane *,
2924 		     int);
2925 struct layout_cell *layout_split_pane(struct window_pane *, enum layout_type,
2926 		     int, int);
2927 void		 layout_close_pane(struct window_pane *);
2928 int		 layout_spread_cell(struct window *, struct layout_cell *);
2929 void		 layout_spread_out(struct window_pane *);
2930 
2931 /* layout-custom.c */
2932 char		*layout_dump(struct layout_cell *);
2933 int		 layout_parse(struct window *, const char *);
2934 
2935 /* layout-set.c */
2936 int		 layout_set_lookup(const char *);
2937 u_int		 layout_set_select(struct window *, u_int);
2938 u_int		 layout_set_next(struct window *);
2939 u_int		 layout_set_previous(struct window *);
2940 
2941 /* mode-tree.c */
2942 typedef void (*mode_tree_build_cb)(void *, struct mode_tree_sort_criteria *,
2943 				   uint64_t *, const char *);
2944 typedef void (*mode_tree_draw_cb)(void *, void *, struct screen_write_ctx *,
2945 	     u_int, u_int);
2946 typedef int (*mode_tree_search_cb)(void *, void *, const char *);
2947 typedef void (*mode_tree_menu_cb)(void *, struct client *, key_code);
2948 typedef u_int (*mode_tree_height_cb)(void *, u_int);
2949 typedef key_code (*mode_tree_key_cb)(void *, void *, u_int);
2950 typedef void (*mode_tree_each_cb)(void *, void *, struct client *, key_code);
2951 u_int	 mode_tree_count_tagged(struct mode_tree_data *);
2952 void	*mode_tree_get_current(struct mode_tree_data *);
2953 const char *mode_tree_get_current_name(struct mode_tree_data *);
2954 void	 mode_tree_expand_current(struct mode_tree_data *);
2955 void	 mode_tree_collapse_current(struct mode_tree_data *);
2956 void	 mode_tree_expand(struct mode_tree_data *, uint64_t);
2957 int	 mode_tree_set_current(struct mode_tree_data *, uint64_t);
2958 void	 mode_tree_each_tagged(struct mode_tree_data *, mode_tree_each_cb,
2959 	     struct client *, key_code, int);
2960 void	 mode_tree_up(struct mode_tree_data *, int);
2961 void	 mode_tree_down(struct mode_tree_data *, int);
2962 struct mode_tree_data *mode_tree_start(struct window_pane *, struct args *,
2963 	     mode_tree_build_cb, mode_tree_draw_cb, mode_tree_search_cb,
2964 	     mode_tree_menu_cb, mode_tree_height_cb, mode_tree_key_cb, void *,
2965 	     const struct menu_item *, const char **, u_int, struct screen **);
2966 void	 mode_tree_zoom(struct mode_tree_data *, struct args *);
2967 void	 mode_tree_build(struct mode_tree_data *);
2968 void	 mode_tree_free(struct mode_tree_data *);
2969 void	 mode_tree_resize(struct mode_tree_data *, u_int, u_int);
2970 struct mode_tree_item *mode_tree_add(struct mode_tree_data *,
2971 	     struct mode_tree_item *, void *, uint64_t, const char *,
2972 	     const char *, int);
2973 void	 mode_tree_draw_as_parent(struct mode_tree_item *);
2974 void	 mode_tree_no_tag(struct mode_tree_item *);
2975 void	 mode_tree_remove(struct mode_tree_data *, struct mode_tree_item *);
2976 void	 mode_tree_draw(struct mode_tree_data *);
2977 int	 mode_tree_key(struct mode_tree_data *, struct client *, key_code *,
2978 	     struct mouse_event *, u_int *, u_int *);
2979 void	 mode_tree_run_command(struct client *, struct cmd_find_state *,
2980 	     const char *, const char *);
2981 
2982 /* window-buffer.c */
2983 extern const struct window_mode window_buffer_mode;
2984 
2985 /* window-tree.c */
2986 extern const struct window_mode window_tree_mode;
2987 
2988 /* window-clock.c */
2989 extern const struct window_mode window_clock_mode;
2990 extern const char window_clock_table[14][5][5];
2991 
2992 /* window-client.c */
2993 extern const struct window_mode window_client_mode;
2994 
2995 /* window-copy.c */
2996 extern const struct window_mode window_copy_mode;
2997 extern const struct window_mode window_view_mode;
2998 void printflike(2, 3) window_copy_add(struct window_pane *, const char *, ...);
2999 void printflike(2, 0) window_copy_vadd(struct window_pane *, const char *,
3000 		     va_list);
3001 void		 window_copy_pageup(struct window_pane *, int);
3002 void		 window_copy_start_drag(struct client *, struct mouse_event *);
3003 char		*window_copy_get_word(struct window_pane *, u_int, u_int);
3004 char		*window_copy_get_line(struct window_pane *, u_int);
3005 
3006 /* window-option.c */
3007 extern const struct window_mode window_customize_mode;
3008 
3009 /* names.c */
3010 void	 check_window_name(struct window *);
3011 char	*default_window_name(struct window *);
3012 char	*parse_window_name(const char *);
3013 
3014 /* control.c */
3015 void	control_discard(struct client *);
3016 void	control_start(struct client *);
3017 void	control_stop(struct client *);
3018 void	control_set_pane_on(struct client *, struct window_pane *);
3019 void	control_set_pane_off(struct client *, struct window_pane *);
3020 void	control_continue_pane(struct client *, struct window_pane *);
3021 void	control_pause_pane(struct client *, struct window_pane *);
3022 struct window_pane_offset *control_pane_offset(struct client *,
3023 	   struct window_pane *, int *);
3024 void	control_reset_offsets(struct client *);
3025 void printflike(2, 3) control_write(struct client *, const char *, ...);
3026 void	control_write_output(struct client *, struct window_pane *);
3027 int	control_all_done(struct client *);
3028 void	control_add_sub(struct client *, const char *, enum control_sub_type,
3029     	   int, const char *);
3030 void	control_remove_sub(struct client *, const char *);
3031 
3032 /* control-notify.c */
3033 void	control_notify_input(struct client *, struct window_pane *,
3034 	    const u_char *, size_t);
3035 void	control_notify_pane_mode_changed(int);
3036 void	control_notify_window_layout_changed(struct window *);
3037 void	control_notify_window_pane_changed(struct window *);
3038 void	control_notify_window_unlinked(struct session *, struct window *);
3039 void	control_notify_window_linked(struct session *, struct window *);
3040 void	control_notify_window_renamed(struct window *);
3041 void	control_notify_client_session_changed(struct client *);
3042 void	control_notify_client_detached(struct client *);
3043 void	control_notify_session_renamed(struct session *);
3044 void	control_notify_session_created(struct session *);
3045 void	control_notify_session_closed(struct session *);
3046 void	control_notify_session_window_changed(struct session *);
3047 
3048 /* session.c */
3049 extern struct sessions sessions;
3050 int	session_cmp(struct session *, struct session *);
3051 RB_PROTOTYPE(sessions, session, entry, session_cmp);
3052 int		 session_alive(struct session *);
3053 struct session	*session_find(const char *);
3054 struct session	*session_find_by_id_str(const char *);
3055 struct session	*session_find_by_id(u_int);
3056 struct session	*session_create(const char *, const char *, const char *,
3057 		     struct environ *, struct options *, struct termios *);
3058 void		 session_destroy(struct session *, int,	 const char *);
3059 void		 session_add_ref(struct session *, const char *);
3060 void		 session_remove_ref(struct session *, const char *);
3061 char		*session_check_name(const char *);
3062 void		 session_update_activity(struct session *, struct timeval *);
3063 struct session	*session_next_session(struct session *);
3064 struct session	*session_previous_session(struct session *);
3065 struct winlink	*session_new(struct session *, const char *, int, char **,
3066 		     const char *, const char *, int, char **);
3067 struct winlink	*session_attach(struct session *, struct window *, int,
3068 		     char **);
3069 int		 session_detach(struct session *, struct winlink *);
3070 int		 session_has(struct session *, struct window *);
3071 int		 session_is_linked(struct session *, struct window *);
3072 int		 session_next(struct session *, int);
3073 int		 session_previous(struct session *, int);
3074 int		 session_select(struct session *, int);
3075 int		 session_last(struct session *);
3076 int		 session_set_current(struct session *, struct winlink *);
3077 struct session_group *session_group_contains(struct session *);
3078 struct session_group *session_group_find(const char *);
3079 struct session_group *session_group_new(const char *);
3080 void		 session_group_add(struct session_group *, struct session *);
3081 void		 session_group_synchronize_to(struct session *);
3082 void		 session_group_synchronize_from(struct session *);
3083 u_int		 session_group_count(struct session_group *);
3084 u_int		 session_group_attached_count(struct session_group *);
3085 void		 session_renumber_windows(struct session *);
3086 
3087 /* utf8.c */
3088 utf8_char	 utf8_build_one(u_char);
3089 enum utf8_state	 utf8_from_data(const struct utf8_data *, utf8_char *);
3090 void		 utf8_to_data(utf8_char, struct utf8_data *);
3091 void		 utf8_set(struct utf8_data *, u_char);
3092 void		 utf8_copy(struct utf8_data *, const struct utf8_data *);
3093 enum utf8_state	 utf8_open(struct utf8_data *, u_char);
3094 enum utf8_state	 utf8_append(struct utf8_data *, u_char);
3095 int		 utf8_isvalid(const char *);
3096 int		 utf8_strvis(char *, const char *, size_t, int);
3097 int		 utf8_stravis(char **, const char *, int);
3098 int		 utf8_stravisx(char **, const char *, size_t, int);
3099 char		*utf8_sanitize(const char *);
3100 size_t		 utf8_strlen(const struct utf8_data *);
3101 u_int		 utf8_strwidth(const struct utf8_data *, ssize_t);
3102 struct utf8_data *utf8_fromcstr(const char *);
3103 char		*utf8_tocstr(struct utf8_data *);
3104 u_int		 utf8_cstrwidth(const char *);
3105 char		*utf8_padcstr(const char *, u_int);
3106 char		*utf8_rpadcstr(const char *, u_int);
3107 int		 utf8_cstrhas(const char *, const struct utf8_data *);
3108 
3109 /* procname.c */
3110 char   *get_proc_name(int, char *);
3111 char   *get_proc_cwd(int);
3112 
3113 /* log.c */
3114 void	log_add_level(void);
3115 int	log_get_level(void);
3116 void	log_open(const char *);
3117 void	log_toggle(const char *);
3118 void	log_close(void);
3119 void printflike(1, 2) log_debug(const char *, ...);
3120 __dead void printflike(1, 2) fatal(const char *, ...);
3121 __dead void printflike(1, 2) fatalx(const char *, ...);
3122 
3123 /* menu.c */
3124 #define MENU_NOMOUSE 0x1
3125 #define MENU_TAB 0x2
3126 #define MENU_STAYOPEN 0x4
3127 struct menu	*menu_create(const char *);
3128 void		 menu_add_items(struct menu *, const struct menu_item *,
3129 		    struct cmdq_item *, struct client *,
3130 		    struct cmd_find_state *);
3131 void		 menu_add_item(struct menu *, const struct menu_item *,
3132 		    struct cmdq_item *, struct client *,
3133 		    struct cmd_find_state *);
3134 void		 menu_free(struct menu *);
3135 struct menu_data *menu_prepare(struct menu *, int, struct cmdq_item *, u_int,
3136 		    u_int, struct client *, struct cmd_find_state *,
3137 		    menu_choice_cb, void *);
3138 int		 menu_display(struct menu *, int, struct cmdq_item *, u_int,
3139 		    u_int, struct client *, struct cmd_find_state *,
3140 		    menu_choice_cb, void *);
3141 struct screen	*menu_mode_cb(struct client *, void *, u_int *, u_int *);
3142 void		 menu_check_cb(struct client *, void *, u_int, u_int, u_int,
3143 		    struct overlay_ranges *);
3144 void		 menu_draw_cb(struct client *, void *,
3145 		    struct screen_redraw_ctx *);
3146 void		 menu_free_cb(struct client *, void *);
3147 int		 menu_key_cb(struct client *, void *, struct key_event *);
3148 
3149 /* popup.c */
3150 #define POPUP_CLOSEEXIT 0x1
3151 #define POPUP_CLOSEEXITZERO 0x2
3152 #define POPUP_INTERNAL 0x4
3153 typedef void (*popup_close_cb)(int, void *);
3154 typedef void (*popup_finish_edit_cb)(char *, size_t, void *);
3155 int		 popup_display(int, int, struct cmdq_item *, u_int, u_int,
3156 		    u_int, u_int, struct environ *, const char *, int, char **,
3157 		    const char *, const char *, struct client *,
3158 		    struct session *, popup_close_cb, void *);
3159 int		 popup_editor(struct client *, const char *, size_t,
3160 		    popup_finish_edit_cb, void *);
3161 
3162 /* style.c */
3163 int		 style_parse(struct style *,const struct grid_cell *,
3164 		     const char *);
3165 const char	*style_tostring(struct style *);
3166 void		 style_add(struct grid_cell *, struct options *,
3167 		     const char *, struct format_tree *);
3168 void		 style_apply(struct grid_cell *, struct options *,
3169 		     const char *, struct format_tree *);
3170 void		 style_set(struct style *, const struct grid_cell *);
3171 void		 style_copy(struct style *, struct style *);
3172 
3173 /* spawn.c */
3174 struct winlink	*spawn_window(struct spawn_context *, char **);
3175 struct window_pane *spawn_pane(struct spawn_context *, char **);
3176 
3177 /* regsub.c */
3178 char		*regsub(const char *, const char *, const char *, int);
3179 
3180 #endif /* TMUX_H */
3181