From 9d42bd328c094c679415c623f7a87c200b64984e Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 12 Jun 2019 08:08:33 +0000 Subject: Do not always resize the window back to its original size after applying a layout, let the normal window resize process do it. This means windows are not resized at all if window-size is manual, and are not resized multiple times if later attached to a different size terminal. --- layout-custom.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/layout-custom.c b/layout-custom.c index 9886afe1..4d9e818b 100644 --- a/layout-custom.c +++ b/layout-custom.c @@ -168,10 +168,7 @@ layout_parse(struct window *w, const char *layout) /* Update pane offsets and sizes. */ layout_fix_offsets(lc); layout_fix_panes(w); - - /* Then resize the layout back to the original window size. */ - layout_resize(w, sx, sy); - window_resize(w, sx, sy); + recalculate_sizes(); layout_print_cell(lc, __func__, 0); -- cgit From b12df0186139bb4761292629871205dc46d4c302 Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 12 Jun 2019 08:47:07 +0000 Subject: Pass target on to new commands with if -F. --- cmd-if-shell.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cmd-if-shell.c b/cmd-if-shell.c index 84f66657..f795575a 100644 --- a/cmd-if-shell.c +++ b/cmd-if-shell.c @@ -67,10 +67,11 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item) struct cmd_if_shell_data *cdata; char *shellcmd, *cmd; struct cmdq_item *new_item; + struct cmd_find_state *fs = &item->target; struct client *c = cmd_find_client(item, NULL, 1); - struct session *s = item->target.s; - struct winlink *wl = item->target.wl; - struct window_pane *wp = item->target.wp; + struct session *s = fs->s; + struct winlink *wl = fs->wl; + struct window_pane *wp = fs->wp; struct cmd_parse_input pi; struct cmd_parse_result *pr; @@ -92,7 +93,7 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item) pi.line = self->line; pi.item = item; pi.c = c; - cmd_find_copy_state(&pi.fs, &item->target); + cmd_find_copy_state(&pi.fs, fs); pr = cmd_parse_from_string(cmd, &pi); switch (pr->status) { @@ -103,7 +104,7 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item) free(pr->error); return (CMD_RETURN_ERROR); case CMD_PARSE_SUCCESS: - new_item = cmdq_get_command(pr->cmdlist, NULL, m, 0); + new_item = cmdq_get_command(pr->cmdlist, fs, m, 0); cmdq_insert_after(item, new_item); cmd_list_free(pr->cmdlist); break; @@ -137,7 +138,7 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item) cdata->input.c = c; if (cdata->input.c != NULL) cdata->input.c->references++; - cmd_find_copy_state(&cdata->input.fs, &item->target); + cmd_find_copy_state(&cdata->input.fs, fs); if (job_run(shellcmd, s, server_client_get_cwd(item->client, s), NULL, cmd_if_shell_callback, cmd_if_shell_free, cdata, 0) == NULL) { -- cgit From 7e6a26cc9d857ffc53fdb2395aa5413ff1865f9e Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 12 Jun 2019 09:10:29 +0000 Subject: Do not use $TMUX to find the session because for windows in multiple sessions it is wrong as often as it is right, and for windows in one session it is pointless. Instead check TMUX_PANE to find the pane and look for the MRU session as usual. GitHub issue 1793. --- cmd-find.c | 73 ++++++++------------------------------------------------------ 1 file changed, 9 insertions(+), 64 deletions(-) diff --git a/cmd-find.c b/cmd-find.c index e5ef8b99..e3e14f55 100644 --- a/cmd-find.c +++ b/cmd-find.c @@ -76,38 +76,12 @@ static const char *cmd_find_pane_table[][2] = { { NULL, NULL } }; -/* Get session from TMUX if present. */ -static struct session * -cmd_find_try_TMUX(struct client *c) -{ - struct environ_entry *envent; - char tmp[256]; - long long pid; - u_int session; - struct session *s; - - envent = environ_find(c->environ, "TMUX"); - if (envent == NULL) - return (NULL); - - if (sscanf(envent->value, "%255[^,],%lld,%d", tmp, &pid, &session) != 3) - return (NULL); - if (pid != getpid()) - return (NULL); - log_debug("%s: client %p TMUX %s (session $%u)", __func__, c, - envent->value, session); - - s = session_find_by_id(session); - if (s != NULL) - log_debug("%s: session $%u still exists", __func__, s->id); - return (s); -} - /* Find pane containing client if any. */ static struct window_pane * cmd_find_inside_pane(struct client *c) { struct window_pane *wp; + struct environ_entry *envent; if (c == NULL) return (NULL); @@ -116,6 +90,11 @@ cmd_find_inside_pane(struct client *c) if (wp->fd != -1 && strcmp(wp->tty, c->ttyname) == 0) break; } + if (wp == NULL) { + envent = environ_find(c->environ, "TMUX_PANE"); + if (envent != NULL) + wp = window_pane_find_by_id_str(envent->value); + } if (wp != NULL) log_debug("%s: got pane %%%u (%s)", __func__, wp->id, wp->tty); return (wp); @@ -880,8 +859,6 @@ cmd_find_from_mouse(struct cmd_find_state *fs, struct mouse_event *m, int flags) int cmd_find_from_client(struct cmd_find_state *fs, struct client *c, int flags) { - struct session *s; - struct winlink *wl; struct window_pane *wp; /* If no client, treat as from nothing. */ @@ -903,30 +880,6 @@ cmd_find_from_client(struct cmd_find_state *fs, struct client *c, int flags) if (wp == NULL) goto unknown_pane; - /* If we have a session in TMUX, see if it has this pane. */ - s = cmd_find_try_TMUX(c); - if (s != NULL) { - RB_FOREACH(wl, winlinks, &s->windows) { - if (window_has_pane(wl->window, wp)) - break; - } - if (wl != NULL) { - log_debug("%s: session $%u has pane %%%u", __func__, - s->id, wp->id); - - fs->s = s; - fs->wl = s->curw; /* use current session */ - fs->w = fs->wl->window; - fs->wp = fs->w->active; /* use active pane */ - - cmd_find_log_state(__func__, fs); - return (0); - } else { - log_debug("%s: session $%u does not have pane %%%u", - __func__, s->id, wp->id); - } - } - /* * Don't have a session, or it doesn't have this pane. Try all * sessions. @@ -948,17 +901,7 @@ cmd_find_from_client(struct cmd_find_state *fs, struct client *c, int flags) return (0); unknown_pane: - /* - * We're not running in a known pane, but maybe this client has TMUX - * in the environment. That'd give us a session. - */ - s = cmd_find_try_TMUX(c); - if (s != NULL) { - cmd_find_from_session(fs, s, flags); - return (0); - } - - /* Otherwise we need to guess. */ + /* We can't find the pane so need to guess. */ return (cmd_find_from_nothing(fs, flags)); } @@ -1006,6 +949,8 @@ cmd_find_target(struct cmd_find_state *fs, struct cmdq_item *item, strlcat(tmp, "CANFAIL,", sizeof tmp); if (*tmp != '\0') tmp[strlen(tmp) - 1] = '\0'; + else + strlcat(tmp, "NONE", sizeof tmp); log_debug("%s: target %s, type %s, item %p, flags %s", __func__, target == NULL ? "none" : target, s, item, tmp); -- cgit