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