diff options
author | Nicholas Marriott <nicm@openbsd.org> | 2011-03-27 20:27:26 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@openbsd.org> | 2011-03-27 20:27:26 +0000 |
commit | 808502ac3d86193d9a371728b2ea2055100c76c3 (patch) | |
tree | 18ba306e7e15c1a0a04108bc139a0938cd4ce96e /window.c | |
parent | d74e5bffbad33df742749b5983479dc2cfac273b (diff) | |
download | rtmux-808502ac3d86193d9a371728b2ea2055100c76c3.tar.gz rtmux-808502ac3d86193d9a371728b2ea2055100c76c3.tar.bz2 rtmux-808502ac3d86193d9a371728b2ea2055100c76c3.zip |
Give each pane created in a tmux server a unique id (starting from 0),
put it in the TMUX_PANE environment variable and accept it as a
target. Suggested by and with testing and tweaks from Ben Boeckel.
Diffstat (limited to 'window.c')
-rw-r--r-- | window.c | 31 |
1 files changed, 30 insertions, 1 deletions
@@ -56,6 +56,10 @@ /* 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,6 +71,14 @@ winlink_cmp(struct winlink *wl1, struct winlink *wl2) 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,6 +507,16 @@ window_printable_flags(struct session *s, struct winlink *wl) 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) { @@ -503,6 +525,9 @@ window_pane_create(struct window *w, u_int sx, u_int sy, u_int hlimit) 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,6 +580,8 @@ window_pane_destroy(struct window_pane *wp) 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,7 +596,7 @@ window_pane_spawn(struct window_pane *wp, const char *cmd, const char *shell, const char *cwd, struct environ *env, struct termios *tio, char **cause) { struct winsize ws; - char *argv0; + char *argv0, paneid[16]; const char *ptr; struct termios tio2; @@ -616,6 +643,8 @@ window_pane_spawn(struct window_pane *wp, const char *cmd, const char *shell, closefrom(STDERR_FILENO + 1); + xsnprintf(paneid, sizeof paneid, "%%%u", wp->id); + environ_set(env, "TMUX_PANE", paneid); environ_push(env); clear_signals(1); |