=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/window.c,v retrieving revision 1.63 retrieving revision 1.64 diff -c -r1.63 -r1.64 *** src/usr.bin/tmux/window.c 2011/01/25 22:31:50 1.63 --- src/usr.bin/tmux/window.c 2011/03/27 20:27:27 1.64 *************** *** 1,4 **** ! /* $OpenBSD: window.c,v 1.63 2011/01/25 22:31:50 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: window.c,v 1.64 2011/03/27 20:27:27 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott *************** *** 56,61 **** --- 56,65 ---- /* Global window list. */ struct windows windows; + /* Global panes tree. */ + struct window_pane_tree all_window_panes; + u_int next_window_pane; + void window_pane_read_callback(struct bufferevent *, void *); void window_pane_error_callback(struct bufferevent *, short, void *); *************** *** 67,72 **** --- 71,84 ---- return (wl1->idx - wl2->idx); } + RB_GENERATE(window_pane_tree, window_pane, tree_entry, window_pane_cmp); + + int + window_pane_cmp(struct window_pane *wp1, struct window_pane *wp2) + { + return (wp1->id - wp2->id); + } + struct winlink * winlink_find_by_window(struct winlinks *wwl, struct window *w) { *************** *** 495,501 **** --- 507,523 ---- return (xstrdup(flags)); } + /* Find pane in global tree by id. */ struct window_pane * + window_pane_find_by_id(u_int id) + { + struct window_pane wp; + + wp.id = id; + return (RB_FIND(window_pane_tree, &all_window_panes, &wp)); + } + + struct window_pane * window_pane_create(struct window *w, u_int sx, u_int sy, u_int hlimit) { struct window_pane *wp; *************** *** 503,508 **** --- 525,533 ---- wp = xcalloc(1, sizeof *wp); wp->window = w; + wp->id = next_window_pane++; + RB_INSERT(window_pane_tree, &all_window_panes, wp); + wp->cmd = NULL; wp->shell = NULL; wp->cwd = NULL; *************** *** 555,560 **** --- 580,587 ---- bufferevent_free(wp->pipe_event); } + RB_REMOVE(window_pane_tree, &all_window_panes, wp); + if (wp->cwd != NULL) xfree(wp->cwd); if (wp->shell != NULL) *************** *** 569,575 **** const char *cwd, struct environ *env, struct termios *tio, char **cause) { struct winsize ws; ! char *argv0; const char *ptr; struct termios tio2; --- 596,602 ---- const char *cwd, struct environ *env, struct termios *tio, char **cause) { struct winsize ws; ! char *argv0, paneid[16]; const char *ptr; struct termios tio2; *************** *** 616,621 **** --- 643,650 ---- closefrom(STDERR_FILENO + 1); + xsnprintf(paneid, sizeof paneid, "%%%u", wp->id); + environ_set(env, "TMUX_PANE", paneid); environ_push(env); clear_signals(1);