Skip to content

Commit

Permalink
Pass flags into cmd_find_from_* to fix prefer-unattached, reported by
Browse files Browse the repository at this point in the history
Thomas Sattler.
  • Loading branch information
nicm committed Aug 30, 2017
1 parent a7d1ee5 commit 17cf1b2
Show file tree
Hide file tree
Showing 17 changed files with 71 additions and 69 deletions.
4 changes: 2 additions & 2 deletions cmd-attach-session.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,
window_set_active_pane(wp->window, wp);
session_set_current(s, wl);
if (wp != NULL)
cmd_find_from_winlink_pane(current, wl, wp);
cmd_find_from_winlink_pane(current, wl, wp, 0);
else
cmd_find_from_winlink(current, wl);
cmd_find_from_winlink(current, wl, 0);
}

if (cflag != NULL) {
Expand Down
2 changes: 1 addition & 1 deletion cmd-break-pane.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
wl = session_attach(dst_s, w, idx, &cause); /* can't fail */
if (!args_has(self->args, 'd')) {
session_select(dst_s, wl->idx);
cmd_find_from_session(current, dst_s);
cmd_find_from_session(current, dst_s, 0);
}

server_redraw_session(src_s);
Expand Down
58 changes: 29 additions & 29 deletions cmd-find.c
Original file line number Diff line number Diff line change
Expand Up @@ -728,9 +728,9 @@ cmd_find_log_state(const char *prefix, struct cmd_find_state *fs)

/* Find state from a session. */
void
cmd_find_from_session(struct cmd_find_state *fs, struct session *s)
cmd_find_from_session(struct cmd_find_state *fs, struct session *s, int flags)
{
cmd_find_clear_state(fs, 0);
cmd_find_clear_state(fs, flags);

fs->s = s;
fs->wl = fs->s->curw;
Expand All @@ -742,9 +742,9 @@ cmd_find_from_session(struct cmd_find_state *fs, struct session *s)

/* Find state from a winlink. */
void
cmd_find_from_winlink(struct cmd_find_state *fs, struct winlink *wl)
cmd_find_from_winlink(struct cmd_find_state *fs, struct winlink *wl, int flags)
{
cmd_find_clear_state(fs, 0);
cmd_find_clear_state(fs, flags);

fs->s = wl->session;
fs->wl = wl;
Expand All @@ -757,14 +757,14 @@ cmd_find_from_winlink(struct cmd_find_state *fs, struct winlink *wl)
/* Find state from a session and window. */
int
cmd_find_from_session_window(struct cmd_find_state *fs, struct session *s,
struct window *w)
struct window *w, int flags)
{
cmd_find_clear_state(fs, 0);
cmd_find_clear_state(fs, flags);

fs->s = s;
fs->w = w;
if (cmd_find_best_winlink_with_window(fs) != 0) {
cmd_find_clear_state(fs, 0);
cmd_find_clear_state(fs, flags);
return (-1);
}
fs->wp = fs->w->active;
Expand All @@ -775,17 +775,17 @@ cmd_find_from_session_window(struct cmd_find_state *fs, struct session *s,

/* Find state from a window. */
int
cmd_find_from_window(struct cmd_find_state *fs, struct window *w)
cmd_find_from_window(struct cmd_find_state *fs, struct window *w, int flags)
{
cmd_find_clear_state(fs, 0);
cmd_find_clear_state(fs, flags);

fs->w = w;
if (cmd_find_best_session_with_window(fs) != 0) {
cmd_find_clear_state(fs, 0);
cmd_find_clear_state(fs, flags);
return (-1);
}
if (cmd_find_best_winlink_with_window(fs) != 0) {
cmd_find_clear_state(fs, 0);
cmd_find_clear_state(fs, flags);
return (-1);
}
fs->wp = fs->w->active;
Expand All @@ -797,9 +797,9 @@ cmd_find_from_window(struct cmd_find_state *fs, struct window *w)
/* Find state from a winlink and pane. */
void
cmd_find_from_winlink_pane(struct cmd_find_state *fs, struct winlink *wl,
struct window_pane *wp)
struct window_pane *wp, int flags)
{
cmd_find_clear_state(fs, 0);
cmd_find_clear_state(fs, flags);

fs->s = wl->session;
fs->wl = wl;
Expand All @@ -812,9 +812,9 @@ cmd_find_from_winlink_pane(struct cmd_find_state *fs, struct winlink *wl,

/* Find state from a pane. */
int
cmd_find_from_pane(struct cmd_find_state *fs, struct window_pane *wp)
cmd_find_from_pane(struct cmd_find_state *fs, struct window_pane *wp, int flags)
{
if (cmd_find_from_window(fs, wp->window) != 0)
if (cmd_find_from_window(fs, wp->window, flags) != 0)
return (-1);
fs->wp = wp;

Expand All @@ -824,13 +824,13 @@ cmd_find_from_pane(struct cmd_find_state *fs, struct window_pane *wp)

/* Find state from nothing. */
int
cmd_find_from_nothing(struct cmd_find_state *fs)
cmd_find_from_nothing(struct cmd_find_state *fs, int flags)
{
cmd_find_clear_state(fs, 0);
cmd_find_clear_state(fs, flags);

fs->s = cmd_find_best_session(NULL, 0, fs->flags);
fs->s = cmd_find_best_session(NULL, 0, flags);
if (fs->s == NULL) {
cmd_find_clear_state(fs, 0);
cmd_find_clear_state(fs, flags);
return (-1);
}
fs->wl = fs->s->curw;
Expand All @@ -844,16 +844,16 @@ cmd_find_from_nothing(struct cmd_find_state *fs)

/* Find state from mouse. */
int
cmd_find_from_mouse(struct cmd_find_state *fs, struct mouse_event *m)
cmd_find_from_mouse(struct cmd_find_state *fs, struct mouse_event *m, int flags)
{
cmd_find_clear_state(fs, 0);
cmd_find_clear_state(fs, flags);

if (!m->valid)
return (-1);

fs->wp = cmd_mouse_pane(m, &fs->s, &fs->wl);
if (fs->wp == NULL) {
cmd_find_clear_state(fs, 0);
cmd_find_clear_state(fs, flags);
return (-1);
}
fs->w = fs->wl->window;
Expand All @@ -864,22 +864,22 @@ cmd_find_from_mouse(struct cmd_find_state *fs, struct mouse_event *m)

/* Find state from client. */
int
cmd_find_from_client(struct cmd_find_state *fs, struct client *c)
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. */
if (c == NULL)
return (cmd_find_from_nothing(fs));
return (cmd_find_from_nothing(fs, flags));

/* If this is an attached client, all done. */
if (c->session != NULL) {
cmd_find_from_session(fs, c->session);
cmd_find_from_session(fs, c->session, flags);
return (0);
}
cmd_find_clear_state(fs, 0);
cmd_find_clear_state(fs, flags);

/*
* If this is an unattached client running in a pane, we can use that
Expand Down Expand Up @@ -938,12 +938,12 @@ cmd_find_from_client(struct cmd_find_state *fs, struct client *c)
*/
s = cmd_find_try_TMUX(c);
if (s != NULL) {
cmd_find_from_session(fs, s);
cmd_find_from_session(fs, s, flags);
return (0);
}

/* Otherwise we need to guess. */
return (cmd_find_from_nothing(fs));
return (cmd_find_from_nothing(fs, flags));
}

/*
Expand Down Expand Up @@ -989,7 +989,7 @@ cmd_find_target(struct cmd_find_state *fs, struct cmdq_item *item,
} else if (cmd_find_valid_state(&item->shared->current)) {
fs->current = &item->shared->current;
log_debug("%s: current is from queue", __func__);
} else if (cmd_find_from_client(&current, item->client) == 0) {
} else if (cmd_find_from_client(&current, item->client, flags) == 0) {
fs->current = &current;
log_debug("%s: current is from client", __func__);
} else {
Expand Down
2 changes: 1 addition & 1 deletion cmd-join-pane.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
if (!args_has(args, 'd')) {
window_set_active_pane(dst_w, src_wp);
session_select(dst_s, dst_idx);
cmd_find_from_session(current, dst_s);
cmd_find_from_session(current, dst_s, 0);
server_redraw_session(dst_s);
} else
server_status_session(dst_s);
Expand Down
4 changes: 2 additions & 2 deletions cmd-new-session.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,10 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)

if (!detached) {
c->flags |= CLIENT_ATTACHED;
cmd_find_from_session(&item->shared->current, s);
cmd_find_from_session(&item->shared->current, s, 0);
}

cmd_find_from_session(&fs, s);
cmd_find_from_session(&fs, s, 0);
hooks_insert(s->hooks, item, &fs, "after-new-session");

free(to_free);
Expand Down
4 changes: 2 additions & 2 deletions cmd-new-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
}
if (!detached) {
session_select(s, wl->idx);
cmd_find_from_winlink(current, wl);
cmd_find_from_winlink(current, wl, 0);
server_redraw_session_group(s);
} else
server_status_session_group(s);
Expand All @@ -146,7 +146,7 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
free(cp);
}

cmd_find_from_winlink(&fs, wl);
cmd_find_from_winlink(&fs, wl, 0);
hooks_insert(s->hooks, item, &fs, "after-new-window");

free(to_free);
Expand Down
2 changes: 1 addition & 1 deletion cmd-queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ cmdq_fire_command(struct cmdq_item *item)
fsp = &item->target;
else if (cmd_find_valid_state(&item->shared->current))
fsp = &item->shared->current;
else if (cmd_find_from_client(&fs, item->client) == 0)
else if (cmd_find_from_client(&fs, item->client, 0) == 0)
fsp = &fs;
else
goto out;
Expand Down
4 changes: 2 additions & 2 deletions cmd-rotate-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ cmd_rotate_window_exec(struct cmd *self, struct cmdq_item *item)
if ((wp = TAILQ_PREV(w->active, window_panes, entry)) == NULL)
wp = TAILQ_LAST(&w->panes, window_panes);
window_set_active_pane(w, wp);
cmd_find_from_winlink_pane(current, wl, wp);
cmd_find_from_winlink_pane(current, wl, wp, 0);
server_redraw_window(w);
} else {
wp = TAILQ_FIRST(&w->panes);
Expand Down Expand Up @@ -106,7 +106,7 @@ cmd_rotate_window_exec(struct cmd *self, struct cmdq_item *item)
if ((wp = TAILQ_NEXT(w->active, entry)) == NULL)
wp = TAILQ_FIRST(&w->panes);
window_set_active_pane(w, wp);
cmd_find_from_winlink_pane(current, wl, wp);
cmd_find_from_winlink_pane(current, wl, wp, 0);
server_redraw_window(w);
}

Expand Down
2 changes: 1 addition & 1 deletion cmd-run-shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ cmd_run_shell_print(struct job *job, const char *msg)
cmdq_print(cdata->item, "%s", msg);
return;
}
if (cmd_find_from_nothing(&fs) != 0)
if (cmd_find_from_nothing(&fs, 0) != 0)
return;
wp = fs.wp;
if (wp == NULL)
Expand Down
4 changes: 2 additions & 2 deletions cmd-select-pane.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
server_unzoom_window(w);
window_redraw_active_switch(w, lastwp);
if (window_set_active_pane(w, lastwp)) {
cmd_find_from_winlink(current, wl);
cmd_find_from_winlink(current, wl, 0);
server_status_window(w);
server_redraw_window_borders(w);
}
Expand Down Expand Up @@ -156,7 +156,7 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
}
window_redraw_active_switch(w, wp);
if (window_set_active_pane(w, wp)) {
cmd_find_from_winlink_pane(current, wl, wp);
cmd_find_from_winlink_pane(current, wl, wp, 0);
hooks_insert(s->hooks, item, current, "after-select-pane");
server_status_window(w);
server_redraw_window_borders(w);
Expand Down
6 changes: 3 additions & 3 deletions cmd-select-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ cmd_select_window_exec(struct cmd *self, struct cmdq_item *item)
return (CMD_RETURN_ERROR);
}
}
cmd_find_from_session(current, s);
cmd_find_from_session(current, s, 0);
server_redraw_session(s);
hooks_insert(s->hooks, item, current, "after-select-window");
} else {
Expand All @@ -131,10 +131,10 @@ cmd_select_window_exec(struct cmd *self, struct cmdq_item *item)
return (-1);
}
if (current->s == s)
cmd_find_from_session(current, s);
cmd_find_from_session(current, s, 0);
server_redraw_session(s);
} else if (session_select(s, wl->idx) == 0) {
cmd_find_from_session(current, s);
cmd_find_from_session(current, s, 0);
server_redraw_session(s);
}
hooks_insert(s->hooks, item, current, "after-select-window");
Expand Down
4 changes: 2 additions & 2 deletions cmd-split-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
if (!args_has(args, 'd')) {
window_set_active_pane(w, new_wp);
session_select(s, wl->idx);
cmd_find_from_session(current, s);
cmd_find_from_session(current, s, 0);
server_redraw_session(s);
} else
server_status_session(s);
Expand All @@ -172,7 +172,7 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
}
notify_window("window-layout-changed", w);

cmd_find_from_winlink_pane(&fs, wl, new_wp);
cmd_find_from_winlink_pane(&fs, wl, new_wp, 0);
hooks_insert(s->hooks, item, &fs, "after-split-window");

free(to_free);
Expand Down
2 changes: 1 addition & 1 deletion cmd-switch-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item)
if (wp != NULL)
window_set_active_pane(wp->window, wp);
session_set_current(s, wl);
cmd_find_from_session(&item->shared->current, s);
cmd_find_from_session(&item->shared->current, s, 0);
}
}

Expand Down
Loading

0 comments on commit 17cf1b2

Please sign in to comment.