diff options
author | Thomas Adam <thomas@xteddy.org> | 2015-10-25 09:21:37 +0000 |
---|---|---|
committer | Thomas Adam <thomas@xteddy.org> | 2015-10-25 09:21:37 +0000 |
commit | 4acc8d0ff5d99fadd1ef91a3898f561dec5adfb7 (patch) | |
tree | fcccdefa5179eaa064f129ab44a229e284a934b4 /cmd-find.c | |
parent | 8c3981366574f5c6496985e0127ca817f3d70037 (diff) | |
parent | 2e2b8a95bd13dab848a61113c9974c9ac936f9d6 (diff) | |
download | rtmux-4acc8d0ff5d99fadd1ef91a3898f561dec5adfb7.tar.gz rtmux-4acc8d0ff5d99fadd1ef91a3898f561dec5adfb7.tar.bz2 rtmux-4acc8d0ff5d99fadd1ef91a3898f561dec5adfb7.zip |
Merge branch 'obsd-master'
Conflicts:
cmd-find.c
Diffstat (limited to 'cmd-find.c')
-rw-r--r-- | cmd-find.c | 38 |
1 files changed, 37 insertions, 1 deletions
@@ -50,6 +50,7 @@ struct cmd_find_state { int idx; }; +struct session *cmd_find_try_TMUX(struct client *, struct window *); int cmd_find_client_better(struct client *, struct client *); struct client *cmd_find_best_client(struct client **, u_int); int cmd_find_session_better(struct session *, struct session *, @@ -108,6 +109,33 @@ const char *cmd_find_pane_table[][2] = { { NULL, NULL } }; +/* Get session from TMUX if present. */ +struct session * +cmd_find_try_TMUX(struct client *c, struct window *w) +{ + 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("client %d TMUX is %s (session @%u)", c->ibuf.fd, + envent->value, session); + + s = session_find_by_id(session); + if (s == NULL || (w != NULL && !session_has(s, w))) + return (NULL); + return (s); +} + /* Is this client better? */ int cmd_find_client_better(struct client *c, struct client *than) @@ -191,6 +219,12 @@ cmd_find_best_session_with_window(struct cmd_find_state *fs) u_int ssize; struct session *s; + if (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)); + } + ssize = 0; RB_FOREACH(s, sessions, &sessions) { if (!session_has(s, fs->w)) @@ -276,7 +310,9 @@ cmd_find_current_session_with_client(struct cmd_find_state *fs) return (0); unknown_pane: - fs->s = cmd_find_best_session(NULL, 0, fs->flags); + 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) return (-1); fs->wl = fs->s->curw; |