The following patch includes these changes: - Define a window ID and a session ID that is unique for the lifetime of a tmux server. (session ID isn't yet exposed, but will be visible to control clients in a future patch) - Change layout_dump to include window pane IDs in its output - Define a window_id format - Change list-windows to accept either a window or session as its target - Change cmd_lookup_window to accept @number as a window ID. - Updates the man page to describe these changes.
Index: tmux.h =================================================================== --- tmux.h (revision 2682) +++ tmux.h (working copy) @@ -844,6 +844,7 @@ /* Window structure. */ struct window { + u_int id; char *name; struct event name_timer; struct timeval silence_timer; @@ -947,6 +948,7 @@ struct session { u_int idx; + u_int id; char *name; char *cwd; @@ -1318,6 +1320,7 @@ #define CMD_TARGET_PANE_USAGE "[-t target-pane]" #define CMD_TARGET_WINDOW_USAGE "[-t target-window]" #define CMD_TARGET_SESSION_USAGE "[-t target-session]" +#define CMD_TARGET_SESSION_OR_WINDOW_USAGE "[-t target]" #define CMD_TARGET_CLIENT_USAGE "[-t target-client]" #define CMD_SRCDST_PANE_USAGE "[-s src-pane] [-t dst-pane]" #define CMD_SRCDST_WINDOW_USAGE "[-s src-window] [-t dst-window]" @@ -1544,6 +1547,9 @@ struct client *cmd_current_client(struct cmd_ctx *); struct client *cmd_find_client(struct cmd_ctx *, const char *); struct session *cmd_find_session(struct cmd_ctx *, const char *, int); +struct winlink *cmd_find_session_or_window( + struct cmd_ctx *ctx, const char *arg, struct session **sp, + int prefer_unattached); struct winlink *cmd_find_window( struct cmd_ctx *, const char *, struct session **); int cmd_find_index( @@ -1897,6 +1903,7 @@ RB_PROTOTYPE(window_pane_tree, window_pane, tree_entry, window_pane_cmp); struct winlink *winlink_find_by_index(struct winlinks *, int); struct winlink *winlink_find_by_window(struct winlinks *, struct window *); +struct winlink *winlink_find_by_window_id(struct winlinks *, u_int); int winlink_next_index(struct winlinks *, int); u_int winlink_count(struct winlinks *); struct winlink *winlink_add(struct winlinks *, int); Index: layout-custom.c =================================================================== --- layout-custom.c (revision 2682) +++ layout-custom.c (working copy) @@ -78,9 +78,15 @@ if (len == 0) return (-1); - - tmplen = xsnprintf(tmp, sizeof tmp, - "%ux%u,%u,%u", lc->sx, lc->sy, lc->xoff, lc->yoff); + if (lc->wp) { + tmplen = xsnprintf(tmp, sizeof tmp, + "%ux%u,%u,%u,%u", lc->sx, lc->sy, lc->xoff, + lc->yoff, lc->wp->id); + } else { + tmplen = xsnprintf(tmp, sizeof tmp, + "%ux%u,%u,%u,na", lc->sx, lc->sy, lc->xoff, + lc->yoff); + } if (tmplen > (sizeof tmp) - 1) return (-1); if (strlcat(buf, tmp, len) >= len) Index: session.c =================================================================== --- session.c (revision 2682) +++ session.c (working copy) @@ -34,6 +34,7 @@ struct winlink *session_next_alert(struct winlink *); struct winlink *session_previous_alert(struct winlink *); +u_int next_session_id = 0; RB_GENERATE(sessions, session, entry, session_cmp); @@ -91,6 +92,7 @@ struct session *s; s = xmalloc(sizeof *s); + s->id = next_session_id++; s->references = 0; s->flags = 0; Index: format.c =================================================================== --- format.c (revision 2682) +++ format.c (working copy) @@ -71,7 +71,7 @@ "window_name", /* W */ NULL, /* X */ NULL, /* Y */ - NULL /* Z */ + NULL /* Z */ }; /* Create a new tree. */ @@ -210,7 +210,7 @@ char *buf, *ptr; const char *s; size_t off, len, n; - int ch; + int ch; len = 64; buf = xmalloc(len); @@ -341,6 +341,7 @@ layout = layout_dump(w); flags = window_printable_flags(s, wl); + format_add(ft, "window_id", "%u", w->id); format_add(ft, "window_index", "%d", wl->idx); format_add(ft, "window_name", "%s", w->name); format_add(ft, "window_width", "%u", w->sx); Index: cmd-list-windows.c =================================================================== --- cmd-list-windows.c (revision 2682) +++ cmd-list-windows.c (working copy) @@ -30,12 +30,13 @@ void cmd_list_windows_server(struct cmd *, struct cmd_ctx *); void cmd_list_windows_session( - struct cmd *, struct session *, struct cmd_ctx *, int); + struct cmd *, struct session *,struct winlink *, + struct cmd_ctx *, int); const struct cmd_entry cmd_list_windows_entry = { "list-windows", "lsw", "aF:t:", 0, 0, - "[-a] [-F format] " CMD_TARGET_SESSION_USAGE, + "[-a] [-F format] " CMD_TARGET_SESSION_OR_WINDOW_USAGE, 0, NULL, NULL, @@ -47,14 +48,16 @@ { struct args *args = self->args; struct session *s; + struct winlink *wl; if (args_has(args, 'a')) cmd_list_windows_server(self, ctx); else { - s = cmd_find_session(ctx, args_get(args, 't'), 0); + s = NULL; + wl = cmd_find_session_or_window(ctx, args_get(args, 't'), &s, 0); if (s == NULL) return (-1); - cmd_list_windows_session(self, s, ctx, 0); + cmd_list_windows_session(self, s, wl, ctx, 0); } return (0); @@ -66,12 +69,13 @@ struct session *s; RB_FOREACH(s, sessions, &sessions) - cmd_list_windows_session(self, s, ctx, 1); + cmd_list_windows_session(self, s, NULL, ctx, 1); } void cmd_list_windows_session( - struct cmd *self, struct session *s, struct cmd_ctx *ctx, int type) + struct cmd *self, struct session *s, struct winlink *target_wl, + struct cmd_ctx *ctx, int type) { struct args *args = self->args; struct winlink *wl; @@ -102,6 +106,9 @@ n = 0; RB_FOREACH(wl, winlinks, &s->windows) { + if (target_wl && target_wl->window->id != wl->window->id) + continue; + ft = format_create(); format_add(ft, "line", "%u", n); format_session(ft, s); Index: tmux.1 =================================================================== --- tmux.1 (revision 2682) +++ tmux.1 (working copy) @@ -389,8 +389,9 @@ .Ar target-session , and .Em window -is looked for in order: as a window index, for example mysession:1; as an exact -window name, such as mysession:mywindow; then as an +is looked for in order: as a window index, for example mysession:1; +as a window id, such as @1; +as an exact window name, such as mysession:mywindow; then as an .Xr fnmatch 3 pattern or the start of a window name, such as mysession:mywin* or mysession:mywin. @@ -1200,14 +1201,18 @@ .It Xo Ic list-windows .Op Fl a .Op Fl F Ar format -.Op Fl t Ar target-session +.Op Fl t Ar target .Xc .D1 (alias: Ic lsw ) If .Fl a is given, list all windows on the server. -Otherwise, list windows in the current session or in -.Ar target-session . +Otherwise, list windows in the current session or, if +.Ar target +names a session, list all the windows in that session. +If +.Ar target +names a session and window, list only that window. For the meaning of the .Fl F flag, see the Index: cmd.c =================================================================== --- cmd.c (revision 2682) +++ cmd.c (working copy) @@ -593,6 +593,20 @@ return (wl); } + /* Look up by window ID. @n gives an id. */ + if (name[0] == '@') { + struct winlink *c_wl; + errstr = NULL; + u_int id = strtonum(name + 1, 0, INT_MAX, &errstr); + if (errstr == NULL) { + RB_FOREACH(c_wl, winlinks, &s->windows) { + if (c_wl->window->id == id) { + return (c_wl); + } + } + } + } + /* Look for exact matches, error if more than one. */ wlfound = NULL; RB_FOREACH(wl, winlinks, &s->windows) { @@ -750,6 +764,22 @@ return (s); } +/* The target may specify a session to find or "session:window". */ +struct winlink * +cmd_find_session_or_window(struct cmd_ctx *ctx, const char *arg, + struct session **sp, int prefer_unattached) +{ + const char *colon; + if (arg) + colon = strchr(arg, ':'); + if (arg && colon && colon[1]) + return cmd_find_window(ctx, arg, sp); + else { + *sp = cmd_find_session(ctx, arg, prefer_unattached); + return NULL; + } +} + /* Find the target session and window or report an error and return NULL. */ struct winlink * cmd_find_window(struct cmd_ctx *ctx, const char *arg, struct session **sp) Index: window.c =================================================================== --- window.c (revision 2682) +++ window.c (working copy) @@ -56,6 +56,7 @@ /* Global panes tree. */ struct window_pane_tree all_window_panes; u_int next_window_pane; +u_int next_window; void window_pane_read_callback(struct bufferevent *, void *); void window_pane_error_callback(struct bufferevent *, short, void *); @@ -101,6 +102,18 @@ return (RB_FIND(winlinks, wwl, &wl)); } +struct winlink * +winlink_find_by_window_id(struct winlinks *wwl, u_int id) +{ + struct winlink *c_wl; + RB_FOREACH(c_wl, winlinks, wwl) { + if (c_wl->window->id == id) { + return (c_wl); + } + } + return NULL; +} + int winlink_next_index(struct winlinks *wwl, int idx) { @@ -252,6 +265,7 @@ u_int i; w = xcalloc(1, sizeof *w); + w->id = next_window++; w->name = NULL; w->flags = 0; @@ -732,7 +746,7 @@ window_pane_read_callback(unused struct bufferevent *bufev, void *data) { struct window_pane *wp = data; - char *new_data; + char *new_data; size_t new_size; new_size = EVBUFFER_LENGTH(wp->event->input) - wp->pipe_off; @@ -964,7 +978,7 @@ { struct screen *s = &wp->base; char *newsearchstr, *line, *msg; - u_int i; + u_int i; msg = NULL; xasprintf(&newsearchstr, "*%s*", searchstr); ------------------------------------------------------------------------------ Try before you buy = See our experts in action! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-dev2 _______________________________________________ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users