tmux  3.2a
About: tmux is a terminal multiplexer that lets you switch easily between several programs in one terminal.
  Fossies Dox: tmux-3.2a.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

server-client.c
Go to the documentation of this file.
1 /* $OpenBSD$ */
2 
3 /*
4  * Copyright (c) 2009 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 #include <sys/types.h>
20 #include <sys/ioctl.h>
21 #include <sys/uio.h>
22 
23 #include <errno.h>
24 #include <fcntl.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <time.h>
28 #include <unistd.h>
29 
30 #include "tmux.h"
31 
32 static void server_client_free(int, short, void *);
33 static void server_client_check_pane_focus(struct window_pane *);
34 static void server_client_check_pane_resize(struct window_pane *);
35 static void server_client_check_pane_buffer(struct window_pane *);
36 static void server_client_check_window_resize(struct window *);
37 static key_code server_client_check_mouse(struct client *, struct key_event *);
38 static void server_client_repeat_timer(int, short, void *);
39 static void server_client_click_timer(int, short, void *);
40 static void server_client_check_exit(struct client *);
41 static void server_client_check_redraw(struct client *);
42 static void server_client_check_modes(struct client *);
43 static void server_client_set_title(struct client *);
44 static void server_client_reset_state(struct client *);
45 static int server_client_assume_paste(struct session *);
46 static void server_client_update_latest(struct client *);
47 
48 static void server_client_dispatch(struct imsg *, void *);
49 static void server_client_dispatch_command(struct client *, struct imsg *);
50 static void server_client_dispatch_identify(struct client *, struct imsg *);
51 static void server_client_dispatch_shell(struct client *);
52 
53 /* Compare client windows. */
54 static int
56  struct client_window *cw2)
57 {
58  if (cw1->window < cw2->window)
59  return (-1);
60  if (cw1->window > cw2->window)
61  return (1);
62  return (0);
63 }
65 
66 /* Number of attached clients. */
67 u_int
69 {
70  struct client *c;
71  u_int n;
72 
73  n = 0;
74  TAILQ_FOREACH(c, &clients, entry) {
75  if (c->session != NULL && (~c->flags & CLIENT_UNATTACHEDFLAGS))
76  n++;
77  }
78  return (n);
79 }
80 
81 /* Overlay timer callback. */
82 static void
83 server_client_overlay_timer(__unused int fd, __unused short events, void *data)
84 {
86 }
87 
88 /* Set an overlay on client. */
89 void
90 server_client_set_overlay(struct client *c, u_int delay,
91  overlay_check_cb checkcb, overlay_mode_cb modecb,
92  overlay_draw_cb drawcb, overlay_key_cb keycb, overlay_free_cb freecb,
93  void *data)
94 {
95  struct timeval tv;
96 
97  if (c->overlay_draw != NULL)
99 
100  tv.tv_sec = delay / 1000;
101  tv.tv_usec = (delay % 1000) * 1000L;
102 
103  if (event_initialized(&c->overlay_timer))
104  evtimer_del(&c->overlay_timer);
105  evtimer_set(&c->overlay_timer, server_client_overlay_timer, c);
106  if (delay != 0)
107  evtimer_add(&c->overlay_timer, &tv);
108 
109  c->overlay_check = checkcb;
110  c->overlay_mode = modecb;
111  c->overlay_draw = drawcb;
112  c->overlay_key = keycb;
113  c->overlay_free = freecb;
114  c->overlay_data = data;
115 
116  c->tty.flags |= TTY_FREEZE;
117  if (c->overlay_mode == NULL)
118  c->tty.flags |= TTY_NOCURSOR;
120 }
121 
122 /* Clear overlay mode on client. */
123 void
125 {
126  if (c->overlay_draw == NULL)
127  return;
128 
129  if (event_initialized(&c->overlay_timer))
130  evtimer_del(&c->overlay_timer);
131 
132  if (c->overlay_free != NULL)
133  c->overlay_free(c);
134 
135  c->overlay_check = NULL;
136  c->overlay_mode = NULL;
137  c->overlay_draw = NULL;
138  c->overlay_key = NULL;
139  c->overlay_free = NULL;
140  c->overlay_data = NULL;
141 
142  c->tty.flags &= ~(TTY_FREEZE|TTY_NOCURSOR);
144 }
145 
146 /* Check if this client is inside this server. */
147 int
149 {
150  struct environ_entry *envent;
151  struct window_pane *wp;
152 
153  envent = environ_find(c->environ, "TMUX");
154  if (envent == NULL || *envent->value == '\0')
155  return (0);
156 
157  RB_FOREACH(wp, window_pane_tree, &all_window_panes) {
158  if (strcmp(wp->tty, c->ttyname) == 0)
159  return (1);
160  }
161  return (0);
162 }
163 
164 /* Set client key table. */
165 void
166 server_client_set_key_table(struct client *c, const char *name)
167 {
168  if (name == NULL)
170 
173  c->keytable->references++;
174 }
175 
176 /* Get default key table. */
177 const char *
179 {
180  struct session *s = c->session;
181  const char *name;
182 
183  if (s == NULL)
184  return ("root");
185 
186  name = options_get_string(s->options, "key-table");
187  if (*name == '\0')
188  return ("root");
189  return (name);
190 }
191 
192 /* Is this table the default key table? */
193 static int
195 {
196  return (strcmp(table->name, server_client_get_key_table(c)) == 0);
197 }
198 
199 /* Create a new client. */
200 struct client *
202 {
203  struct client *c;
204 
205  setblocking(fd, 0);
206 
207  c = xcalloc(1, sizeof *c);
208  c->references = 1;
210 
211  if (gettimeofday(&c->creation_time, NULL) != 0)
212  fatal("gettimeofday failed");
213  memcpy(&c->activity_time, &c->creation_time, sizeof c->activity_time);
214 
215  c->environ = environ_create();
216 
217  c->fd = -1;
218  c->out_fd = -1;
219 
220  c->queue = cmdq_new();
221  RB_INIT(&c->windows);
222  RB_INIT(&c->files);
223 
224  c->tty.sx = 80;
225  c->tty.sy = 24;
226 
227  status_init(c);
228  c->flags |= CLIENT_FOCUSED;
229 
230  c->keytable = key_bindings_get_table("root", 1);
231  c->keytable->references++;
232 
233  evtimer_set(&c->repeat_timer, server_client_repeat_timer, c);
234  evtimer_set(&c->click_timer, server_client_click_timer, c);
235 
236  TAILQ_INSERT_TAIL(&clients, c, entry);
237  log_debug("new client %p", c);
238  return (c);
239 }
240 
241 /* Open client terminal if needed. */
242 int
243 server_client_open(struct client *c, char **cause)
244 {
245  const char *ttynam = _PATH_TTY;
246 
247  if (c->flags & CLIENT_CONTROL)
248  return (0);
249 
250  if (strcmp(c->ttyname, ttynam) == 0||
251  ((isatty(STDIN_FILENO) &&
252  (ttynam = ttyname(STDIN_FILENO)) != NULL &&
253  strcmp(c->ttyname, ttynam) == 0) ||
254  (isatty(STDOUT_FILENO) &&
255  (ttynam = ttyname(STDOUT_FILENO)) != NULL &&
256  strcmp(c->ttyname, ttynam) == 0) ||
257  (isatty(STDERR_FILENO) &&
258  (ttynam = ttyname(STDERR_FILENO)) != NULL &&
259  strcmp(c->ttyname, ttynam) == 0))) {
260  xasprintf(cause, "can't use %s", c->ttyname);
261  return (-1);
262  }
263 
264  if (!(c->flags & CLIENT_TERMINAL)) {
265  *cause = xstrdup("not a terminal");
266  return (-1);
267  }
268 
269  if (tty_open(&c->tty, cause) != 0)
270  return (-1);
271 
272  return (0);
273 }
274 
275 /* Lost an attached client. */
276 static void
278 {
279  struct session *s = c->session;
280  struct window *w;
281  struct client *loop;
282  struct client *found;
283 
284  log_debug("lost attached client %p", c);
285 
286  /*
287  * By this point the session in the client has been cleared so walk all
288  * windows to find any with this client as the latest.
289  */
290  RB_FOREACH(w, windows, &windows) {
291  if (w->latest != c)
292  continue;
293 
294  found = NULL;
295  TAILQ_FOREACH(loop, &clients, entry) {
296  s = loop->session;
297  if (loop == c || s == NULL || s->curw->window != w)
298  continue;
299  if (found == NULL ||
300  timercmp(&loop->activity_time, &found->activity_time,
301  >))
302  found = loop;
303  }
304  if (found != NULL)
306  }
307 }
308 
309 /* Lost a client. */
310 void
312 {
313  struct client_file *cf, *cf1;
314  struct client_window *cw, *cw1;
315 
316  c->flags |= CLIENT_DEAD;
317 
321 
322  RB_FOREACH_SAFE(cf, client_files, &c->files, cf1) {
323  cf->error = EINTR;
324  file_fire_done(cf);
325  }
326  RB_FOREACH_SAFE(cw, client_windows, &c->windows, cw1) {
327  RB_REMOVE(client_windows, &c->windows, cw);
328  free(cw);
329  }
330 
331  TAILQ_REMOVE(&clients, c, entry);
332  log_debug("lost client %p", c);
333 
334  if (c->flags & CLIENT_ATTACHED) {
336  notify_client("client-detached", c);
337  }
338 
339  if (c->flags & CLIENT_CONTROL)
340  control_stop(c);
341  if (c->flags & CLIENT_TERMINAL)
342  tty_free(&c->tty);
343  free(c->ttyname);
344 
345  free(c->term_name);
346  free(c->term_type);
348 
349  status_free(c);
350 
351  free(c->title);
352  free((void *)c->cwd);
353 
354  evtimer_del(&c->repeat_timer);
355  evtimer_del(&c->click_timer);
356 
358 
359  free(c->message_string);
360  if (event_initialized(&c->message_timer))
361  evtimer_del(&c->message_timer);
362 
363  free(c->prompt_saved);
364  free(c->prompt_string);
365  free(c->prompt_buffer);
366 
368  environ_free(c->environ);
369 
371  c->peer = NULL;
372 
373  if (c->out_fd != -1)
374  close(c->out_fd);
375  if (c->fd != -1) {
376  close(c->fd);
377  c->fd = -1;
378  }
380 
381  server_add_accept(0); /* may be more file descriptors now */
382 
386 }
387 
388 /* Remove reference from a client. */
389 void
391 {
392  log_debug("unref client %p (%d references)", c, c->references);
393 
394  c->references--;
395  if (c->references == 0)
396  event_once(-1, EV_TIMEOUT, server_client_free, c, NULL);
397 }
398 
399 /* Free dead client. */
400 static void
401 server_client_free(__unused int fd, __unused short events, void *arg)
402 {
403  struct client *c = arg;
404 
405  log_debug("free client %p (%d references)", c, c->references);
406 
407  cmdq_free(c->queue);
408 
409  if (c->references == 0) {
410  free((void *)c->name);
411  free(c);
412  }
413 }
414 
415 /* Suspend a client. */
416 void
418 {
419  struct session *s = c->session;
420 
421  if (s == NULL || (c->flags & CLIENT_UNATTACHEDFLAGS))
422  return;
423 
424  tty_stop_tty(&c->tty);
425  c->flags |= CLIENT_SUSPENDED;
426  proc_send(c->peer, MSG_SUSPEND, -1, NULL, 0);
427 }
428 
429 /* Detach a client. */
430 void
432 {
433  struct session *s = c->session;
434 
435  if (s == NULL || (c->flags & CLIENT_UNATTACHEDFLAGS))
436  return;
437 
438  c->flags |= CLIENT_EXIT;
439 
440  c->exit_type = CLIENT_EXIT_DETACH;
441  c->exit_msgtype = msgtype;
442  c->exit_session = xstrdup(s->name);
443 }
444 
445 /* Execute command to replace a client. */
446 void
447 server_client_exec(struct client *c, const char *cmd)
448 {
449  struct session *s = c->session;
450  char *msg;
451  const char *shell;
452  size_t cmdsize, shellsize;
453 
454  if (*cmd == '\0')
455  return;
456  cmdsize = strlen(cmd) + 1;
457 
458  if (s != NULL)
459  shell = options_get_string(s->options, "default-shell");
460  else
461  shell = options_get_string(global_s_options, "default-shell");
462  if (!checkshell(shell))
463  shell = _PATH_BSHELL;
464  shellsize = strlen(shell) + 1;
465 
466  msg = xmalloc(cmdsize + shellsize);
467  memcpy(msg, cmd, cmdsize);
468  memcpy(msg + cmdsize, shell, shellsize);
469 
470  proc_send(c->peer, MSG_EXEC, -1, msg, cmdsize + shellsize);
471  free(msg);
472 }
473 
474 /* Check for mouse keys. */
475 static key_code
476 server_client_check_mouse(struct client *c, struct key_event *event)
477 {
478  struct mouse_event *m = &event->m;
479  struct session *s = c->session;
480  struct winlink *wl;
481  struct window_pane *wp;
482  u_int x, y, b, sx, sy, px, py;
483  int ignore = 0;
484  key_code key;
485  struct timeval tv;
486  struct style_range *sr;
487  enum { NOTYPE,
488  MOVE,
489  DOWN,
490  UP,
491  DRAG,
492  WHEEL,
493  SECOND,
494  DOUBLE,
495  TRIPLE } type = NOTYPE;
496  enum { NOWHERE,
497  PANE,
498  STATUS,
499  STATUS_LEFT,
500  STATUS_RIGHT,
501  STATUS_DEFAULT,
502  BORDER } where = NOWHERE;
503 
504  log_debug("%s mouse %02x at %u,%u (last %u,%u) (%d)", c->name, m->b,
505  m->x, m->y, m->lx, m->ly, c->tty.mouse_drag_flag);
506 
507  /* What type of event is this? */
508  if (event->key == KEYC_DOUBLECLICK) {
509  type = DOUBLE;
510  x = m->x, y = m->y, b = m->b;
511  ignore = 1;
512  log_debug("double-click at %u,%u", x, y);
513  } else if ((m->sgr_type != ' ' &&
514  MOUSE_DRAG(m->sgr_b) &&
515  MOUSE_BUTTONS(m->sgr_b) == 3) ||
516  (m->sgr_type == ' ' &&
517  MOUSE_DRAG(m->b) &&
518  MOUSE_BUTTONS(m->b) == 3 &&
519  MOUSE_BUTTONS(m->lb) == 3)) {
520  type = MOVE;
521  x = m->x, y = m->y, b = 0;
522  log_debug("move at %u,%u", x, y);
523  } else if (MOUSE_DRAG(m->b)) {
524  type = DRAG;
525  if (c->tty.mouse_drag_flag) {
526  x = m->x, y = m->y, b = m->b;
527  if (x == m->lx && y == m->ly)
528  return (KEYC_UNKNOWN);
529  log_debug("drag update at %u,%u", x, y);
530  } else {
531  x = m->lx, y = m->ly, b = m->lb;
532  log_debug("drag start at %u,%u", x, y);
533  }
534  } else if (MOUSE_WHEEL(m->b)) {
535  type = WHEEL;
536  x = m->x, y = m->y, b = m->b;
537  log_debug("wheel at %u,%u", x, y);
538  } else if (MOUSE_RELEASE(m->b)) {
539  type = UP;
540  x = m->x, y = m->y, b = m->lb;
541  log_debug("up at %u,%u", x, y);
542  } else {
543  if (c->flags & CLIENT_DOUBLECLICK) {
544  evtimer_del(&c->click_timer);
545  c->flags &= ~~CLIENT_DOUBLECLICK;
546  if (m->b == c->click_button) {
547  type = SECOND;
548  x = m->x, y = m->y, b = m->b;
549  log_debug("second-click at %u,%u", x, y);
551  }
552  } else if (c->flags & CLIENT_TRIPLECLICK) {
553  evtimer_del(&c->click_timer);
554  c->flags &= ~~CLIENT_TRIPLECLICK;
555  if (m->b == c->click_button) {
556  type = TRIPLE;
557  x = m->x, y = m->y, b = m->b;
558  log_debug("triple-click at %u,%u", x, y);
559  goto have_event;
560  }
561  } else {
562  type = DOWN;
563  x = m->x, y = m->y, b = m->b;
564  log_debug("down at %u,%u", x, y);
566  }
567 
568  if (KEYC_CLICK_TIMEOUT != 0) {
569  memcpy(&c->click_event, m, sizeof c->click_event);
570  c->click_button = m->b;
571 
572  log_debug("click timer started");
573  tv.tv_sec = KEYC_CLICK_TIMEOUT / 1000;
574  tv.tv_usec = (KEYC_CLICK_TIMEOUT % 1000) * 1000L;
575  evtimer_del(&c->click_timer);
576  evtimer_add(&c->click_timer, &tv);
577  }
578  }
579 
580 have_event:
581  if (type == NOTYPE)
582  return (KEYC_UNKNOWN);
583 
584  /* Save the session. */
585  m->s = s->id;
586  m->w = -1;
587  m->ignore = ignore;
588 
589  /* Is this on the status line? */
590  m->statusat = status_at_line(c);
592  if (m->statusat != -1 &&
593  y >= (u_int)m->statusat &&
594  y < m->statusat + m->statuslines) {
595  sr = status_get_range(c, x, y - m->statusat);
596  if (sr == NULL) {
597  where = STATUS_DEFAULT;
598  } else {
599  switch (sr->type) {
600  case STYLE_RANGE_NONE:
601  return (KEYC_UNKNOWN);
602  case STYLE_RANGE_LEFT:
603  where = STATUS_LEFT;
604  break;
605  case STYLE_RANGE_RIGHT:
606  where = STATUS_RIGHT;
607  break;
608  case STYLE_RANGE_WINDOW:
610  sr->argument);
611  if (wl == NULL)
612  return (KEYC_UNKNOWN);
613  m->w = wl->window->id;
614 
615  where = STATUS;
616  break;
617  }
618  }
619  }
620 
621  /* Not on status line. Adjust position and check for border or pane. */
622  if (where == NOWHERE) {
623  px = x;
624  if (m->statusat == 0 && y >= m->statuslines)
625  py = y - m->statuslines;
626  else if (m->statusat > 0 && y >= (u_int)m->statusat)
627  py = m->statusat - 1;
628  else
629  py = y;
630 
631  tty_window_offset(&c->tty, &m->ox, &m->oy, &sx, &sy);
632  log_debug("mouse window @%u at %u,%u (%ux%u)",
633  s->curw->window->id, m->ox, m->oy, sx, sy);
634  if (px > sx || py > sy)
635  return (KEYC_UNKNOWN);
636  px = px + m->ox;
637  py = py + m->oy;
638 
639  /* Try the pane borders if not zoomed. */
640  if (~s->curw->window->flags & WINDOW_ZOOMED) {
641  TAILQ_FOREACH(wp, &s->curw->window->panes, entry) {
642  if ((wp->xoff + wp->sx == px &&
643  wp->yoff <= 1 + py &&
644  wp->yoff + wp->sy >= py) ||
645  (wp->yoff + wp->sy == py &&
646  wp->xoff <= 1 + px &&
647  wp->xoff + wp->sx >= px))
648  break;
649  }
650  if (wp != NULL)
651  where = BORDER;
652  }
653 
654  /* Otherwise try inside the pane. */
655  if (where == NOWHERE) {
656  wp = window_get_active_at(s->curw->window, px, py);
657  if (wp != NULL)
658  where = PANE;
659  else
660  return (KEYC_UNKNOWN);
661  }
662  if (where == PANE)
663  log_debug("mouse %u,%u on pane %%%u", x, y, wp->id);
664  else if (where == BORDER)
665  log_debug("mouse on pane %%%u border", wp->id);
666  m->wp = wp->id;
667  m->w = wp->window->id;
668  } else
669  m->wp = -1;
670 
671  /* Stop dragging if needed. */
672  if (type != DRAG && type != WHEEL && c->tty.mouse_drag_flag) {
673  if (c->tty.mouse_drag_release != NULL)
674  c->tty.mouse_drag_release(c, m);
675 
676  c->tty.mouse_drag_update = NULL;
677  c->tty.mouse_drag_release = NULL;
678 
679  /*
680  * End a mouse drag by passing a MouseDragEnd key corresponding
681  * to the button that started the drag.
682  */
683  switch (c->tty.mouse_drag_flag) {
684  case 1:
685  if (where == PANE)
687  if (where == STATUS)
689  if (where == STATUS_LEFT)
691  if (where == STATUS_RIGHT)
693  if (where == STATUS_DEFAULT)
695  if (where == BORDER)
697  break;
698  case 2:
699  if (where == PANE)
701  if (where == STATUS)
703  if (where == STATUS_LEFT)
705  if (where == STATUS_RIGHT)
707  if (where == STATUS_DEFAULT)
709  if (where == BORDER)
711  break;
712  case 3:
713  if (where == PANE)
715  if (where == STATUS)
717  if (where == STATUS_LEFT)
719  if (where == STATUS_RIGHT)
721  if (where == STATUS_DEFAULT)
723  if (where == BORDER)
725  break;
726  default:
727  key = KEYC_MOUSE;
728  break;
729  }
730  c->tty.mouse_drag_flag = 0;
731  goto out;
732  }
733 
734  /* Convert to a key binding. */
735  key = KEYC_UNKNOWN;
736  switch (type) {
737  case NOTYPE:
738  break;
739  case MOVE:
740  if (where == PANE)
742  if (where == STATUS)
744  if (where == STATUS_LEFT)
746  if (where == STATUS_RIGHT)
748  if (where == STATUS_DEFAULT)
750  if (where == BORDER)
752  break;
753  case DRAG:
754  if (c->tty.mouse_drag_update != NULL)
755  key = KEYC_DRAGGING;
756  else {
757  switch (MOUSE_BUTTONS(b)) {
758  case 0:
759  if (where == PANE)
761  if (where == STATUS)
763  if (where == STATUS_LEFT)
765  if (where == STATUS_RIGHT)
767  if (where == STATUS_DEFAULT)
769  if (where == BORDER)
771  break;
772  case 1:
773  if (where == PANE)
775  if (where == STATUS)
777  if (where == STATUS_LEFT)
779  if (where == STATUS_RIGHT)
781  if (where == STATUS_DEFAULT)
783  if (where == BORDER)
785  break;
786  case 2:
787  if (where == PANE)
789  if (where == STATUS)
791  if (where == STATUS_LEFT)
793  if (where == STATUS_RIGHT)
795  if (where == STATUS_DEFAULT)
797  if (where == BORDER)
799  break;
800  }
801  }
802 
803  /*
804  * Begin a drag by setting the flag to a non-zero value that
805  * corresponds to the mouse button in use.
806  */
807  c->tty.mouse_drag_flag = MOUSE_BUTTONS(b) + 1;
808  break;
809  case WHEEL:
810  if (MOUSE_BUTTONS(b) == MOUSE_WHEEL_UP) {
811  if (where == PANE)
813  if (where == STATUS)
815  if (where == STATUS_LEFT)
817  if (where == STATUS_RIGHT)
819  if (where == STATUS_DEFAULT)
821  if (where == BORDER)
823  } else {
824  if (where == PANE)
826  if (where == STATUS)
828  if (where == STATUS_LEFT)
830  if (where == STATUS_RIGHT)
832  if (where == STATUS_DEFAULT)
834  if (where == BORDER)
836  }
837  break;
838  case UP:
839  switch (MOUSE_BUTTONS(b)) {
840  case 0:
841  if (where == PANE)
843  if (where == STATUS)
845  if (where == STATUS_LEFT)
847  if (where == STATUS_RIGHT)
849  if (where == STATUS_DEFAULT)
851  if (where == BORDER)
853  break;
854  case 1:
855  if (where == PANE)
857  if (where == STATUS)
859  if (where == STATUS_LEFT)
861  if (where == STATUS_RIGHT)
863  if (where == STATUS_DEFAULT)
865  if (where == BORDER)
867  break;
868  case 2:
869  if (where == PANE)
871  if (where == STATUS)
873  if (where == STATUS_LEFT)
875  if (where == STATUS_RIGHT)
877  if (where == STATUS_DEFAULT)
879  if (where == BORDER)
881  break;
882  }
883  break;
884  case DOWN:
885  switch (MOUSE_BUTTONS(b)) {
886  case 0:
887  if (where == PANE)
889  if (where == STATUS)
891  if (where == STATUS_LEFT)
893  if (where == STATUS_RIGHT)
895  if (where == STATUS_DEFAULT)
897  if (where == BORDER)
899  break;
900  case 1:
901  if (where == PANE)
903  if (where == STATUS)
905  if (where == STATUS_LEFT)
907  if (where == STATUS_RIGHT)
909  if (where == STATUS_DEFAULT)
911  if (where == BORDER)
913  break;
914  case 2:
915  if (where == PANE)
917  if (where == STATUS)
919  if (where == STATUS_LEFT)
921  if (where == STATUS_RIGHT)
923  if (where == STATUS_DEFAULT)
925  if (where == BORDER)
927  break;
928  }
929  break;
930  case SECOND:
931  switch (MOUSE_BUTTONS(b)) {
932  case 0:
933  if (where == PANE)
935  if (where == STATUS)
937  if (where == STATUS_LEFT)
939  if (where == STATUS_RIGHT)
941  if (where == STATUS_DEFAULT)
943  if (where == BORDER)
945  break;
946  case 1:
947  if (where == PANE)
949  if (where == STATUS)
951  if (where == STATUS_LEFT)
953  if (where == STATUS_RIGHT)
955  if (where == STATUS_DEFAULT)
957  if (where == BORDER)
959  break;
960  case 2:
961  if (where == PANE)
963  if (where == STATUS)
965  if (where == STATUS_LEFT)
967  if (where == STATUS_RIGHT)
969  if (where == STATUS_DEFAULT)
971  if (where == BORDER)
973  break;
974  }
975  break;
976  case DOUBLE:
977  switch (MOUSE_BUTTONS(b)) {
978  case 0:
979  if (where == PANE)
981  if (where == STATUS)
983  if (where == STATUS_LEFT)
985  if (where == STATUS_RIGHT)
987  if (where == STATUS_DEFAULT)
989  if (where == BORDER)
991  break;
992  case 1:
993  if (where == PANE)
995  if (where == STATUS)
997  if (where == STATUS_LEFT)
999  if (where == STATUS_RIGHT)
1001  if (where == STATUS_DEFAULT)
1003  if (where == BORDER)
1005  break;
1006  case 2:
1007  if (where == PANE)
1009  if (where == STATUS)
1011  if (where == STATUS_LEFT)
1013  if (where == STATUS_RIGHT)
1015  if (where == STATUS_DEFAULT)
1017  if (where == BORDER)
1019  break;
1020  }
1021  break;
1022  case TRIPLE:
1023  switch (MOUSE_BUTTONS(b)) {
1024  case 0:
1025  if (where == PANE)
1027  if (where == STATUS)
1029  if (where == STATUS_LEFT)
1031  if (where == STATUS_RIGHT)
1033  if (where == STATUS_DEFAULT)
1035  if (where == BORDER)
1037  break;
1038  case 1:
1039  if (where == PANE)
1041  if (where == STATUS)
1043  if (where == STATUS_LEFT)
1045  if (where == STATUS_RIGHT)
1047  if (where == STATUS_DEFAULT)
1049  if (where == BORDER)
1051  break;
1052  case 2:
1053  if (where == PANE)
1055  if (where == STATUS)
1057  if (where == STATUS_LEFT)
1059  if (where == STATUS_RIGHT)
1061  if (where == STATUS_DEFAULT)
1063  if (where == BORDER)
1065  break;
1066  }
1067  break;
1068  }
1069  if (key == KEYC_UNKNOWN)
1070  return (KEYC_UNKNOWN);
1071 
1072 out:
1073  /* Apply modifiers if any. */
1074  if (b & MOUSE_MASK_META)
1075  key |= KEYC_META;
1076  if (b & MOUSE_MASK_CTRL)
1077  key |= KEYC_CTRL;
1078  if (b & MOUSE_MASK_SHIFT)
1079  key |= KEYC_SHIFT;
1080 
1081  if (log_get_level() != 0)
1082  log_debug("mouse key is %s", key_string_lookup_key (key, 1));
1083  return (key);
1084 }
1085 
1086 /* Is this fast enough to probably be a paste? */
1087 static int
1089 {
1090  struct timeval tv;
1091  int t;
1092 
1093  if ((t = options_get_number(s->options, "assume-paste-time")) == 0)
1094  return (0);
1095 
1096  timersub(&s->activity_time, &s->last_activity_time, &tv);
1097  if (tv.tv_sec == 0 && tv.tv_usec < t * 1000) {
1098  log_debug("session %s pasting (flag %d)", s->name,
1099  !!(s->flags & SESSION_PASTING));
1100  if (s->flags & SESSION_PASTING)
1101  return (1);
1102  s->flags |= SESSION_PASTING;
1103  return (0);
1104  }
1105  log_debug("session %s not pasting", s->name);
1106  s->flags &= ~~SESSION_PASTING;
1107  return (0);
1108 }
1109 
1110 /* Has the latest client changed? */
1111 static void
1113 {
1114  struct window *w;
1115 
1116  if (c->session == NULL)
1117  return;
1118  w = c->session->curw->window;
1119 
1120  if (w->latest == c)
1121  return;
1122  w->latest = c;
1123 
1124  if (options_get_number(w->options, "window-size") == WINDOW_SIZE_LATEST)
1125  recalculate_size(w, 0);
1126 }
1127 
1128 /*
1129  * Handle data key input from client. This owns and can modify the key event it
1130  * is given and is responsible for freeing it.
1131  */
1132 static enum cmd_retval
1133 server_client_key_callback(struct cmdq_item *item, void *data)
1134 {
1135  struct client *c = cmdq_get_client(item);
1136  struct key_event *event = data;
1137  key_code key = event->key;
1138  struct mouse_event *m = &event->m;
1139  struct session *s = c->session;
1140  struct winlink *wl;
1141  struct window_pane *wp;
1142  struct window_mode_entry *wme;
1143  struct timeval tv;
1144  struct key_table *table, *first;
1145  struct key_binding *bd;
1146  int xtimeout, flags;
1147  struct cmd_find_state fs;
1148  key_code key0;
1149 
1150  /* Check the client is good to accept input. */
1151  if (s == NULL || (c->flags & CLIENT_UNATTACHEDFLAGS))
1152  goto out;
1153  wl = s->curw;
1154 
1155  /* Update the activity timer. */
1156  if (gettimeofday(&c->activity_time, NULL) != 0)
1157  fatal("gettimeofday failed");
1159 
1160  /* Check for mouse keys. */
1161  m->valid = 0;
1162  if (key == KEYC_MOUSE || key == KEYC_DOUBLECLICK) {
1163  if (c->flags & CLIENT_READONLY)
1164  goto out;
1165  key = server_client_check_mouse(c, event);
1166  if (key == KEYC_UNKNOWN)
1167  goto out;
1168 
1169  m->valid = 1;
1170  m->key = key;
1171 
1172  /*
1173  * Mouse drag is in progress, so fire the callback (now that
1174  * the mouse event is valid).
1175  */
1176  if ((key & KEYC_MASK_KEY) == KEYC_DRAGGING) {
1177  c->tty.mouse_drag_update(c, m);
1178  goto out;
1179  }
1180  event->key = key;
1181  }
1182 
1183  /* Find affected pane. */
1184  if (!KEYC_IS_MOUSE(key) || cmd_find_from_mouse(&fs, m, 0) != 0)
1185  cmd_find_from_client(&fs, c, 0);
1186  wp = fs.wp;
1187 
1188  /* Forward mouse keys if disabled. */
1189  if (KEYC_IS_MOUSE(key) && !options_get_number(s->options, "mouse"))
1190  goto forward_key;
1191 
1192  /* Treat everything as a regular key when pasting is detected. */
1194  goto forward_key;
1195 
1196  /*
1197  * Work out the current key table. If the pane is in a mode, use
1198  * the mode table instead of the default key table.
1199  */
1201  wp != NULL &&
1202  (wme = TAILQ_FIRST(&wp->modes)) != NULL &&
1203  wme->mode->key_table != NULL)
1204  table = key_bindings_get_table(wme->mode->key_table(wme), 1);
1205  else
1206  table = c->keytable;
1207  first = table;
1208 
1209 table_changed:
1210  /*
1211  * The prefix always takes precedence and forces a switch to the prefix
1212  * table, unless we are already there.
1213  */
1214  key0 = (key & (KEYC_MASK_KEY|KEYC_MASK_MODIFIERS));
1215  if ((key0 == (key_code)options_get_number(s->options, "prefix") ||
1216  key0 == (key_code)options_get_number(s->options, "prefix2")) &&
1217  strcmp(table->name, "prefix") != 0) {
1218  server_client_set_key_table(c, "prefix");
1220  goto out;
1221  }
1222  flags = c->flags;
1223 
1224 try_again:
1225  /* Log key table. */
1226  if (wp == NULL)
1227  log_debug("key table %s (no pane)", table->name);
1228  else
1229  log_debug("key table %s (pane %%%u)", table->name, wp->id);
1230  if (c->flags & CLIENT_REPEAT)
1231  log_debug("currently repeating");
1232 
1233  /* Try to see if there is a key binding in the current table. */
1234  bd = key_bindings_get(table, key0);
1235  if (bd != NULL) {
1236  /*
1237  * Key was matched in this table. If currently repeating but a
1238  * non-repeating binding was found, stop repeating and try
1239  * again in the root table.
1240  */
1241  if ((c->flags & CLIENT_REPEAT) &&
1242  (~bd->flags & KEY_BINDING_REPEAT)) {
1243  log_debug("found in key table %s (not repeating)",
1244  table->name);
1245  server_client_set_key_table(c, NULL);
1246  first = table = c->keytable;
1247  c->flags &= ~~CLIENT_REPEAT;
1249  goto table_changed;
1250  }
1251  log_debug("found in key table %s", table->name);
1252 
1253  /*
1254  * Take a reference to this table to make sure the key binding
1255  * doesn't disappear.
1256  */
1257  table->references++;
1258 
1259  /*
1260  * If this is a repeating key, start the timer. Otherwise reset
1261  * the client back to the root table.
1262  */
1263  xtimeout = options_get_number(s->options, "repeat-time");
1264  if (xtimeout != 0 && (bd->flags & KEY_BINDING_REPEAT)) {
1265  c->flags |= CLIENT_REPEAT;
1266 
1267  tv.tv_sec = xtimeout / 1000;
1268  tv.tv_usec = (xtimeout % 1000) * 1000L;
1269  evtimer_del(&c->repeat_timer);
1270  evtimer_add(&c->repeat_timer, &tv);
1271  } else {
1272  c->flags &= ~~CLIENT_REPEAT;
1273  server_client_set_key_table(c, NULL);
1274  }
1276 
1277  /* Execute the key binding. */
1278  key_bindings_dispatch(bd, item, c, event, &fs);
1279  key_bindings_unref_table(table);
1280  goto out;
1281  }
1282 
1283  /*
1284  * No match, try the ANY key.
1285  */
1286  if (key0 != KEYC_ANY) {
1287  key0 = KEYC_ANY;
1288  goto try_again;
1289  }
1290 
1291  /*
1292  * No match in this table. If not in the root table or if repeating,
1293  * switch the client back to the root table and try again.
1294  */
1295  log_debug("not found in key table %s", table->name);
1296  if (!server_client_is_default_key_table(c, table) ||
1297  (c->flags & CLIENT_REPEAT)) {
1298  log_debug("trying in root table");
1299  server_client_set_key_table(c, NULL);
1300  table = c->keytable;
1301  if (c->flags & CLIENT_REPEAT)
1302  first = table;
1303  c->flags &= ~~CLIENT_REPEAT;
1305  goto table_changed;
1306  }
1307 
1308  /*
1309  * No match in the root table either. If this wasn't the first table
1310  * tried, don't pass the key to the pane.
1311  */
1312  if (first != table && (~flags & CLIENT_REPEAT)) {
1313  server_client_set_key_table(c, NULL);
1315  goto out;
1316  }
1317 
1318 forward_key:
1319  if (c->flags & CLIENT_READONLY)
1320  goto out;
1321  if (wp != NULL)
1322  window_pane_key(wp, c, s, wl, key, m);
1323 
1324 out:
1325  if (s != NULL && key != KEYC_FOCUS_OUT)
1327  free(event);
1328  return (CMD_RETURN_NORMAL);
1329 }
1330 
1331 /* Handle a key event. */
1332 int
1333 server_client_handle_key(struct client *c, struct key_event *event)
1334 {
1335  struct session *s = c->session;
1336  struct cmdq_item *item;
1337 
1338  /* Check the client is good to accept input. */
1339  if (s == NULL || (c->flags & CLIENT_UNATTACHEDFLAGS))
1340  return (0);
1341 
1342  /*
1343  * Key presses in overlay mode and the command prompt are a special
1344  * case. The queue might be blocked so they need to be processed
1345  * immediately rather than queued.
1346  */
1347  if (~c->flags & CLIENT_READONLY) {
1348  if (c->message_string != NULL) {
1349  if (c->message_ignore_keys)
1350  return (0);
1352  }
1353  if (c->overlay_key != NULL) {
1354  switch (c->overlay_key(c, event)) {
1355  case 0:
1356  return (0);
1357  case 1:
1359  return (0);
1360  }
1361  }
1363  if (c->prompt_string != NULL) {
1364  if (status_prompt_key(c, event->key) == 0)
1365  return (0);
1366  }
1367  }
1368 
1369  /*
1370  * Add the key to the queue so it happens after any commands queued by
1371  * previous keys.
1372  */
1374  cmdq_append(c, item);
1375  return (1);
1376 }
1377 
1378 /* Client functions that need to happen every loop. */
1379 void
1381 {
1382  struct client *c;
1383  struct window *w;
1384  struct window_pane *wp;
1385  int focus;
1386 
1387  /* Check for window resize. This is done before redrawing. */
1388  RB_FOREACH(w, windows, &windows)
1390 
1391  /* Check clients. */
1392  TAILQ_FOREACH(c, &clients, entry) {
1394  if (c->session != NULL) {
1398  }
1399  }
1400 
1401  /*
1402  * Any windows will have been redrawn as part of clients, so clear
1403  * their flags now. Also check pane focus and resize.
1404  */
1405  focus = options_get_number(global_options, "focus-events");
1406  RB_FOREACH(w, windows, &windows) {
1407  TAILQ_FOREACH(wp, &w->panes, entry) {
1408  if (wp->fd != -1) {
1409  if (focus)
1413  }
1414  wp->flags &= ~~PANE_REDRAW;
1415  }
1416  check_window_name(w);
1417  }
1418 }
1419 
1420 /* Check if window needs to be resized. */
1421 static void
1423 {
1424  struct winlink *wl;
1425 
1426  if (~w->flags & WINDOW_RESIZE)
1427  return;
1428 
1429  TAILQ_FOREACH(wl, &w->winlinks, wentry) {
1430  if (wl->session->attached != 0 && wl->session->curw == wl)
1431  break;
1432  }
1433  if (wl == NULL)
1434  return;
1435 
1436  log_debug("%s: resizing window @%u", __func__, w->id);
1437  resize_window(w, w->new_sx, w->new_sy, w->new_xpixel, w->new_ypixel);
1438 }
1439 
1440 /* Resize timer event. */
1441 static void
1442 server_client_resize_timer(__unused int fd, __unused short events, void *data)
1443 {
1444  struct window_pane *wp = data;
1445 
1446  log_debug("%s: %%%u resize timer expired", __func__, wp->id);
1447  evtimer_del(&wp->resize_timer);
1448 }
1449 
1450 /* Check if pane should be resized. */
1451 static void
1453 {
1454  struct window_pane_resize *r;
1455  struct window_pane_resize *r1;
1456  struct window_pane_resize *first;
1457  struct window_pane_resize *last;
1458  struct timeval tv = { .tv_usec = 250000 };
1459 
1460  if (TAILQ_EMPTY(&wp->resize_queue))
1461  return;
1462 
1463  if (!event_initialized(&wp->resize_timer))
1464  evtimer_set(&wp->resize_timer, server_client_resize_timer, wp);
1465  if (evtimer_pending(&wp->resize_timer, NULL))
1466  return;
1467 
1468  log_debug("%s: %%%u needs to be resized", __func__, wp->id);
1469  TAILQ_FOREACH(r, &wp->resize_queue, entry) {
1470  log_debug("queued resize: %ux%u -> %ux%u", r->osx, r->osy,
1471  r->sx, r->sy);
1472  }
1473 
1474  /*
1475  * There are three cases that matter:
1476  *
1477  * - Only one resize. It can just be applied.
1478  *
1479  * - Multiple resizes and the ending size is different from the
1480  * starting size. We can discard all resizes except the most recent.
1481  *
1482  * - Multiple resizes and the ending size is the same as the starting
1483  * size. We must resize at least twice to force the application to
1484  * redraw. So apply the first and leave the last on the queue for
1485  * next time.
1486  */
1487  first = TAILQ_FIRST(&wp->resize_queue);
1488  last = TAILQ_LAST(&wp->resize_queue, window_pane_resizes);
1489  if (first == last) {
1490  /* Only one resize. */
1491  window_pane_send_resize(wp, first->sx, first->sy);
1492  TAILQ_REMOVE(&wp->resize_queue, first, entry);
1493  free(first);
1494  } else if (last->sx != first->osx || last->sy != first->osy) {
1495  /* Multiple resizes ending up with a different size. */
1496  window_pane_send_resize(wp, last->sx, last->sy);
1497  TAILQ_FOREACH_SAFE(r, &wp->resize_queue, entry, r1) {
1498  TAILQ_REMOVE(&wp->resize_queue, r, entry);
1499  free(r);
1500  }
1501  } else {
1502  /*
1503  * Multiple resizes ending up with the same size. There will
1504  * not be more than one to the same size in succession so we
1505  * can just use the last-but-one on the list and leave the last
1506  * for later. We reduce the time until the next check to avoid
1507  * a long delay between the resizes.
1508  */
1509  r = TAILQ_PREV(last, window_pane_resizes, entry);
1510  window_pane_send_resize(wp, r->sx, r->sy);
1511  TAILQ_FOREACH_SAFE(r, &wp->resize_queue, entry, r1) {
1512  if (r == last)
1513  break;
1514  TAILQ_REMOVE(&wp->resize_queue, r, entry);
1515  free(r);
1516  }
1517  tv.tv_usec = 10000;
1518  }
1519  evtimer_add(&wp->resize_timer, &tv);
1520 }
1521 
1522 
1523 /* Check pane buffer size. */
1524 static void
1526 {
1527  struct evbuffer *evb = wp->event->input;
1528  size_t minimum;
1529  struct client *c;
1530  struct window_pane_offset *wpo;
1531  int off = 1, flag;
1532  u_int attached_clients = 0;
1533  size_t new_size;
1534 
1535  /*
1536  * Work out the minimum used size. This is the most that can be removed
1537  * from the buffer.
1538  */
1539  minimum = wp->offset.used;
1540  if (wp->pipe_fd != -1 && wp->pipe_offset.used < minimum)
1541  minimum = wp->pipe_offset.used;
1542  TAILQ_FOREACH(c, &clients, entry) {
1543  if (c->session == NULL)
1544  continue;
1545  attached_clients++;
1546 
1547  if (~c->flags & CLIENT_CONTROL) {
1548  off = 0;
1549  continue;
1550  }
1551  wpo = control_pane_offset(c, wp, &flag);
1552  if (wpo == NULL) {
1553  off = 0;
1554  continue;
1555  }
1556  if (!flag)
1557  off = 0;
1558 
1559  window_pane_get_new_data(wp, wpo, &new_size);
1560  log_debug("%s: %s has %zu bytes used and %zu left for %%%u",
1561  __func__, c->name, wpo->used - wp->base_offset, new_size,
1562  wp->id);
1563  if (wpo->used < minimum)
1564  minimum = wpo->used;
1565  }
1566  if (attached_clients == 0)
1567  off = 0;
1568  minimum -= wp->base_offset;
1569  if (minimum == 0)
1570  goto out;
1571 
1572  /* Drain the buffer. */
1573  log_debug("%s: %%%u has %zu minimum (of %zu) bytes used", __func__,
1574  wp->id, minimum, EVBUFFER_LENGTH(evb));
1575  evbuffer_drain(evb, minimum);
1576 
1577  /*
1578  * Adjust the base offset. If it would roll over, all the offsets into
1579  * the buffer need to be adjusted.
1580  */
1581  if (wp->base_offset > SIZE_MAX - minimum) {
1582  log_debug("%s: %%%u base offset has wrapped", __func__, wp->id);
1583  wp->offset.used -= wp->base_offset;
1584  if (wp->pipe_fd != -1)
1585  wp->pipe_offset.used -= wp->base_offset;
1586  TAILQ_FOREACH(c, &clients, entry) {
1587  if (c->session == NULL || (~c->flags & CLIENT_CONTROL))
1588  continue;
1589  wpo = control_pane_offset(c, wp, &flag);
1590  if (wpo != NULL && !flag)
1591  wpo->used -= wp->base_offset;
1592  }
1593  wp->base_offset = minimum;
1594  } else
1595  wp->base_offset += minimum;
1596 
1597 out:
1598  /*
1599  * If there is data remaining, and there are no clients able to consume
1600  * it, do not read any more. This is true when there are attached
1601  * clients, all of which are control clients which are not able to
1602  * accept any more data.
1603  */
1604  log_debug("%s: pane %%%u is %s", __func__, wp->id, off ? "off" : "on");
1605  if (off)
1606  bufferevent_disable(wp->event, EV_READ);
1607  else
1608  bufferevent_enable(wp->event, EV_READ);
1609 }
1610 
1611 /* Check whether pane should be focused. */
1612 static void
1614 {
1615  struct client *c;
1616  int push;
1617 
1618  /* Do we need to push the focus state? */
1619  push = wp->flags & PANE_FOCUSPUSH;
1620  wp->flags &= ~~PANE_FOCUSPUSH;
1621 
1622  /* If we're not the active pane in our window, we're not focused. */
1623  if (wp->window->active != wp)
1624  goto not_focused;
1625 
1626  /*
1627  * If our window is the current window in any focused clients with an
1628  * attached session, we're focused.
1629  */
1630  TAILQ_FOREACH(c, &clients, entry) {
1631  if (c->session == NULL || !(c->flags & CLIENT_FOCUSED))
1632  continue;
1633  if (c->session->attached == 0)
1634  continue;
1635 
1636  if (c->session->curw->window == wp->window)
1637  goto focused;
1638  }
1639 
1640 not_focused:
1641  if (push || (wp->flags & PANE_FOCUSED)) {
1642  if (wp->base.mode & MODE_FOCUSON)
1643  bufferevent_write(wp->event, "\033[O", 3);
1644  notify_pane("pane-focus-out", wp);
1645  }
1646  wp->flags &= ~~PANE_FOCUSED;
1647  return;
1648 
1649 focused:
1650  if (push || !(wp->flags & PANE_FOCUSED)) {
1651  if (wp->base.mode & MODE_FOCUSON)
1652  bufferevent_write(wp->event, "\033[I", 3);
1653  notify_pane("pane-focus-in", wp);
1654  session_update_activity(c->session, NULL);
1655  }
1656  wp->flags |= PANE_FOCUSED;
1657 }
1658 
1659 /*
1660  * Update cursor position and mode settings. The scroll region and attributes
1661  * are cleared when idle (waiting for an event) as this is the most likely time
1662  * a user may interrupt tmux, for example with ~^Z in ssh(1). This is a
1663  * compromise between excessive resets and likelihood of an interrupt.
1664  *
1665  * tty_region/tty_reset/tty_update_mode already take care of not resetting
1666  * things that are already in their default state.
1667  */
1668 static void
1670 {
1671  struct tty *tty = &c->tty;
1672  struct window *w = c->session->curw->window;
1673  struct window_pane *wp = server_client_get_pane(c), *loop;
1674  struct screen *s = NULL;
1675  struct options *oo = c->session->options;
1676  int mode = 0, cursor, flags;
1677  u_int cx = 0, cy = 0, ox, oy, sx, sy;
1678 
1680  return;
1681 
1682  /* Disable the block flag. */
1683  flags = (tty->flags & TTY_BLOCK);
1684  tty->flags &= ~~TTY_BLOCK;
1685 
1686  /* Get mode from overlay if any, else from screen. */
1687  if (c->overlay_draw != NULL) {
1688  if (c->overlay_mode != NULL)
1689  s = c->overlay_mode(c, &cx, &cy);
1690  } else
1691  s = wp->screen;
1692  if (s != NULL)
1693  mode = s->mode;
1694  log_debug("%s: client %s mode %x", __func__, c->name, mode);
1695 
1696  /* Reset region and margin. */
1699 
1700  /* Move cursor to pane cursor and offset. */
1701  if (c->overlay_draw == NULL) {
1702  cursor = 0;
1703  tty_window_offset(tty, &ox, &oy, &sx, &sy);
1704  if (wp->xoff + s->cx >= ox && wp->xoff + s->cx <= ox + sx &&
1705  wp->yoff + s->cy >= oy && wp->yoff + s->cy <= oy + sy) {
1706  cursor = 1;
1707 
1708  cx = wp->xoff + s->cx - ox;
1709  cy = wp->yoff + s->cy - oy;
1710 
1711  if (status_at_line(c) == 0)
1712  cy += status_line_size(c);
1713  }
1714  if (!cursor)
1715  mode &= ~~MODE_CURSOR;
1716  }
1717  log_debug("%s: cursor to %u,%u", __func__, cx, cy);
1718  tty_cursor(tty, cx, cy);
1719 
1720  /*
1721  * Set mouse mode if requested. To support dragging, always use button
1722  * mode.
1723  */
1724  if (options_get_number(oo, "mouse")) {
1725  if (c->overlay_draw == NULL) {
1726  mode &= ~~ALL_MOUSE_MODES;
1727  TAILQ_FOREACH(loop, &w->panes, entry) {
1728  if (loop->screen->mode & MODE_MOUSE_ALL)
1729  mode |= MODE_MOUSE_ALL;
1730  }
1731  }
1732  if (~mode & MODE_MOUSE_ALL)
1733  mode |= MODE_MOUSE_BUTTON;
1734  }
1735 
1736  /* Clear bracketed paste mode if at the prompt. */
1737  if (c->overlay_draw == NULL && c->prompt_string != NULL)
1738  mode &= ~~MODE_BRACKETPASTE;
1739 
1740  /* Set the terminal mode and reset attributes. */
1741  tty_update_mode(tty, mode, s);
1742  tty_reset(tty);
1743 
1744  /* All writing must be done, send a sync end (if it was started). */
1745  tty_sync_end(tty);
1746  tty->flags |= flags;
1747 }
1748 
1749 /* Repeat time callback. */
1750 static void
1751 server_client_repeat_timer(__unused int fd, __unused short events, void *data)
1752 {
1753  struct client *c = data;
1754 
1755  if (c->flags & CLIENT_REPEAT) {
1756  server_client_set_key_table(c, NULL);
1757  c->flags &= ~~CLIENT_REPEAT;
1759  }
1760 }
1761 
1762 /* Double-click callback. */
1763 static void
1764 server_client_click_timer(__unused int fd, __unused short events, void *data)
1765 {
1766  struct client *c = data;
1767  struct key_event *event;
1768 
1769  log_debug("click timer expired");
1770 
1771  if (c->flags & CLIENT_TRIPLECLICK) {
1772  /*
1773  * Waiting for a third click that hasn't happened, so this must
1774  * have been a double click.
1775  */
1776  event = xmalloc(sizeof *event);
1777  event->key = KEYC_DOUBLECLICK;
1778  memcpy(&event->m, &c->click_event, sizeof event->m);
1779  if (!server_client_handle_key(c, event))
1780  free(event);
1781  }
1783 }
1784 
1785 /* Check if client should be exited. */
1786 static void
1788 {
1789  struct client_file *cf;
1790  const char *name = c->exit_session;
1791  char *data;
1792  size_t size, msize;
1793 
1794  if (c->flags & (CLIENT_DEAD|CLIENT_EXITED))
1795  return;
1796  if (~c->flags & CLIENT_EXIT)
1797  return;
1798 
1799  if (c->flags & CLIENT_CONTROL) {
1800  control_discard(c);
1801  if (!control_all_done(c))
1802  return;
1803  }
1804  RB_FOREACH(cf, client_files, &c->files) {
1805  if (EVBUFFER_LENGTH(cf->buffer) != 0)
1806  return;
1807  }
1808  c->flags |= CLIENT_EXITED;
1809 
1810  switch (c->exit_type) {
1811  case CLIENT_EXIT_RETURN:
1812  if (c->exit_message != NULL)
1813  msize = strlen(c->exit_message) + 1;
1814  else
1815  msize = 0;
1816  size = (sizeof c->retval) + msize;
1817  data = xmalloc(size);
1818  memcpy(data, &c->retval, sizeof c->retval);
1819  if (c->exit_message != NULL)
1820  memcpy(data + sizeof c->retval, c->exit_message, msize);
1821  proc_send(c->peer, MSG_EXIT, -1, data, size);
1822  free(data);
1823  break;
1824  case CLIENT_EXIT_SHUTDOWN:
1825  proc_send(c->peer, MSG_SHUTDOWN, -1, NULL, 0);
1826  break;
1827  case CLIENT_EXIT_DETACH:
1828  proc_send(c->peer, c->exit_msgtype, -1, name, strlen(name) + 1);
1829  break;
1830  }
1831  free(c->exit_session);
1832  free(c->exit_message);
1833 }
1834 
1835 /* Redraw timer callback. */
1836 static void
1838  __unused void *data)
1839 {
1840  log_debug("redraw timer fired");
1841 }
1842 
1843 /*
1844  * Check if modes need to be updated. Only modes in the current window are
1845  * updated and it is done when the status line is redrawn.
1846  */
1847 static void
1849 {
1850  struct window *w = c->session->curw->window;
1851  struct window_pane *wp;
1852  struct window_mode_entry *wme;
1853 
1855  return;
1856  if (~c->flags & CLIENT_REDRAWSTATUS)
1857  return;
1858  TAILQ_FOREACH(wp, &w->panes, entry) {
1859  wme = TAILQ_FIRST(&wp->modes);
1860  if (wme != NULL && wme->mode->update != NULL)
1861  wme->mode->update(wme);
1862  }
1863 }
1864 
1865 /* Check for client redraws. */
1866 static void
1868 {
1869  struct session *s = c->session;
1870  struct tty *tty = &c->tty;
1871  struct window *w = c->session->curw->window;
1872  struct window_pane *wp;
1873  int needed, flags, mode = tty->mode, new_flags = 0;
1874  int redraw;
1875  u_int bit = 0;
1876  struct timeval tv = { .tv_usec = 1000 };
1877  static struct event ev;
1878  size_t left;
1879 
1881  return;
1882  if (c->flags & CLIENT_ALLREDRAWFLAGS) {
1883  log_debug("%s: redraw%s%s%s%s%s", c->name,
1884  (c->flags & CLIENT_REDRAWWINDOW) ? " window" : "",
1885  (c->flags & CLIENT_REDRAWSTATUS) ? " status" : "",
1886  (c->flags & CLIENT_REDRAWBORDERS) ? " borders" : "",
1887  (c->flags & CLIENT_REDRAWOVERLAY) ? " overlay" : "",
1888  (c->flags & CLIENT_REDRAWPANES) ? " panes" : "");
1889  }
1890 
1891  /*
1892  * If there is outstanding data, defer the redraw until it has been
1893  * consumed. We can just add a timer to get out of the event loop and
1894  * end up back here.
1895  */
1896  needed = 0;
1897  if (c->flags & CLIENT_ALLREDRAWFLAGS)
1898  needed = 1;
1899  else {
1900  TAILQ_FOREACH(wp, &w->panes, entry) {
1901  if (wp->flags & PANE_REDRAW) {
1902  needed = 1;
1903  break;
1904  }
1905  }
1906  if (needed)
1907  new_flags |= CLIENT_REDRAWPANES;
1908  }
1909  if (needed && (left = EVBUFFER_LENGTH(tty->out)) != 0) {
1910  log_debug("%s: redraw deferred (%zu left)", c->name, left);
1911  if (!evtimer_initialized(&ev))
1912  evtimer_set(&ev, server_client_redraw_timer, NULL);
1913  if (!evtimer_pending(&ev, NULL)) {
1914  log_debug("redraw timer started");
1915  evtimer_add(&ev, &tv);
1916  }
1917 
1918  if (~c->flags & CLIENT_REDRAWWINDOW) {
1919  TAILQ_FOREACH(wp, &w->panes, entry) {
1920  if (wp->flags & PANE_REDRAW) {
1921  log_debug("%s: pane %%%u needs redraw",
1922  c->name, wp->id);
1923  c->redraw_panes |= (1 << bit);
1924  }
1925  if (++bit == 64) {
1926  /*
1927  * If more that 64 panes, give up and
1928  * just redraw the window.
1929  */
1930  new_flags &= CLIENT_REDRAWPANES;
1931  new_flags |= CLIENT_REDRAWWINDOW;
1932  break;
1933  }
1934  }
1935  if (c->redraw_panes != 0)
1936  c->flags |= CLIENT_REDRAWPANES;
1937  }
1938  c->flags |= new_flags;
1939  return;
1940  } else if (needed)
1941  log_debug("%s: redraw needed", c->name);
1942 
1943  flags = tty->flags & (TTY_BLOCK|TTY_FREEZE|TTY_NOCURSOR);
1945 
1946  if (~c->flags & CLIENT_REDRAWWINDOW) {
1947  /*
1948  * If not redrawing the entire window, check whether each pane
1949  * needs to be redrawn.
1950  */
1951  TAILQ_FOREACH(wp, &w->panes, entry) {
1952  redraw = 0;
1953  if (wp->flags & PANE_REDRAW)
1954  redraw = 1;
1955  else if (c->flags & CLIENT_REDRAWPANES)
1956  redraw = !!(c->redraw_panes & (1 << bit));
1957  bit++;
1958  if (!redraw)
1959  continue;
1960  log_debug("%s: redrawing pane %%%u", __func__, wp->id);
1961  screen_redraw_pane(c, wp);
1962  }
1963  c->redraw_panes = 0;
1964  c->flags &= ~~CLIENT_REDRAWPANES;
1965  }
1966 
1967  if (c->flags & CLIENT_ALLREDRAWFLAGS) {
1968  if (options_get_number(s->options, "set-titles"))
1971  }
1972 
1973  tty->flags = (tty->flags & ~~TTY_NOCURSOR)|(flags & TTY_NOCURSOR);
1974  tty_update_mode(tty, mode, NULL);
1975  tty->flags = (tty->flags & ~(TTY_BLOCK|TTY_FREEZE|TTY_NOCURSOR))|flags;
1976 
1978 
1979  if (needed) {
1980  /*
1981  * We would have deferred the redraw unless the output buffer
1982  * was empty, so we can record how many bytes the redraw
1983  * generated.
1984  */
1985  c->redraw = EVBUFFER_LENGTH(tty->out);
1986  log_debug("%s: redraw added %zu bytes", c->name, c->redraw);
1987  }
1988 }
1989 
1990 /* Set client title. */
1991 static void
1993 {
1994  struct session *s = c->session;
1995  const char *template;
1996  char *title;
1997  struct format_tree *ft;
1998 
1999  template = options_get_string(s->options, "set-titles-string");
2000 
2001  ft = format_create(c, NULL, FORMAT_NONE, 0);
2002  format_defaults(ft, c, NULL, NULL, NULL);
2003 
2004  title = format_expand_time(ft, template);
2005  if (c->title == NULL || strcmp(title, c->title) != 0) {
2006  free(c->title);
2007  c->title = xstrdup(title);
2008  tty_set_title(&c->tty, c->title);
2009  }
2010  free(title);
2011 
2012  format_free(ft);
2013 }
2014 
2015 /* Dispatch message from client. */
2016 static void
2017 server_client_dispatch(struct imsg *imsg, void *arg)
2018 {
2019  struct client *c = arg;
2020  ssize_t datalen;
2021  struct session *s;
2022 
2023  if (c->flags & CLIENT_DEAD)
2024  return;
2025 
2026  if (imsg == NULL) {
2027  server_client_lost(c);
2028  return;
2029  }
2030 
2031  datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
2032 
2033  switch (imsg->hdr.type) {
2035  case MSG_IDENTIFY_CWD:
2036  case MSG_IDENTIFY_ENVIRON:
2037  case MSG_IDENTIFY_FEATURES:
2038  case MSG_IDENTIFY_FLAGS:
2040  case MSG_IDENTIFY_STDIN:
2041  case MSG_IDENTIFY_STDOUT:
2042  case MSG_IDENTIFY_TERM:
2043  case MSG_IDENTIFY_TERMINFO:
2044  case MSG_IDENTIFY_TTYNAME:
2045  case MSG_IDENTIFY_DONE:
2047  break;
2048  case MSG_COMMAND:
2050  break;
2051  case MSG_RESIZE:
2052  if (datalen != 0)
2053  fatalx("bad MSG_RESIZE size");
2054 
2055  if (c->flags & CLIENT_CONTROL)
2056  break;
2059  tty_resize(&c->tty);
2062  if (c->session != NULL)
2063  notify_client("client-resized", c);
2064  break;
2065  case MSG_EXITING:
2066  if (datalen != 0)
2067  fatalx("bad MSG_EXITING size");
2068  c->session = NULL;
2069  tty_close(&c->tty);
2070  proc_send(c->peer, MSG_EXITED, -1, NULL, 0);
2071  break;
2072  case MSG_WAKEUP:
2073  case MSG_UNLOCK:
2074  if (datalen != 0)
2075  fatalx("bad MSG_WAKEUP size");
2076 
2077  if (!(c->flags & CLIENT_SUSPENDED))
2078  break;
2079  c->flags &= ~~CLIENT_SUSPENDED;
2080 
2081  if (c->fd == -1 || c->session == NULL) /* exited already */
2082  break;
2083  s = c->session;
2084 
2085  if (gettimeofday(&c->activity_time, NULL) != 0)
2086  fatal("gettimeofday failed");
2087 
2088  tty_start_tty(&c->tty);
2091 
2092  if (s != NULL)
2094  break;
2095  case MSG_SHELL:
2096  if (datalen != 0)
2097  fatalx("bad MSG_SHELL size");
2098 
2100  break;
2101  case MSG_WRITE_READY:
2102  file_write_ready(&c->files, imsg);
2103  break;
2104  case MSG_READ:
2105  file_read_data(&c->files, imsg);
2106  break;
2107  case MSG_READ_DONE:
2108  file_read_done(&c->files, imsg);
2109  break;
2110  }
2111 }
2112 
2113 /* Callback when command is done. */
2114 static enum cmd_retval
2115 server_client_command_done(struct cmdq_item *item, __unused void *data)
2116 {
2117  struct client *c = cmdq_get_client(item);
2118 
2119  if (~c->flags & CLIENT_ATTACHED)
2120  c->flags |= CLIENT_EXIT;
2121  else if (~c->flags & CLIENT_EXIT)
2122  tty_send_requests(&c->tty);
2123  return (CMD_RETURN_NORMAL);
2124 }
2125 
2126 /* Handle command message. */
2127 static void
2128 server_client_dispatch_command(struct client *c, struct imsg *imsg)
2129 {
2130  struct msg_command data;
2131  char *buf;
2132  size_t len;
2133  int argc;
2134  char **argv, *cause;
2135  struct cmd_parse_result *pr;
2136 
2137  if (c->flags & CLIENT_EXIT)
2138  return;
2139 
2140  if (imsg->hdr.len - IMSG_HEADER_SIZE < sizeof data)
2141  fatalx("bad MSG_COMMAND size");
2142  memcpy(&data, imsg->data, sizeof data);
2143 
2144  buf = (char *)imsg->data + sizeof data;
2145  len = imsg->hdr.len - IMSG_HEADER_SIZE - sizeof data;
2146  if (len > 0 && buf[len - 1] != '\0')
2147  fatalx("bad MSG_COMMAND string");
2148 
2149  argc = data.argc;
2150  if (cmd_unpack_argv(buf, len, argc, &argv) != 0) {
2151  cause = xstrdup("command too long");
2152  goto error;
2153  }
2154 
2155  if (argc == 0) {
2156  argc = 1;
2157  argv = xcalloc(1, sizeof *argv);
2158  *argv = xstrdup("new-session");
2159  }
2160 
2161  pr = cmd_parse_from_arguments(argc, argv, NULL);
2162  switch (pr->status) {
2163  case CMD_PARSE_EMPTY:
2164  cause = xstrdup("empty command");
2165  goto error;
2166  case CMD_PARSE_ERROR:
2167  cause = pr->error;
2168  goto error;
2169  case CMD_PARSE_SUCCESS:
2170  break;
2171  }
2172  cmd_free_argv(argc, argv);
2173 
2174  cmdq_append(c, cmdq_get_command(pr->cmdlist, NULL));
2176 
2177  cmd_list_free(pr->cmdlist);
2178  return;
2179 
2180 error:
2181  cmd_free_argv(argc, argv);
2182 
2183  cmdq_append(c, cmdq_get_error(cause));
2184  free(cause);
2185 
2186  c->flags |= CLIENT_EXIT;
2187 }
2188 
2189 /* Handle identify message. */
2190 static void
2191 server_client_dispatch_identify(struct client *c, struct imsg *imsg)
2192 {
2193  const char *data, *home;
2194  size_t datalen;
2195  int flags, feat;
2196  uint64_t longflags;
2197  char *name;
2198 
2199  if (c->flags & CLIENT_IDENTIFIED)
2200  fatalx("out-of-order identify message");
2201 
2202  data = imsg->data;
2203  datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
2204 
2205  switch (imsg->hdr.type) {
2206  case MSG_IDENTIFY_FEATURES:
2207  if (datalen != sizeof feat)
2208  fatalx("bad MSG_IDENTIFY_FEATURES size");
2209  memcpy(&feat, data, sizeof feat);
2210  c->term_features |= feat;
2211  log_debug("client %p IDENTIFY_FEATURES %s", c,
2212  tty_get_features(feat));
2213  break;
2214  case MSG_IDENTIFY_FLAGS:
2215  if (datalen != sizeof flags)
2216  fatalx("bad MSG_IDENTIFY_FLAGS size");
2217  memcpy(&flags, data, sizeof flags);
2218  c->flags |= flags;
2219  log_debug("client %p IDENTIFY_FLAGS %#x", c, flags);
2220  break;
2222  if (datalen != sizeof longflags)
2223  fatalx("bad MSG_IDENTIFY_LONGFLAGS size");
2224  memcpy(&longflags, data, sizeof longflags);
2225  c->flags |= longflags;
2226  log_debug("client %p IDENTIFY_LONGFLAGS %#llx", c,
2227  (unsigned long long)longflags);
2228  break;
2229  case MSG_IDENTIFY_TERM:
2230  if (datalen == 0 || data[datalen - 1] != '\0')
2231  fatalx("bad MSG_IDENTIFY_TERM string");
2232  if (*data == '\0')
2233  c->term_name = xstrdup("unknown");
2234  else
2235  c->term_name = xstrdup(data);
2236  log_debug("client %p IDENTIFY_TERM %s", c, data);
2237  break;
2238  case MSG_IDENTIFY_TERMINFO:
2239  if (datalen == 0 || data[datalen - 1] != '\0')
2240  fatalx("bad MSG_IDENTIFY_TERMINFO string");
2241  c->term_caps = xreallocarray(c->term_caps, c->term_ncaps + 1,
2242  sizeof *c->term_caps);
2243  c->term_caps[c->term_ncaps++] = xstrdup(data);
2244  log_debug("client %p IDENTIFY_TERMINFO %s", c, data);
2245  break;
2246  case MSG_IDENTIFY_TTYNAME:
2247  if (datalen == 0 || data[datalen - 1] != '\0')
2248  fatalx("bad MSG_IDENTIFY_TTYNAME string");
2249  c->ttyname = xstrdup(data);
2250  log_debug("client %p IDENTIFY_TTYNAME %s", c, data);
2251  break;
2252  case MSG_IDENTIFY_CWD:
2253  if (datalen == 0 || data[datalen - 1] != '\0')
2254  fatalx("bad MSG_IDENTIFY_CWD string");
2255  if (access(data, X_OK) == 0)
2256  c->cwd = xstrdup(data);
2257  else if ((home = find_home()) != NULL)
2258  c->cwd = xstrdup(home);
2259  else
2260  c->cwd = xstrdup("/");
2261  log_debug("client %p IDENTIFY_CWD %s", c, data);
2262  break;
2263  case MSG_IDENTIFY_STDIN:
2264  if (datalen != 0)
2265  fatalx("bad MSG_IDENTIFY_STDIN size");
2266  c->fd = imsg->fd;
2267  log_debug("client %p IDENTIFY_STDIN %d", c, imsg->fd);
2268  break;
2269  case MSG_IDENTIFY_STDOUT:
2270  if (datalen != 0)
2271  fatalx("bad MSG_IDENTIFY_STDOUT size");
2272  c->out_fd = imsg->fd;
2273  log_debug("client %p IDENTIFY_STDOUT %d", c, imsg->fd);
2274  break;
2275  case MSG_IDENTIFY_ENVIRON:
2276  if (datalen == 0 || data[datalen - 1] != '\0')
2277  fatalx("bad MSG_IDENTIFY_ENVIRON string");
2278  if (strchr(data, '=') != NULL)
2279  environ_put(c->environ, data, 0);
2280  log_debug("client %p IDENTIFY_ENVIRON %s", c, data);
2281  break;
2283  if (datalen != sizeof c->pid)
2284  fatalx("bad MSG_IDENTIFY_CLIENTPID size");
2285  memcpy(&c->pid, data, sizeof c->pid);
2286  log_debug("client %p IDENTIFY_CLIENTPID %ld", c, (long)c->pid);
2287  break;
2288  default:
2289  break;
2290  }
2291 
2292  if (imsg->hdr.type != MSG_IDENTIFY_DONE)
2293  return;
2294  c->flags |= CLIENT_IDENTIFIED;
2295 
2296  if (*c->ttyname != '\0')
2297  name = xstrdup(c->ttyname);
2298  else
2299  xasprintf(&name, "client-%ld", (long)c->pid);
2300  c->name = name;
2301  log_debug("client %p name is %s", c, c->name);
2302 
2303 #ifdef __CYGWIN__
2304  c->fd = open(c->ttyname, O_RDWR|O_NOCTTY);
2305 #endif
2306 
2307  if (c->flags & CLIENT_CONTROL)
2308  control_start(c);
2309  else if (c->fd != -1) {
2310  if (tty_init(&c->tty, c) != 0) {
2311  close(c->fd);
2312  c->fd = -1;
2313  } else {
2314  tty_resize(&c->tty);
2315  c->flags |= CLIENT_TERMINAL;
2316  }
2317  close(c->out_fd);
2318  c->out_fd = -1;
2319  }
2320 
2321  /*
2322  * If this is the first client, load configuration files. Any later
2323  * clients are allowed to continue with their command even if the
2324  * config has not been loaded - they might have been run from inside it
2325  */
2326  if ((~c->flags & CLIENT_EXIT) &&
2327  !cfg_finished &&
2328  c == TAILQ_FIRST(&clients))
2329  start_cfg();
2330 }
2331 
2332 /* Handle shell message. */
2333 static void
2335 {
2336  const char *shell;
2337 
2338  shell = options_get_string(global_s_options, "default-shell");
2339  if (!checkshell(shell))
2340  shell = _PATH_BSHELL;
2341  proc_send(c->peer, MSG_SHELL, -1, shell, strlen(shell) + 1);
2342 
2343  proc_kill_peer(c->peer);
2344 }
2345 
2346 /* Get client working directory. */
2347 const char *
2348 server_client_get_cwd(struct client *c, struct session *s)
2349 {
2350  const char *home;
2351 
2352  if (!cfg_finished && cfg_client != NULL)
2353  return (cfg_client->cwd);
2354  if (c != NULL && c->session == NULL && c->cwd != NULL)
2355  return (c->cwd);
2356  if (s != NULL && s->cwd != NULL)
2357  return (s->cwd);
2358  if (c != NULL && (s = c->session) != NULL && s->cwd != NULL)
2359  return (s->cwd);
2360  if ((home = find_home()) != NULL)
2361  return (home);
2362  return ("/");
2363 }
2364 
2365 /* Get control client flags. */
2366 static uint64_t
2367 server_client_control_flags(struct client *c, const char *next)
2368 {
2369  if (strcmp(next, "pause-after") == 0) {
2370  c->pause_age = 0;
2371  return (CLIENT_CONTROL_PAUSEAFTER);
2372  }
2373  if (sscanf(next, "pause-after=%u", &c->pause_age) == 1) {
2374  c->pause_age *= 1000;
2375  return (CLIENT_CONTROL_PAUSEAFTER);
2376  }
2377  if (strcmp(next, "no-output") == 0)
2378  return (CLIENT_CONTROL_NOOUTPUT);
2379  if (strcmp(next, "wait-exit") == 0)
2380  return (CLIENT_CONTROL_WAITEXIT);
2381  return (0);
2382 }
2383 
2384 /* Set client flags. */
2385 void
2386 server_client_set_flags(struct client *c, const char *flags)
2387 {
2388  char *s, *copy, *next;
2389  uint64_t flag;
2390  int not;
2391 
2392  s = copy = xstrdup (flags);
2393  while ((next = strsep(&s, ",")) != NULL) {
2394  not = (*next == '!');
2395  if (not)
2396  next++;
2397 
2398  if (c->flags & CLIENT_CONTROL)
2399  flag = server_client_control_flags(c, next);
2400  else
2401  flag = 0;
2402  if (strcmp(next, "read-only") == 0)
2403  flag = CLIENT_READONLY;
2404  else if (strcmp(next, "ignore-size") == 0)
2405  flag = CLIENT_IGNORESIZE;
2406  else if (strcmp(next, "active-pane") == 0)
2407  flag = CLIENT_ACTIVEPANE;
2408  if (flag == 0)
2409  continue;
2410 
2411  log_debug("client %s set flag %s", c->name, next);
2412  if (not)
2413  c->flags &= ~~flag;
2414  else
2415  c->flags |= flag;
2416  if (flag == CLIENT_CONTROL_NOOUTPUT)
2418  }
2419  free(copy);
2420  proc_send(c->peer, MSG_FLAGS, -1, &c->flags, sizeof c->flags);
2421 }
2422 
2423 /* Get client flags. This is only flags useful to show to users. */
2424 const char *
2426 {
2427  static char s[256];
2428  char tmp[32];
2429 
2430  *s = '\0';
2431  if (c->flags & CLIENT_ATTACHED)
2432  strlcat(s, "attached,", sizeof s);
2433  if (c->flags & CLIENT_FOCUSED)
2434  strlcat(s, "focused,", sizeof s);
2435  if (c->flags & CLIENT_CONTROL)
2436  strlcat(s, "control-mode,", sizeof s);
2437  if (c->flags & CLIENT_IGNORESIZE)
2438  strlcat(s, "ignore-size,", sizeof s);
2439  if (c->flags & CLIENT_CONTROL_NOOUTPUT)
2440  strlcat(s, "no-output,", sizeof s);
2441  if (c->flags & CLIENT_CONTROL_WAITEXIT)
2442  strlcat(s, "wait-exit,", sizeof s);
2443  if (c->flags & CLIENT_CONTROL_PAUSEAFTER) {
2444  xsnprintf(tmp, sizeof tmp, "pause-after=%u,",
2445  c->pause_age / 1000);
2446  strlcat(s, tmp, sizeof s);
2447  }
2448  if (c->flags & CLIENT_READONLY)
2449  strlcat(s, "read-only,", sizeof s);
2450  if (c->flags & CLIENT_ACTIVEPANE)
2451  strlcat(s, "active-pane,", sizeof s);
2452  if (c->flags & CLIENT_SUSPENDED)
2453  strlcat(s, "suspended,", sizeof s);
2454  if (c->flags & CLIENT_UTF8)
2455  strlcat(s, "UTF-8,", sizeof s);
2456  if (*s != '\0')
2457  s[strlen(s) - 1] = '\0';
2458  return (s);
2459 }
2460 
2461 /* Get client window. */
2462 static struct client_window *
2464 {
2465  struct client_window cw = { .window = id };
2466 
2467  return (RB_FIND(client_windows, &c->windows, &cw));
2468 }
2469 
2470 /* Get client active pane. */
2471 struct window_pane *
2473 {
2474  struct session *s = c->session;
2475  struct client_window *cw;
2476 
2477  if (s == NULL)
2478  return (NULL);
2479 
2480  if (~c->flags & CLIENT_ACTIVEPANE)
2481  return (s->curw->window->active);
2483  if (cw == NULL)
2484  return (s->curw->window->active);
2485  return (cw->pane);
2486 }
2487 
2488 /* Set client active pane. */
2489 void
2491 {
2492  struct session *s = c->session;
2493  struct client_window *cw;
2494 
2495  if (s == NULL)
2496  return;
2497 
2499  if (cw == NULL) {
2500  cw = xcalloc(1, sizeof *cw);
2501  cw->window = s->curw->window->id;
2502  RB_INSERT(client_windows, &c->windows, cw);
2503  }
2504  cw->pane = wp;
2505  log_debug("%s pane now %%%u", c->name, wp->id);
2506 }
2507 
2508 /* Remove pane from client lists. */
2509 void
2511 {
2512  struct client *c;
2513  struct window *w = wp->window;
2514  struct client_window *cw;
2515 
2516  TAILQ_FOREACH(c, &clients, entry) {
2517  cw = server_client_get_client_window(c, w->id);
2518  if (cw != NULL && cw->pane == wp) {
2519  RB_REMOVE(client_windows, &c->windows, cw);
2520  free(cw);
2521  }
2522  }
2523 }
struct client * cfg_client
Definition: cfg.c:29
void start_cfg(void)
Definition: cfg.c:66
int cfg_finished
Definition: cfg.c:30
static struct client_files client_files
Definition: client.c:58
int cmd_find_from_mouse(struct cmd_find_state *fs, struct mouse_event *m, int flags)
Definition: cmd-find.c:839
int cmd_find_from_client(struct cmd_find_state *fs, struct client *c, int flags)
Definition: cmd-find.c:859
struct cmd_parse_result * cmd_parse_from_arguments(int argc, char **argv, struct cmd_parse_input *pi)
Definition: cmd-parse.c:697
void cmdq_free(struct cmdq_list *queue)
Definition: cmd-queue.c:134
struct client * cmdq_get_client(struct cmdq_item *item)
Definition: cmd-queue.c:150
struct cmdq_item * cmdq_get_error(const char *error)
Definition: cmd-queue.c:671
struct cmdq_list * cmdq_new(void)
Definition: cmd-queue.c:123
struct cmdq_item * cmdq_get_command(struct cmd_list *cmdlist, struct cmdq_state *state)
Definition: cmd-queue.c:474
struct cmdq_item * cmdq_append(struct client *c, struct cmdq_item *item)
Definition: cmd-queue.c:288
int cmd_unpack_argv(char *buf, size_t len, int argc, char ***argv)
Definition: cmd.c:298
void cmd_list_free(struct cmd_list *cmdlist)
Definition: cmd.c:606
void cmd_free_argv(int argc, char **argv)
Definition: cmd.c:344
#define __unused
Definition: compat.h:60
char * strsep(char **, const char *)
size_t strlcat(char *, const char *, size_t)
#define timercmp(tvp, uvp, cmp)
Definition: compat.h:230
#define _PATH_TTY
Definition: compat.h:110
#define timersub(tvp, uvp, vvp)
Definition: compat.h:249
#define _PATH_BSHELL
Definition: compat.h:98
struct window_pane_offset * control_pane_offset(struct client *c, struct window_pane *wp, int *off)
Definition: control.c:311
void control_discard(struct client *c)
Definition: control.c:797
int control_all_done(struct client *c)
Definition: control.c:579
void control_stop(struct client *c)
Definition: control.c:809
void control_reset_offsets(struct client *c)
Definition: control.c:295
void control_start(struct client *c)
Definition: control.c:759
struct environ * environ_create(void)
Definition: environ.c:44
void environ_put(struct environ *env, const char *var, int flags)
Definition: environ.c:150
struct environ_entry * environ_find(struct environ *env, const char *name)
Definition: environ.c:99
void environ_free(struct environ *env)
Definition: environ.c:56
void file_write_ready(struct client_files *files, struct imsg *imsg)
Definition: file.c:758
void file_read_done(struct client_files *files, struct imsg *imsg)
Definition: file.c:804
void file_read_data(struct client_files *files, struct imsg *imsg)
Definition: file.c:778
void file_fire_done(struct client_file *cf)
Definition: file.c:159
void format_defaults(struct format_tree *ft, struct client *c, struct session *s, struct winlink *wl, struct window_pane *wp)
Definition: format.c:4684
struct format_tree * format_create(struct client *c, struct cmdq_item *item, int tag, int flags)
Definition: format.c:3042
void format_free(struct format_tree *ft)
Definition: format.c:3066
char * format_expand_time(struct format_tree *ft, const char *fmt)
Definition: format.c:4597
void format_lost_client(struct client *c)
Definition: format.c:454
struct cmdq_item * key_bindings_dispatch(struct key_binding *bd, struct cmdq_item *item, struct client *c, struct key_event *event, struct cmd_find_state *fs)
Definition: key-bindings.c:650
void key_bindings_unref_table(struct key_table *table)
Definition: key-bindings.c:133
struct key_table * key_bindings_get_table(const char *name, int create)
Definition: key-bindings.c:100
struct key_binding * key_bindings_get(struct key_table *table, key_code key)
Definition: key-bindings.c:155
key_code key
Definition: key-string.c:32
const char * key_string_lookup_key(key_code key, int with_flags)
Definition: key-string.c:265
const char * name
Definition: layout-set.c:38
void fatal(const char *msg,...)
Definition: log.c:144
void fatalx(const char *msg,...)
Definition: log.c:159
int log_get_level(void)
Definition: log.c:51
void log_debug(const char *msg,...)
Definition: log.c:130
void check_window_name(struct window *w)
Definition: names.c:54
void notify_client(const char *name, struct client *c)
Definition: notify.c:214
void notify_pane(const char *name, struct window_pane *wp)
Definition: notify.c:262
const char * options_get_string(struct options *oo, const char *name)
Definition: options.c:686
long long options_get_number(struct options *oo, const char *name)
Definition: options.c:699
struct tmuxpeer * proc_add_peer(struct tmuxproc *tp, int fd, void(*dispatchcb)(struct imsg *, void *), void *arg)
Definition: proc.c:307
void proc_kill_peer(struct tmuxpeer *peer)
Definition: proc.c:342
int proc_send(struct tmuxpeer *peer, enum msgtype type, int fd, const void *buf, size_t len)
Definition: proc.c:162
void proc_remove_peer(struct tmuxpeer *peer)
Definition: proc.c:329
void recalculate_size(struct window *w, int now)
Definition: resize.c:289
void resize_window(struct window *w, u_int sx, u_int sy, int xpixel, int ypixel)
Definition: resize.c:26
void recalculate_sizes(void)
Definition: resize.c:355
void screen_redraw_screen(struct client *c)
void screen_redraw_pane(struct client *c, struct window_pane *wp)
static void server_client_redraw_timer(int fd, short events, void *data)
static void server_client_repeat_timer(int, short, void *)
static void server_client_dispatch_identify(struct client *, struct imsg *)
int server_client_check_nested(struct client *c)
int server_client_handle_key(struct client *c, struct key_event *event)
static void server_client_reset_state(struct client *)
static void server_client_update_latest(struct client *)
void server_client_set_key_table(struct client *c, const char *name)
static int server_client_assume_paste(struct session *)
void server_client_set_flags(struct client *c, const char *flags)
void server_client_set_overlay(struct client *c, u_int delay, overlay_check_cb checkcb, overlay_mode_cb modecb, overlay_draw_cb drawcb, overlay_key_cb keycb, overlay_free_cb freecb, void *data)
Definition: server-client.c:90
static int server_client_window_cmp(struct client_window *cw1, struct client_window *cw2)
Definition: server-client.c:55
void server_client_remove_pane(struct window_pane *wp)
void server_client_clear_overlay(struct client *c)
static void server_client_check_modes(struct client *)
void server_client_set_pane(struct client *c, struct window_pane *wp)
static void server_client_check_window_resize(struct window *)
static void server_client_overlay_timer(int fd, short events, void *data)
Definition: server-client.c:83
void server_client_unref(struct client *c)
static void server_client_attached_lost(struct client *c)
static void server_client_click_timer(int, short, void *)
const char * server_client_get_flags(struct client *c)
static void server_client_check_pane_buffer(struct window_pane *)
static void server_client_check_exit(struct client *)
static void server_client_check_pane_focus(struct window_pane *)
static void server_client_resize_timer(int fd, short events, void *data)
static void server_client_dispatch(struct imsg *, void *)
RB_GENERATE(client_windows, client_window, entry, server_client_window_cmp)
static uint64_t server_client_control_flags(struct client *c, const char *next)
const char * server_client_get_cwd(struct client *c, struct session *s)
static enum cmd_retval server_client_key_callback(struct cmdq_item *item, void *data)
static void server_client_dispatch_command(struct client *, struct imsg *)
const char * server_client_get_key_table(struct client *c)
static void server_client_free(int, short, void *)
struct client * server_client_create(int fd)
void server_client_suspend(struct client *c)
u_int server_client_how_many(void)
Definition: server-client.c:68
static void server_client_set_title(struct client *)
void server_client_lost(struct client *c)
void server_client_loop(void)
static void server_client_check_redraw(struct client *)
static void server_client_check_pane_resize(struct window_pane *)
void server_client_detach(struct client *c, enum msgtype msgtype)
static enum cmd_retval server_client_command_done(struct cmdq_item *item, void *data)
struct window_pane * server_client_get_pane(struct client *c)
void server_client_exec(struct client *c, const char *cmd)
static struct client_window * server_client_get_client_window(struct client *c, u_int id)
static int server_client_is_default_key_table(struct client *c, struct key_table *table)
static void server_client_dispatch_shell(struct client *)
static key_code server_client_check_mouse(struct client *, struct key_event *)
int server_client_open(struct client *c, char **cause)
void server_check_unattached(void)
Definition: server-fn.c:469
void server_redraw_client(struct client *c)
Definition: server-fn.c:34
void server_status_client(struct client *c)
Definition: server-fn.c:40
void server_add_accept(int timeout)
Definition: server.c:389
struct tmuxproc * server_proc
Definition: server.c:44
struct clients clients
Definition: server.c:42
void server_update_socket(void)
Definition: server.c:320
void session_update_activity(struct session *s, struct timeval *from)
Definition: session.c:266
void status_free(struct client *c)
Definition: status.c:304
int status_at_line(struct client *c)
Definition: status.c:210
void status_init(struct client *c)
Definition: status.c:290
u_int status_line_size(struct client *c)
Definition: status.c:223
void status_prompt_clear(struct client *c)
Definition: status.c:602
int status_prompt_key(struct client *c, key_code key)
Definition: status.c:1033
void status_message_clear(struct client *c)
Definition: status.c:470
struct style_range * status_get_range(struct client *c, u_int x, u_int y)
Definition: status.c:236
struct evbuffer * buffer
Definition: tmux.h:1578
void * data
Definition: tmux.h:1586
int error
Definition: tmux.h:1582
int fd
Definition: tmux.h:1581
struct client * c
Definition: tmux.h:1571
struct window_pane * pane
Definition: tmux.h:1595
u_int window
Definition: tmux.h:1594
Definition: tmux.h:1608
struct client_files files
Definition: tmux.h:1760
char ** term_caps
Definition: tmux.h:1636
int message_ignore_keys
Definition: tmux.h:1718
struct event overlay_timer
Definition: tmux.h:1758
int retval
Definition: tmux.h:1622
char * term_name
Definition: tmux.h:1633
struct client_windows windows
Definition: tmux.h:1613
struct tty tty
Definition: tmux.h:1640
uint64_t redraw_panes
Definition: tmux.h:1716
enum msgtype exit_msgtype
Definition: tmux.h:1710
char * ttyname
Definition: tmux.h:1639
struct utf8_data * prompt_saved
Definition: tmux.h:1732
char * term_type
Definition: tmux.h:1635
struct cmdq_list * queue
Definition: tmux.h:1611
void * overlay_data
Definition: tmux.h:1757
char * exit_session
Definition: tmux.h:1711
int references
Definition: tmux.h:1746
int out_fd
Definition: tmux.h:1620
struct timeval creation_time
Definition: tmux.h:1624
char * title
Definition: tmux.h:1630
overlay_check_cb overlay_check
Definition: tmux.h:1752
const char * cwd
Definition: tmux.h:1631
struct timeval activity_time
Definition: tmux.h:1625
char * exit_message
Definition: tmux.h:1712
struct event click_timer
Definition: tmux.h:1648
char * prompt_string
Definition: tmux.h:1723
const char * name
Definition: tmux.h:1609
struct session * session
Definition: tmux.h:1743
size_t redraw
Definition: tmux.h:1644
overlay_free_cb overlay_free
Definition: tmux.h:1756
int fd
Definition: tmux.h:1619
u_int term_ncaps
Definition: tmux.h:1637
u_int pause_age
Definition: tmux.h:1616
struct mouse_event click_event
Definition: tmux.h:1650
uint64_t flags
Definition: tmux.h:1703
struct event message_timer
Definition: tmux.h:1721
pid_t pid
Definition: tmux.h:1618
overlay_key_cb overlay_key
Definition: tmux.h:1755
struct key_table * keytable
Definition: tmux.h:1714
struct tmuxpeer * peer
Definition: tmux.h:1610
int term_features
Definition: tmux.h:1634
struct event repeat_timer
Definition: tmux.h:1646
overlay_mode_cb overlay_mode
Definition: tmux.h:1753
struct utf8_data * prompt_buffer
Definition: tmux.h:1724
u_int click_button
Definition: tmux.h:1649
enum client::@17 exit_type
overlay_draw_cb overlay_draw
Definition: tmux.h:1754
char * message_string
Definition: tmux.h:1720
struct environ * environ
Definition: tmux.h:1627
struct window_pane * wp
Definition: tmux.h:1454
struct session * s
Definition: tmux.h:1451
struct winlink * wl
Definition: tmux.h:1452
enum cmd_parse_status status
Definition: tmux.h:1489
char * error
Definition: tmux.h:1491
struct cmd_list * cmdlist
Definition: tmux.h:1490
Definition: cmd.c:212
Definition: tmux.h:1160
char * value
Definition: tmux.h:1162
int flags
Definition: tmux.h:1781
struct mouse_event m
Definition: tmux.h:1268
key_code key
Definition: tmux.h:1267
const char * name
Definition: tmux.h:1789
u_int references
Definition: tmux.h:1793
u_int y
Definition: tmux.h:1247
int valid
Definition: tmux.h:1238
u_int statuslines
Definition: tmux.h:1244
u_int lx
Definition: tmux.h:1250
int w
Definition: tmux.h:1258
u_int b
Definition: tmux.h:1248
u_int sgr_type
Definition: tmux.h:1261
int s
Definition: tmux.h:1257
u_int x
Definition: tmux.h:1246
int ignore
Definition: tmux.h:1239
u_int oy
Definition: tmux.h:1255
key_code key
Definition: tmux.h:1241
u_int ly
Definition: tmux.h:1251
int wp
Definition: tmux.h:1259
u_int lb
Definition: tmux.h:1252
u_int ox
Definition: tmux.h:1254
int statusat
Definition: tmux.h:1243
u_int sgr_b
Definition: tmux.h:1262
int argc
Definition: tmux.h:557
Definition: tmux.h:816
u_int cy
Definition: tmux.h:824
int mode
Definition: tmux.h:832
u_int cx
Definition: tmux.h:823
Definition: tmux.h:1179
char * name
Definition: tmux.h:1182
u_int id
Definition: tmux.h:1180
struct winlinks windows
Definition: tmux.h:1194
struct timeval activity_time
Definition: tmux.h:1187
struct timeval last_activity_time
Definition: tmux.h:1188
struct winlink * curw
Definition: tmux.h:1192
const char * cwd
Definition: tmux.h:1183
struct options * options
Definition: tmux.h:1199
u_int attached
Definition: tmux.h:1205
int flags
Definition: tmux.h:1203
u_int argument
Definition: tmux.h:782
enum style_range_type type
Definition: tmux.h:781
Definition: tmux.h:1304
u_int sx
Definition: tmux.h:1308
void(* mouse_drag_release)(struct client *, struct mouse_event *)
Definition: tmux.h:1365
int mouse_drag_flag
Definition: tmux.h:1362
u_int sy
Definition: tmux.h:1309
int mode
Definition: tmux.h:1324
int flags
Definition: tmux.h:1355
void(* mouse_drag_update)(struct client *, struct mouse_event *)
Definition: tmux.h:1363
struct evbuffer * out
Definition: tmux.h:1335
Definition: tmux.h:927
const struct window_mode * mode
Definition: tmux.h:931
struct window_pane * wp
Definition: tmux.h:928
void(* update)(struct window_mode_entry *)
Definition: tmux.h:913
const char *(* key_table)(struct window_mode_entry *)
Definition: tmux.h:918
size_t used
Definition: tmux.h:942
struct screen * screen
Definition: tmux.h:1020
struct event resize_timer
Definition: tmux.h:1008
u_int xoff
Definition: tmux.h:971
struct window_pane_offset pipe_offset
Definition: tmux.h:1018
int fd
Definition: tmux.h:1001
struct window_pane_resizes resize_queue
Definition: tmux.h:1007
char tty[32]
Definition: tmux.h:998
struct window_pane_offset offset
Definition: tmux.h:1004
u_int yoff
Definition: tmux.h:972
int flags
Definition: tmux.h:977
int pipe_fd
Definition: tmux.h:1016
struct screen base
Definition: tmux.h:1021
u_int sy
Definition: tmux.h:969
struct bufferevent * event
Definition: tmux.h:1002
struct window * window
Definition: tmux.h:962
u_int sx
Definition: tmux.h:968
size_t base_offset
Definition: tmux.h:1005
u_int id
Definition: tmux.h:959
Definition: tmux.h:1041
u_int id
Definition: tmux.h:1042
int flags
Definition: tmux.h:1073
u_int new_sx
Definition: tmux.h:1068
struct options * options
Definition: tmux.h:1085
u_int new_xpixel
Definition: tmux.h:1070
void * latest
Definition: tmux.h:1043
u_int new_sy
Definition: tmux.h:1069
struct window_panes panes
Definition: tmux.h:1056
u_int new_ypixel
Definition: tmux.h:1071
struct window_pane * active
Definition: tmux.h:1054
const char * find_home(void)
Definition: tmux.c:299
int checkshell(const char *shell)
Definition: tmux.c:80
struct options * global_s_options
Definition: tmux.c:37
void setblocking(int fd, int state)
Definition: tmux.c:233
struct options * global_options
Definition: tmux.c:36
#define WINDOW_SIZE_LATEST
Definition: tmux.h:1117
#define CLIENT_DOUBLECLICK
Definition: tmux.h:1674
void tty_free(struct tty *)
Definition: tty.c:445
#define KEYC_UNKNOWN
Definition: tmux.h:114
#define MOUSE_MASK_CTRL
Definition: tmux.h:1222
#define CLIENT_TRIPLECLICK
Definition: tmux.h:1675
void(* overlay_draw_cb)(struct client *, struct screen_redraw_ctx *)
Definition: tmux.h:1605
#define cmdq_get_callback(cb, data)
Definition: tmux.h:2364
#define KEYC_IS_MOUSE(key)
Definition: tmux.h:144
#define CLIENT_UTF8
Definition: tmux.h:1670
#define WINDOW_ZOOMED
Definition: tmux.h:1077
const char * tty_get_features(int)
Definition: tty-features.c:290
#define CLIENT_CONTROL_PAUSEAFTER
Definition: tmux.h:1686
#define SESSION_PASTING
Definition: tmux.h:1201
#define KEYC_META
Definition: tmux.h:124
#define MOUSE_RELEASE(b)
Definition: tmux.h:1234
#define KEYC_SHIFT
Definition: tmux.h:126
cmd_retval
Definition: tmux.h:1475
@ CMD_RETURN_NORMAL
Definition: tmux.h:1477
int(* overlay_key_cb)(struct client *, struct key_event *)
Definition: tmux.h:1606
#define CLIENT_EXITED
Definition: tmux.h:1662
void * window_pane_get_new_data(struct window_pane *, struct window_pane_offset *, size_t *)
Definition: window.c:1571
int window_pane_key(struct window_pane *, struct client *, struct session *, struct winlink *, key_code, struct mouse_event *)
Definition: window.c:1158
#define KEYC_CTRL
Definition: tmux.h:125
void tty_margin_off(struct tty *)
Definition: tty.c:2048
void tty_reset(struct tty *)
Definition: tty.c:1963
void tty_region_off(struct tty *)
Definition: tty.c:2003
struct window_pane * window_get_active_at(struct window *, u_int, u_int)
Definition: window.c:525
#define MOUSE_WHEEL_UP
Definition: tmux.h:1227
#define KEYC_CLICK_TIMEOUT
Definition: tmux.h:155
msgtype
Definition: tmux.h:505
@ MSG_IDENTIFY_TERMINFO
Definition: tmux.h:520
@ MSG_READ
Definition: tmux.h:543
@ MSG_RESIZE
Definition: tmux.h:530
@ MSG_IDENTIFY_FEATURES
Definition: tmux.h:517
@ MSG_IDENTIFY_CLIENTPID
Definition: tmux.h:515
@ MSG_EXIT
Definition: tmux.h:525
@ MSG_IDENTIFY_STDIN
Definition: tmux.h:512
@ MSG_IDENTIFY_STDOUT
Definition: tmux.h:518
@ MSG_SUSPEND
Definition: tmux.h:536
@ MSG_IDENTIFY_LONGFLAGS
Definition: tmux.h:519
@ MSG_SHUTDOWN
Definition: tmux.h:532
@ MSG_IDENTIFY_DONE
Definition: tmux.h:514
@ MSG_WAKEUP
Definition: tmux.h:538
@ MSG_UNLOCK
Definition: tmux.h:537
@ MSG_EXITING
Definition: tmux.h:527
@ MSG_COMMAND
Definition: tmux.h:522
@ MSG_EXITED
Definition: tmux.h:526
@ MSG_SHELL
Definition: tmux.h:531
@ MSG_IDENTIFY_TERM
Definition: tmux.h:509
@ MSG_IDENTIFY_FLAGS
Definition: tmux.h:508
@ MSG_EXEC
Definition: tmux.h:539
@ MSG_IDENTIFY_TTYNAME
Definition: tmux.h:510
@ MSG_IDENTIFY_CWD
Definition: tmux.h:516
@ MSG_IDENTIFY_ENVIRON
Definition: tmux.h:513
@ MSG_FLAGS
Definition: tmux.h:540
@ MSG_READ_DONE
Definition: tmux.h:544
@ MSG_WRITE_READY
Definition: tmux.h:547
void tty_term_free_list(char **, u_int)
Definition: tty-term.c:736
#define CLIENT_REDRAWOVERLAY
Definition: tmux.h:1679
void tty_stop_tty(struct tty *)
Definition: tty.c:362
unsigned long long key_code
Definition: tmux.h:177
#define TTY_BLOCK
Definition: tmux.h:1351
@ CMD_PARSE_ERROR
Definition: tmux.h:1485
@ CMD_PARSE_EMPTY
Definition: tmux.h:1484
@ CMD_PARSE_SUCCESS
Definition: tmux.h:1486
#define KEY_BINDING_REPEAT
Definition: tmux.h:1782
int(* overlay_check_cb)(struct client *, u_int, u_int)
Definition: tmux.h:1603
#define CLIENT_REPEAT
Definition: tmux.h:1659
#define CLIENT_FOCUSED
Definition: tmux.h:1669
#define PANE_FOCUSED
Definition: tmux.h:980
#define CLIENT_CONTROL_WAITEXIT
Definition: tmux.h:1687
void tty_update_mode(struct tty *, int, struct screen *)
Definition: tty.c:658
void tty_resize(struct tty *)
Definition: tty.c:110
#define FORMAT_NONE
Definition: tmux.h:1973
#define CLIENT_READONLY
Definition: tmux.h:1665
#define CLIENT_UNATTACHEDFLAGS
Definition: tmux.h:1695
void tty_send_requests(struct tty *)
Definition: tty.c:347
#define CLIENT_ATTACHED
Definition: tmux.h:1661
int tty_init(struct tty *, struct client *)
Definition: tty.c:93
#define CLIENT_CONTROL
Definition: tmux.h:1667
#define TTY_NOCURSOR
Definition: tmux.h:1344
void window_pane_send_resize(struct window_pane *, u_int, u_int)
Definition: window.c:428
#define CLIENT_STATUSFORCE
Definition: tmux.h:1673
#define PANE_REDRAW
Definition: tmux.h:978
#define MOUSE_DRAG(b)
Definition: tmux.h:1233
#define MODE_MOUSE_ALL
Definition: tmux.h:610
#define CLIENT_ALLREDRAWFLAGS
Definition: tmux.h:1688
#define CLIENT_REDRAWWINDOW
Definition: tmux.h:1657
#define WINDOW_RESIZE
Definition: tmux.h:1079
#define CLIENT_REDRAWSTATUS
Definition: tmux.h:1658
#define CLIENT_CONTROL_NOOUTPUT
Definition: tmux.h:1680
void tty_set_title(struct tty *, const char *)
Definition: tty.c:635
struct screen *(* overlay_mode_cb)(struct client *, u_int *, u_int *)
Definition: tmux.h:1604
struct windows windows
Definition: window.c:56
#define PANE_FOCUSPUSH
Definition: tmux.h:983
@ KEYC_SECONDCLICK2_PANE
Definition: tmux.h:212
@ KEYC_MOUSEDRAG2_STATUS
Definition: tmux.h:204
@ KEYC_MOUSEDRAGEND1_STATUS_LEFT
Definition: tmux.h:206
@ KEYC_MOUSEDOWN2_STATUS_RIGHT
Definition: tmux.h:198
@ KEYC_MOUSEDRAGEND1_BORDER
Definition: tmux.h:206
@ KEYC_DOUBLECLICK1_PANE
Definition: tmux.h:214
@ KEYC_SECONDCLICK1_PANE
Definition: tmux.h:211
@ KEYC_SECONDCLICK2_BORDER
Definition: tmux.h:212
@ KEYC_TRIPLECLICK3_STATUS_LEFT
Definition: tmux.h:219
@ KEYC_MOUSEDRAGEND2_BORDER
Definition: tmux.h:207
@ KEYC_MOUSEUP1_STATUS_DEFAULT
Definition: tmux.h:200
@ KEYC_MOUSEDRAGEND3_STATUS_RIGHT
Definition: tmux.h:208
@ KEYC_DOUBLECLICK3_STATUS_LEFT
Definition: tmux.h:216
@ KEYC_DOUBLECLICK2_STATUS_LEFT
Definition: tmux.h:215
@ KEYC_MOUSEDRAGEND1_STATUS_DEFAULT
Definition: tmux.h:206
@ KEYC_DOUBLECLICK1_STATUS_LEFT
Definition: tmux.h:214
@ KEYC_MOUSEDRAGEND3_STATUS
Definition: tmux.h:208
@ KEYC_MOUSEDRAGEND1_PANE
Definition: tmux.h:206
@ KEYC_MOUSEDOWN2_STATUS
Definition: tmux.h:198
@ KEYC_MOUSEMOVE_BORDER
Definition: tmux.h:196
@ KEYC_MOUSEDRAGEND2_STATUS_RIGHT
Definition: tmux.h:207
@ KEYC_SECONDCLICK3_STATUS
Definition: tmux.h:213
@ KEYC_SECONDCLICK1_STATUS_LEFT
Definition: tmux.h:211
@ KEYC_MOUSEDOWN3_STATUS_DEFAULT
Definition: tmux.h:199
@ KEYC_DOUBLECLICK1_STATUS
Definition: tmux.h:214
@ KEYC_MOUSEMOVE_STATUS_RIGHT
Definition: tmux.h:196
@ KEYC_MOUSEUP1_PANE
Definition: tmux.h:200
@ KEYC_MOUSEMOVE_STATUS
Definition: tmux.h:196
@ KEYC_ANY
Definition: tmux.h:186
@ KEYC_MOUSEUP2_STATUS_DEFAULT
Definition: tmux.h:201
@ KEYC_MOUSEDRAG3_BORDER
Definition: tmux.h:205
@ KEYC_MOUSE
Definition: tmux.h:193
@ KEYC_DOUBLECLICK
Definition: tmux.h:195
@ KEYC_TRIPLECLICK2_BORDER
Definition: tmux.h:218
@ KEYC_DOUBLECLICK1_STATUS_RIGHT
Definition: tmux.h:214
@ KEYC_WHEELDOWN_STATUS_DEFAULT
Definition: tmux.h:210
@ KEYC_MOUSEUP2_STATUS_RIGHT
Definition: tmux.h:201
@ KEYC_TRIPLECLICK3_PANE
Definition: tmux.h:219
@ KEYC_MOUSEDOWN3_STATUS_RIGHT
Definition: tmux.h:199
@ KEYC_MOUSEDRAGEND1_STATUS
Definition: tmux.h:206
@ KEYC_MOUSEDRAG2_STATUS_DEFAULT
Definition: tmux.h:204
@ KEYC_MOUSEMOVE_STATUS_DEFAULT
Definition: tmux.h:196
@ KEYC_MOUSEDRAGEND3_PANE
Definition: tmux.h:208
@ KEYC_TRIPLECLICK2_STATUS_LEFT
Definition: tmux.h:218
@ KEYC_DOUBLECLICK2_BORDER
Definition: tmux.h:215
@ KEYC_WHEELUP_STATUS_DEFAULT
Definition: tmux.h:209
@ KEYC_DOUBLECLICK3_STATUS_DEFAULT
Definition: tmux.h:216
@ KEYC_SECONDCLICK2_STATUS_DEFAULT
Definition: tmux.h:212
@ KEYC_MOUSEDRAGEND2_STATUS_DEFAULT
Definition: tmux.h:207
@ KEYC_MOUSEDOWN3_PANE
Definition: tmux.h:199
@ KEYC_MOUSEUP2_STATUS_LEFT
Definition: tmux.h:201
@ KEYC_MOUSEDOWN1_BORDER
Definition: tmux.h:197
@ KEYC_TRIPLECLICK1_STATUS
Definition: tmux.h:217
@ KEYC_MOUSEUP3_STATUS_DEFAULT
Definition: tmux.h:202
@ KEYC_WHEELUP_STATUS_LEFT
Definition: tmux.h:209
@ KEYC_DOUBLECLICK3_PANE
Definition: tmux.h:216
@ KEYC_TRIPLECLICK3_BORDER
Definition: tmux.h:219
@ KEYC_MOUSEDRAGEND2_PANE
Definition: tmux.h:207
@ KEYC_SECONDCLICK3_STATUS_DEFAULT
Definition: tmux.h:213
@ KEYC_MOUSEDRAG3_PANE
Definition: tmux.h:205
@ KEYC_SECONDCLICK1_BORDER
Definition: tmux.h:211
@ KEYC_MOUSEDOWN2_STATUS_LEFT
Definition: tmux.h:198
@ KEYC_MOUSEDOWN1_STATUS_DEFAULT
Definition: tmux.h:197
@ KEYC_MOUSEUP2_BORDER
Definition: tmux.h:201
@ KEYC_MOUSEUP1_BORDER
Definition: tmux.h:200
@ KEYC_WHEELUP_BORDER
Definition: tmux.h:209
@ KEYC_MOUSEUP2_PANE
Definition: tmux.h:201
@ KEYC_MOUSEUP2_STATUS
Definition: tmux.h:201
@ KEYC_WHEELDOWN_STATUS
Definition: tmux.h:210
@ KEYC_DOUBLECLICK3_BORDER
Definition: tmux.h:216
@ KEYC_MOUSEUP3_PANE
Definition: tmux.h:202
@ KEYC_MOUSEDRAG2_PANE
Definition: tmux.h:204
@ KEYC_MOUSEDRAG3_STATUS_LEFT
Definition: tmux.h:205
@ KEYC_SECONDCLICK2_STATUS_LEFT
Definition: tmux.h:212
@ KEYC_MOUSEDRAG1_STATUS
Definition: tmux.h:203
@ KEYC_SECONDCLICK2_STATUS
Definition: tmux.h:212
@ KEYC_DOUBLECLICK1_STATUS_DEFAULT
Definition: tmux.h:214
@ KEYC_MOUSEDRAG2_STATUS_LEFT
Definition: tmux.h:204
@ KEYC_TRIPLECLICK3_STATUS_DEFAULT
Definition: tmux.h:219
@ KEYC_SECONDCLICK1_STATUS_DEFAULT
Definition: tmux.h:211
@ KEYC_DOUBLECLICK2_STATUS_DEFAULT
Definition: tmux.h:215
@ KEYC_MOUSEDOWN2_STATUS_DEFAULT
Definition: tmux.h:198
@ KEYC_TRIPLECLICK1_STATUS_DEFAULT
Definition: tmux.h:217
@ KEYC_TRIPLECLICK2_STATUS_RIGHT
Definition: tmux.h:218
@ KEYC_TRIPLECLICK2_STATUS_DEFAULT
Definition: tmux.h:218
@ KEYC_MOUSEUP1_STATUS
Definition: tmux.h:200
@ KEYC_FOCUS_OUT
Definition: tmux.h:183
@ KEYC_WHEELUP_STATUS_RIGHT
Definition: tmux.h:209
@ KEYC_WHEELDOWN_STATUS_RIGHT
Definition: tmux.h:210
@ KEYC_MOUSEDRAG1_STATUS_DEFAULT
Definition: tmux.h:203
@ KEYC_MOUSEDRAGEND1_STATUS_RIGHT
Definition: tmux.h:206
@ KEYC_WHEELDOWN_PANE
Definition: tmux.h:210
@ KEYC_WHEELDOWN_STATUS_LEFT
Definition: tmux.h:210
@ KEYC_MOUSEDRAGEND3_STATUS_LEFT
Definition: tmux.h:208
@ KEYC_TRIPLECLICK3_STATUS
Definition: tmux.h:219
@ KEYC_TRIPLECLICK1_BORDER
Definition: tmux.h:217
@ KEYC_WHEELUP_STATUS
Definition: tmux.h:209
@ KEYC_MOUSEUP3_STATUS_LEFT
Definition: tmux.h:202
@ KEYC_MOUSEDRAGEND2_STATUS_LEFT
Definition: tmux.h:207
@ KEYC_MOUSEDRAG3_STATUS
Definition: tmux.h:205
@ KEYC_MOUSEDRAG1_STATUS_LEFT
Definition: tmux.h:203
@ KEYC_DOUBLECLICK1_BORDER
Definition: tmux.h:214
@ KEYC_MOUSEDOWN3_STATUS
Definition: tmux.h:199
@ KEYC_MOUSEDOWN1_PANE
Definition: tmux.h:197
@ KEYC_WHEELUP_PANE
Definition: tmux.h:209
@ KEYC_MOUSEDOWN3_BORDER
Definition: tmux.h:199
@ KEYC_WHEELDOWN_BORDER
Definition: tmux.h:210
@ KEYC_MOUSEDRAG2_BORDER
Definition: tmux.h:204
@ KEYC_SECONDCLICK3_STATUS_LEFT
Definition: tmux.h:213
@ KEYC_SECONDCLICK1_STATUS_RIGHT
Definition: tmux.h:211
@ KEYC_MOUSEUP1_STATUS_LEFT
Definition: tmux.h:200
@ KEYC_SECONDCLICK3_BORDER
Definition: tmux.h:213
@ KEYC_TRIPLECLICK2_PANE
Definition: tmux.h:218
@ KEYC_MOUSEDRAG3_STATUS_DEFAULT
Definition: tmux.h:205
@ KEYC_TRIPLECLICK2_STATUS
Definition: tmux.h:218
@ KEYC_SECONDCLICK2_STATUS_RIGHT
Definition: tmux.h:212
@ KEYC_DOUBLECLICK3_STATUS
Definition: tmux.h:216
@ KEYC_MOUSEDRAG1_BORDER
Definition: tmux.h:203
@ KEYC_MOUSEDOWN3_STATUS_LEFT
Definition: tmux.h:199
@ KEYC_MOUSEDOWN2_PANE
Definition: tmux.h:198
@ KEYC_MOUSEDRAGEND2_STATUS
Definition: tmux.h:207
@ KEYC_MOUSEUP3_STATUS_RIGHT
Definition: tmux.h:202
@ KEYC_MOUSEDRAGEND3_STATUS_DEFAULT
Definition: tmux.h:208
@ KEYC_SECONDCLICK3_STATUS_RIGHT
Definition: tmux.h:213
@ KEYC_SECONDCLICK3_PANE
Definition: tmux.h:213
@ KEYC_MOUSEUP3_BORDER
Definition: tmux.h:202
@ KEYC_DRAGGING
Definition: tmux.h:194
@ KEYC_TRIPLECLICK3_STATUS_RIGHT
Definition: tmux.h:219
@ KEYC_MOUSEDRAG1_STATUS_RIGHT
Definition: tmux.h:203
@ KEYC_DOUBLECLICK3_STATUS_RIGHT
Definition: tmux.h:216
@ KEYC_MOUSEDOWN1_STATUS
Definition: tmux.h:197
@ KEYC_DOUBLECLICK2_PANE
Definition: tmux.h:215
@ KEYC_MOUSEMOVE_STATUS_LEFT
Definition: tmux.h:196
@ KEYC_MOUSEDRAGEND3_BORDER
Definition: tmux.h:208
@ KEYC_MOUSEDRAG2_STATUS_RIGHT
Definition: tmux.h:204
@ KEYC_TRIPLECLICK1_STATUS_LEFT
Definition: tmux.h:217
@ KEYC_MOUSEDOWN1_STATUS_RIGHT
Definition: tmux.h:197
@ KEYC_MOUSEDRAG3_STATUS_RIGHT
Definition: tmux.h:205
@ KEYC_TRIPLECLICK1_PANE
Definition: tmux.h:217
@ KEYC_MOUSEDOWN1_STATUS_LEFT
Definition: tmux.h:197
@ KEYC_MOUSEMOVE_PANE
Definition: tmux.h:196
@ KEYC_DOUBLECLICK2_STATUS
Definition: tmux.h:215
@ KEYC_DOUBLECLICK2_STATUS_RIGHT
Definition: tmux.h:215
@ KEYC_MOUSEDRAG1_PANE
Definition: tmux.h:203
@ KEYC_MOUSEUP1_STATUS_RIGHT
Definition: tmux.h:200
@ KEYC_MOUSEUP3_STATUS
Definition: tmux.h:202
@ KEYC_MOUSEDOWN2_BORDER
Definition: tmux.h:198
@ KEYC_SECONDCLICK1_STATUS
Definition: tmux.h:211
@ KEYC_TRIPLECLICK1_STATUS_RIGHT
Definition: tmux.h:217
#define CLIENT_REDRAWBORDERS
Definition: tmux.h:1664
int tty_open(struct tty *, char **)
Definition: tty.c:248
#define MODE_MOUSE_BUTTON
Definition: tmux.h:604
void tty_cursor(struct tty *, u_int, u_int)
Definition: tty.c:2111
#define CLIENT_IDENTIFIED
Definition: tmux.h:1672
#define KEYC_MASK_MODIFIERS
Definition: tmux.h:136
#define CLIENT_DEAD
Definition: tmux.h:1663
#define TTY_FREEZE
Definition: tmux.h:1345
#define CLIENT_ACTIVEPANE
Definition: tmux.h:1685
#define MOUSE_MASK_META
Definition: tmux.h:1221
#define CLIENT_IGNORESIZE
Definition: tmux.h:1671
struct winlink * winlink_find_by_index(struct winlinks *, int)
Definition: window.c:109
void tty_sync_end(struct tty *)
Definition: tty.c:1453
#define CLIENT_SUSPENDED
Definition: tmux.h:1660
#define MOUSE_WHEEL(b)
Definition: tmux.h:1232
#define MOUSE_MASK_SHIFT
Definition: tmux.h:1220
void tty_close(struct tty *)
Definition: tty.c:425
@ STYLE_RANGE_NONE
Definition: tmux.h:775
@ STYLE_RANGE_LEFT
Definition: tmux.h:776
@ STYLE_RANGE_WINDOW
Definition: tmux.h:778
@ STYLE_RANGE_RIGHT
Definition: tmux.h:777
#define MOUSE_BUTTONS(b)
Definition: tmux.h:1231
#define CLIENT_TERMINAL
Definition: tmux.h:1654
struct window_pane_tree all_window_panes
Definition: window.c:59
#define CLIENT_EXIT
Definition: tmux.h:1656
#define KEYC_MASK_KEY
Definition: tmux.h:138
#define CLIENT_REDRAWPANES
Definition: tmux.h:1683
#define MODE_FOCUSON
Definition: tmux.h:609
int tty_window_offset(struct tty *, u_int *, u_int *, u_int *, u_int *)
Definition: tty.c:780
void tty_start_tty(struct tty *)
Definition: tty.c:295
void(* overlay_free_cb)(struct client *)
Definition: tmux.h:1607
void * xmalloc(size_t size)
Definition: xmalloc.c:27
int xsnprintf(char *str, size_t len, const char *fmt,...)
Definition: xmalloc.c:135
void * xreallocarray(void *ptr, size_t nmemb, size_t size)
Definition: xmalloc.c:61
int xasprintf(char **ret, const char *fmt,...)
Definition: xmalloc.c:109
void * xcalloc(size_t nmemb, size_t size)
Definition: xmalloc.c:41
char * xstrdup(const char *str)
Definition: xmalloc.c:89