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)  

window-tree.c
Go to the documentation of this file.
1 /* $OpenBSD$ */
2 
3 /*
4  * Copyright (c) 2017 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 
21 #include <ctype.h>
22 #include <stdlib.h>
23 #include <string.h>
24 
25 #include "tmux.h"
26 
27 static struct screen *window_tree_init(struct window_mode_entry *,
28  struct cmd_find_state *, struct args *);
29 static void window_tree_free(struct window_mode_entry *);
30 static void window_tree_resize(struct window_mode_entry *, u_int,
31  u_int);
32 static void window_tree_update(struct window_mode_entry *);
33 static void window_tree_key(struct window_mode_entry *,
34  struct client *, struct session *,
35  struct winlink *, key_code, struct mouse_event *);
36 
37 #define WINDOW_TREE_DEFAULT_COMMAND "switch-client -Zt '%%'"
38 
39 #define WINDOW_TREE_DEFAULT_FORMAT \
40  "#{?pane_format," \
41  "#{?pane_marked,#[reverse],}" \
42  "#{pane_current_command}#{?pane_active,*,}#{?pane_marked,M,}" \
43  "#{?#{&&:#{pane_title},#{!=:#{pane_title},#{host_short}}},: \"#{pane_title}\",}" \
44  "," \
45  "#{?window_format," \
46  "#{?window_marked_flag,#[reverse],}" \
47  "#{window_name}#{window_flags}" \
48  "#{?#{&&:#{==:#{window_panes},1},#{&&:#{pane_title},#{!=:#{pane_title},#{host_short}}}},: \"#{pane_title}\",}" \
49  "," \
50  "#{session_windows} windows" \
51  "#{?session_grouped, " \
52  "(group #{session_group}: " \
53  "#{session_group_list})," \
54  "}" \
55  "#{?session_attached, (attached),}" \
56  "}" \
57  "}"
58 
59 #define WINDOW_TREE_DEFAULT_KEY_FORMAT \
60  "#{?#{e|<:#{line},10}," \
61  "#{line}" \
62  "," \
63  "#{?#{e|<:#{line},36}," \
64  "M-#{a:#{e|+:97,#{e|-:#{line},10}}}" \
65  "," \
66  "" \
67  "}" \
68  "}"
69 
70 static const struct menu_item window_tree_menu_items[] = {
71  { "Select", '\r', NULL },
72  { "Expand", KEYC_RIGHT, NULL },
73  { "Mark", 'm', NULL },
74  { "", KEYC_NONE, NULL },
75  { "Tag", 't', NULL },
76  { "Tag All", '\024', NULL },
77  { "Tag None", 'T', NULL },
78  { "", KEYC_NONE, NULL },
79  { "Kill", 'x', NULL },
80  { "Kill Tagged", 'X', NULL },
81  { "", KEYC_NONE, NULL },
82  { "Cancel", 'q', NULL },
83 
84  { NULL, KEYC_NONE, NULL }
85 };
86 
87 const struct window_mode window_tree_mode = {
88  .name = "tree-mode",
89  .default_format = WINDOW_TREE_DEFAULT_FORMAT,
90 
91  .init = window_tree_init,
92  .free = window_tree_free,
93  .resize = window_tree_resize,
94  .update = window_tree_update,
95  .key = window_tree_key,
96 };
97 
102 };
103 static const char *window_tree_sort_list[] = {
104  "index",
105  "name",
106  "time"
107 };
109 
115 };
116 
118  enum window_tree_type type;
119  int session;
120  int winlink;
121  int pane;
122 };
123 
125  struct window_pane *wp;
126  int dead;
128 
130  char *format;
131  char *key_format;
132  char *command;
134 
136  u_int item_size;
137 
138  const char *entered;
139 
140  struct cmd_find_state fs;
141  enum window_tree_type type;
142 
143  int offset;
144 
145  int left;
146  int right;
147  u_int start;
148  u_int end;
149  u_int each;
150 };
151 
152 static void
154  struct winlink **wlp, struct window_pane **wp)
155 {
156  *wp = NULL;
157  *wlp = NULL;
158  *sp = session_find_by_id(item->session);
159  if (*sp == NULL)
160  return;
161  if (item->type == WINDOW_TREE_SESSION) {
162  *wlp = (*sp)->curw;
163  *wp = (*wlp)->window->active;
164  return;
165  }
166 
167  *wlp = winlink_find_by_index(&(*sp)->windows, item->winlink);
168  if (*wlp == NULL) {
169  *sp = NULL;
170  return;
171  }
172  if (item->type == WINDOW_TREE_WINDOW) {
173  *wp = (*wlp)->window->active;
174  return;
175  }
176 
177  *wp = window_pane_find_by_id(item->pane);
178  if (!window_has_pane((*wlp)->window, *wp))
179  *wp = NULL;
180  if (*wp == NULL) {
181  *sp = NULL;
182  *wlp = NULL;
183  return;
184  }
185 }
186 
187 static struct window_tree_itemdata *
189 {
190  struct window_tree_itemdata *item;
191 
192  data->item_list = xreallocarray(data->item_list, data->item_size + 1,
193  sizeof *data->item_list);
194  item = data->item_list[data->item_size++] = xcalloc(1, sizeof *item);
195  return (item);
196 }
197 
198 static void
200 {
201  free(item);
202 }
203 
204 static int
205 window_tree_cmp_session(const void *a0, const void *b0)
206 {
207  const struct session *const *a = a0;
208  const struct session *const *b = b0;
209  const struct session *sa = *a;
210  const struct session *sb = *b;
211  int result = 0;
212 
213  switch (window_tree_sort->field) {
215  result = sa->id - sb->id;
216  break;
217  case WINDOW_TREE_BY_TIME:
218  if (timercmp(&sa->activity_time, &sb->activity_time, >)) {
219  result = -1;
220  break;
221  }
222  if (timercmp(&sa->activity_time, &sb->activity_time, <)) {
223  result = 1;
224  break;
225  }
226  /* FALLTHROUGH */
227  case WINDOW_TREE_BY_NAME:
228  result = strcmp(sa->name, sb->name);
229  break;
230  }
231 
233  result = -result;
234  return (result);
235 }
236 
237 static int
238 window_tree_cmp_window(const void *a0, const void *b0)
239 {
240  const struct winlink *const *a = a0;
241  const struct winlink *const *b = b0;
242  const struct winlink *wla = *a;
243  const struct winlink *wlb = *b;
244  struct window *wa = wla->window;
245  struct window *wb = wlb->window;
246  int result = 0;
247 
248  switch (window_tree_sort->field) {
250  result = wla->idx - wlb->idx;
251  break;
252  case WINDOW_TREE_BY_TIME:
253  if (timercmp(&wa->activity_time, &wb->activity_time, >)) {
254  result = -1;
255  break;
256  }
257  if (timercmp(&wa->activity_time, &wb->activity_time, <)) {
258  result = 1;
259  break;
260  }
261  /* FALLTHROUGH */
262  case WINDOW_TREE_BY_NAME:
263  result = strcmp(wa->name, wb->name);
264  break;
265  }
266 
268  result = -result;
269  return (result);
270 }
271 
272 static int
273 window_tree_cmp_pane(const void *a0, const void *b0)
274 {
275  const struct window_pane *const *a = a0;
276  const struct window_pane *const *b = b0;
277  int result;
278 
280  result = (*a)->active_point - (*b)->active_point;
281  else {
282  /*
283  * Panes don't have names, so use number order for any other
284  * sort field.
285  */
286  result = (*a)->id - (*b)->id;
287  }
289  result = -result;
290  return (result);
291 }
292 
293 static void
294 window_tree_build_pane(struct session *s, struct winlink *wl,
295  struct window_pane *wp, void *modedata, struct mode_tree_item *parent)
296 {
297  struct window_tree_modedata *data = modedata;
298  struct window_tree_itemdata *item;
299  char *name, *text;
300  u_int idx;
301 
302  window_pane_index(wp, &idx);
303 
304  item = window_tree_add_item(data);
305  item->type = WINDOW_TREE_PANE;
306  item->session = s->id;
307  item->winlink = wl->idx;
308  item->pane = wp->id;
309 
310  text = format_single(NULL, data->format, NULL, s, wl, wp);
311  xasprintf(&name, "%u", idx);
312 
313  mode_tree_add(data->data, parent, item, (uint64_t)wp, name, text, -1);
314  free(text);
315  free(name);
316 }
317 
318 static int
320  struct window_pane *wp, const char *filter)
321 {
322  char *cp;
323  int result;
324 
325  if (filter == NULL)
326  return (1);
327 
328  cp = format_single(NULL, filter, NULL, s, wl, wp);
329  result = format_true(cp);
330  free(cp);
331 
332  return (result);
333 }
334 
335 static int
337  void *modedata, struct mode_tree_sort_criteria *sort_crit,
338  struct mode_tree_item *parent, const char *filter)
339 {
340  struct window_tree_modedata *data = modedata;
341  struct window_tree_itemdata *item;
342  struct mode_tree_item *mti;
343  char *name, *text;
344  struct window_pane *wp, **l;
345  u_int n, i;
346  int expanded;
347 
348  item = window_tree_add_item(data);
349  item->type = WINDOW_TREE_WINDOW;
350  item->session = s->id;
351  item->winlink = wl->idx;
352  item->pane = -1;
353 
354  text = format_single(NULL, data->format, NULL, s, wl, NULL);
355  xasprintf(&name, "%u", wl->idx);
356 
357  if (data->type == WINDOW_TREE_SESSION ||
358  data->type == WINDOW_TREE_WINDOW)
359  expanded = 0;
360  else
361  expanded = 1;
362  mti = mode_tree_add(data->data, parent, item, (uint64_t)wl, name, text,
363  expanded);
364  free(text);
365  free(name);
366 
367  if ((wp = TAILQ_FIRST(&wl->window->panes)) == NULL)
368  goto empty;
369  if (TAILQ_NEXT(wp, entry) == NULL) {
370  if (!window_tree_filter_pane(s, wl, wp, filter))
371  goto empty;
372  return (1);
373  }
374 
375  l = NULL;
376  n = 0;
377 
378  TAILQ_FOREACH(wp, &wl->window->panes, entry) {
379  if (!window_tree_filter_pane(s, wl, wp, filter))
380  continue;
381  l = xreallocarray(l, n + 1, sizeof *l);
382  l[n++] = wp;
383  }
384  if (n == 0)
385  goto empty;
386 
387  window_tree_sort = sort_crit;
388  qsort(l, n, sizeof *l, window_tree_cmp_pane);
389 
390  for (i = 0; i < n; i++)
391  window_tree_build_pane(s, wl, l[i], modedata, mti);
392  free(l);
393  return (1);
394 
395 empty:
396  window_tree_free_item(item);
397  data->item_size--;
398  mode_tree_remove(data->data, mti);
399  return (0);
400 }
401 
402 static void
403 window_tree_build_session(struct session *s, void *modedata,
404  struct mode_tree_sort_criteria *sort_crit, const char *filter)
405 {
406  struct window_tree_modedata *data = modedata;
407  struct window_tree_itemdata *item;
408  struct mode_tree_item *mti;
409  char *text;
410  struct winlink *wl, **l;
411  u_int n, i, empty;
412  int expanded;
413 
414  item = window_tree_add_item(data);
415  item->type = WINDOW_TREE_SESSION;
416  item->session = s->id;
417  item->winlink = -1;
418  item->pane = -1;
419 
420  text = format_single(NULL, data->format, NULL, s, NULL, NULL);
421 
422  if (data->type == WINDOW_TREE_SESSION)
423  expanded = 0;
424  else
425  expanded = 1;
426  mti = mode_tree_add(data->data, NULL, item, (uint64_t)s, s->name, text,
427  expanded);
428  free(text);
429 
430  l = NULL;
431  n = 0;
432  RB_FOREACH(wl, winlinks, &s->windows) {
433  l = xreallocarray(l, n + 1, sizeof *l);
434  l[n++] = wl;
435  }
436  window_tree_sort = sort_crit;
437  qsort(l, n, sizeof *l, window_tree_cmp_window);
438 
439  empty = 0;
440  for (i = 0; i < n; i++) {
441  if (!window_tree_build_window(s, l[i], modedata, sort_crit, mti,
442  filter))
443  empty++;
444  }
445  if (empty == n) {
446  window_tree_free_item(item);
447  data->item_size--;
448  mode_tree_remove(data->data, mti);
449  }
450  free(l);
451 }
452 
453 static void
454 window_tree_build(void *modedata, struct mode_tree_sort_criteria *sort_crit,
455  uint64_t *tag, const char *filter)
456 {
457  struct window_tree_modedata *data = modedata;
458  struct session *s, **l;
459  struct session_group *sg, *current;
460  u_int n, i;
461 
462  current = session_group_contains(data->fs.s);
463 
464  for (i = 0; i < data->item_size; i++)
466  free(data->item_list);
467  data->item_list = NULL;
468  data->item_size = 0;
469 
470  l = NULL;
471  n = 0;
472  RB_FOREACH(s, sessions, &sessions) {
473  if (data->squash_groups &&
474  (sg = session_group_contains(s)) != NULL) {
475  if ((sg == current && s != data->fs.s) ||
476  (sg != current && s != TAILQ_FIRST(&sg->sessions)))
477  continue;
478  }
479  l = xreallocarray(l, n + 1, sizeof *l);
480  l[n++] = s;
481  }
482  window_tree_sort = sort_crit;
483  qsort(l, n, sizeof *l, window_tree_cmp_session);
484 
485  for (i = 0; i < n; i++)
486  window_tree_build_session(l[i], modedata, sort_crit, filter);
487  free(l);
488 
489  switch (data->type) {
490  case WINDOW_TREE_NONE:
491  break;
492  case WINDOW_TREE_SESSION:
493  *tag = (uint64_t)data->fs.s;
494  break;
495  case WINDOW_TREE_WINDOW:
496  *tag = (uint64_t)data->fs.wl;
497  break;
498  case WINDOW_TREE_PANE:
499  if (window_count_panes(data->fs.wl->window) == 1)
500  *tag = (uint64_t)data->fs.wl;
501  else
502  *tag = (uint64_t)data->fs.wp;
503  break;
504  }
505 }
506 
507 static void
508 window_tree_draw_label(struct screen_write_ctx *ctx, u_int px, u_int py,
509  u_int sx, u_int sy, const struct grid_cell *gc, const char *label)
510 {
511  size_t len;
512  u_int ox, oy;
513 
514  len = strlen(label);
515  if (sx == 0 || sy == 1 || len > sx)
516  return;
517  ox = (sx - len + 1) / 2;
518  oy = (sy + 1) / 2;
519 
520  if (ox > 1 && ox + len < sx - 1 && sy >= 3) {
521  screen_write_cursormove(ctx, px + ox - 1, py + oy - 1, 0);
522  screen_write_box(ctx, len + 2, 3);
523  }
524  screen_write_cursormove(ctx, px + ox, py + oy, 0);
525  screen_write_puts(ctx, gc, "%s", label);
526 }
527 
528 static void
530  struct screen_write_ctx *ctx, u_int sx, u_int sy)
531 {
532  struct options *oo = s->options;
533  struct winlink *wl;
534  struct window *w;
535  u_int cx = ctx->s->cx, cy = ctx->s->cy;
536  u_int loop, total, visible, each, width, offset;
537  u_int current, start, end, remaining, i;
538  struct grid_cell gc;
539  int colour, active_colour, left, right;
540  char *label;
541 
542  total = winlink_count(&s->windows);
543 
544  memcpy(&gc, &grid_default_cell, sizeof gc);
545  colour = options_get_number(oo, "display-panes-colour");
546  active_colour = options_get_number(oo, "display-panes-active-colour");
547 
548  if (sx / total < 24) {
549  visible = sx / 24;
550  if (visible == 0)
551  visible = 1;
552  } else
553  visible = total;
554 
555  current = 0;
556  RB_FOREACH(wl, winlinks, &s->windows) {
557  if (wl == s->curw)
558  break;
559  current++;
560  }
561 
562  if (current < visible) {
563  start = 0;
564  end = visible;
565  } else if (current >= total - visible) {
566  start = total - visible;
567  end = total;
568  } else {
569  start = current - (visible / 2);
570  end = start + visible;
571  }
572 
573  if (data->offset < -(int)start)
574  data->offset = -(int)start;
575  if (data->offset > (int)(total - end))
576  data->offset = (int)(total - end);
577  start += data->offset;
578  end += data->offset;
579 
580  left = (start != 0);
581  right = (end != total);
582  if (((left && right) && sx <= 6) || ((left || right) && sx <= 3))
583  left = right = 0;
584  if (left && right) {
585  each = (sx - 6) / visible;
586  remaining = (sx - 6) - (visible * each);
587  } else if (left || right) {
588  each = (sx - 3) / visible;
589  remaining = (sx - 3) - (visible * each);
590  } else {
591  each = sx / visible;
592  remaining = sx - (visible * each);
593  }
594  if (each == 0)
595  return;
596 
597  if (left) {
598  data->left = cx + 2;
599  screen_write_cursormove(ctx, cx + 2, cy, 0);
600  screen_write_vline(ctx, sy, 0, 0);
601  screen_write_cursormove(ctx, cx, cy + sy / 2, 0);
603  } else
604  data->left = -1;
605  if (right) {
606  data->right = cx + sx - 3;
607  screen_write_cursormove(ctx, cx + sx - 3, cy, 0);
608  screen_write_vline(ctx, sy, 0, 0);
609  screen_write_cursormove(ctx, cx + sx - 1, cy + sy / 2, 0);
611  } else
612  data->right = -1;
613 
614  data->start = start;
615  data->end = end;
616  data->each = each;
617 
618  i = loop = 0;
619  RB_FOREACH(wl, winlinks, &s->windows) {
620  if (loop == end)
621  break;
622  if (loop < start) {
623  loop++;
624  continue;
625  }
626  w = wl->window;
627 
628  if (wl == s->curw)
629  gc.fg = active_colour;
630  else
631  gc.fg = colour;
632 
633  if (left)
634  offset = 3 + (i * each);
635  else
636  offset = (i * each);
637  if (loop == end - 1)
638  width = each + remaining;
639  else
640  width = each - 1;
641 
642  screen_write_cursormove(ctx, cx + offset, cy, 0);
643  screen_write_preview(ctx, &w->active->base, width, sy);
644 
645  xasprintf(&label, " %u:%s ", wl->idx, w->name);
646  if (strlen(label) > width)
647  xasprintf(&label, " %u ", wl->idx);
648  window_tree_draw_label(ctx, cx + offset, cy, width, sy, &gc,
649  label);
650  free(label);
651 
652  if (loop != end - 1) {
653  screen_write_cursormove(ctx, cx + offset + width, cy, 0);
654  screen_write_vline(ctx, sy, 0, 0);
655  }
656  loop++;
657 
658  i++;
659  }
660 }
661 
662 static void
664  struct window *w, struct screen_write_ctx *ctx, u_int sx, u_int sy)
665 {
666  struct options *oo = s->options;
667  struct window_pane *wp;
668  u_int cx = ctx->s->cx, cy = ctx->s->cy;
669  u_int loop, total, visible, each, width, offset;
670  u_int current, start, end, remaining, i;
671  struct grid_cell gc;
672  int colour, active_colour, left, right, pane_idx;
673  char *label;
674 
675  total = window_count_panes(w);
676 
677  memcpy(&gc, &grid_default_cell, sizeof gc);
678  colour = options_get_number(oo, "display-panes-colour");
679  active_colour = options_get_number(oo, "display-panes-active-colour");
680 
681  if (sx / total < 24) {
682  visible = sx / 24;
683  if (visible == 0)
684  visible = 1;
685  } else
686  visible = total;
687 
688  current = 0;
689  TAILQ_FOREACH(wp, &w->panes, entry) {
690  if (wp == w->active)
691  break;
692  current++;
693  }
694 
695  if (current < visible) {
696  start = 0;
697  end = visible;
698  } else if (current >= total - visible) {
699  start = total - visible;
700  end = total;
701  } else {
702  start = current - (visible / 2);
703  end = start + visible;
704  }
705 
706  if (data->offset < -(int)start)
707  data->offset = -(int)start;
708  if (data->offset > (int)(total - end))
709  data->offset = (int)(total - end);
710  start += data->offset;
711  end += data->offset;
712 
713  left = (start != 0);
714  right = (end != total);
715  if (((left && right) && sx <= 6) || ((left || right) && sx <= 3))
716  left = right = 0;
717  if (left && right) {
718  each = (sx - 6) / visible;
719  remaining = (sx - 6) - (visible * each);
720  } else if (left || right) {
721  each = (sx - 3) / visible;
722  remaining = (sx - 3) - (visible * each);
723  } else {
724  each = sx / visible;
725  remaining = sx - (visible * each);
726  }
727  if (each == 0)
728  return;
729 
730  if (left) {
731  data->left = cx + 2;
732  screen_write_cursormove(ctx, cx + 2, cy, 0);
733  screen_write_vline(ctx, sy, 0, 0);
734  screen_write_cursormove(ctx, cx, cy + sy / 2, 0);
736  } else
737  data->left = -1;
738  if (right) {
739  data->right = cx + sx - 3;
740  screen_write_cursormove(ctx, cx + sx - 3, cy, 0);
741  screen_write_vline(ctx, sy, 0, 0);
742  screen_write_cursormove(ctx, cx + sx - 1, cy + sy / 2, 0);
744  } else
745  data->right = -1;
746 
747  data->start = start;
748  data->end = end;
749  data->each = each;
750 
751  i = loop = 0;
752  TAILQ_FOREACH(wp, &w->panes, entry) {
753  if (loop == end)
754  break;
755  if (loop < start) {
756  loop++;
757  continue;
758  }
759 
760  if (wp == w->active)
761  gc.fg = active_colour;
762  else
763  gc.fg = colour;
764 
765  if (left)
766  offset = 3 + (i * each);
767  else
768  offset = (i * each);
769  if (loop == end - 1)
770  width = each + remaining;
771  else
772  width = each - 1;
773 
774  screen_write_cursormove(ctx, cx + offset, cy, 0);
775  screen_write_preview(ctx, &wp->base, width, sy);
776 
777  if (window_pane_index(wp, &pane_idx) != 0)
778  pane_idx = loop;
779  xasprintf(&label, " %u ", pane_idx);
780  window_tree_draw_label(ctx, cx + offset, cy, each, sy, &gc,
781  label);
782  free(label);
783 
784  if (loop != end - 1) {
785  screen_write_cursormove(ctx, cx + offset + width, cy, 0);
786  screen_write_vline(ctx, sy, 0, 0);
787  }
788  loop++;
789 
790  i++;
791  }
792 }
793 
794 static void
795 window_tree_draw(void *modedata, void *itemdata, struct screen_write_ctx *ctx,
796  u_int sx, u_int sy)
797 {
798  struct window_tree_itemdata *item = itemdata;
799  struct session *sp;
800  struct winlink *wlp;
801  struct window_pane *wp;
802 
803  window_tree_pull_item(item, &sp, &wlp, &wp);
804  if (wp == NULL)
805  return;
806 
807  switch (item->type) {
808  case WINDOW_TREE_NONE:
809  break;
810  case WINDOW_TREE_SESSION:
811  window_tree_draw_session(modedata, sp, ctx, sx, sy);
812  break;
813  case WINDOW_TREE_WINDOW:
814  window_tree_draw_window(modedata, sp, wlp->window, ctx, sx, sy);
815  break;
816  case WINDOW_TREE_PANE:
817  screen_write_preview(ctx, &wp->base, sx, sy);
818  break;
819  }
820 }
821 
822 static int
823 window_tree_search(__unused void *modedata, void *itemdata, const char *ss)
824 {
825  struct window_tree_itemdata *item = itemdata;
826  struct session *s;
827  struct winlink *wl;
828  struct window_pane *wp;
829  char *cmd;
830  int retval;
831 
832  window_tree_pull_item(item, &s, &wl, &wp);
833 
834  switch (item->type) {
835  case WINDOW_TREE_NONE:
836  return (0);
837  case WINDOW_TREE_SESSION:
838  if (s == NULL)
839  return (0);
840  return (strstr(s->name, ss) != NULL);
841  case WINDOW_TREE_WINDOW:
842  if (s == NULL || wl == NULL)
843  return (0);
844  return (strstr(wl->window->name, ss) != NULL);
845  case WINDOW_TREE_PANE:
846  if (s == NULL || wl == NULL || wp == NULL)
847  break;
848  cmd = osdep_get_name(wp->fd, wp->tty);
849  if (cmd == NULL || *cmd == '\0')
850  return (0);
851  retval = (strstr(cmd, ss) != NULL);
852  free(cmd);
853  return (retval);
854  }
855  return (0);
856 }
857 
858 static void
859 window_tree_menu(void *modedata, struct client *c, key_code key)
860 {
861  struct window_tree_modedata *data = modedata;
862  struct window_pane *wp = data->wp;
863  struct window_mode_entry *wme;
864 
865  wme = TAILQ_FIRST(&wp->modes);
866  if (wme == NULL || wme->data != modedata)
867  return;
868  window_tree_key(wme, c, NULL, NULL, key, NULL);
869 }
870 
871 static key_code
872 window_tree_get_key(void *modedata, void *itemdata, u_int line)
873 {
874  struct window_tree_modedata *data = modedata;
875  struct window_tree_itemdata *item = itemdata;
876  struct format_tree *ft;
877  struct session *s;
878  struct winlink *wl;
879  struct window_pane *wp;
880  char *expanded;
881  key_code key;
882 
883  ft = format_create(NULL, NULL, FORMAT_NONE, 0);
884  window_tree_pull_item(item, &s, &wl, &wp);
885  if (item->type == WINDOW_TREE_SESSION)
886  format_defaults(ft, NULL, s, NULL, NULL);
887  else if (item->type == WINDOW_TREE_WINDOW)
888  format_defaults(ft, NULL, s, wl, NULL);
889  else
890  format_defaults(ft, NULL, s, wl, wp);
891  format_add(ft, "line", "%u", line);
892 
893  expanded = format_expand(ft, data->key_format);
894  key = key_string_lookup_string(expanded);
895  free(expanded);
896  format_free(ft);
897  return key;
898 }
899 
900 static struct screen *
902  struct args *args)
903 {
904  struct window_pane *wp = wme->wp;
905  struct window_tree_modedata *data;
906  struct screen *s;
907 
908  wme->data = data = xcalloc(1, sizeof *data);
909  data->wp = wp;
910  data->references = 1;
911 
912  if (args_has(args, 's'))
913  data->type = WINDOW_TREE_SESSION;
914  else if (args_has(args, 'w'))
915  data->type = WINDOW_TREE_WINDOW;
916  else
917  data->type = WINDOW_TREE_PANE;
918  memcpy(&data->fs, fs, sizeof data->fs);
919 
920  if (args == NULL || !args_has(args, 'F'))
922  else
923  data->format = xstrdup(args_get(args, 'F'));
924  if (args == NULL || !args_has(args, 'K'))
926  else
927  data->key_format = xstrdup(args_get(args, 'K'));
928  if (args == NULL || args->argc == 0)
930  else
931  data->command = xstrdup(args->argv[0]);
932  data->squash_groups = !args_has(args, 'G');
933 
938  mode_tree_zoom(data->data, args);
939 
940  mode_tree_build(data->data);
941  mode_tree_draw(data->data);
942 
943  data->type = WINDOW_TREE_NONE;
944 
945  return (s);
946 }
947 
948 static void
950 {
951  u_int i;
952 
953  if (--data->references != 0)
954  return;
955 
956  for (i = 0; i < data->item_size; i++)
958  free(data->item_list);
959 
960  free(data->format);
961  free(data->key_format);
962  free(data->command);
963 
964  free(data);
965 }
966 
967 static void
969 {
970  struct window_tree_modedata *data = wme->data;
971 
972  if (data == NULL)
973  return;
974 
975  data->dead = 1;
976  mode_tree_free(data->data);
978 }
979 
980 static void
981 window_tree_resize(struct window_mode_entry *wme, u_int sx, u_int sy)
982 {
983  struct window_tree_modedata *data = wme->data;
984 
985  mode_tree_resize(data->data, sx, sy);
986 }
987 
988 static void
990 {
991  struct window_tree_modedata *data = wme->data;
992 
993  mode_tree_build(data->data);
994  mode_tree_draw(data->data);
995  data->wp->flags |= PANE_REDRAW;
996 }
997 
998 static char *
1000  struct cmd_find_state *fs)
1001 {
1002  struct session *s;
1003  struct winlink *wl;
1004  struct window_pane *wp;
1005  char *target;
1006 
1007  window_tree_pull_item(item, &s, &wl, &wp);
1008 
1009  target = NULL;
1010  switch (item->type) {
1011  case WINDOW_TREE_NONE:
1012  break;
1013  case WINDOW_TREE_SESSION:
1014  if (s == NULL)
1015  break;
1016  xasprintf(&target, "=%s:", s->name);
1017  break;
1018  case WINDOW_TREE_WINDOW:
1019  if (s == NULL || wl == NULL)
1020  break;
1021  xasprintf(&target, "=%s:%u.", s->name, wl->idx);
1022  break;
1023  case WINDOW_TREE_PANE:
1024  if (s == NULL || wl == NULL || wp == NULL)
1025  break;
1026  xasprintf(&target, "=%s:%u.%%%u", s->name, wl->idx, wp->id);
1027  break;
1028  }
1029  if (target == NULL)
1030  cmd_find_clear_state(fs, 0);
1031  else
1032  cmd_find_from_winlink_pane(fs, wl, wp, 0);
1033  return (target);
1034 }
1035 
1036 static void
1037 window_tree_command_each(void *modedata, void *itemdata, struct client *c,
1039 {
1040  struct window_tree_modedata *data = modedata;
1041  struct window_tree_itemdata *item = itemdata;
1042  char *name;
1043  struct cmd_find_state fs;
1044 
1045  name = window_tree_get_target(item, &fs);
1046  if (name != NULL)
1047  mode_tree_run_command(c, &fs, data->entered, name);
1048  free(name);
1049 }
1050 
1051 static enum cmd_retval
1052 window_tree_command_done(__unused struct cmdq_item *item, void *modedata)
1053 {
1054  struct window_tree_modedata *data = modedata;
1055 
1056  if (!data->dead) {
1057  mode_tree_build(data->data);
1058  mode_tree_draw(data->data);
1059  data->wp->flags |= PANE_REDRAW;
1060  }
1062  return (CMD_RETURN_NORMAL);
1063 }
1064 
1065 static int
1066 window_tree_command_callback(struct client *c, void *modedata, const char *s,
1067  __unused int done)
1068 {
1069  struct window_tree_modedata *data = modedata;
1070 
1071  if (s == NULL || *s == '\0' || data->dead)
1072  return (0);
1073 
1074  data->entered = s;
1076  KEYC_NONE, 1);
1077  data->entered = NULL;
1078 
1079  data->references++;
1081 
1082  return (0);
1083 }
1084 
1085 static void
1087 {
1088  struct window_tree_modedata *data = modedata;
1089 
1091 }
1092 
1093 static void
1094 window_tree_kill_each(__unused void *modedata, void *itemdata,
1095  __unused struct client *c, __unused key_code key)
1096 {
1097  struct window_tree_itemdata *item = itemdata;
1098  struct session *s;
1099  struct winlink *wl;
1100  struct window_pane *wp;
1101 
1102  window_tree_pull_item(item, &s, &wl, &wp);
1103 
1104  switch (item->type) {
1105  case WINDOW_TREE_NONE:
1106  break;
1107  case WINDOW_TREE_SESSION:
1108  if (s != NULL) {
1110  session_destroy(s, 1, __func__);
1111  }
1112  break;
1113  case WINDOW_TREE_WINDOW:
1114  if (wl != NULL)
1115  server_kill_window(wl->window, 0);
1116  break;
1117  case WINDOW_TREE_PANE:
1118  if (wp != NULL)
1119  server_kill_pane(wp);
1120  break;
1121  }
1122 }
1123 
1124 static int
1125 window_tree_kill_current_callback(struct client *c, void *modedata,
1126  const char *s, __unused int done)
1127 {
1128  struct window_tree_modedata *data = modedata;
1129  struct mode_tree_data *mtd = data->data;
1130 
1131  if (s == NULL || *s == '\0' || data->dead)
1132  return (0);
1133  if (tolower((u_char) s[0]) != 'y' || s[1] != '\0')
1134  return (0);
1135 
1138 
1139  data->references++;
1141 
1142  return (0);
1143 }
1144 
1145 static int
1147  const char *s, __unused int done)
1148 {
1149  struct window_tree_modedata *data = modedata;
1150  struct mode_tree_data *mtd = data->data;
1151 
1152  if (s == NULL || *s == '\0' || data->dead)
1153  return (0);
1154  if (tolower((u_char) s[0]) != 'y' || s[1] != '\0')
1155  return (0);
1156 
1159 
1160  data->references++;
1162 
1163  return (0);
1164 }
1165 
1166 static key_code
1168  struct window_tree_itemdata *item)
1169 {
1170  struct session *s;
1171  struct winlink *wl;
1172  struct window_pane *wp;
1173  u_int loop;
1174 
1175  if (key != KEYC_MOUSEDOWN1_PANE)
1176  return (KEYC_NONE);
1177 
1178  if (data->left != -1 && x <= (u_int)data->left)
1179  return ('<');
1180  if (data->right != -1 && x >= (u_int)data->right)
1181  return ('>');
1182 
1183  if (data->left != -1)
1184  x -= data->left;
1185  else if (x != 0)
1186  x--;
1187  if (x == 0 || data->end == 0)
1188  x = 0;
1189  else {
1190  x = x / data->each;
1191  if (data->start + x >= data->end)
1192  x = data->end - 1;
1193  }
1194 
1195  window_tree_pull_item(item, &s, &wl, &wp);
1196  if (item->type == WINDOW_TREE_SESSION) {
1197  if (s == NULL)
1198  return (KEYC_NONE);
1200  loop = 0;
1201  RB_FOREACH(wl, winlinks, &s->windows) {
1202  if (loop == data->start + x)
1203  break;
1204  loop++;
1205  }
1206  if (wl != NULL)
1207  mode_tree_set_current(data->data, (uint64_t)wl);
1208  return ('\r');
1209  }
1210  if (item->type == WINDOW_TREE_WINDOW) {
1211  if (wl == NULL)
1212  return (KEYC_NONE);
1214  loop = 0;
1215  TAILQ_FOREACH(wp, &wl->window->panes, entry) {
1216  if (loop == data->start + x)
1217  break;
1218  loop++;
1219  }
1220  if (wp != NULL)
1221  mode_tree_set_current(data->data, (uint64_t)wp);
1222  return ('\r');
1223  }
1224  return (KEYC_NONE);
1225 }
1226 
1227 static void
1229  __unused struct session *s, __unused struct winlink *wl, key_code key,
1230  struct mouse_event *m)
1231 {
1232  struct window_pane *wp = wme->wp;
1233  struct window_tree_modedata *data = wme->data;
1234  struct window_tree_itemdata *item, *new_item;
1235  char *name, *prompt = NULL;
1236  struct cmd_find_state fs, *fsp = &data->fs;
1237  int finished;
1238  u_int tagged, x, y, idx;
1239  struct session *ns;
1240  struct winlink *nwl;
1241  struct window_pane *nwp;
1242 
1243  item = mode_tree_get_current(data->data);
1244  finished = mode_tree_key(data->data, c, &key, m, &x, &y);
1245  if (item != (new_item = mode_tree_get_current(data->data))) {
1246  item = new_item;
1247  data->offset = 0;
1248  }
1249  if (KEYC_IS_MOUSE(key) && m != NULL)
1250  key = window_tree_mouse(data, key, x, item);
1251  switch (key) {
1252  case '<':
1253  data->offset--;
1254  break;
1255  case '>':
1256  data->offset++;
1257  break;
1258  case 'H':
1259  mode_tree_expand(data->data, (uint64_t)fsp->s);
1260  mode_tree_expand(data->data, (uint64_t)fsp->wl);
1261  if (!mode_tree_set_current(data->data, (uint64_t)wme->wp))
1262  mode_tree_set_current(data->data, (uint64_t)fsp->wl);
1263  break;
1264  case 'm':
1265  window_tree_pull_item(item, &ns, &nwl, &nwp);
1266  server_set_marked(ns, nwl, nwp);
1267  mode_tree_build(data->data);
1268  break;
1269  case 'M':
1271  mode_tree_build(data->data);
1272  break;
1273  case 'x':
1274  window_tree_pull_item(item, &ns, &nwl, &nwp);
1275  switch (item->type) {
1276  case WINDOW_TREE_NONE:
1277  break;
1278  case WINDOW_TREE_SESSION:
1279  if (ns == NULL)
1280  break;
1281  xasprintf(&prompt, "Kill session %s? ", ns->name);
1282  break;
1283  case WINDOW_TREE_WINDOW:
1284  if (nwl == NULL)
1285  break;
1286  xasprintf(&prompt, "Kill window %u? ", nwl->idx);
1287  break;
1288  case WINDOW_TREE_PANE:
1289  if (nwp == NULL || window_pane_index(nwp, &idx) != 0)
1290  break;
1291  xasprintf(&prompt, "Kill pane %u? ", idx);
1292  break;
1293  }
1294  if (prompt == NULL)
1295  break;
1296  data->references++;
1297  status_prompt_set(c, NULL, prompt, "",
1300  free(prompt);
1301  break;
1302  case 'X':
1303  tagged = mode_tree_count_tagged(data->data);
1304  if (tagged == 0)
1305  break;
1306  xasprintf(&prompt, "Kill %u tagged? ", tagged);
1307  data->references++;
1308  status_prompt_set(c, NULL, prompt, "",
1311  free(prompt);
1312  break;
1313  case ':':
1314  tagged = mode_tree_count_tagged(data->data);
1315  if (tagged != 0)
1316  xasprintf(&prompt, "(%u tagged) ", tagged);
1317  else
1318  xasprintf(&prompt, "(current) ");
1319  data->references++;
1320  status_prompt_set(c, NULL, prompt, "",
1322  data, PROMPT_NOFORMAT);
1323  free(prompt);
1324  break;
1325  case '\r':
1326  name = window_tree_get_target(item, &fs);
1327  if (name != NULL)
1328  mode_tree_run_command(c, NULL, data->command, name);
1329  finished = 1;
1330  free(name);
1331  break;
1332  }
1333  if (finished)
1335  else {
1336  mode_tree_draw(data->data);
1337  wp->flags |= PANE_REDRAW;
1338  }
1339 }
int args_has(struct args *args, u_char flag)
Definition: arguments.c:259
const char * args_get(struct args *args, u_char flag)
Definition: arguments.c:295
void cmd_find_from_winlink_pane(struct cmd_find_state *fs, struct winlink *wl, struct window_pane *wp, int flags)
Definition: cmd-find.c:791
void cmd_find_clear_state(struct cmd_find_state *fs, int flags)
Definition: cmd-find.c:644
struct cmdq_item * cmdq_append(struct client *c, struct cmdq_item *item)
Definition: cmd-queue.c:288
#define __unused
Definition: compat.h:60
#define timercmp(tvp, uvp, cmp)
Definition: compat.h:230
void format_defaults(struct format_tree *ft, struct client *c, struct session *s, struct winlink *wl, struct window_pane *wp)
Definition: format.c:4684
char * format_single(struct cmdq_item *item, const char *fmt, struct client *c, struct session *s, struct winlink *wl, struct window_pane *wp)
Definition: format.c:4621
void format_add(struct format_tree *ft, const char *key, const char *fmt,...)
Definition: format.c:3126
struct format_tree * format_create(struct client *c, struct cmdq_item *item, int tag, int flags)
Definition: format.c:3042
char * format_expand(struct format_tree *ft, const char *fmt)
Definition: format.c:4609
void format_free(struct format_tree *ft)
Definition: format.c:3066
int format_true(const char *s)
Definition: format.c:3471
const struct grid_cell grid_default_cell
Definition: grid.c:39
key_code key_string_lookup_string(const char *string)
Definition: key-string.c:165
key_code key
Definition: key-string.c:32
const char * name
Definition: layout-set.c:38
void mode_tree_build(struct mode_tree_data *mtd)
Definition: mode-tree.c:477
void mode_tree_free(struct mode_tree_data *mtd)
Definition: mode-tree.c:521
struct mode_tree_data * mode_tree_start(struct window_pane *wp, struct args *args, mode_tree_build_cb buildcb, mode_tree_draw_cb drawcb, mode_tree_search_cb searchcb, mode_tree_menu_cb menucb, mode_tree_height_cb heightcb, mode_tree_key_cb keycb, void *modedata, const struct menu_item *menu, const char **sort_list, u_int sort_size, struct screen **s)
Definition: mode-tree.c:389
void mode_tree_expand_current(struct mode_tree_data *mtd)
Definition: mode-tree.c:287
void mode_tree_expand(struct mode_tree_data *mtd, uint64_t tag)
Definition: mode-tree.c:321
void mode_tree_zoom(struct mode_tree_data *mtd, struct args *args)
Definition: mode-tree.c:443
u_int mode_tree_count_tagged(struct mode_tree_data *mtd)
Definition: mode-tree.c:352
int mode_tree_set_current(struct mode_tree_data *mtd, uint64_t tag)
Definition: mode-tree.c:334
struct mode_tree_item * mode_tree_add(struct mode_tree_data *mtd, struct mode_tree_item *parent, void *itemdata, uint64_t tag, const char *name, const char *text, int expanded)
Definition: mode-tree.c:553
void mode_tree_run_command(struct client *c, struct cmd_find_state *fs, const char *template, const char *name)
Definition: mode-tree.c:1193
void mode_tree_remove(struct mode_tree_data *mtd, struct mode_tree_item *mti)
Definition: mode-tree.c:604
int mode_tree_key(struct mode_tree_data *mtd, struct client *c, key_code *key, struct mouse_event *m, u_int *xp, u_int *yp)
Definition: mode-tree.c:977
void * mode_tree_get_current(struct mode_tree_data *mtd)
Definition: mode-tree.c:275
void mode_tree_each_tagged(struct mode_tree_data *mtd, mode_tree_each_cb cb, struct client *c, key_code key, int current)
Definition: mode-tree.c:367
void mode_tree_resize(struct mode_tree_data *mtd, u_int sx, u_int sy)
Definition: mode-tree.c:540
void mode_tree_draw(struct mode_tree_data *mtd)
Definition: mode-tree.c:616
long long options_get_number(struct options *oo, const char *name)
Definition: options.c:699
char * osdep_get_name(int fd, char *tty)
Definition: osdep-aix.c:29
#define nitems(_a)
void screen_write_puts(struct screen_write_ctx *ctx, const struct grid_cell *gcp, const char *fmt,...)
Definition: screen-write.c:464
void screen_write_box(struct screen_write_ctx *ctx, u_int nx, u_int ny)
Definition: screen-write.c:672
void screen_write_cursormove(struct screen_write_ctx *ctx, int px, int py, int origin)
void screen_write_preview(struct screen_write_ctx *ctx, struct screen *src, u_int nx, u_int ny)
Definition: screen-write.c:712
void screen_write_vline(struct screen_write_ctx *ctx, u_int ny, int top, int bottom)
Definition: screen-write.c:601
void server_renumber_all(void)
Definition: server-fn.c:235
void server_destroy_session(struct session *s)
Definition: server-fn.c:433
void server_kill_window(struct window *w, int renumber)
Definition: server-fn.c:196
void server_kill_pane(struct window_pane *wp)
Definition: server-fn.c:179
void server_clear_marked(void)
Definition: server.c:77
void server_set_marked(struct session *s, struct winlink *wl, struct window_pane *wp)
Definition: server.c:66
struct session * session_find_by_id(u_int id)
Definition: session.c:101
struct sessions sessions
Definition: session.c:29
struct session_group * session_group_contains(struct session *target)
Definition: session.c:505
void session_destroy(struct session *s, int notify, const char *from)
Definition: session.c:201
void status_prompt_set(struct client *c, struct cmd_find_state *fs, const char *msg, const char *input, prompt_input_cb inputcb, prompt_free_cb freecb, void *data, int flags)
Definition: status.c:546
Definition: tmux.h:1435
int argc
Definition: tmux.h:1437
char ** argv
Definition: tmux.h:1438
Definition: tmux.h:1608
struct window_pane * wp
Definition: tmux.h:1454
struct session * s
Definition: tmux.h:1451
struct winlink * wl
Definition: tmux.h:1452
Definition: cmd.c:212
struct utf8_data data
Definition: tmux.h:689
int fg
Definition: tmux.h:692
u_int references
Definition: mode-tree.c:33
void * modedata
Definition: mode-tree.c:37
struct window_pane * wp
Definition: mode-tree.c:36
const char * text
Definition: mode-tree.c:84
struct screen * s
Definition: tmux.h:851
Definition: tmux.h:816
u_int cy
Definition: tmux.h:824
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 winlink * curw
Definition: tmux.h:1192
struct options * options
Definition: tmux.h:1199
Definition: tmux.h:927
void * data
Definition: tmux.h:932
struct window_pane * wp
Definition: tmux.h:928
const char * name
Definition: tmux.h:906
u_int active_point
Definition: tmux.h:960
int fd
Definition: tmux.h:1001
char tty[32]
Definition: tmux.h:998
struct window_pane_offset offset
Definition: tmux.h:1004
int flags
Definition: tmux.h:977
struct screen base
Definition: tmux.h:1021
u_int sy
Definition: tmux.h:969
struct window * window
Definition: tmux.h:962
u_int sx
Definition: tmux.h:968
u_int id
Definition: tmux.h:959
enum window_tree_type type
Definition: window-tree.c:118
struct mode_tree_data * data
Definition: window-tree.c:129
struct cmd_find_state fs
Definition: window-tree.c:140
struct window_tree_itemdata ** item_list
Definition: window-tree.c:135
struct window_pane * wp
Definition: window-tree.c:125
const char * entered
Definition: window-tree.c:138
enum window_tree_type type
Definition: window-tree.c:141
Definition: tmux.h:1041
struct timeval activity_time
Definition: tmux.h:1052
char * name
Definition: tmux.h:1045
struct window_panes panes
Definition: tmux.h:1056
struct window_pane * active
Definition: tmux.h:1054
#define cmdq_get_callback(cb, data)
Definition: tmux.h:2364
u_int winlink_count(struct winlinks *)
Definition: window.c:150
#define KEYC_IS_MOUSE(key)
Definition: tmux.h:144
int window_has_pane(struct window *, struct window_pane *)
Definition: window.c:457
cmd_retval
Definition: tmux.h:1475
@ CMD_RETURN_NORMAL
Definition: tmux.h:1477
#define PROMPT_SINGLE
Definition: tmux.h:1734
int window_pane_index(struct window_pane *, u_int *)
Definition: window.c:756
struct window_pane * window_pane_find_by_id(u_int)
Definition: window.c:841
unsigned long long key_code
Definition: tmux.h:177
#define KEYC_NONE
Definition: tmux.h:113
#define FORMAT_NONE
Definition: tmux.h:1973
#define PROMPT_NOFORMAT
Definition: tmux.h:1737
#define PANE_REDRAW
Definition: tmux.h:978
@ KEYC_MOUSEDOWN1_PANE
Definition: tmux.h:197
@ KEYC_RIGHT
Definition: tmux.h:249
struct winlink * winlink_find_by_index(struct winlinks *, int)
Definition: window.c:109
u_int window_count_panes(struct window *)
Definition: window.c:773
void window_pane_reset_mode(struct window_pane *)
Definition: window.c:1105
static void window_tree_draw_session(struct window_tree_modedata *data, struct session *s, struct screen_write_ctx *ctx, u_int sx, u_int sy)
Definition: window-tree.c:529
static void window_tree_draw_window(struct window_tree_modedata *data, struct session *s, struct window *w, struct screen_write_ctx *ctx, u_int sx, u_int sy)
Definition: window-tree.c:663
static void window_tree_build(void *modedata, struct mode_tree_sort_criteria *sort_crit, uint64_t *tag, const char *filter)
Definition: window-tree.c:454
#define WINDOW_TREE_DEFAULT_COMMAND
Definition: window-tree.c:37
static void window_tree_free(struct window_mode_entry *)
Definition: window-tree.c:968
static void window_tree_build_pane(struct session *s, struct winlink *wl, struct window_pane *wp, void *modedata, struct mode_tree_item *parent)
Definition: window-tree.c:294
static char * window_tree_get_target(struct window_tree_itemdata *item, struct cmd_find_state *fs)
Definition: window-tree.c:999
static void window_tree_destroy(struct window_tree_modedata *data)
Definition: window-tree.c:949
static const char * window_tree_sort_list[]
Definition: window-tree.c:103
#define WINDOW_TREE_DEFAULT_KEY_FORMAT
Definition: window-tree.c:59
static void window_tree_update(struct window_mode_entry *)
Definition: window-tree.c:989
static void window_tree_free_item(struct window_tree_itemdata *item)
Definition: window-tree.c:199
static int window_tree_cmp_pane(const void *a0, const void *b0)
Definition: window-tree.c:273
static void window_tree_build_session(struct session *s, void *modedata, struct mode_tree_sort_criteria *sort_crit, const char *filter)
Definition: window-tree.c:403
static int window_tree_command_callback(struct client *c, void *modedata, const char *s, int done)
Definition: window-tree.c:1066
static int window_tree_filter_pane(struct session *s, struct winlink *wl, struct window_pane *wp, const char *filter)
Definition: window-tree.c:319
window_tree_type
Definition: window-tree.c:110
@ WINDOW_TREE_WINDOW
Definition: window-tree.c:113
@ WINDOW_TREE_SESSION
Definition: window-tree.c:112
@ WINDOW_TREE_PANE
Definition: window-tree.c:114
@ WINDOW_TREE_NONE
Definition: window-tree.c:111
#define WINDOW_TREE_DEFAULT_FORMAT
Definition: window-tree.c:39
static enum cmd_retval window_tree_command_done(struct cmdq_item *item, void *modedata)
Definition: window-tree.c:1052
static int window_tree_kill_current_callback(struct client *c, void *modedata, const char *s, int done)
Definition: window-tree.c:1125
static void window_tree_menu(void *modedata, struct client *c, key_code key)
Definition: window-tree.c:859
static void window_tree_resize(struct window_mode_entry *, u_int, u_int)
Definition: window-tree.c:981
static struct mode_tree_sort_criteria * window_tree_sort
Definition: window-tree.c:108
static const struct menu_item window_tree_menu_items[]
Definition: window-tree.c:70
static void window_tree_command_each(void *modedata, void *itemdata, struct client *c, key_code key)
Definition: window-tree.c:1037
static key_code window_tree_mouse(struct window_tree_modedata *data, key_code key, u_int x, struct window_tree_itemdata *item)
Definition: window-tree.c:1167
static void window_tree_draw_label(struct screen_write_ctx *ctx, u_int px, u_int py, u_int sx, u_int sy, const struct grid_cell *gc, const char *label)
Definition: window-tree.c:508
static key_code window_tree_get_key(void *modedata, void *itemdata, u_int line)
Definition: window-tree.c:872
static void window_tree_kill_each(void *modedata, void *itemdata, struct client *c, key_code key)
Definition: window-tree.c:1094
static void window_tree_key(struct window_mode_entry *, struct client *, struct session *, struct winlink *, key_code, struct mouse_event *)
Definition: window-tree.c:1228
static struct window_tree_itemdata * window_tree_add_item(struct window_tree_modedata *data)
Definition: window-tree.c:188
static void window_tree_pull_item(struct window_tree_itemdata *item, struct session **sp, struct winlink **wlp, struct window_pane **wp)
Definition: window-tree.c:153
static int window_tree_cmp_window(const void *a0, const void *b0)
Definition: window-tree.c:238
static int window_tree_build_window(struct session *s, struct winlink *wl, void *modedata, struct mode_tree_sort_criteria *sort_crit, struct mode_tree_item *parent, const char *filter)
Definition: window-tree.c:336
static struct screen * window_tree_init(struct window_mode_entry *, struct cmd_find_state *, struct args *)
Definition: window-tree.c:901
static void window_tree_command_free(void *modedata)
Definition: window-tree.c:1086
static int window_tree_kill_tagged_callback(struct client *c, void *modedata, const char *s, int done)
Definition: window-tree.c:1146
static int window_tree_cmp_session(const void *a0, const void *b0)
Definition: window-tree.c:205
const struct window_mode window_tree_mode
Definition: window-tree.c:87
static void window_tree_draw(void *modedata, void *itemdata, struct screen_write_ctx *ctx, u_int sx, u_int sy)
Definition: window-tree.c:795
static int window_tree_search(void *modedata, void *itemdata, const char *ss)
Definition: window-tree.c:823
window_tree_sort_type
Definition: window-tree.c:98
@ WINDOW_TREE_BY_TIME
Definition: window-tree.c:101
@ WINDOW_TREE_BY_NAME
Definition: window-tree.c:100
@ WINDOW_TREE_BY_INDEX
Definition: window-tree.c:99
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