mirror of
https://github.com/tmux/tmux.git
synced 2025-09-01 20:57:00 +00:00
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.
This commit is contained in:
31
window.c
31
window.c
@ -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);
|
||||
|
Reference in New Issue
Block a user