summaryrefslogtreecommitdiffstats
path: root/cmd-find.c
diff options
context:
space:
mode:
authornicm <nicm>2015-12-16 21:50:37 +0000
committernicm <nicm>2015-12-16 21:50:37 +0000
commit021c64310daa4ae4c4e8af08f17c994f21237758 (patch)
tree7f0556b343bba058dec19c87c8f52f215cdbd2eb /cmd-find.c
parent8eb1a7d5dc8d66ca7d17c72e4d8d0e58d6fd2824 (diff)
Add infrastructure to work out the best target given a pane or window
alone and use it to add pane_died and pane_exited hooks.
Diffstat (limited to 'cmd-find.c')
-rw-r--r--cmd-find.c53
1 files changed, 49 insertions, 4 deletions
diff --git a/cmd-find.c b/cmd-find.c
index cf39240a..15dfa596 100644
--- a/cmd-find.c
+++ b/cmd-find.c
@@ -190,7 +190,7 @@ cmd_find_best_session_with_window(struct cmd_find_state *fs)
u_int ssize;
struct session *s;
- if (fs->cmdq->client != NULL) {
+ if (fs->cmdq != NULL && fs->cmdq->client != NULL) {
fs->s = cmd_find_try_TMUX(fs->cmdq->client, fs->w);
if (fs->s != NULL)
return (cmd_find_best_winlink_with_window(fs));
@@ -254,7 +254,7 @@ cmd_find_current_session_with_client(struct cmd_find_state *fs)
* sessions to those containing that pane (we still use the current
* window in the best session).
*/
- if (fs->cmdq->client->tty.path != NULL) {
+ if (fs->cmdq != NULL && 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)
break;
@@ -289,7 +289,9 @@ cmd_find_current_session_with_client(struct cmd_find_state *fs)
return (0);
unknown_pane:
- fs->s = cmd_find_try_TMUX(fs->cmdq->client, NULL);
+ fs->s = NULL;
+ if (fs->cmdq != NULL)
+ fs->s = cmd_find_try_TMUX(fs->cmdq->client, NULL);
if (fs->s == NULL)
fs->s = cmd_find_best_session(NULL, 0, fs->flags);
if (fs->s == NULL)
@@ -310,7 +312,7 @@ int
cmd_find_current_session(struct cmd_find_state *fs)
{
/* If we know the current client, use it. */
- if (fs->cmdq->client != NULL) {
+ if (fs->cmdq != NULL && fs->cmdq->client != NULL) {
log_debug("%s: have client %p%s", __func__, fs->cmdq->client,
fs->cmdq->client->session == NULL ? "" : " (with session)");
if (fs->cmdq->client->session == NULL)
@@ -862,6 +864,49 @@ cmd_find_log_state(const char *prefix, struct cmd_find_state *fs)
log_debug("%s: idx=none", prefix);
}
+/* Find state from a session. */
+int
+cmd_find_from_session(struct cmd_find_state *fs, struct session *s)
+{
+ cmd_find_clear_state(fs, NULL, 0);
+
+ fs->s = s;
+ fs->wl = fs->s->curw;
+ fs->w = fs->wl->window;
+ fs->wp = fs->w->active;
+
+ cmd_find_log_state(__func__, fs);
+ return (0);
+}
+
+/* Find state from a window. */
+int
+cmd_find_from_window(struct cmd_find_state *fs, struct window *w)
+{
+ cmd_find_clear_state(fs, NULL, 0);
+
+ fs->w = w;
+ if (cmd_find_best_session_with_window(fs) != 0)
+ return (-1);
+ if (cmd_find_best_winlink_with_window(fs) != 0)
+ return (-1);
+
+ cmd_find_log_state(__func__, fs);
+ return (0);
+}
+
+/* Find state from a pane. */
+int
+cmd_find_from_pane(struct cmd_find_state *fs, struct window_pane *wp)
+{
+ if (cmd_find_from_window(fs, wp->window) != 0)
+ return (-1);
+ fs->wp = wp;
+
+ cmd_find_log_state(__func__, fs);
+ return (0);
+}
+
/*
* Split target into pieces and resolve for the given type. Fills in the given
* state. Returns 0 on success or -1 on error.