version 1.36, 2016/10/16 17:55:14 |
version 1.37, 2016/10/16 19:04:05 |
|
|
|
|
static int cmd_find_current_session_with_client(struct cmd_find_state *); |
static int cmd_find_current_session_with_client(struct cmd_find_state *); |
static int cmd_find_current_session(struct cmd_find_state *); |
static int cmd_find_current_session(struct cmd_find_state *); |
static struct client *cmd_find_current_client(struct cmd_q *); |
static struct client *cmd_find_current_client(struct cmdq_item *); |
|
|
static const char *cmd_find_map_table(const char *[][2], const char *); |
static const char *cmd_find_map_table(const char *[][2], const char *); |
|
|
|
|
u_int ssize; |
u_int ssize; |
struct session *s; |
struct session *s; |
|
|
if (fs->cmdq != NULL && fs->cmdq->client != NULL) { |
if (fs->item != NULL && fs->item->client != NULL) { |
fs->s = cmd_find_try_TMUX(fs->cmdq->client, fs->w); |
fs->s = cmd_find_try_TMUX(fs->item->client, fs->w); |
if (fs->s != NULL) |
if (fs->s != NULL) |
return (cmd_find_best_winlink_with_window(fs)); |
return (cmd_find_best_winlink_with_window(fs)); |
} |
} |
|
|
* sessions to those containing that pane (we still use the current |
* sessions to those containing that pane (we still use the current |
* window in the best session). |
* window in the best session). |
*/ |
*/ |
if (fs->cmdq != NULL && fs->cmdq->client->tty.path != NULL) { |
if (fs->item != NULL && fs->item->client->tty.path != NULL) { |
RB_FOREACH(wp, window_pane_tree, &all_window_panes) { |
RB_FOREACH(wp, window_pane_tree, &all_window_panes) { |
if (strcmp(wp->tty, fs->cmdq->client->tty.path) == 0) |
if (strcmp(wp->tty, fs->item->client->tty.path) == 0) |
break; |
break; |
} |
} |
} else |
} else |
|
|
|
|
unknown_pane: |
unknown_pane: |
fs->s = NULL; |
fs->s = NULL; |
if (fs->cmdq != NULL) |
if (fs->item != NULL) |
fs->s = cmd_find_try_TMUX(fs->cmdq->client, NULL); |
fs->s = cmd_find_try_TMUX(fs->item->client, NULL); |
if (fs->s == NULL) |
if (fs->s == NULL) |
fs->s = cmd_find_best_session(NULL, 0, fs->flags); |
fs->s = cmd_find_best_session(NULL, 0, fs->flags); |
if (fs->s == NULL) |
if (fs->s == NULL) |
|
|
cmd_find_current_session(struct cmd_find_state *fs) |
cmd_find_current_session(struct cmd_find_state *fs) |
{ |
{ |
/* If we know the current client, use it. */ |
/* If we know the current client, use it. */ |
if (fs->cmdq != NULL && fs->cmdq->client != NULL) { |
if (fs->item != NULL && fs->item->client != NULL) { |
log_debug("%s: have client %p%s", __func__, fs->cmdq->client, |
log_debug("%s: have client %p%s", __func__, fs->item->client, |
fs->cmdq->client->session == NULL ? "" : " (with session)"); |
fs->item->client->session == NULL ? "" : " (with session)"); |
if (fs->cmdq->client->session == NULL) |
if (fs->item->client->session == NULL) |
return (cmd_find_current_session_with_client(fs)); |
return (cmd_find_current_session_with_client(fs)); |
fs->s = fs->cmdq->client->session; |
fs->s = fs->item->client->session; |
fs->wl = fs->s->curw; |
fs->wl = fs->s->curw; |
fs->idx = fs->wl->idx; |
fs->idx = fs->wl->idx; |
fs->w = fs->wl->window; |
fs->w = fs->wl->window; |
|
|
|
|
/* Work out the best current client. */ |
/* Work out the best current client. */ |
static struct client * |
static struct client * |
cmd_find_current_client(struct cmd_q *cmdq) |
cmd_find_current_client(struct cmdq_item *item) |
{ |
{ |
struct cmd_find_state current; |
struct cmd_find_state current; |
struct session *s; |
struct session *s; |
|
|
u_int csize; |
u_int csize; |
|
|
/* If the queue client has a session, use it. */ |
/* If the queue client has a session, use it. */ |
if (cmdq->client != NULL && cmdq->client->session != NULL) { |
if (item->client != NULL && item->client->session != NULL) { |
log_debug("%s: using cmdq %p client %p", __func__, cmdq, |
log_debug("%s: using item %p client %p", __func__, item, |
cmdq->client); |
item->client); |
return (cmdq->client); |
return (item->client); |
} |
} |
|
|
/* Otherwise find the current session. */ |
/* Otherwise find the current session. */ |
cmd_find_clear_state(¤t, cmdq, 0); |
cmd_find_clear_state(¤t, item, 0); |
if (cmd_find_current_session(¤t) != 0) |
if (cmd_find_current_session(¤t) != 0) |
return (NULL); |
return (NULL); |
|
|
|
|
|
|
/* Clear state. */ |
/* Clear state. */ |
void |
void |
cmd_find_clear_state(struct cmd_find_state *fs, struct cmd_q *cmdq, int flags) |
cmd_find_clear_state(struct cmd_find_state *fs, struct cmdq_item *item, |
|
int flags) |
{ |
{ |
memset(fs, 0, sizeof *fs); |
memset(fs, 0, sizeof *fs); |
|
|
fs->cmdq = cmdq; |
fs->item = item; |
fs->flags = flags; |
fs->flags = flags; |
|
|
fs->idx = -1; |
fs->idx = -1; |
|
|
|
|
/* Find current state. */ |
/* Find current state. */ |
int |
int |
cmd_find_current(struct cmd_find_state *fs, struct cmd_q *cmdq, int flags) |
cmd_find_current(struct cmd_find_state *fs, struct cmdq_item *item, int flags) |
{ |
{ |
cmd_find_clear_state(fs, cmdq, flags); |
cmd_find_clear_state(fs, item, flags); |
if (cmd_find_current_session(fs) != 0) { |
if (cmd_find_current_session(fs) != 0) { |
if (~flags & CMD_FIND_QUIET) |
if (~flags & CMD_FIND_QUIET) |
cmdq_error(cmdq, "no current session"); |
cmdq_error(item, "no current session"); |
return (-1); |
return (-1); |
} |
} |
return (0); |
return (0); |
|
|
*/ |
*/ |
int |
int |
cmd_find_target(struct cmd_find_state *fs, struct cmd_find_state *current, |
cmd_find_target(struct cmd_find_state *fs, struct cmd_find_state *current, |
struct cmd_q *cmdq, const char *target, enum cmd_find_type type, int flags) |
struct cmdq_item *item, const char *target, enum cmd_find_type type, |
|
int flags) |
{ |
{ |
struct mouse_event *m; |
struct mouse_event *m; |
char *colon, *period, *copy = NULL; |
char *colon, *period, *copy = NULL; |
|
|
log_debug("%s: target none, type %d", __func__, type); |
log_debug("%s: target none, type %d", __func__, type); |
else |
else |
log_debug("%s: target %s, type %d", __func__, target, type); |
log_debug("%s: target %s, type %d", __func__, target, type); |
log_debug("%s: cmdq %p, flags %#x", __func__, cmdq, flags); |
log_debug("%s: item %p, flags %#x", __func__, item, flags); |
|
|
/* Clear new state. */ |
/* Clear new state. */ |
cmd_find_clear_state(fs, cmdq, flags); |
cmd_find_clear_state(fs, item, flags); |
|
|
/* Find current state. */ |
/* Find current state. */ |
if (server_check_marked() && (flags & CMD_FIND_DEFAULT_MARKED)) { |
if (server_check_marked() && (flags & CMD_FIND_DEFAULT_MARKED)) { |
fs->current = &marked_pane; |
fs->current = &marked_pane; |
log_debug(" current is marked pane"); |
log_debug(" current is marked pane"); |
} else if (cmd_find_valid_state(&cmdq->current)) { |
} else if (cmd_find_valid_state(&item->current)) { |
fs->current = &cmdq->current; |
fs->current = &item->current; |
log_debug(" current is from queue"); |
log_debug(" current is from queue"); |
} else { |
} else { |
fs->current = current; |
fs->current = current; |
|
|
|
|
/* Mouse target is a plain = or {mouse}. */ |
/* Mouse target is a plain = or {mouse}. */ |
if (strcmp(target, "=") == 0 || strcmp(target, "{mouse}") == 0) { |
if (strcmp(target, "=") == 0 || strcmp(target, "{mouse}") == 0) { |
m = &cmdq->mouse; |
m = &item->mouse; |
switch (type) { |
switch (type) { |
case CMD_FIND_PANE: |
case CMD_FIND_PANE: |
fs->wp = cmd_mouse_pane(m, &fs->s, &fs->wl); |
fs->wp = cmd_mouse_pane(m, &fs->s, &fs->wl); |
|
|
} |
} |
if (fs->wp == NULL) { |
if (fs->wp == NULL) { |
if (~flags & CMD_FIND_QUIET) |
if (~flags & CMD_FIND_QUIET) |
cmdq_error(cmdq, "no mouse target"); |
cmdq_error(item, "no mouse target"); |
goto error; |
goto error; |
} |
} |
goto found; |
goto found; |
|
|
if (strcmp(target, "~") == 0 || strcmp(target, "{marked}") == 0) { |
if (strcmp(target, "~") == 0 || strcmp(target, "{marked}") == 0) { |
if (!server_check_marked()) { |
if (!server_check_marked()) { |
if (~flags & CMD_FIND_QUIET) |
if (~flags & CMD_FIND_QUIET) |
cmdq_error(cmdq, "no marked target"); |
cmdq_error(item, "no marked target"); |
goto error; |
goto error; |
} |
} |
cmd_find_copy_state(fs, &marked_pane); |
cmd_find_copy_state(fs, &marked_pane); |
|
|
/* No pane is allowed if want an index. */ |
/* No pane is allowed if want an index. */ |
if (pane != NULL && (flags & CMD_FIND_WINDOW_INDEX)) { |
if (pane != NULL && (flags & CMD_FIND_WINDOW_INDEX)) { |
if (~flags & CMD_FIND_QUIET) |
if (~flags & CMD_FIND_QUIET) |
cmdq_error(cmdq, "can't specify pane here"); |
cmdq_error(item, "can't specify pane here"); |
goto error; |
goto error; |
} |
} |
|
|
|
|
|
|
no_session: |
no_session: |
if (~flags & CMD_FIND_QUIET) |
if (~flags & CMD_FIND_QUIET) |
cmdq_error(cmdq, "can't find session %s", session); |
cmdq_error(item, "can't find session %s", session); |
goto error; |
goto error; |
|
|
no_window: |
no_window: |
if (~flags & CMD_FIND_QUIET) |
if (~flags & CMD_FIND_QUIET) |
cmdq_error(cmdq, "can't find window %s", window); |
cmdq_error(item, "can't find window %s", window); |
goto error; |
goto error; |
|
|
no_pane: |
no_pane: |
if (~flags & CMD_FIND_QUIET) |
if (~flags & CMD_FIND_QUIET) |
cmdq_error(cmdq, "can't find pane %s", pane); |
cmdq_error(item, "can't find pane %s", pane); |
goto error; |
goto error; |
} |
} |
|
|
/* Find the target client or report an error and return NULL. */ |
/* Find the target client or report an error and return NULL. */ |
struct client * |
struct client * |
cmd_find_client(struct cmd_q *cmdq, const char *target, int quiet) |
cmd_find_client(struct cmdq_item *item, const char *target, int quiet) |
{ |
{ |
struct client *c; |
struct client *c; |
char *copy; |
char *copy; |
|
|
const char *path; |
const char *path; |
|
|
/* A NULL argument means the current client. */ |
/* A NULL argument means the current client. */ |
if (cmdq != NULL && target == NULL) { |
if (item != NULL && target == NULL) { |
c = cmd_find_current_client(cmdq); |
c = cmd_find_current_client(item); |
if (c == NULL && !quiet) |
if (c == NULL && !quiet) |
cmdq_error(cmdq, "no current client"); |
cmdq_error(item, "no current client"); |
log_debug("%s: no target, return %p", __func__, c); |
log_debug("%s: no target, return %p", __func__, c); |
return (c); |
return (c); |
} |
} |
|
|
|
|
/* If no client found, report an error. */ |
/* If no client found, report an error. */ |
if (c == NULL && !quiet) |
if (c == NULL && !quiet) |
cmdq_error(cmdq, "can't find client %s", copy); |
cmdq_error(item, "can't find client %s", copy); |
|
|
free(copy); |
free(copy); |
log_debug("%s: target %s, return %p", __func__, target, c); |
log_debug("%s: target %s, return %p", __func__, target, c); |