From 12da13c9d1e0e015ed19761e352ee6b877b23aa4 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 15 Dec 2015 00:00:01 +0000 Subject: Make the marked pane a cmd_find_state. --- cmd-find.c | 109 +++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 70 insertions(+), 39 deletions(-) (limited to 'cmd-find.c') diff --git a/cmd-find.c b/cmd-find.c index 8e118c00..b7728ea2 100644 --- a/cmd-find.c +++ b/cmd-find.c @@ -792,6 +792,67 @@ cmd_find_clear_state(struct cmd_find_state *fs, struct cmd_q *cmdq, int flags) fs->idx = -1; } +/* Check if a state if valid. */ +int +cmd_find_valid_state(struct cmd_find_state *fs) +{ + struct winlink *wl; + + if (fs->s == NULL || fs->wl == NULL || fs->w == NULL || fs->wp == NULL) + return (0); + + if (!session_alive(fs->s)) + return (0); + + RB_FOREACH(wl, winlinks, &fs->s->windows) { + if (wl->window == fs->w && wl == fs->wl) + break; + } + if (wl == NULL) + return (0); + + if (fs->w != fs->wl->window) + return (0); + + if (!window_has_pane(fs->w, fs->wp)) + return (0); + return (window_pane_visible(fs->wp)); +} + +/* Copy a state. */ +void +cmd_find_copy_state(struct cmd_find_state *dst, struct cmd_find_state *src) +{ + dst->s = src->s; + dst->wl = src->wl; + dst->idx = dst->wl->idx; + dst->w = dst->wl->window; + dst->wp = src->wp; +} + +/* Log the result. */ +void +cmd_find_log_state(const char *prefix, struct cmd_find_state *fs) +{ + if (fs->s != NULL) + log_debug("%s: s=$%u", prefix, fs->s->id); + else + log_debug("%s: s=none", prefix); + if (fs->wl != NULL) { + log_debug("%s: wl=%u %d w=@%u %s", prefix, fs->wl->idx, + fs->wl->window == fs->w, fs->w->id, fs->w->name); + } else + log_debug("%s: wl=none", prefix); + if (fs->wp != NULL) + log_debug("%s: wp=%%%u", prefix, fs->wp->id); + else + log_debug("%s: wp=none", prefix); + if (fs->idx != -1) + log_debug("%s: idx=%d", prefix, fs->idx); + else + log_debug("%s: idx=none", prefix); +} + /* * Split target into pieces and resolve for the given type. Fills in the given * state. Returns 0 on success or -1 on error. @@ -814,17 +875,14 @@ cmd_find_target(struct cmd_find_state *fs, struct cmd_q *cmdq, /* Find current state. */ cmd_find_clear_state(¤t, cmdq, flags); - if (server_check_marked() && (flags & CMD_FIND_DEFAULT_MARKED)) { - current.s = marked_session; - current.wl = marked_winlink; - current.idx = current.wl->idx; - current.w = current.wl->window; - current.wp = marked_window_pane; - } - if (current.s == NULL && cmd_find_current_session(¤t) != 0) { - if (~flags & CMD_FIND_QUIET) - cmdq_error(cmdq, "no current session"); - goto error; + if (server_check_marked() && (flags & CMD_FIND_DEFAULT_MARKED)) + cmd_find_copy_state(¤t, &marked_pane); + else { + if (cmd_find_current_session(¤t) != 0) { + if (~flags & CMD_FIND_QUIET) + cmdq_error(cmdq, "no current session"); + goto error; + } } /* Clear new state. */ @@ -868,11 +926,7 @@ cmd_find_target(struct cmd_find_state *fs, struct cmd_q *cmdq, cmdq_error(cmdq, "no marked target"); goto error; } - fs->s = marked_session; - fs->wl = marked_winlink; - fs->idx = fs->wl->idx; - fs->w = fs->wl->window; - fs->wp = marked_window_pane; + cmd_find_copy_state(fs, &marked_pane); goto found; } @@ -1068,29 +1122,6 @@ no_pane: goto error; } -/* Log the result. */ -void -cmd_find_log_state(const char *prefix, struct cmd_find_state *fs) -{ - if (fs->s != NULL) - log_debug("%s: s=$%u", prefix, fs->s->id); - else - log_debug("%s: s=none", prefix); - if (fs->wl != NULL) { - log_debug("%s: wl=%u %d w=@%u %s", prefix, fs->wl->idx, - fs->wl->window == fs->w, fs->w->id, fs->w->name); - } else - log_debug("%s: wl=none", prefix); - if (fs->wp != NULL) - log_debug("%s: wp=%%%u", prefix, fs->wp->id); - else - log_debug("%s: wp=none", prefix); - if (fs->idx != -1) - log_debug("%s: idx=%d", prefix, fs->idx); - else - log_debug("%s: idx=none", prefix); -} - /* Find the target client or report an error and return NULL. */ struct client * cmd_find_client(struct cmd_q *cmdq, const char *target, int quiet) -- cgit From 56d097cfe053f6cd50db9607503c25a80e3cd989 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 15 Dec 2015 00:11:24 +0000 Subject: Don't copy marked pane when can just point to it. --- cmd-find.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'cmd-find.c') diff --git a/cmd-find.c b/cmd-find.c index b7728ea2..ea1389a9 100644 --- a/cmd-find.c +++ b/cmd-find.c @@ -873,22 +873,23 @@ cmd_find_target(struct cmd_find_state *fs, struct cmd_q *cmdq, log_debug("%s: target %s, type %d", __func__, target, type); log_debug("%s: cmdq %p, flags %#x", __func__, cmdq, flags); + /* Clear new state. */ + cmd_find_clear_state(fs, cmdq, flags); + /* Find current state. */ - cmd_find_clear_state(¤t, cmdq, flags); + fs->current = NULL; if (server_check_marked() && (flags & CMD_FIND_DEFAULT_MARKED)) - cmd_find_copy_state(¤t, &marked_pane); - else { + fs->current = &marked_pane; + if (fs->current == NULL) { + cmd_find_clear_state(¤t, cmdq, flags); if (cmd_find_current_session(¤t) != 0) { if (~flags & CMD_FIND_QUIET) cmdq_error(cmdq, "no current session"); goto error; } + fs->current = ¤t; } - /* Clear new state. */ - cmd_find_clear_state(fs, cmdq, flags); - fs->current = ¤t; - /* An empty or NULL target is the current. */ if (target == NULL || *target == '\0') goto current; @@ -1087,9 +1088,9 @@ cmd_find_target(struct cmd_find_state *fs, struct cmd_q *cmdq, current: /* Use the current session. */ + cmd_find_copy_state(fs, fs->current); if (flags & CMD_FIND_WINDOW_INDEX) - current.idx = -1; - memcpy(fs, ¤t, sizeof *fs); + fs->idx = -1; goto found; error: -- cgit From 6f417ec9438de4440522483be02c51803d628313 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 15 Dec 2015 00:45:02 +0000 Subject: We changed somewhat recently to us the pty when tmux was run inside itself to work out the current pane. This is confusing in many cases (particularly notable is that "tmux neww\; splitw" would not split the new window), and the few advantages do not make up for the confusion. So drop this behaviour and return to using the current window and pane; keep the pty check but only use it to limit the list of possible current sessions. --- cmd-find.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'cmd-find.c') diff --git a/cmd-find.c b/cmd-find.c index ea1389a9..dbfe99ef 100644 --- a/cmd-find.c +++ b/cmd-find.c @@ -249,7 +249,11 @@ cmd_find_current_session_with_client(struct cmd_find_state *fs) { struct window_pane *wp; - /* If this is running in a pane, that's great. */ + /* + * If this is running in a pane, we can use that to limit the list of + * sessions to those containing that pane (we still use the current + * window in the best session). + */ if (fs->cmdq->client->tty.path != NULL) { RB_FOREACH(wp, window_pane_tree, &all_window_panes) { if (strcmp(wp->tty, fs->cmdq->client->tty.path) == 0) @@ -262,11 +266,8 @@ cmd_find_current_session_with_client(struct cmd_find_state *fs) if (wp == NULL) goto unknown_pane; - /* We now know the window and pane. */ + /* Find the best session and winlink containing this pane. */ fs->w = wp->window; - fs->wp = wp; - - /* Find the best session and winlink. */ if (cmd_find_best_session_with_window(fs) != 0) { if (wp != NULL) { /* @@ -278,6 +279,13 @@ cmd_find_current_session_with_client(struct cmd_find_state *fs) } return (-1); } + + /* Use the current window and pane from this session. */ + fs->wl = fs->s->curw; + fs->idx = fs->wl->idx; + fs->w = fs->wl->window; + fs->wp = fs->w->active; + return (0); unknown_pane: @@ -290,6 +298,7 @@ unknown_pane: fs->idx = fs->wl->idx; fs->w = fs->wl->window; fs->wp = fs->w->active; + return (0); } -- cgit