xref: /openbsd-src/usr.bin/tmux/tmux.h (revision 4b70baf6e17fc8b27fc1f7fa7929335753fa94c3)
1 /* $OpenBSD: tmux.h,v 1.887 2019/05/03 20:44:24 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 #include <wchar.h>
34 
35 #include "xmalloc.h"
36 
37 extern char   **environ;
38 
39 struct args;
40 struct args_value;
41 struct client;
42 struct cmd_find_state;
43 struct cmdq_item;
44 struct cmdq_list;
45 struct environ;
46 struct format_job_tree;
47 struct format_tree;
48 struct input_ctx;
49 struct job;
50 struct mode_tree_data;
51 struct mouse_event;
52 struct options;
53 struct options_entry;
54 struct options_array_item;
55 struct session;
56 struct tmuxpeer;
57 struct tmuxproc;
58 struct winlink;
59 
60 /* Client-server protocol version. */
61 #define PROTOCOL_VERSION 8
62 
63 /* Default global configuration file. */
64 #ifndef TMUX_CONF
65 #define TMUX_CONF "/etc/tmux.conf"
66 #endif
67 
68 /* Minimum layout cell size, NOT including border lines. */
69 #define PANE_MINIMUM 1
70 
71 /* Minimum and maximum window size. */
72 #define WINDOW_MINIMUM PANE_MINIMUM
73 #define WINDOW_MAXIMUM 10000
74 
75 /* Automatic name refresh interval, in microseconds. Must be < 1 second. */
76 #define NAME_INTERVAL 500000
77 
78 /* Maximum size of data to hold from a pane. */
79 #define READ_SIZE 4096
80 
81 /* Attribute to make GCC check printf-like arguments. */
82 #define printflike(a, b) __attribute__ ((format (printf, a, b)))
83 
84 /* Number of items in array. */
85 #ifndef nitems
86 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
87 #endif
88 
89 /* Alert option values. */
90 #define ALERT_NONE 0
91 #define ALERT_ANY 1
92 #define ALERT_CURRENT 2
93 #define ALERT_OTHER 3
94 
95 /* Visual option values. */
96 #define VISUAL_OFF 0
97 #define VISUAL_ON 1
98 #define VISUAL_BOTH 2
99 
100 /* Special key codes. */
101 #define KEYC_NONE 0xffff00000000ULL
102 #define KEYC_UNKNOWN 0xfffe00000000ULL
103 #define KEYC_BASE 0x000010000000ULL
104 #define KEYC_USER 0x000020000000ULL
105 
106 /* Available user keys. */
107 #define KEYC_NUSER 1000
108 
109 /* Key modifier bits. */
110 #define KEYC_ESCAPE 0x200000000000ULL
111 #define KEYC_CTRL 0x400000000000ULL
112 #define KEYC_SHIFT 0x800000000000ULL
113 #define KEYC_XTERM 0x1000000000000ULL
114 
115 /* Mask to obtain key w/o modifiers. */
116 #define KEYC_MASK_MOD (KEYC_ESCAPE|KEYC_CTRL|KEYC_SHIFT|KEYC_XTERM)
117 #define KEYC_MASK_KEY (~KEYC_MASK_MOD)
118 
119 /* Is this a mouse key? */
120 #define KEYC_IS_MOUSE(key) (((key) & KEYC_MASK_KEY) >= KEYC_MOUSE &&	\
121     ((key) & KEYC_MASK_KEY) < KEYC_BSPACE)
122 
123 /* Multiple click timeout. */
124 #define KEYC_CLICK_TIMEOUT 300
125 
126 /* Mouse key codes. */
127 #define KEYC_MOUSE_KEY(name)					\
128 	KEYC_ ## name ## _PANE,					\
129 	KEYC_ ## name ## _STATUS,				\
130 	KEYC_ ## name ## _STATUS_LEFT,				\
131 	KEYC_ ## name ## _STATUS_RIGHT,				\
132 	KEYC_ ## name ## _STATUS_DEFAULT,			\
133 	KEYC_ ## name ## _BORDER
134 #define KEYC_MOUSE_STRING(name, s)				\
135 	{ #s "Pane", KEYC_ ## name ## _PANE },			\
136 	{ #s "Status", KEYC_ ## name ## _STATUS },		\
137 	{ #s "StatusLeft", KEYC_ ## name ## _STATUS_LEFT },	\
138 	{ #s "StatusRight", KEYC_ ## name ## _STATUS_RIGHT },	\
139 	{ #s "StatusDefault", KEYC_ ## name ## _STATUS_DEFAULT }, \
140 	{ #s "Border", KEYC_ ## name ## _BORDER }
141 
142 /*
143  * A single key. This can be ASCII or Unicode or one of the keys starting at
144  * KEYC_BASE.
145  */
146 typedef unsigned long long key_code;
147 
148 /* Special key codes. */
149 enum {
150 	/* Focus events. */
151 	KEYC_FOCUS_IN = KEYC_BASE,
152 	KEYC_FOCUS_OUT,
153 
154 	/* "Any" key, used if not found in key table. */
155 	KEYC_ANY,
156 
157 	/* Paste brackets. */
158 	KEYC_PASTE_START,
159 	KEYC_PASTE_END,
160 
161 	/* Mouse keys. */
162 	KEYC_MOUSE, /* unclassified mouse event */
163 	KEYC_DRAGGING, /* dragging in progress */
164 	KEYC_MOUSE_KEY(MOUSEMOVE),
165 	KEYC_MOUSE_KEY(MOUSEDOWN1),
166 	KEYC_MOUSE_KEY(MOUSEDOWN2),
167 	KEYC_MOUSE_KEY(MOUSEDOWN3),
168 	KEYC_MOUSE_KEY(MOUSEUP1),
169 	KEYC_MOUSE_KEY(MOUSEUP2),
170 	KEYC_MOUSE_KEY(MOUSEUP3),
171 	KEYC_MOUSE_KEY(MOUSEDRAG1),
172 	KEYC_MOUSE_KEY(MOUSEDRAG2),
173 	KEYC_MOUSE_KEY(MOUSEDRAG3),
174 	KEYC_MOUSE_KEY(MOUSEDRAGEND1),
175 	KEYC_MOUSE_KEY(MOUSEDRAGEND2),
176 	KEYC_MOUSE_KEY(MOUSEDRAGEND3),
177 	KEYC_MOUSE_KEY(WHEELUP),
178 	KEYC_MOUSE_KEY(WHEELDOWN),
179 	KEYC_MOUSE_KEY(DOUBLECLICK1),
180 	KEYC_MOUSE_KEY(DOUBLECLICK2),
181 	KEYC_MOUSE_KEY(DOUBLECLICK3),
182 	KEYC_MOUSE_KEY(TRIPLECLICK1),
183 	KEYC_MOUSE_KEY(TRIPLECLICK2),
184 	KEYC_MOUSE_KEY(TRIPLECLICK3),
185 
186 	/* Backspace key. */
187 	KEYC_BSPACE,
188 
189 	/* Function keys. */
190 	KEYC_F1,
191 	KEYC_F2,
192 	KEYC_F3,
193 	KEYC_F4,
194 	KEYC_F5,
195 	KEYC_F6,
196 	KEYC_F7,
197 	KEYC_F8,
198 	KEYC_F9,
199 	KEYC_F10,
200 	KEYC_F11,
201 	KEYC_F12,
202 	KEYC_IC,
203 	KEYC_DC,
204 	KEYC_HOME,
205 	KEYC_END,
206 	KEYC_NPAGE,
207 	KEYC_PPAGE,
208 	KEYC_BTAB,
209 
210 	/* Arrow keys. */
211 	KEYC_UP,
212 	KEYC_DOWN,
213 	KEYC_LEFT,
214 	KEYC_RIGHT,
215 
216 	/* Numeric keypad. */
217 	KEYC_KP_SLASH,
218 	KEYC_KP_STAR,
219 	KEYC_KP_MINUS,
220 	KEYC_KP_SEVEN,
221 	KEYC_KP_EIGHT,
222 	KEYC_KP_NINE,
223 	KEYC_KP_PLUS,
224 	KEYC_KP_FOUR,
225 	KEYC_KP_FIVE,
226 	KEYC_KP_SIX,
227 	KEYC_KP_ONE,
228 	KEYC_KP_TWO,
229 	KEYC_KP_THREE,
230 	KEYC_KP_ENTER,
231 	KEYC_KP_ZERO,
232 	KEYC_KP_PERIOD,
233 };
234 
235 /* Termcap codes. */
236 enum tty_code_code {
237 	TTYC_ACSC,
238 	TTYC_AX,
239 	TTYC_BCE,
240 	TTYC_BEL,
241 	TTYC_BLINK,
242 	TTYC_BOLD,
243 	TTYC_CIVIS,
244 	TTYC_CLEAR,
245 	TTYC_CNORM,
246 	TTYC_COLORS,
247 	TTYC_CR,
248 	TTYC_CS,
249 	TTYC_CSR,
250 	TTYC_CUB,
251 	TTYC_CUB1,
252 	TTYC_CUD,
253 	TTYC_CUD1,
254 	TTYC_CUF,
255 	TTYC_CUF1,
256 	TTYC_CUP,
257 	TTYC_CUU,
258 	TTYC_CUU1,
259 	TTYC_CVVIS,
260 	TTYC_DCH,
261 	TTYC_DCH1,
262 	TTYC_DIM,
263 	TTYC_DL,
264 	TTYC_DL1,
265 	TTYC_E3,
266 	TTYC_ECH,
267 	TTYC_ED,
268 	TTYC_EL,
269 	TTYC_EL1,
270 	TTYC_ENACS,
271 	TTYC_FSL,
272 	TTYC_HOME,
273 	TTYC_HPA,
274 	TTYC_ICH,
275 	TTYC_ICH1,
276 	TTYC_IL,
277 	TTYC_IL1,
278 	TTYC_INDN,
279 	TTYC_INVIS,
280 	TTYC_KCBT,
281 	TTYC_KCUB1,
282 	TTYC_KCUD1,
283 	TTYC_KCUF1,
284 	TTYC_KCUU1,
285 	TTYC_KDC2,
286 	TTYC_KDC3,
287 	TTYC_KDC4,
288 	TTYC_KDC5,
289 	TTYC_KDC6,
290 	TTYC_KDC7,
291 	TTYC_KDCH1,
292 	TTYC_KDN2,
293 	TTYC_KDN3,
294 	TTYC_KDN4,
295 	TTYC_KDN5,
296 	TTYC_KDN6,
297 	TTYC_KDN7,
298 	TTYC_KEND,
299 	TTYC_KEND2,
300 	TTYC_KEND3,
301 	TTYC_KEND4,
302 	TTYC_KEND5,
303 	TTYC_KEND6,
304 	TTYC_KEND7,
305 	TTYC_KF1,
306 	TTYC_KF10,
307 	TTYC_KF11,
308 	TTYC_KF12,
309 	TTYC_KF13,
310 	TTYC_KF14,
311 	TTYC_KF15,
312 	TTYC_KF16,
313 	TTYC_KF17,
314 	TTYC_KF18,
315 	TTYC_KF19,
316 	TTYC_KF2,
317 	TTYC_KF20,
318 	TTYC_KF21,
319 	TTYC_KF22,
320 	TTYC_KF23,
321 	TTYC_KF24,
322 	TTYC_KF25,
323 	TTYC_KF26,
324 	TTYC_KF27,
325 	TTYC_KF28,
326 	TTYC_KF29,
327 	TTYC_KF3,
328 	TTYC_KF30,
329 	TTYC_KF31,
330 	TTYC_KF32,
331 	TTYC_KF33,
332 	TTYC_KF34,
333 	TTYC_KF35,
334 	TTYC_KF36,
335 	TTYC_KF37,
336 	TTYC_KF38,
337 	TTYC_KF39,
338 	TTYC_KF4,
339 	TTYC_KF40,
340 	TTYC_KF41,
341 	TTYC_KF42,
342 	TTYC_KF43,
343 	TTYC_KF44,
344 	TTYC_KF45,
345 	TTYC_KF46,
346 	TTYC_KF47,
347 	TTYC_KF48,
348 	TTYC_KF49,
349 	TTYC_KF5,
350 	TTYC_KF50,
351 	TTYC_KF51,
352 	TTYC_KF52,
353 	TTYC_KF53,
354 	TTYC_KF54,
355 	TTYC_KF55,
356 	TTYC_KF56,
357 	TTYC_KF57,
358 	TTYC_KF58,
359 	TTYC_KF59,
360 	TTYC_KF6,
361 	TTYC_KF60,
362 	TTYC_KF61,
363 	TTYC_KF62,
364 	TTYC_KF63,
365 	TTYC_KF7,
366 	TTYC_KF8,
367 	TTYC_KF9,
368 	TTYC_KHOM2,
369 	TTYC_KHOM3,
370 	TTYC_KHOM4,
371 	TTYC_KHOM5,
372 	TTYC_KHOM6,
373 	TTYC_KHOM7,
374 	TTYC_KHOME,
375 	TTYC_KIC2,
376 	TTYC_KIC3,
377 	TTYC_KIC4,
378 	TTYC_KIC5,
379 	TTYC_KIC6,
380 	TTYC_KIC7,
381 	TTYC_KICH1,
382 	TTYC_KIND,
383 	TTYC_KLFT2,
384 	TTYC_KLFT3,
385 	TTYC_KLFT4,
386 	TTYC_KLFT5,
387 	TTYC_KLFT6,
388 	TTYC_KLFT7,
389 	TTYC_KMOUS,
390 	TTYC_KNP,
391 	TTYC_KNXT2,
392 	TTYC_KNXT3,
393 	TTYC_KNXT4,
394 	TTYC_KNXT5,
395 	TTYC_KNXT6,
396 	TTYC_KNXT7,
397 	TTYC_KPP,
398 	TTYC_KPRV2,
399 	TTYC_KPRV3,
400 	TTYC_KPRV4,
401 	TTYC_KPRV5,
402 	TTYC_KPRV6,
403 	TTYC_KPRV7,
404 	TTYC_KRI,
405 	TTYC_KRIT2,
406 	TTYC_KRIT3,
407 	TTYC_KRIT4,
408 	TTYC_KRIT5,
409 	TTYC_KRIT6,
410 	TTYC_KRIT7,
411 	TTYC_KUP2,
412 	TTYC_KUP3,
413 	TTYC_KUP4,
414 	TTYC_KUP5,
415 	TTYC_KUP6,
416 	TTYC_KUP7,
417 	TTYC_MS,
418 	TTYC_OP,
419 	TTYC_REV,
420 	TTYC_RGB,
421 	TTYC_RI,
422 	TTYC_RMACS,
423 	TTYC_RMCUP,
424 	TTYC_RMKX,
425 	TTYC_SE,
426 	TTYC_SETAB,
427 	TTYC_SETAF,
428 	TTYC_SETRGBB,
429 	TTYC_SETRGBF,
430 	TTYC_SGR0,
431 	TTYC_SITM,
432 	TTYC_SMACS,
433 	TTYC_SMCUP,
434 	TTYC_SMKX,
435 	TTYC_SMSO,
436 	TTYC_SMULX,
437 	TTYC_SMUL,
438 	TTYC_SMXX,
439 	TTYC_SS,
440 	TTYC_TC,
441 	TTYC_TSL,
442 	TTYC_U8,
443 	TTYC_VPA,
444 	TTYC_XENL,
445 	TTYC_XT,
446 };
447 
448 /* Message codes. */
449 enum msgtype {
450 	MSG_VERSION = 12,
451 
452 	MSG_IDENTIFY_FLAGS = 100,
453 	MSG_IDENTIFY_TERM,
454 	MSG_IDENTIFY_TTYNAME,
455 	MSG_IDENTIFY_OLDCWD, /* unused */
456 	MSG_IDENTIFY_STDIN,
457 	MSG_IDENTIFY_ENVIRON,
458 	MSG_IDENTIFY_DONE,
459 	MSG_IDENTIFY_CLIENTPID,
460 	MSG_IDENTIFY_CWD,
461 
462 	MSG_COMMAND = 200,
463 	MSG_DETACH,
464 	MSG_DETACHKILL,
465 	MSG_EXIT,
466 	MSG_EXITED,
467 	MSG_EXITING,
468 	MSG_LOCK,
469 	MSG_READY,
470 	MSG_RESIZE,
471 	MSG_SHELL,
472 	MSG_SHUTDOWN,
473 	MSG_STDERR,
474 	MSG_STDIN,
475 	MSG_STDOUT,
476 	MSG_SUSPEND,
477 	MSG_UNLOCK,
478 	MSG_WAKEUP,
479 	MSG_EXEC,
480 };
481 
482 /*
483  * Message data.
484  *
485  * Don't forget to bump PROTOCOL_VERSION if any of these change!
486  */
487 struct msg_command_data {
488 	int	argc;
489 }; /* followed by packed argv */
490 
491 struct msg_stdin_data {
492 	ssize_t	size;
493 	char	data[BUFSIZ];
494 };
495 
496 struct msg_stdout_data {
497 	ssize_t	size;
498 	char	data[BUFSIZ];
499 };
500 
501 struct msg_stderr_data {
502 	ssize_t	size;
503 	char	data[BUFSIZ];
504 };
505 
506 /* Mode keys. */
507 #define MODEKEY_EMACS 0
508 #define MODEKEY_VI 1
509 
510 /* Modes. */
511 #define MODE_CURSOR 0x1
512 #define MODE_INSERT 0x2
513 #define MODE_KCURSOR 0x4
514 #define MODE_KKEYPAD 0x8	/* set = application, clear = number */
515 #define MODE_WRAP 0x10		/* whether lines wrap */
516 #define MODE_MOUSE_STANDARD 0x20
517 #define MODE_MOUSE_BUTTON 0x40
518 #define MODE_BLINKING 0x80
519 #define MODE_MOUSE_UTF8 0x100
520 #define MODE_MOUSE_SGR 0x200
521 #define MODE_BRACKETPASTE 0x400
522 #define MODE_FOCUSON 0x800
523 #define MODE_MOUSE_ALL 0x1000
524 #define MODE_ORIGIN 0x2000
525 #define MODE_CRLF 0x4000
526 
527 #define ALL_MODES 0xffffff
528 #define ALL_MOUSE_MODES (MODE_MOUSE_STANDARD|MODE_MOUSE_BUTTON|MODE_MOUSE_ALL)
529 
530 /*
531  * A single UTF-8 character. UTF8_SIZE must be big enough to hold
532  * combining characters as well, currently at most five (of three
533  * bytes) are supported.
534 */
535 #define UTF8_SIZE 18
536 struct utf8_data {
537 	u_char	data[UTF8_SIZE];
538 
539 	u_char	have;
540 	u_char	size;
541 
542 	u_char	width;	/* 0xff if invalid */
543 } __packed;
544 enum utf8_state {
545 	UTF8_MORE,
546 	UTF8_DONE,
547 	UTF8_ERROR
548 };
549 
550 /* Colour flags. */
551 #define COLOUR_FLAG_256 0x01000000
552 #define COLOUR_FLAG_RGB 0x02000000
553 
554 /* Special colours. */
555 #define COLOUR_DEFAULT(c) ((c) == 8 || (c) == 9)
556 
557 /* Grid attributes. Anything above 0xff is stored in an extended cell. */
558 #define GRID_ATTR_BRIGHT 0x1
559 #define GRID_ATTR_DIM 0x2
560 #define GRID_ATTR_UNDERSCORE 0x4
561 #define GRID_ATTR_BLINK 0x8
562 #define GRID_ATTR_REVERSE 0x10
563 #define GRID_ATTR_HIDDEN 0x20
564 #define GRID_ATTR_ITALICS 0x40
565 #define GRID_ATTR_CHARSET 0x80	/* alternative character set */
566 #define GRID_ATTR_STRIKETHROUGH 0x100
567 #define GRID_ATTR_UNDERSCORE_2 0x200
568 #define GRID_ATTR_UNDERSCORE_3 0x400
569 #define GRID_ATTR_UNDERSCORE_4 0x800
570 #define GRID_ATTR_UNDERSCORE_5 0x1000
571 
572 /* All underscore attributes. */
573 #define GRID_ATTR_ALL_UNDERSCORE \
574 	(GRID_ATTR_UNDERSCORE|	 \
575 	 GRID_ATTR_UNDERSCORE_2| \
576 	 GRID_ATTR_UNDERSCORE_3| \
577 	 GRID_ATTR_UNDERSCORE_4| \
578 	 GRID_ATTR_UNDERSCORE_5)
579 
580 /* Grid flags. */
581 #define GRID_FLAG_FG256 0x1
582 #define GRID_FLAG_BG256 0x2
583 #define GRID_FLAG_PADDING 0x4
584 #define GRID_FLAG_EXTENDED 0x8
585 #define GRID_FLAG_SELECTED 0x10
586 #define GRID_FLAG_NOPALETTE 0x20
587 #define GRID_FLAG_CLEARED 0x40
588 
589 /* Grid line flags. */
590 #define GRID_LINE_WRAPPED 0x1
591 #define GRID_LINE_EXTENDED 0x2
592 #define GRID_LINE_DEAD 0x4
593 
594 /* Grid cell data. */
595 struct grid_cell {
596 	u_char			flags;
597 	u_short			attr;
598 	int			fg;
599 	int			bg;
600 	struct utf8_data	data;
601 };
602 struct grid_cell_entry {
603 	u_char			flags;
604 	union {
605 		u_int		offset;
606 		struct {
607 			u_char	attr;
608 			u_char	fg;
609 			u_char	bg;
610 			u_char	data;
611 		} data;
612 	};
613 } __packed;
614 
615 /* Grid line. */
616 struct grid_line {
617 	u_int			 cellused;
618 	u_int			 cellsize;
619 	struct grid_cell_entry	*celldata;
620 
621 	u_int			 extdsize;
622 	struct grid_cell	*extddata;
623 
624 	int			 flags;
625 } __packed;
626 
627 /* Entire grid of cells. */
628 struct grid {
629 	int			 flags;
630 #define GRID_HISTORY 0x1 /* scroll lines into history */
631 
632 	u_int			 sx;
633 	u_int			 sy;
634 
635 	u_int			 hscrolled;
636 	u_int			 hsize;
637 	u_int			 hlimit;
638 
639 	struct grid_line	*linedata;
640 };
641 
642 /* Style alignment. */
643 enum style_align {
644 	STYLE_ALIGN_DEFAULT,
645 	STYLE_ALIGN_LEFT,
646 	STYLE_ALIGN_CENTRE,
647 	STYLE_ALIGN_RIGHT
648 };
649 
650 /* Style list. */
651 enum style_list {
652 	STYLE_LIST_OFF,
653 	STYLE_LIST_ON,
654 	STYLE_LIST_FOCUS,
655 	STYLE_LIST_LEFT_MARKER,
656 	STYLE_LIST_RIGHT_MARKER,
657 };
658 
659 /* Style range. */
660 enum style_range_type {
661 	STYLE_RANGE_NONE,
662 	STYLE_RANGE_LEFT,
663 	STYLE_RANGE_RIGHT,
664 	STYLE_RANGE_WINDOW
665 };
666 struct style_range {
667 	enum style_range_type	 type;
668 	u_int			 argument;
669 
670 	u_int			 start;
671 	u_int			 end; /* not included */
672 
673 	TAILQ_ENTRY(style_range) entry;
674 };
675 TAILQ_HEAD(style_ranges, style_range);
676 
677 /* Style option. */
678 struct style {
679 	struct grid_cell	gc;
680 
681 	enum style_align	align;
682 	enum style_list		list;
683 
684 	enum style_range_type	range_type;
685 	u_int			range_argument;
686 };
687 
688 /* Virtual screen. */
689 struct screen_sel;
690 struct screen_titles;
691 struct screen {
692 	char			*title;
693 	struct screen_titles	*titles;
694 
695 	struct grid		*grid;		/* grid data */
696 
697 	u_int			 cx;		/* cursor x */
698 	u_int			 cy;		/* cursor y */
699 
700 	u_int			 cstyle;	/* cursor style */
701 	char			*ccolour;	/* cursor colour string */
702 
703 	u_int			 rupper;	/* scroll region top */
704 	u_int			 rlower;	/* scroll region bottom */
705 
706 	int			 mode;
707 
708 	bitstr_t		*tabs;
709 
710 	struct screen_sel	*sel;
711 };
712 
713 /* Screen write context. */
714 struct screen_write_collect_item;
715 struct screen_write_collect_line;
716 struct screen_write_ctx {
717 	struct window_pane	*wp;
718 	struct screen		*s;
719 
720 	struct screen_write_collect_item *item;
721 	struct screen_write_collect_line *list;
722 	u_int			 scrolled;
723 	u_int			 bg;
724 
725 	u_int			 cells;
726 	u_int			 written;
727 	u_int			 skipped;
728 };
729 
730 /* Screen size. */
731 #define screen_size_x(s) ((s)->grid->sx)
732 #define screen_size_y(s) ((s)->grid->sy)
733 #define screen_hsize(s) ((s)->grid->hsize)
734 #define screen_hlimit(s) ((s)->grid->hlimit)
735 
736 /*
737  * Window mode. Windows can be in several modes and this is used to call the
738  * right function to handle input and output.
739  */
740 struct window_mode_entry;
741 struct window_mode {
742 	const char	*name;
743 	const char	*default_format;
744 
745 	struct screen	*(*init)(struct window_mode_entry *,
746 			     struct cmd_find_state *, struct args *);
747 	void		 (*free)(struct window_mode_entry *);
748 	void		 (*resize)(struct window_mode_entry *, u_int, u_int);
749 	void		 (*key)(struct window_mode_entry *, struct client *,
750 			     struct session *, struct winlink *, key_code,
751 			     struct mouse_event *);
752 
753 	const char	*(*key_table)(struct window_mode_entry *);
754 	void		 (*command)(struct window_mode_entry *, struct client *,
755 			     struct session *, struct winlink *, struct args *,
756 			     struct mouse_event *);
757 	void		 (*formats)(struct window_mode_entry *,
758 			     struct format_tree *);
759 };
760 #define WINDOW_MODE_TIMEOUT 180
761 
762 /* Active window mode. */
763 struct window_mode_entry {
764 	struct window_pane		*wp;
765 
766 	const struct window_mode	*mode;
767 	void				*data;
768 
769 	struct screen			*screen;
770 	u_int				 prefix;
771 
772 	TAILQ_ENTRY (window_mode_entry)	 entry;
773 };
774 
775 /* Child window structure. */
776 struct window_pane {
777 	u_int		 id;
778 	u_int		 active_point;
779 
780 	struct window	*window;
781 
782 	struct layout_cell *layout_cell;
783 	struct layout_cell *saved_layout_cell;
784 
785 	u_int		 sx;
786 	u_int		 sy;
787 
788 	u_int		 osx;
789 	u_int		 osy;
790 
791 	u_int		 xoff;
792 	u_int		 yoff;
793 
794 	int		 flags;
795 #define PANE_REDRAW 0x1
796 #define PANE_DROP 0x2
797 #define PANE_FOCUSED 0x4
798 #define PANE_RESIZE 0x8
799 #define PANE_RESIZEFORCE 0x10
800 #define PANE_FOCUSPUSH 0x20
801 #define PANE_INPUTOFF 0x40
802 #define PANE_CHANGED 0x80
803 #define PANE_EXITED 0x100
804 #define PANE_STATUSREADY 0x200
805 #define PANE_STATUSDRAWN 0x400
806 #define PANE_EMPTY 0x800
807 
808 	int		 argc;
809 	char	       **argv;
810 	char		*shell;
811 	char		*cwd;
812 
813 	pid_t		 pid;
814 	char		 tty[TTY_NAME_MAX];
815 	int		 status;
816 
817 	int		 fd;
818 	struct bufferevent *event;
819 	u_int		 disabled;
820 
821 	struct event	 resize_timer;
822 
823 	struct input_ctx *ictx;
824 
825 	struct style	 style;
826 	int		*palette;
827 
828 	int		 pipe_fd;
829 	struct bufferevent *pipe_event;
830 	size_t		 pipe_off;
831 
832 	struct screen	*screen;
833 	struct screen	 base;
834 
835 	struct screen	 status_screen;
836 	size_t		 status_size;
837 
838 	/* Saved in alternative screen mode. */
839 	u_int		 saved_cx;
840 	u_int		 saved_cy;
841 	struct grid	*saved_grid;
842 	struct grid_cell saved_cell;
843 
844 	TAILQ_HEAD (, window_mode_entry) modes;
845 	struct event	 modetimer;
846 	time_t		 modelast;
847 	char		*searchstr;
848 
849 	TAILQ_ENTRY(window_pane) entry;
850 	RB_ENTRY(window_pane) tree_entry;
851 };
852 TAILQ_HEAD(window_panes, window_pane);
853 RB_HEAD(window_pane_tree, window_pane);
854 
855 /* Window structure. */
856 struct window {
857 	u_int		 id;
858 
859 	char		*name;
860 	struct event	 name_event;
861 	struct timeval	 name_time;
862 
863 	struct event	 alerts_timer;
864 	struct event	 offset_timer;
865 
866 	struct timeval	 activity_time;
867 
868 	struct window_pane *active;
869 	struct window_pane *last;
870 	struct window_panes panes;
871 
872 	int		 lastlayout;
873 	struct layout_cell *layout_root;
874 	struct layout_cell *saved_layout_root;
875 	char		*old_layout;
876 
877 	u_int		 sx;
878 	u_int		 sy;
879 
880 	int		 flags;
881 #define WINDOW_BELL 0x1
882 #define WINDOW_ACTIVITY 0x2
883 #define WINDOW_SILENCE 0x4
884 #define WINDOW_ZOOMED 0x8
885 #define WINDOW_STYLECHANGED 0x10
886 #define WINDOW_ALERTFLAGS (WINDOW_BELL|WINDOW_ACTIVITY|WINDOW_SILENCE)
887 
888 	int		 alerts_queued;
889 	TAILQ_ENTRY(window) alerts_entry;
890 
891 	struct options	*options;
892 
893 	struct style	 style;
894 	struct style	 active_style;
895 
896 	u_int		 references;
897 	TAILQ_HEAD(, winlink) winlinks;
898 
899 	RB_ENTRY(window) entry;
900 };
901 RB_HEAD(windows, window);
902 
903 /* Entry on local window list. */
904 struct winlink {
905 	int		 idx;
906 	struct session	*session;
907 	struct window	*window;
908 
909 	int		 flags;
910 #define WINLINK_BELL 0x1
911 #define WINLINK_ACTIVITY 0x2
912 #define WINLINK_SILENCE 0x4
913 #define WINLINK_ALERTFLAGS (WINLINK_BELL|WINLINK_ACTIVITY|WINLINK_SILENCE)
914 
915 	RB_ENTRY(winlink) entry;
916 	TAILQ_ENTRY(winlink) wentry;
917 	TAILQ_ENTRY(winlink) sentry;
918 };
919 RB_HEAD(winlinks, winlink);
920 TAILQ_HEAD(winlink_stack, winlink);
921 
922 /* Window size option. */
923 #define WINDOW_SIZE_LARGEST 0
924 #define WINDOW_SIZE_SMALLEST 1
925 #define WINDOW_SIZE_MANUAL 2
926 
927 /* Layout direction. */
928 enum layout_type {
929 	LAYOUT_LEFTRIGHT,
930 	LAYOUT_TOPBOTTOM,
931 	LAYOUT_WINDOWPANE
932 };
933 
934 /* Layout cells queue. */
935 TAILQ_HEAD(layout_cells, layout_cell);
936 
937 /* Layout cell. */
938 struct layout_cell {
939 	enum layout_type type;
940 
941 	struct layout_cell *parent;
942 
943 	u_int		 sx;
944 	u_int		 sy;
945 
946 	u_int		 xoff;
947 	u_int		 yoff;
948 
949 	struct window_pane *wp;
950 	struct layout_cells cells;
951 
952 	TAILQ_ENTRY(layout_cell) entry;
953 };
954 
955 /* Environment variable. */
956 struct environ_entry {
957 	char		*name;
958 	char		*value;
959 
960 	RB_ENTRY(environ_entry) entry;
961 };
962 
963 /* Client session. */
964 struct session_group {
965 	const char		*name;
966 	TAILQ_HEAD(, session)	 sessions;
967 
968 	RB_ENTRY(session_group)	 entry;
969 };
970 RB_HEAD(session_groups, session_group);
971 
972 struct session {
973 	u_int		 id;
974 
975 	char		*name;
976 	const char	*cwd;
977 
978 	struct timeval	 creation_time;
979 	struct timeval	 last_attached_time;
980 	struct timeval	 activity_time;
981 	struct timeval	 last_activity_time;
982 
983 	struct event	 lock_timer;
984 
985 	struct winlink	*curw;
986 	struct winlink_stack lastw;
987 	struct winlinks	 windows;
988 
989 	int		 statusat;
990 	u_int		 statuslines;
991 
992 	struct options	*options;
993 
994 #define SESSION_PASTING 0x1
995 #define SESSION_ALERTED 0x2
996 	int		 flags;
997 
998 	u_int		 attached;
999 
1000 	struct termios	*tio;
1001 
1002 	struct environ	*environ;
1003 
1004 	int		 references;
1005 
1006 	TAILQ_ENTRY(session) gentry;
1007 	RB_ENTRY(session)    entry;
1008 };
1009 RB_HEAD(sessions, session);
1010 
1011 /* Mouse button masks. */
1012 #define MOUSE_MASK_BUTTONS 3
1013 #define MOUSE_MASK_SHIFT 4
1014 #define MOUSE_MASK_META 8
1015 #define MOUSE_MASK_CTRL 16
1016 #define MOUSE_MASK_DRAG 32
1017 #define MOUSE_MASK_WHEEL 64
1018 
1019 /* Mouse wheel states. */
1020 #define MOUSE_WHEEL_UP 0
1021 #define MOUSE_WHEEL_DOWN 1
1022 
1023 /* Mouse helpers. */
1024 #define MOUSE_BUTTONS(b) ((b) & MOUSE_MASK_BUTTONS)
1025 #define MOUSE_WHEEL(b) ((b) & MOUSE_MASK_WHEEL)
1026 #define MOUSE_DRAG(b) ((b) & MOUSE_MASK_DRAG)
1027 #define MOUSE_RELEASE(b) (((b) & MOUSE_MASK_BUTTONS) == 3)
1028 
1029 /* Mouse input. */
1030 struct mouse_event {
1031 	int		valid;
1032 
1033 	key_code	key;
1034 
1035 	int		statusat;
1036 	u_int		statuslines;
1037 
1038 	u_int		x;
1039 	u_int		y;
1040 	u_int		b;
1041 
1042 	u_int		lx;
1043 	u_int		ly;
1044 	u_int		lb;
1045 
1046 	u_int		ox;
1047 	u_int		oy;
1048 
1049 	int		s;
1050 	int		w;
1051 	int		wp;
1052 
1053 	u_int		sgr_type;
1054 	u_int		sgr_b;
1055 };
1056 
1057 /* Key event. */
1058 struct key_event {
1059 	key_code		key;
1060 	struct mouse_event	m;
1061 };
1062 
1063 /* TTY information. */
1064 struct tty_key {
1065 	char		 ch;
1066 	key_code	 key;
1067 
1068 	struct tty_key	*left;
1069 	struct tty_key	*right;
1070 
1071 	struct tty_key	*next;
1072 };
1073 
1074 struct tty_code;
1075 struct tty_term {
1076 	char		*name;
1077 	u_int		 references;
1078 
1079 	char		 acs[UCHAR_MAX + 1][2];
1080 
1081 	struct tty_code	*codes;
1082 
1083 #define TERM_256COLOURS 0x1
1084 #define TERM_EARLYWRAP 0x2
1085 	int		 flags;
1086 
1087 	LIST_ENTRY(tty_term) entry;
1088 };
1089 LIST_HEAD(tty_terms, tty_term);
1090 
1091 struct tty {
1092 	struct client	*client;
1093 
1094 	u_int		 sx;
1095 	u_int		 sy;
1096 
1097 	u_int		 cx;
1098 	u_int		 cy;
1099 	u_int		 cstyle;
1100 	char		*ccolour;
1101 
1102 	int		 oflag;
1103 	u_int		 oox;
1104 	u_int		 ooy;
1105 	u_int		 osx;
1106 	u_int		 osy;
1107 
1108 	int		 mode;
1109 
1110 	u_int		 rlower;
1111 	u_int		 rupper;
1112 
1113 	u_int		 rleft;
1114 	u_int		 rright;
1115 
1116 	int		 fd;
1117 	struct event	 event_in;
1118 	struct evbuffer	*in;
1119 	struct event	 event_out;
1120 	struct evbuffer	*out;
1121 	struct event	 timer;
1122 	size_t		 discarded;
1123 
1124 	struct termios	 tio;
1125 
1126 	struct grid_cell cell;
1127 
1128 	int		 last_wp;
1129 	struct grid_cell last_cell;
1130 
1131 #define TTY_NOCURSOR 0x1
1132 #define TTY_FREEZE 0x2
1133 #define TTY_TIMER 0x4
1134 #define TTY_UTF8 0x8
1135 #define TTY_STARTED 0x10
1136 #define TTY_OPENED 0x20
1137 #define TTY_FOCUS 0x40
1138 #define TTY_BLOCK 0x80
1139 	int		 flags;
1140 
1141 	struct tty_term	*term;
1142 	char		*term_name;
1143 	int		 term_flags;
1144 	enum {
1145 		TTY_VT100,
1146 		TTY_VT101,
1147 		TTY_VT102,
1148 		TTY_VT220,
1149 		TTY_VT320,
1150 		TTY_VT420,
1151 		TTY_UNKNOWN
1152 	} term_type;
1153 
1154 	u_int		 mouse_last_x;
1155 	u_int		 mouse_last_y;
1156 	int		 mouse_drag_flag;
1157 	void		(*mouse_drag_update)(struct client *,
1158 			    struct mouse_event *);
1159 	void		(*mouse_drag_release)(struct client *,
1160 			    struct mouse_event *);
1161 
1162 	struct event	 key_timer;
1163 	struct tty_key	*key_tree;
1164 };
1165 #define TTY_TYPES \
1166 	{ "VT100", "VT101", "VT102", "VT220", "VT320", "VT420", "Unknown" }
1167 
1168 /* TTY command context. */
1169 struct tty_ctx {
1170 	struct window_pane	*wp;
1171 
1172 	const struct grid_cell	*cell;
1173 	int			 wrapped;
1174 
1175 	u_int		 num;
1176 	void		*ptr;
1177 
1178 	/*
1179 	 * Cursor and region position before the screen was updated - this is
1180 	 * where the command should be applied; the values in the screen have
1181 	 * already been updated.
1182 	 */
1183 	u_int		 ocx;
1184 	u_int		 ocy;
1185 
1186 	u_int		 orupper;
1187 	u_int		 orlower;
1188 
1189 	/* Pane offset. */
1190 	u_int		 xoff;
1191 	u_int		 yoff;
1192 
1193 	/* The background colour used for clearing (erasing). */
1194 	u_int		 bg;
1195 
1196 	/* Window offset and size. */
1197 	int		 bigger;
1198 	u_int		 ox;
1199 	u_int		 oy;
1200 	u_int		 sx;
1201 	u_int		 sy;
1202 };
1203 
1204 /* Saved message entry. */
1205 struct message_entry {
1206 	char	*msg;
1207 	u_int	 msg_num;
1208 	time_t	 msg_time;
1209 	TAILQ_ENTRY(message_entry) entry;
1210 };
1211 
1212 /* Parsed arguments structures. */
1213 struct args_entry;
1214 RB_HEAD(args_tree, args_entry);
1215 struct args {
1216 	struct args_tree	  tree;
1217 	int			  argc;
1218 	char			**argv;
1219 };
1220 
1221 /* Command find structures. */
1222 enum cmd_find_type {
1223 	CMD_FIND_PANE,
1224 	CMD_FIND_WINDOW,
1225 	CMD_FIND_SESSION,
1226 };
1227 struct cmd_find_state {
1228 	int			 flags;
1229 	struct cmd_find_state	*current;
1230 
1231 	struct session		*s;
1232 	struct winlink		*wl;
1233 	struct window		*w;
1234 	struct window_pane	*wp;
1235 	int			 idx;
1236 };
1237 
1238 /* Command find flags. */
1239 #define CMD_FIND_PREFER_UNATTACHED 0x1
1240 #define CMD_FIND_QUIET 0x2
1241 #define CMD_FIND_WINDOW_INDEX 0x4
1242 #define CMD_FIND_DEFAULT_MARKED 0x8
1243 #define CMD_FIND_EXACT_SESSION 0x10
1244 #define CMD_FIND_EXACT_WINDOW 0x20
1245 #define CMD_FIND_CANFAIL 0x40
1246 
1247 /* Command and list of commands. */
1248 struct cmd {
1249 	const struct cmd_entry	*entry;
1250 	struct args		*args;
1251 
1252 	char			*file;
1253 	u_int			 line;
1254 
1255 #define CMD_CONTROL 0x1
1256 	int			 flags;
1257 
1258 	TAILQ_ENTRY(cmd)	 qentry;
1259 };
1260 
1261 struct cmd_list {
1262 	int			 references;
1263 	TAILQ_HEAD(, cmd)	 list;
1264 };
1265 
1266 /* Command return values. */
1267 enum cmd_retval {
1268 	CMD_RETURN_ERROR = -1,
1269 	CMD_RETURN_NORMAL = 0,
1270 	CMD_RETURN_WAIT,
1271 	CMD_RETURN_STOP
1272 };
1273 
1274 /* Command queue item type. */
1275 enum cmdq_type {
1276 	CMDQ_COMMAND,
1277 	CMDQ_CALLBACK,
1278 };
1279 
1280 /* Command queue item shared state. */
1281 struct cmdq_shared {
1282 	int			 references;
1283 
1284 	int			 flags;
1285 #define CMDQ_SHARED_REPEAT 0x1
1286 
1287 	struct format_tree	*formats;
1288 
1289 	struct mouse_event	 mouse;
1290 	struct cmd_find_state	 current;
1291 };
1292 
1293 /* Command queue item. */
1294 typedef enum cmd_retval (*cmdq_cb) (struct cmdq_item *, void *);
1295 struct cmdq_item {
1296 	char			*name;
1297 	struct cmdq_list	*queue;
1298 	struct cmdq_item	*next;
1299 
1300 	struct client		*client;
1301 
1302 	enum cmdq_type		 type;
1303 	u_int			 group;
1304 
1305 	u_int			 number;
1306 	time_t			 time;
1307 
1308 	int			 flags;
1309 #define CMDQ_FIRED 0x1
1310 #define CMDQ_WAITING 0x2
1311 #define CMDQ_NOHOOKS 0x4
1312 
1313 	struct cmdq_shared	*shared;
1314 	struct cmd_find_state	 source;
1315 	struct cmd_find_state	 target;
1316 
1317 	struct cmd_list		*cmdlist;
1318 	struct cmd		*cmd;
1319 
1320 	cmdq_cb			 cb;
1321 	void			*data;
1322 
1323 	TAILQ_ENTRY(cmdq_item)	 entry;
1324 };
1325 TAILQ_HEAD(cmdq_list, cmdq_item);
1326 
1327 /* Command definition flag. */
1328 struct cmd_entry_flag {
1329 	char			 flag;
1330 	enum cmd_find_type	 type;
1331 	int			 flags;
1332 };
1333 
1334 /* Command definition. */
1335 struct cmd_entry {
1336 	const char		*name;
1337 	const char		*alias;
1338 
1339 	struct {
1340 		const char	*template;
1341 		int		 lower;
1342 		int		 upper;
1343 	} args;
1344 	const char		*usage;
1345 
1346 	struct cmd_entry_flag	 source;
1347 	struct cmd_entry_flag	 target;
1348 
1349 #define CMD_STARTSERVER 0x1
1350 #define CMD_READONLY 0x2
1351 #define CMD_AFTERHOOK 0x4
1352 	int		 flags;
1353 
1354 	enum cmd_retval	 (*exec)(struct cmd *, struct cmdq_item *);
1355 };
1356 
1357 /* Status line. */
1358 #define STATUS_LINES_LIMIT 5
1359 struct status_line_entry {
1360 	char			*expanded;
1361 	struct style_ranges	 ranges;
1362 };
1363 struct status_line {
1364 	struct event		 timer;
1365 
1366 	struct screen		 screen;
1367 	struct screen		*active;
1368 	int			 references;
1369 
1370 	struct grid_cell	 style;
1371 	struct status_line_entry entries[STATUS_LINES_LIMIT];
1372 };
1373 
1374 /* Client connection. */
1375 typedef int (*prompt_input_cb)(struct client *, void *, const char *, int);
1376 typedef void (*prompt_free_cb)(void *);
1377 struct client {
1378 	const char	*name;
1379 	struct tmuxpeer	*peer;
1380 	struct cmdq_list queue;
1381 
1382 	pid_t		 pid;
1383 	int		 fd;
1384 	struct event	 event;
1385 	int		 retval;
1386 
1387 	struct timeval	 creation_time;
1388 	struct timeval	 activity_time;
1389 
1390 	struct environ	*environ;
1391 	struct format_job_tree	*jobs;
1392 
1393 	char		*title;
1394 	const char	*cwd;
1395 
1396 	char		*term;
1397 	char		*ttyname;
1398 	struct tty	 tty;
1399 
1400 	size_t		 written;
1401 	size_t		 discarded;
1402 	size_t		 redraw;
1403 
1404 	void		(*stdin_callback)(struct client *, int, void *);
1405 	void		*stdin_callback_data;
1406 	struct evbuffer	*stdin_data;
1407 	int		 stdin_closed;
1408 	struct evbuffer	*stdout_data;
1409 	struct evbuffer	*stderr_data;
1410 
1411 	struct event	 repeat_timer;
1412 
1413 	struct event	 click_timer;
1414 	u_int		 click_button;
1415 
1416 	struct status_line status;
1417 
1418 #define CLIENT_TERMINAL 0x1
1419 #define CLIENT_LOGIN 0x2
1420 #define CLIENT_EXIT 0x4
1421 #define CLIENT_REDRAWWINDOW 0x8
1422 #define CLIENT_REDRAWSTATUS 0x10
1423 #define CLIENT_REPEAT 0x20
1424 #define CLIENT_SUSPENDED 0x40
1425 #define CLIENT_ATTACHED 0x80
1426 #define CLIENT_IDENTIFY 0x100
1427 #define CLIENT_DEAD 0x200
1428 #define CLIENT_REDRAWBORDERS 0x400
1429 #define CLIENT_READONLY 0x800
1430 #define CLIENT_DETACHING 0x1000
1431 #define CLIENT_CONTROL 0x2000
1432 #define CLIENT_CONTROLCONTROL 0x4000
1433 #define CLIENT_FOCUSED 0x8000
1434 #define CLIENT_UTF8 0x10000
1435 #define CLIENT_256COLOURS 0x20000
1436 #define CLIENT_IDENTIFIED 0x40000
1437 #define CLIENT_STATUSFORCE 0x80000
1438 #define CLIENT_DOUBLECLICK 0x100000
1439 #define CLIENT_TRIPLECLICK 0x200000
1440 #define CLIENT_SIZECHANGED 0x400000
1441 #define CLIENT_STATUSOFF 0x800000
1442 #define CLIENT_REDRAWSTATUSALWAYS 0x1000000
1443 #define CLIENT_ALLREDRAWFLAGS		\
1444 	(CLIENT_REDRAWWINDOW|		\
1445 	 CLIENT_REDRAWSTATUS|		\
1446 	 CLIENT_REDRAWSTATUSALWAYS|	\
1447 	 CLIENT_REDRAWBORDERS)
1448 #define CLIENT_NOSIZEFLAGS	\
1449 	(CLIENT_DEAD|		\
1450 	 CLIENT_SUSPENDED|	\
1451 	 CLIENT_DETACHING)
1452 	int		 flags;
1453 	struct key_table *keytable;
1454 
1455 	struct event	 identify_timer;
1456 	void		(*identify_callback)(struct client *,
1457 			     struct window_pane *);
1458 	void		*identify_callback_data;
1459 	struct cmdq_item *identify_callback_item;
1460 
1461 	char		*message_string;
1462 	struct event	 message_timer;
1463 	u_int		 message_next;
1464 	TAILQ_HEAD(, message_entry) message_log;
1465 
1466 	char		*prompt_string;
1467 	struct utf8_data *prompt_buffer;
1468 	size_t		 prompt_index;
1469 	prompt_input_cb	 prompt_inputcb;
1470 	prompt_free_cb	 prompt_freecb;
1471 	void		*prompt_data;
1472 	u_int		 prompt_hindex;
1473 	enum { PROMPT_ENTRY, PROMPT_COMMAND } prompt_mode;
1474 	struct utf8_data *prompt_saved;
1475 
1476 #define PROMPT_SINGLE 0x1
1477 #define PROMPT_NUMERIC 0x2
1478 #define PROMPT_INCREMENTAL 0x4
1479 #define PROMPT_NOFORMAT 0x8
1480 	int		 prompt_flags;
1481 
1482 	struct session	*session;
1483 	struct session	*last_session;
1484 
1485 	int		 references;
1486 
1487 	void		*pan_window;
1488 	u_int		 pan_ox;
1489 	u_int		 pan_oy;
1490 
1491 	TAILQ_ENTRY(client) entry;
1492 };
1493 TAILQ_HEAD(clients, client);
1494 
1495 /* Key binding and key table. */
1496 struct key_binding {
1497 	key_code		 key;
1498 	struct cmd_list		*cmdlist;
1499 
1500 	int			 flags;
1501 #define KEY_BINDING_REPEAT 0x1
1502 
1503 	RB_ENTRY(key_binding)	 entry;
1504 };
1505 RB_HEAD(key_bindings, key_binding);
1506 
1507 struct key_table {
1508 	const char		*name;
1509 	struct key_bindings	 key_bindings;
1510 
1511 	u_int			 references;
1512 
1513 	RB_ENTRY(key_table)	 entry;
1514 };
1515 RB_HEAD(key_tables, key_table);
1516 
1517 /* Option data. */
1518 RB_HEAD(options_array, options_array_item);
1519 union options_value {
1520 	char				 *string;
1521 	long long			  number;
1522 	struct style			  style;
1523 	struct options_array		  array;
1524 	struct cmd_list			 *cmdlist;
1525 };
1526 
1527 /* Option table entries. */
1528 enum options_table_type {
1529 	OPTIONS_TABLE_STRING,
1530 	OPTIONS_TABLE_NUMBER,
1531 	OPTIONS_TABLE_KEY,
1532 	OPTIONS_TABLE_COLOUR,
1533 	OPTIONS_TABLE_FLAG,
1534 	OPTIONS_TABLE_CHOICE,
1535 	OPTIONS_TABLE_STYLE,
1536 	OPTIONS_TABLE_COMMAND
1537 };
1538 
1539 enum options_table_scope {
1540 	OPTIONS_TABLE_NONE,
1541 	OPTIONS_TABLE_SERVER,
1542 	OPTIONS_TABLE_SESSION,
1543 	OPTIONS_TABLE_WINDOW
1544 };
1545 
1546 #define OPTIONS_TABLE_IS_ARRAY 0x1
1547 #define OPTIONS_TABLE_IS_HOOK 0x2
1548 
1549 struct options_table_entry {
1550 	const char		 *name;
1551 	enum options_table_type	  type;
1552 	enum options_table_scope  scope;
1553 	int                       flags;
1554 
1555 	u_int			  minimum;
1556 	u_int			  maximum;
1557 	const char		**choices;
1558 
1559 	const char		 *default_str;
1560 	long long		  default_num;
1561 	const char		**default_arr;
1562 
1563 	const char		 *separator;
1564 	const char		 *pattern;
1565 };
1566 
1567 /* Common command usages. */
1568 #define CMD_TARGET_PANE_USAGE "[-t target-pane]"
1569 #define CMD_TARGET_WINDOW_USAGE "[-t target-window]"
1570 #define CMD_TARGET_SESSION_USAGE "[-t target-session]"
1571 #define CMD_TARGET_CLIENT_USAGE "[-t target-client]"
1572 #define CMD_SRCDST_PANE_USAGE "[-s src-pane] [-t dst-pane]"
1573 #define CMD_SRCDST_WINDOW_USAGE "[-s src-window] [-t dst-window]"
1574 #define CMD_SRCDST_SESSION_USAGE "[-s src-session] [-t dst-session]"
1575 #define CMD_SRCDST_CLIENT_USAGE "[-s src-client] [-t dst-client]"
1576 #define CMD_BUFFER_USAGE "[-b buffer-name]"
1577 
1578 /* Spawn common context. */
1579 struct spawn_context {
1580 	struct cmdq_item	 *item;
1581 
1582 	struct session		 *s;
1583 	struct winlink		 *wl;
1584 
1585 	struct window_pane	 *wp0;
1586 	struct layout_cell	 *lc;
1587 
1588 	const char		 *name;
1589 	char			**argv;
1590 	int			  argc;
1591 	struct environ           *environ;
1592 
1593 	int			  idx;
1594 	const char		 *cwd;
1595 
1596 	int			  flags;
1597 #define SPAWN_KILL 0x1
1598 #define SPAWN_DETACHED 0x2
1599 #define SPAWN_RESPAWN 0x4
1600 #define SPAWN_BEFORE 0x8
1601 #define SPAWN_NONOTIFY 0x10
1602 #define SPAWN_FULLSIZE 0x20
1603 #define SPAWN_EMPTY 0x40
1604 };
1605 
1606 /* tmux.c */
1607 extern struct options	*global_options;
1608 extern struct options	*global_s_options;
1609 extern struct options	*global_w_options;
1610 extern struct environ	*global_environ;
1611 extern struct timeval	 start_time;
1612 extern const char	*socket_path;
1613 extern const char	*shell_command;
1614 extern int		 ptm_fd;
1615 extern const char	*shell_command;
1616 int		 areshell(const char *);
1617 void		 setblocking(int, int);
1618 const char	*find_cwd(void);
1619 const char	*find_home(void);
1620 
1621 /* proc.c */
1622 struct imsg;
1623 int	proc_send(struct tmuxpeer *, enum msgtype, int, const void *, size_t);
1624 struct tmuxproc *proc_start(const char *);
1625 void	proc_loop(struct tmuxproc *, int (*)(void));
1626 void	proc_exit(struct tmuxproc *);
1627 void	proc_set_signals(struct tmuxproc *, void(*)(int));
1628 void	proc_clear_signals(struct tmuxproc *, int);
1629 struct tmuxpeer *proc_add_peer(struct tmuxproc *, int,
1630 	    void (*)(struct imsg *, void *), void *);
1631 void	proc_remove_peer(struct tmuxpeer *);
1632 void	proc_kill_peer(struct tmuxpeer *);
1633 void	proc_toggle_log(struct tmuxproc *);
1634 
1635 /* cfg.c */
1636 extern int cfg_finished;
1637 extern struct client *cfg_client;
1638 void	start_cfg(void);
1639 int	load_cfg(const char *, struct client *, struct cmdq_item *, int);
1640 void	set_cfg_file(const char *);
1641 void printflike(1, 2) cfg_add_cause(const char *, ...);
1642 void	cfg_print_causes(struct cmdq_item *);
1643 void	cfg_show_causes(struct session *);
1644 
1645 /* paste.c */
1646 struct paste_buffer;
1647 const char	*paste_buffer_name(struct paste_buffer *);
1648 u_int		 paste_buffer_order(struct paste_buffer *);
1649 time_t		 paste_buffer_created(struct paste_buffer *);
1650 const char	*paste_buffer_data(struct paste_buffer *, size_t *);
1651 struct paste_buffer *paste_walk(struct paste_buffer *);
1652 struct paste_buffer *paste_get_top(const char **);
1653 struct paste_buffer *paste_get_name(const char *);
1654 void		 paste_free(struct paste_buffer *);
1655 void		 paste_add(const char *, char *, size_t);
1656 int		 paste_rename(const char *, const char *, char **);
1657 int		 paste_set(char *, size_t, const char *, char **);
1658 char		*paste_make_sample(struct paste_buffer *);
1659 
1660 /* format.c */
1661 #define FORMAT_STATUS 0x1
1662 #define FORMAT_FORCE 0x2
1663 #define FORMAT_NOJOBS 0x4
1664 #define FORMAT_VERBOSE 0x8
1665 #define FORMAT_NONE 0
1666 #define FORMAT_PANE 0x80000000U
1667 #define FORMAT_WINDOW 0x40000000U
1668 struct format_tree;
1669 const char	*format_skip(const char *s, const char *end);
1670 int		 format_true(const char *);
1671 struct format_tree *format_create(struct client *, struct cmdq_item *, int,
1672 		     int);
1673 void		 format_free(struct format_tree *);
1674 void printflike(3, 4) format_add(struct format_tree *, const char *,
1675 		     const char *, ...);
1676 void		 format_each(struct format_tree *, void (*)(const char *,
1677 		     const char *, void *), void *);
1678 char		*format_expand_time(struct format_tree *, const char *);
1679 char		*format_expand(struct format_tree *, const char *);
1680 char		*format_single(struct cmdq_item *, const char *,
1681 		     struct client *, struct session *, struct winlink *,
1682 		     struct window_pane *);
1683 void		 format_defaults(struct format_tree *, struct client *,
1684 		     struct session *, struct winlink *, struct window_pane *);
1685 void		 format_defaults_window(struct format_tree *, struct window *);
1686 void		 format_defaults_pane(struct format_tree *,
1687 		     struct window_pane *);
1688 void		 format_defaults_paste_buffer(struct format_tree *,
1689 		     struct paste_buffer *);
1690 void		 format_lost_client(struct client *);
1691 
1692 /* format-draw.c */
1693 void		 format_draw(struct screen_write_ctx *,
1694 		     const struct grid_cell *, u_int, const char *,
1695 		     struct style_ranges *);
1696 u_int		 format_width(const char *);
1697 char		*format_trim_left(const char *, u_int);
1698 char		*format_trim_right(const char *, u_int);
1699 
1700 /* notify.c */
1701 void	notify_hook(struct cmdq_item *, const char *);
1702 void	notify_input(struct window_pane *, struct evbuffer *);
1703 void	notify_client(const char *, struct client *);
1704 void	notify_session(const char *, struct session *);
1705 void	notify_winlink(const char *, struct winlink *);
1706 void	notify_session_window(const char *, struct session *, struct window *);
1707 void	notify_window(const char *, struct window *);
1708 void	notify_pane(const char *, struct window_pane *);
1709 
1710 /* options.c */
1711 struct options	*options_create(struct options *);
1712 void		 options_free(struct options *);
1713 struct options_entry *options_first(struct options *);
1714 struct options_entry *options_next(struct options_entry *);
1715 struct options_entry *options_empty(struct options *,
1716 		     const struct options_table_entry *);
1717 struct options_entry *options_default(struct options *,
1718 		     const struct options_table_entry *);
1719 const char	*options_name(struct options_entry *);
1720 const struct options_table_entry *options_table_entry(struct options_entry *);
1721 struct options_entry *options_get_only(struct options *, const char *);
1722 struct options_entry *options_get(struct options *, const char *);
1723 void		 options_remove(struct options_entry *);
1724 void		 options_array_clear(struct options_entry *);
1725 union options_value *options_array_get(struct options_entry *, u_int);
1726 int		 options_array_set(struct options_entry *, u_int, const char *,
1727 		     int, char **);
1728 int		 options_array_assign(struct options_entry *, const char *,
1729 		     char **);
1730 struct options_array_item *options_array_first(struct options_entry *);
1731 struct options_array_item *options_array_next(struct options_array_item *);
1732 u_int		 options_array_item_index(struct options_array_item *);
1733 union options_value *options_array_item_value(struct options_array_item *);
1734 int		 options_isarray(struct options_entry *);
1735 int		 options_isstring(struct options_entry *);
1736 char		*options_tostring(struct options_entry *, int, int);
1737 char		*options_parse(const char *, int *);
1738 struct options_entry *options_parse_get(struct options *, const char *, int *,
1739 		     int);
1740 char		*options_match(const char *, int *, int *);
1741 struct options_entry *options_match_get(struct options *, const char *, int *,
1742 		     int, int *);
1743 const char	*options_get_string(struct options *, const char *);
1744 long long	 options_get_number(struct options *, const char *);
1745 struct style	*options_get_style(struct options *, const char *);
1746 struct options_entry * printflike(4, 5) options_set_string(struct options *,
1747 		     const char *, int, const char *, ...);
1748 struct options_entry *options_set_number(struct options *, const char *,
1749 		     long long);
1750 struct options_entry *options_set_style(struct options *, const char *, int,
1751 		     const char *);
1752 enum options_table_scope options_scope_from_flags(struct args *, int,
1753 		     struct cmd_find_state *, struct options **, char **);
1754 
1755 /* options-table.c */
1756 extern const struct options_table_entry options_table[];
1757 
1758 /* job.c */
1759 typedef void (*job_update_cb) (struct job *);
1760 typedef void (*job_complete_cb) (struct job *);
1761 typedef void (*job_free_cb) (void *);
1762 #define JOB_NOWAIT 0x1
1763 struct job	*job_run(const char *, struct session *, const char *,
1764 		     job_update_cb, job_complete_cb, job_free_cb, void *, int);
1765 void		 job_free(struct job *);
1766 void		 job_check_died(pid_t, int);
1767 int		 job_get_status(struct job *);
1768 void		*job_get_data(struct job *);
1769 struct bufferevent *job_get_event(struct job *);
1770 void		 job_kill_all(void);
1771 int		 job_still_running(void);
1772 void		 job_print_summary(struct cmdq_item *, int);
1773 
1774 /* environ.c */
1775 struct environ *environ_create(void);
1776 void	environ_free(struct environ *);
1777 struct environ_entry *environ_first(struct environ *);
1778 struct environ_entry *environ_next(struct environ_entry *);
1779 void	environ_copy(struct environ *, struct environ *);
1780 struct environ_entry *environ_find(struct environ *, const char *);
1781 void printflike(3, 4) environ_set(struct environ *, const char *, const char *,
1782 	    ...);
1783 void	environ_clear(struct environ *, const char *);
1784 void	environ_put(struct environ *, const char *);
1785 void	environ_unset(struct environ *, const char *);
1786 void	environ_update(struct options *, struct environ *, struct environ *);
1787 void	environ_push(struct environ *);
1788 void printflike(2, 3) environ_log(struct environ *, const char *, ...);
1789 struct environ *environ_for_session(struct session *, int);
1790 
1791 /* tty.c */
1792 void	tty_create_log(void);
1793 int	tty_window_bigger(struct tty *);
1794 int	tty_window_offset(struct tty *, u_int *, u_int *, u_int *, u_int *);
1795 void	tty_update_window_offset(struct window *);
1796 void	tty_update_client_offset(struct client *);
1797 void	tty_raw(struct tty *, const char *);
1798 void	tty_attributes(struct tty *, const struct grid_cell *,
1799 	    struct window_pane *);
1800 void	tty_reset(struct tty *);
1801 void	tty_region_off(struct tty *);
1802 void	tty_margin_off(struct tty *);
1803 void	tty_cursor(struct tty *, u_int, u_int);
1804 void	tty_putcode(struct tty *, enum tty_code_code);
1805 void	tty_putcode1(struct tty *, enum tty_code_code, int);
1806 void	tty_putcode2(struct tty *, enum tty_code_code, int, int);
1807 void	tty_putcode3(struct tty *, enum tty_code_code, int, int, int);
1808 void	tty_putcode_ptr1(struct tty *, enum tty_code_code, const void *);
1809 void	tty_putcode_ptr2(struct tty *, enum tty_code_code, const void *,
1810 	    const void *);
1811 void	tty_puts(struct tty *, const char *);
1812 void	tty_putc(struct tty *, u_char);
1813 void	tty_putn(struct tty *, const void *, size_t, u_int);
1814 int	tty_init(struct tty *, struct client *, int, char *);
1815 void	tty_resize(struct tty *);
1816 void	tty_set_size(struct tty *, u_int, u_int);
1817 void	tty_start_tty(struct tty *);
1818 void	tty_stop_tty(struct tty *);
1819 void	tty_set_title(struct tty *, const char *);
1820 void	tty_update_mode(struct tty *, int, struct screen *);
1821 void	tty_draw_line(struct tty *, struct window_pane *, struct screen *,
1822 	    u_int, u_int, u_int, u_int, u_int);
1823 int	tty_open(struct tty *, char **);
1824 void	tty_close(struct tty *);
1825 void	tty_free(struct tty *);
1826 void	tty_set_type(struct tty *, int);
1827 void	tty_write(void (*)(struct tty *, const struct tty_ctx *),
1828 	    struct tty_ctx *);
1829 void	tty_cmd_alignmenttest(struct tty *, const struct tty_ctx *);
1830 void	tty_cmd_cell(struct tty *, const struct tty_ctx *);
1831 void	tty_cmd_cells(struct tty *, const struct tty_ctx *);
1832 void	tty_cmd_clearendofline(struct tty *, const struct tty_ctx *);
1833 void	tty_cmd_clearendofscreen(struct tty *, const struct tty_ctx *);
1834 void	tty_cmd_clearline(struct tty *, const struct tty_ctx *);
1835 void	tty_cmd_clearscreen(struct tty *, const struct tty_ctx *);
1836 void	tty_cmd_clearstartofline(struct tty *, const struct tty_ctx *);
1837 void	tty_cmd_clearstartofscreen(struct tty *, const struct tty_ctx *);
1838 void	tty_cmd_deletecharacter(struct tty *, const struct tty_ctx *);
1839 void	tty_cmd_clearcharacter(struct tty *, const struct tty_ctx *);
1840 void	tty_cmd_deleteline(struct tty *, const struct tty_ctx *);
1841 void	tty_cmd_erasecharacter(struct tty *, const struct tty_ctx *);
1842 void	tty_cmd_insertcharacter(struct tty *, const struct tty_ctx *);
1843 void	tty_cmd_insertline(struct tty *, const struct tty_ctx *);
1844 void	tty_cmd_linefeed(struct tty *, const struct tty_ctx *);
1845 void	tty_cmd_scrollup(struct tty *, const struct tty_ctx *);
1846 void	tty_cmd_reverseindex(struct tty *, const struct tty_ctx *);
1847 void	tty_cmd_setselection(struct tty *, const struct tty_ctx *);
1848 void	tty_cmd_rawstring(struct tty *, const struct tty_ctx *);
1849 
1850 /* tty-term.c */
1851 extern struct tty_terms tty_terms;
1852 u_int		 tty_term_ncodes(void);
1853 struct tty_term *tty_term_find(char *, int, char **);
1854 void		 tty_term_free(struct tty_term *);
1855 int		 tty_term_has(struct tty_term *, enum tty_code_code);
1856 const char	*tty_term_string(struct tty_term *, enum tty_code_code);
1857 const char	*tty_term_string1(struct tty_term *, enum tty_code_code, int);
1858 const char	*tty_term_string2(struct tty_term *, enum tty_code_code, int,
1859 		     int);
1860 const char	*tty_term_string3(struct tty_term *, enum tty_code_code, int,
1861 		     int, int);
1862 const char	*tty_term_ptr1(struct tty_term *, enum tty_code_code,
1863 		     const void *);
1864 const char	*tty_term_ptr2(struct tty_term *, enum tty_code_code,
1865 		     const void *, const void *);
1866 int		 tty_term_number(struct tty_term *, enum tty_code_code);
1867 int		 tty_term_flag(struct tty_term *, enum tty_code_code);
1868 const char	*tty_term_describe(struct tty_term *, enum tty_code_code);
1869 
1870 /* tty-acs.c */
1871 int		 tty_acs_needed(struct tty *);
1872 const char	*tty_acs_get(struct tty *, u_char);
1873 
1874 /* tty-keys.c */
1875 void		tty_keys_build(struct tty *);
1876 void		tty_keys_free(struct tty *);
1877 int		tty_keys_next(struct tty *);
1878 
1879 /* arguments.c */
1880 void		 args_set(struct args *, u_char, const char *);
1881 struct args	*args_parse(const char *, int, char **);
1882 void		 args_free(struct args *);
1883 char		*args_print(struct args *);
1884 int		 args_has(struct args *, u_char);
1885 const char	*args_get(struct args *, u_char);
1886 const char	*args_first_value(struct args *, u_char, struct args_value **);
1887 const char	*args_next_value(struct args_value **);
1888 long long	 args_strtonum(struct args *, u_char, long long, long long,
1889 		     char **);
1890 
1891 /* cmd-find.c */
1892 int		 cmd_find_target(struct cmd_find_state *, struct cmdq_item *,
1893 		     const char *, enum cmd_find_type, int);
1894 struct client	*cmd_find_best_client(struct session *);
1895 struct client	*cmd_find_client(struct cmdq_item *, const char *, int);
1896 void		 cmd_find_clear_state(struct cmd_find_state *, int);
1897 int		 cmd_find_empty_state(struct cmd_find_state *);
1898 int		 cmd_find_valid_state(struct cmd_find_state *);
1899 void		 cmd_find_copy_state(struct cmd_find_state *,
1900 		     struct cmd_find_state *);
1901 void		 cmd_find_from_session(struct cmd_find_state *,
1902 		     struct session *, int);
1903 void		 cmd_find_from_winlink(struct cmd_find_state *,
1904 		     struct winlink *, int);
1905 int		 cmd_find_from_session_window(struct cmd_find_state *,
1906 		     struct session *, struct window *, int);
1907 int		 cmd_find_from_window(struct cmd_find_state *, struct window *,
1908 		     int);
1909 void		 cmd_find_from_winlink_pane(struct cmd_find_state *,
1910 		     struct winlink *, struct window_pane *, int);
1911 int		 cmd_find_from_pane(struct cmd_find_state *,
1912 		     struct window_pane *, int);
1913 int		 cmd_find_from_client(struct cmd_find_state *, struct client *,
1914 		     int);
1915 int		 cmd_find_from_mouse(struct cmd_find_state *,
1916 		     struct mouse_event *, int);
1917 int		 cmd_find_from_nothing(struct cmd_find_state *, int);
1918 
1919 /* cmd.c */
1920 void		 cmd_log_argv(int, char **, const char *);
1921 int		 cmd_pack_argv(int, char **, char *, size_t);
1922 int		 cmd_unpack_argv(char *, size_t, int, char ***);
1923 char	       **cmd_copy_argv(int, char **);
1924 void		 cmd_free_argv(int, char **);
1925 char		*cmd_stringify_argv(int, char **);
1926 struct cmd	*cmd_parse(int, char **, const char *, u_int, char **);
1927 char		*cmd_print(struct cmd *);
1928 int		 cmd_mouse_at(struct window_pane *, struct mouse_event *,
1929 		     u_int *, u_int *, int);
1930 struct winlink	*cmd_mouse_window(struct mouse_event *, struct session **);
1931 struct window_pane *cmd_mouse_pane(struct mouse_event *, struct session **,
1932 		     struct winlink **);
1933 char		*cmd_template_replace(const char *, const char *, int);
1934 extern const struct cmd_entry *cmd_table[];
1935 
1936 /* cmd-attach-session.c */
1937 enum cmd_retval	 cmd_attach_session(struct cmdq_item *, const char *, int, int,
1938 		     const char *, int);
1939 
1940 /* cmd-list.c */
1941 struct cmd_list	*cmd_list_parse(int, char **, const char *, u_int, char **);
1942 void		 cmd_list_free(struct cmd_list *);
1943 char		*cmd_list_print(struct cmd_list *);
1944 
1945 /* cmd-queue.c */
1946 struct cmdq_item *cmdq_get_command(struct cmd_list *, struct cmd_find_state *,
1947 		     struct mouse_event *, int);
1948 #define cmdq_get_callback(cb, data) cmdq_get_callback1(#cb, cb, data)
1949 struct cmdq_item *cmdq_get_callback1(const char *, cmdq_cb, void *);
1950 void		 cmdq_insert_after(struct cmdq_item *, struct cmdq_item *);
1951 void		 cmdq_append(struct client *, struct cmdq_item *);
1952 void		 cmdq_insert_hook(struct session *, struct cmdq_item *,
1953 		     struct cmd_find_state *, const char *, ...);
1954 void printflike(3, 4) cmdq_format(struct cmdq_item *, const char *,
1955 		     const char *, ...);
1956 u_int		 cmdq_next(struct client *);
1957 void		 cmdq_guard(struct cmdq_item *, const char *, int);
1958 void printflike(2, 3) cmdq_print(struct cmdq_item *, const char *, ...);
1959 void printflike(2, 3) cmdq_error(struct cmdq_item *, const char *, ...);
1960 
1961 /* cmd-string.c */
1962 int		 cmd_string_split(const char *, int *, char ***);
1963 struct cmd_list	*cmd_string_parse(const char *, const char *, u_int, char **);
1964 
1965 /* cmd-wait-for.c */
1966 void	cmd_wait_for_flush(void);
1967 
1968 /* client.c */
1969 int	client_main(struct event_base *, int, char **, int);
1970 
1971 /* key-bindings.c */
1972 struct key_table *key_bindings_get_table(const char *, int);
1973 struct key_table *key_bindings_first_table(void);
1974 struct key_table *key_bindings_next_table(struct key_table *);
1975 void	 key_bindings_unref_table(struct key_table *);
1976 struct key_binding *key_bindings_get(struct key_table *, key_code);
1977 struct key_binding *key_bindings_first(struct key_table *);
1978 struct key_binding *key_bindings_next(struct key_table *, struct key_binding *);
1979 void	 key_bindings_add(const char *, key_code, int, struct cmd_list *);
1980 void	 key_bindings_remove(const char *, key_code);
1981 void	 key_bindings_remove_table(const char *);
1982 void	 key_bindings_init(void);
1983 void	 key_bindings_dispatch(struct key_binding *, struct cmdq_item *,
1984 	     struct client *, struct mouse_event *, struct cmd_find_state *);
1985 
1986 /* key-string.c */
1987 key_code	 key_string_lookup_string(const char *);
1988 const char	*key_string_lookup_key(key_code);
1989 
1990 /* alerts.c */
1991 void	alerts_reset_all(void);
1992 void	alerts_queue(struct window *, int);
1993 void	alerts_check_session(struct session *);
1994 
1995 /* server.c */
1996 extern struct tmuxproc *server_proc;
1997 extern struct clients clients;
1998 extern struct cmd_find_state marked_pane;
1999 void	 server_set_marked(struct session *, struct winlink *,
2000 	     struct window_pane *);
2001 void	 server_clear_marked(void);
2002 int	 server_is_marked(struct session *, struct winlink *,
2003 	     struct window_pane *);
2004 int	 server_check_marked(void);
2005 int	 server_start(struct tmuxproc *, struct event_base *, int, char *);
2006 void	 server_update_socket(void);
2007 void	 server_add_accept(int);
2008 
2009 /* server-client.c */
2010 u_int	 server_client_how_many(void);
2011 void	 server_client_set_identify(struct client *, u_int);
2012 void	 server_client_set_key_table(struct client *, const char *);
2013 const char *server_client_get_key_table(struct client *);
2014 int	 server_client_check_nested(struct client *);
2015 enum cmd_retval server_client_key_callback(struct cmdq_item *, void *);
2016 struct client *server_client_create(int);
2017 int	 server_client_open(struct client *, char **);
2018 void	 server_client_unref(struct client *);
2019 void	 server_client_lost(struct client *);
2020 void	 server_client_suspend(struct client *);
2021 void	 server_client_detach(struct client *, enum msgtype);
2022 void	 server_client_exec(struct client *, const char *);
2023 void	 server_client_loop(void);
2024 void	 server_client_push_stdout(struct client *);
2025 void	 server_client_push_stderr(struct client *);
2026 void printflike(2, 3) server_client_add_message(struct client *, const char *,
2027 	     ...);
2028 char	*server_client_get_path(struct client *, const char *);
2029 const char *server_client_get_cwd(struct client *, struct session *);
2030 
2031 /* server-fn.c */
2032 void	 server_redraw_client(struct client *);
2033 void	 server_status_client(struct client *);
2034 void	 server_redraw_session(struct session *);
2035 void	 server_redraw_session_group(struct session *);
2036 void	 server_status_session(struct session *);
2037 void	 server_status_session_group(struct session *);
2038 void	 server_redraw_window(struct window *);
2039 void	 server_redraw_window_borders(struct window *);
2040 void	 server_status_window(struct window *);
2041 void	 server_lock(void);
2042 void	 server_lock_session(struct session *);
2043 void	 server_lock_client(struct client *);
2044 void	 server_kill_pane(struct window_pane *);
2045 void	 server_kill_window(struct window *);
2046 int	 server_link_window(struct session *,
2047 	     struct winlink *, struct session *, int, int, int, char **);
2048 void	 server_unlink_window(struct session *, struct winlink *);
2049 void	 server_destroy_pane(struct window_pane *, int);
2050 void	 server_destroy_session(struct session *);
2051 void	 server_check_unattached(void);
2052 int	 server_set_stdin_callback(struct client *, void (*)(struct client *,
2053 	     int, void *), void *, char **);
2054 void	 server_unzoom_window(struct window *);
2055 
2056 /* status.c */
2057 void	 status_timer_start(struct client *);
2058 void	 status_timer_start_all(void);
2059 void	 status_update_cache(struct session *);
2060 int	 status_at_line(struct client *);
2061 u_int	 status_line_size(struct client *);
2062 struct style_range *status_get_range(struct client *, u_int, u_int);
2063 void	 status_init(struct client *);
2064 void	 status_free(struct client *);
2065 int	 status_redraw(struct client *);
2066 void printflike(2, 3) status_message_set(struct client *, const char *, ...);
2067 void	 status_message_clear(struct client *);
2068 int	 status_message_redraw(struct client *);
2069 void	 status_prompt_set(struct client *, const char *, const char *,
2070 	     prompt_input_cb, prompt_free_cb, void *, int);
2071 void	 status_prompt_clear(struct client *);
2072 int	 status_prompt_redraw(struct client *);
2073 int	 status_prompt_key(struct client *, key_code);
2074 void	 status_prompt_update(struct client *, const char *, const char *);
2075 void	 status_prompt_load_history(void);
2076 void	 status_prompt_save_history(void);
2077 
2078 /* resize.c */
2079 void	 resize_window(struct window *, u_int, u_int);
2080 void	 default_window_size(struct session *, struct window *, u_int *,
2081 	     u_int *, int);
2082 void	 recalculate_sizes(void);
2083 
2084 /* input.c */
2085 void	 input_init(struct window_pane *);
2086 void	 input_free(struct window_pane *);
2087 void	 input_reset(struct window_pane *, int);
2088 struct evbuffer *input_pending(struct window_pane *);
2089 void	 input_parse(struct window_pane *);
2090 
2091 /* input-key.c */
2092 void	 input_key(struct window_pane *, key_code, struct mouse_event *);
2093 
2094 /* xterm-keys.c */
2095 char	*xterm_keys_lookup(key_code);
2096 int	 xterm_keys_find(const char *, size_t, size_t *, key_code *);
2097 
2098 /* colour.c */
2099 int	 colour_find_rgb(u_char, u_char, u_char);
2100 int	 colour_join_rgb(u_char, u_char, u_char);
2101 void	 colour_split_rgb(int, u_char *, u_char *, u_char *);
2102 const char *colour_tostring(int);
2103 int	 colour_fromstring(const char *s);
2104 u_char	 colour_256to16(u_char);
2105 
2106 /* attributes.c */
2107 const char *attributes_tostring(int);
2108 int	 attributes_fromstring(const char *);
2109 
2110 /* grid.c */
2111 extern const struct grid_cell grid_default_cell;
2112 int	 grid_cells_equal(const struct grid_cell *, const struct grid_cell *);
2113 struct grid *grid_create(u_int, u_int, u_int);
2114 void	 grid_destroy(struct grid *);
2115 int	 grid_compare(struct grid *, struct grid *);
2116 void	 grid_collect_history(struct grid *);
2117 void	 grid_scroll_history(struct grid *, u_int);
2118 void	 grid_scroll_history_region(struct grid *, u_int, u_int, u_int);
2119 void	 grid_clear_history(struct grid *);
2120 const struct grid_line *grid_peek_line(struct grid *, u_int);
2121 void	 grid_get_cell(struct grid *, u_int, u_int, struct grid_cell *);
2122 void	 grid_set_cell(struct grid *, u_int, u_int, const struct grid_cell *);
2123 void	 grid_set_cells(struct grid *, u_int, u_int, const struct grid_cell *,
2124 	     const char *, size_t);
2125 struct grid_line *grid_get_line(struct grid *, u_int);
2126 void	 grid_adjust_lines(struct grid *, u_int);
2127 void	 grid_clear(struct grid *, u_int, u_int, u_int, u_int, u_int);
2128 void	 grid_clear_lines(struct grid *, u_int, u_int, u_int);
2129 void	 grid_move_lines(struct grid *, u_int, u_int, u_int, u_int);
2130 void	 grid_move_cells(struct grid *, u_int, u_int, u_int, u_int, u_int);
2131 char	*grid_string_cells(struct grid *, u_int, u_int, u_int,
2132 	     struct grid_cell **, int, int, int);
2133 void	 grid_duplicate_lines(struct grid *, u_int, struct grid *, u_int,
2134 	     u_int);
2135 void	 grid_reflow(struct grid *, u_int);
2136 void	 grid_wrap_position(struct grid *, u_int, u_int, u_int *, u_int *);
2137 void	 grid_unwrap_position(struct grid *, u_int *, u_int *, u_int, u_int);
2138 
2139 /* grid-view.c */
2140 void	 grid_view_get_cell(struct grid *, u_int, u_int, struct grid_cell *);
2141 void	 grid_view_set_cell(struct grid *, u_int, u_int,
2142 	     const struct grid_cell *);
2143 void	 grid_view_set_cells(struct grid *, u_int, u_int,
2144 	     const struct grid_cell *, const char *, size_t);
2145 void	 grid_view_clear_history(struct grid *, u_int);
2146 void	 grid_view_clear(struct grid *, u_int, u_int, u_int, u_int, u_int);
2147 void	 grid_view_scroll_region_up(struct grid *, u_int, u_int, u_int);
2148 void	 grid_view_scroll_region_down(struct grid *, u_int, u_int, u_int);
2149 void	 grid_view_insert_lines(struct grid *, u_int, u_int, u_int);
2150 void	 grid_view_insert_lines_region(struct grid *, u_int, u_int, u_int,
2151 	     u_int);
2152 void	 grid_view_delete_lines(struct grid *, u_int, u_int, u_int);
2153 void	 grid_view_delete_lines_region(struct grid *, u_int, u_int, u_int,
2154 	     u_int);
2155 void	 grid_view_insert_cells(struct grid *, u_int, u_int, u_int, u_int);
2156 void	 grid_view_delete_cells(struct grid *, u_int, u_int, u_int, u_int);
2157 char	*grid_view_string_cells(struct grid *, u_int, u_int, u_int);
2158 
2159 /* screen-write.c */
2160 void	 screen_write_start(struct screen_write_ctx *, struct window_pane *,
2161 	     struct screen *);
2162 void	 screen_write_stop(struct screen_write_ctx *);
2163 void	 screen_write_reset(struct screen_write_ctx *);
2164 size_t printflike(1, 2) screen_write_strlen(const char *, ...);
2165 void printflike(3, 4) screen_write_puts(struct screen_write_ctx *,
2166 	     const struct grid_cell *, const char *, ...);
2167 void printflike(4, 5) screen_write_nputs(struct screen_write_ctx *,
2168 	     ssize_t, const struct grid_cell *, const char *, ...);
2169 void	 screen_write_vnputs(struct screen_write_ctx *, ssize_t,
2170 	     const struct grid_cell *, const char *, va_list);
2171 void	 screen_write_putc(struct screen_write_ctx *, const struct grid_cell *,
2172 	     u_char);
2173 void	 screen_write_copy(struct screen_write_ctx *, struct screen *, u_int,
2174 	     u_int, u_int, u_int, bitstr_t *, const struct grid_cell *);
2175 void	 screen_write_fast_copy(struct screen_write_ctx *, struct screen *,
2176 	     u_int, u_int, u_int, u_int);
2177 void	 screen_write_hline(struct screen_write_ctx *, u_int, int, int);
2178 void	 screen_write_vline(struct screen_write_ctx *, u_int, int, int);
2179 void	 screen_write_box(struct screen_write_ctx *, u_int, u_int);
2180 void	 screen_write_preview(struct screen_write_ctx *, struct screen *, u_int,
2181 	     u_int);
2182 void	 screen_write_backspace(struct screen_write_ctx *);
2183 void	 screen_write_mode_set(struct screen_write_ctx *, int);
2184 void	 screen_write_mode_clear(struct screen_write_ctx *, int);
2185 void	 screen_write_cursorup(struct screen_write_ctx *, u_int);
2186 void	 screen_write_cursordown(struct screen_write_ctx *, u_int);
2187 void	 screen_write_cursorright(struct screen_write_ctx *, u_int);
2188 void	 screen_write_cursorleft(struct screen_write_ctx *, u_int);
2189 void	 screen_write_alignmenttest(struct screen_write_ctx *);
2190 void	 screen_write_insertcharacter(struct screen_write_ctx *, u_int, u_int);
2191 void	 screen_write_deletecharacter(struct screen_write_ctx *, u_int, u_int);
2192 void	 screen_write_clearcharacter(struct screen_write_ctx *, u_int, u_int);
2193 void	 screen_write_insertline(struct screen_write_ctx *, u_int, u_int);
2194 void	 screen_write_deleteline(struct screen_write_ctx *, u_int, u_int);
2195 void	 screen_write_clearline(struct screen_write_ctx *, u_int);
2196 void	 screen_write_clearendofline(struct screen_write_ctx *, u_int);
2197 void	 screen_write_clearstartofline(struct screen_write_ctx *, u_int);
2198 void	 screen_write_cursormove(struct screen_write_ctx *, int, int, int);
2199 void	 screen_write_reverseindex(struct screen_write_ctx *, u_int);
2200 void	 screen_write_scrollregion(struct screen_write_ctx *, u_int, u_int);
2201 void	 screen_write_linefeed(struct screen_write_ctx *, int, u_int);
2202 void	 screen_write_scrollup(struct screen_write_ctx *, u_int, u_int);
2203 void	 screen_write_carriagereturn(struct screen_write_ctx *);
2204 void	 screen_write_clearendofscreen(struct screen_write_ctx *, u_int);
2205 void	 screen_write_clearstartofscreen(struct screen_write_ctx *, u_int);
2206 void	 screen_write_clearscreen(struct screen_write_ctx *, u_int);
2207 void	 screen_write_clearhistory(struct screen_write_ctx *);
2208 void	 screen_write_collect_end(struct screen_write_ctx *);
2209 void	 screen_write_collect_add(struct screen_write_ctx *,
2210 	     const struct grid_cell *);
2211 void	 screen_write_cell(struct screen_write_ctx *, const struct grid_cell *);
2212 void	 screen_write_setselection(struct screen_write_ctx *, u_char *, u_int);
2213 void	 screen_write_rawstring(struct screen_write_ctx *, u_char *, u_int);
2214 
2215 /* screen-redraw.c */
2216 void	 screen_redraw_screen(struct client *);
2217 void	 screen_redraw_pane(struct client *, struct window_pane *);
2218 
2219 /* screen.c */
2220 void	 screen_init(struct screen *, u_int, u_int, u_int);
2221 void	 screen_reinit(struct screen *);
2222 void	 screen_free(struct screen *);
2223 void	 screen_reset_tabs(struct screen *);
2224 void	 screen_set_cursor_style(struct screen *, u_int);
2225 void	 screen_set_cursor_colour(struct screen *, const char *);
2226 void	 screen_set_title(struct screen *, const char *);
2227 void	 screen_push_title(struct screen *);
2228 void	 screen_pop_title(struct screen *);
2229 void	 screen_resize(struct screen *, u_int, u_int, int);
2230 void	 screen_set_selection(struct screen *, u_int, u_int, u_int, u_int,
2231 	     u_int, int, struct grid_cell *);
2232 void	 screen_clear_selection(struct screen *);
2233 void	 screen_hide_selection(struct screen *);
2234 int	 screen_check_selection(struct screen *, u_int, u_int);
2235 void	 screen_select_cell(struct screen *, struct grid_cell *,
2236 	     const struct grid_cell *);
2237 
2238 /* window.c */
2239 extern struct windows windows;
2240 extern struct window_pane_tree all_window_panes;
2241 extern const struct window_mode *all_window_modes[];
2242 int		 window_cmp(struct window *, struct window *);
2243 RB_PROTOTYPE(windows, window, entry, window_cmp);
2244 int		 winlink_cmp(struct winlink *, struct winlink *);
2245 RB_PROTOTYPE(winlinks, winlink, entry, winlink_cmp);
2246 int		 window_pane_cmp(struct window_pane *, struct window_pane *);
2247 RB_PROTOTYPE(window_pane_tree, window_pane, tree_entry, window_pane_cmp);
2248 struct winlink	*winlink_find_by_index(struct winlinks *, int);
2249 struct winlink	*winlink_find_by_window(struct winlinks *, struct window *);
2250 struct winlink	*winlink_find_by_window_id(struct winlinks *, u_int);
2251 u_int		 winlink_count(struct winlinks *);
2252 struct winlink	*winlink_add(struct winlinks *, int);
2253 void		 winlink_set_window(struct winlink *, struct window *);
2254 void		 winlink_remove(struct winlinks *, struct winlink *);
2255 struct winlink	*winlink_next(struct winlink *);
2256 struct winlink	*winlink_previous(struct winlink *);
2257 struct winlink	*winlink_next_by_number(struct winlink *, struct session *,
2258 		     int);
2259 struct winlink	*winlink_previous_by_number(struct winlink *, struct session *,
2260 		     int);
2261 void		 winlink_stack_push(struct winlink_stack *, struct winlink *);
2262 void		 winlink_stack_remove(struct winlink_stack *, struct winlink *);
2263 struct window	*window_find_by_id_str(const char *);
2264 struct window	*window_find_by_id(u_int);
2265 void		 window_update_activity(struct window *);
2266 struct window	*window_create(u_int, u_int);
2267 void		 window_destroy(struct window *);
2268 void		 window_pane_set_event(struct window_pane *);
2269 struct window_pane *window_get_active_at(struct window *, u_int, u_int);
2270 struct window_pane *window_find_string(struct window *, const char *);
2271 int		 window_has_pane(struct window *, struct window_pane *);
2272 int		 window_set_active_pane(struct window *, struct window_pane *,
2273 		     int);
2274 void		 window_redraw_active_switch(struct window *,
2275 		     struct window_pane *);
2276 struct window_pane *window_add_pane(struct window *, struct window_pane *,
2277 		     u_int, int);
2278 void		 window_resize(struct window *, u_int, u_int);
2279 int		 window_zoom(struct window_pane *);
2280 int		 window_unzoom(struct window *);
2281 void		 window_lost_pane(struct window *, struct window_pane *);
2282 void		 window_remove_pane(struct window *, struct window_pane *);
2283 struct window_pane *window_pane_at_index(struct window *, u_int);
2284 struct window_pane *window_pane_next_by_number(struct window *,
2285 			struct window_pane *, u_int);
2286 struct window_pane *window_pane_previous_by_number(struct window *,
2287 			struct window_pane *, u_int);
2288 int		 window_pane_index(struct window_pane *, u_int *);
2289 u_int		 window_count_panes(struct window *);
2290 void		 window_destroy_panes(struct window *);
2291 struct window_pane *window_pane_find_by_id_str(const char *);
2292 struct window_pane *window_pane_find_by_id(u_int);
2293 int		 window_pane_destroy_ready(struct window_pane *);
2294 void		 window_pane_resize(struct window_pane *, u_int, u_int);
2295 void		 window_pane_alternate_on(struct window_pane *,
2296 		     struct grid_cell *, int);
2297 void		 window_pane_alternate_off(struct window_pane *,
2298 		     struct grid_cell *, int);
2299 void		 window_pane_set_palette(struct window_pane *, u_int, int);
2300 void		 window_pane_unset_palette(struct window_pane *, u_int);
2301 void		 window_pane_reset_palette(struct window_pane *);
2302 int		 window_pane_get_palette(struct window_pane *, int);
2303 int		 window_pane_set_mode(struct window_pane *,
2304 		     const struct window_mode *, struct cmd_find_state *,
2305 		     struct args *);
2306 void		 window_pane_reset_mode(struct window_pane *);
2307 void		 window_pane_reset_mode_all(struct window_pane *);
2308 void		 window_pane_key(struct window_pane *, struct client *,
2309 		     struct session *, struct winlink *, key_code,
2310 		     struct mouse_event *);
2311 int		 window_pane_visible(struct window_pane *);
2312 u_int		 window_pane_search(struct window_pane *, const char *);
2313 const char	*window_printable_flags(struct winlink *);
2314 struct window_pane *window_pane_find_up(struct window_pane *);
2315 struct window_pane *window_pane_find_down(struct window_pane *);
2316 struct window_pane *window_pane_find_left(struct window_pane *);
2317 struct window_pane *window_pane_find_right(struct window_pane *);
2318 void		 window_set_name(struct window *, const char *);
2319 void		 window_add_ref(struct window *, const char *);
2320 void		 window_remove_ref(struct window *, const char *);
2321 void		 winlink_clear_flags(struct winlink *);
2322 int		 winlink_shuffle_up(struct session *, struct winlink *);
2323 int		 window_pane_start_input(struct window_pane *,
2324 		     struct cmdq_item *, char **);
2325 
2326 /* layout.c */
2327 u_int		 layout_count_cells(struct layout_cell *);
2328 struct layout_cell *layout_create_cell(struct layout_cell *);
2329 void		 layout_free_cell(struct layout_cell *);
2330 void		 layout_print_cell(struct layout_cell *, const char *, u_int);
2331 void		 layout_destroy_cell(struct window *, struct layout_cell *,
2332 		     struct layout_cell **);
2333 void		 layout_resize_layout(struct window *, struct layout_cell *,
2334 		     enum layout_type, int, int);
2335 struct layout_cell *layout_search_by_border(struct layout_cell *, u_int, u_int);
2336 void		 layout_set_size(struct layout_cell *, u_int, u_int, u_int,
2337 		     u_int);
2338 void		 layout_make_leaf(struct layout_cell *, struct window_pane *);
2339 void		 layout_make_node(struct layout_cell *, enum layout_type);
2340 void		 layout_fix_offsets(struct layout_cell *);
2341 void		 layout_fix_panes(struct window *);
2342 void		 layout_resize_adjust(struct window *, struct layout_cell *,
2343 		     enum layout_type, int);
2344 void		 layout_init(struct window *, struct window_pane *);
2345 void		 layout_free(struct window *);
2346 void		 layout_resize(struct window *, u_int, u_int);
2347 void		 layout_resize_pane(struct window_pane *, enum layout_type,
2348 		     int, int);
2349 void		 layout_resize_pane_to(struct window_pane *, enum layout_type,
2350 		     u_int);
2351 void		 layout_assign_pane(struct layout_cell *, struct window_pane *);
2352 struct layout_cell *layout_split_pane(struct window_pane *, enum layout_type,
2353 		     int, int);
2354 void		 layout_close_pane(struct window_pane *);
2355 int		 layout_spread_cell(struct window *, struct layout_cell *);
2356 void		 layout_spread_out(struct window_pane *);
2357 
2358 /* layout-custom.c */
2359 char		*layout_dump(struct layout_cell *);
2360 int		 layout_parse(struct window *, const char *);
2361 
2362 /* layout-set.c */
2363 int		 layout_set_lookup(const char *);
2364 u_int		 layout_set_select(struct window *, u_int);
2365 u_int		 layout_set_next(struct window *);
2366 u_int		 layout_set_previous(struct window *);
2367 
2368 /* mode-tree.c */
2369 typedef void (*mode_tree_build_cb)(void *, u_int, uint64_t *, const char *);
2370 typedef void (*mode_tree_draw_cb)(void *, void *, struct screen_write_ctx *,
2371     u_int, u_int);
2372 typedef int (*mode_tree_search_cb)(void *, void *, const char *);
2373 typedef void (*mode_tree_each_cb)(void *, void *, struct client *, key_code);
2374 u_int	 mode_tree_count_tagged(struct mode_tree_data *);
2375 void	*mode_tree_get_current(struct mode_tree_data *);
2376 void	 mode_tree_expand_current(struct mode_tree_data *);
2377 void	 mode_tree_set_current(struct mode_tree_data *, uint64_t);
2378 void	 mode_tree_each_tagged(struct mode_tree_data *, mode_tree_each_cb,
2379 	     struct client *, key_code, int);
2380 void	 mode_tree_down(struct mode_tree_data *, int);
2381 struct mode_tree_data *mode_tree_start(struct window_pane *, struct args *,
2382 	     mode_tree_build_cb, mode_tree_draw_cb, mode_tree_search_cb,
2383 	     void *, const char **, u_int, struct screen **);
2384 void	 mode_tree_zoom(struct mode_tree_data *, struct args *);
2385 void	 mode_tree_build(struct mode_tree_data *);
2386 void	 mode_tree_free(struct mode_tree_data *);
2387 void	 mode_tree_resize(struct mode_tree_data *, u_int, u_int);
2388 struct mode_tree_item *mode_tree_add(struct mode_tree_data *,
2389 	     struct mode_tree_item *, void *, uint64_t, const char *,
2390 	     const char *, int);
2391 void	 mode_tree_remove(struct mode_tree_data *, struct mode_tree_item *);
2392 void	 mode_tree_draw(struct mode_tree_data *);
2393 int	 mode_tree_key(struct mode_tree_data *, struct client *, key_code *,
2394 	     struct mouse_event *, u_int *, u_int *);
2395 void	 mode_tree_run_command(struct client *, struct cmd_find_state *,
2396 	     const char *, const char *);
2397 
2398 /* window-buffer.c */
2399 extern const struct window_mode window_buffer_mode;
2400 
2401 /* window-tree.c */
2402 extern const struct window_mode window_tree_mode;
2403 
2404 /* window-clock.c */
2405 extern const struct window_mode window_clock_mode;
2406 extern const char window_clock_table[14][5][5];
2407 
2408 /* window-client.c */
2409 extern const struct window_mode window_client_mode;
2410 
2411 /* window-copy.c */
2412 extern const struct window_mode window_copy_mode;
2413 extern const struct window_mode window_view_mode;
2414 void printflike(2, 3) window_copy_add(struct window_pane *, const char *, ...);
2415 void		 window_copy_vadd(struct window_pane *, const char *, va_list);
2416 void		 window_copy_pageup(struct window_pane *, int);
2417 void		 window_copy_start_drag(struct client *, struct mouse_event *);
2418 
2419 /* names.c */
2420 void	 check_window_name(struct window *);
2421 char	*default_window_name(struct window *);
2422 char	*parse_window_name(const char *);
2423 
2424 /* control.c */
2425 void	control_callback(struct client *, int, void *);
2426 void printflike(2, 3) control_write(struct client *, const char *, ...);
2427 void	control_write_buffer(struct client *, struct evbuffer *);
2428 
2429 /* control-notify.c */
2430 void	control_notify_input(struct client *, struct window_pane *,
2431 	    struct evbuffer *);
2432 void	control_notify_pane_mode_changed(int);
2433 void	control_notify_window_layout_changed(struct window *);
2434 void	control_notify_window_pane_changed(struct window *);
2435 void	control_notify_window_unlinked(struct session *, struct window *);
2436 void	control_notify_window_linked(struct session *, struct window *);
2437 void	control_notify_window_renamed(struct window *);
2438 void	control_notify_client_session_changed(struct client *);
2439 void	control_notify_session_renamed(struct session *);
2440 void	control_notify_session_created(struct session *);
2441 void	control_notify_session_closed(struct session *);
2442 void	control_notify_session_window_changed(struct session *);
2443 
2444 /* session.c */
2445 extern struct sessions sessions;
2446 int	session_cmp(struct session *, struct session *);
2447 RB_PROTOTYPE(sessions, session, entry, session_cmp);
2448 int		 session_alive(struct session *);
2449 struct session	*session_find(const char *);
2450 struct session	*session_find_by_id_str(const char *);
2451 struct session	*session_find_by_id(u_int);
2452 struct session	*session_create(const char *, const char *, const char *,
2453 		     struct environ *, struct options *, struct termios *);
2454 void		 session_destroy(struct session *, int,  const char *);
2455 void		 session_add_ref(struct session *, const char *);
2456 void		 session_remove_ref(struct session *, const char *);
2457 int		 session_check_name(const char *);
2458 void		 session_update_activity(struct session *, struct timeval *);
2459 struct session	*session_next_session(struct session *);
2460 struct session	*session_previous_session(struct session *);
2461 struct winlink	*session_new(struct session *, const char *, int, char **,
2462 		     const char *, const char *, int, char **);
2463 struct winlink	*session_attach(struct session *, struct window *, int,
2464 		     char **);
2465 int		 session_detach(struct session *, struct winlink *);
2466 int		 session_has(struct session *, struct window *);
2467 int		 session_is_linked(struct session *, struct window *);
2468 int		 session_next(struct session *, int);
2469 int		 session_previous(struct session *, int);
2470 int		 session_select(struct session *, int);
2471 int		 session_last(struct session *);
2472 int		 session_set_current(struct session *, struct winlink *);
2473 struct session_group *session_group_contains(struct session *);
2474 struct session_group *session_group_find(const char *);
2475 struct session_group *session_group_new(const char *);
2476 void		 session_group_add(struct session_group *, struct session *);
2477 void		 session_group_synchronize_to(struct session *);
2478 void		 session_group_synchronize_from(struct session *);
2479 u_int		 session_group_count(struct session_group *);
2480 void		 session_renumber_windows(struct session *);
2481 
2482 /* utf8.c */
2483 void		 utf8_set(struct utf8_data *, u_char);
2484 void		 utf8_copy(struct utf8_data *, const struct utf8_data *);
2485 enum utf8_state	 utf8_open(struct utf8_data *, u_char);
2486 enum utf8_state	 utf8_append(struct utf8_data *, u_char);
2487 enum utf8_state	 utf8_combine(const struct utf8_data *, wchar_t *);
2488 enum utf8_state	 utf8_split(wchar_t, struct utf8_data *);
2489 int		 utf8_isvalid(const char *);
2490 int		 utf8_strvis(char *, const char *, size_t, int);
2491 int		 utf8_stravis(char **, const char *, int);
2492 char		*utf8_sanitize(const char *);
2493 size_t		 utf8_strlen(const struct utf8_data *);
2494 u_int		 utf8_strwidth(const struct utf8_data *, ssize_t);
2495 struct utf8_data *utf8_fromcstr(const char *);
2496 char		*utf8_tocstr(struct utf8_data *);
2497 u_int		 utf8_cstrwidth(const char *);
2498 char		*utf8_padcstr(const char *, u_int);
2499 
2500 /* procname.c */
2501 char   *get_proc_name(int, char *);
2502 
2503 /* log.c */
2504 void	log_add_level(void);
2505 int	log_get_level(void);
2506 void	log_open(const char *);
2507 void	log_toggle(const char *);
2508 void	log_close(void);
2509 void printflike(1, 2) log_debug(const char *, ...);
2510 __dead void printflike(1, 2) fatal(const char *, ...);
2511 __dead void printflike(1, 2) fatalx(const char *, ...);
2512 
2513 /* style.c */
2514 int		 style_parse(struct style *,const struct grid_cell *,
2515 		     const char *);
2516 const char	*style_tostring(struct style *);
2517 void		 style_apply(struct grid_cell *, struct options *,
2518 		     const char *);
2519 void		 style_apply_update(struct grid_cell *, struct options *,
2520 		     const char *);
2521 int		 style_equal(struct style *, struct style *);
2522 void		 style_set(struct style *, const struct grid_cell *);
2523 void		 style_copy(struct style *, struct style *);
2524 int		 style_is_default(struct style *);
2525 
2526 /* spawn.c */
2527 struct winlink	*spawn_window(struct spawn_context *, char **);
2528 struct window_pane *spawn_pane(struct spawn_context *, char **);
2529 
2530 #endif /* TMUX_H */
2531