diff options
-rw-r--r-- | cmd-display-message.c | 22 | ||||
-rw-r--r-- | cmd-find.c | 2 | ||||
-rw-r--r-- | format.c | 3 | ||||
-rw-r--r-- | grid.c | 31 | ||||
-rw-r--r-- | tmux.h | 1 |
5 files changed, 38 insertions, 21 deletions
diff --git a/cmd-display-message.c b/cmd-display-message.c index eef6ad84..59f25543 100644 --- a/cmd-display-message.c +++ b/cmd-display-message.c @@ -53,7 +53,7 @@ static enum cmd_retval cmd_display_message_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct client *c; + struct client *c, *target_c; struct session *s = item->target.s; struct winlink *wl = item->target.wl; struct window_pane *wp = item->target.wp; @@ -65,7 +65,6 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item) cmdq_error(item, "only one of -F or argument must be given"); return (CMD_RETURN_ERROR); } - c = cmd_find_client(item, args_get(args, 'c'), 1); template = args_get(args, 'F'); if (args->argc != 0) @@ -73,14 +72,27 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item) if (template == NULL) template = DISPLAY_MESSAGE_TEMPLATE; + /* + * -c is intended to be the client where the message should be + * displayed if -p is not given. But it makes sense to use it for the + * formats too, assuming it matches the session. If it doesn't, use the + * best client for the session. + */ + c = cmd_find_client(item, args_get(args, 'c'), 1); + if (c != NULL && c->session == s) + target_c = c; + else + target_c = cmd_find_best_client(s); ft = format_create(item->client, item, FORMAT_NONE, 0); - format_defaults(ft, c, s, wl, wp); + format_defaults(ft, target_c, s, wl, wp); msg = format_expand_time(ft, template, time(NULL)); if (args_has(self->args, 'p')) cmdq_print(item, "%s", msg); - else if (c != NULL) - status_message_set(c, "%s", msg); + else { + if (c != NULL) + status_message_set(c, "%s", msg); + } free(msg); format_free(ft); @@ -121,7 +121,7 @@ cmd_find_client_better(struct client *c, struct client *than) } /* Find best client for session. */ -static struct client * +struct client * cmd_find_best_client(struct session *s) { struct client *c_loop, *c; @@ -1270,6 +1270,9 @@ void format_defaults(struct format_tree *ft, struct client *c, struct session *s, struct winlink *wl, struct window_pane *wp) { + if (c != NULL && s != NULL && c->session != s) + log_debug("%s: session does not match", __func__); + format_add(ft, "session_format", "%d", s != NULL); format_add(ft, "window_format", "%d", wl != NULL); format_add(ft, "pane_format", "%d", wp != NULL); @@ -166,10 +166,10 @@ grid_clear_cell(struct grid *gd, u_int px, u_int py, u_int bg) /* Check grid y position. */ static int -grid_check_y(struct grid *gd, u_int py) +grid_check_y(struct grid *gd, const char* from, u_int py) { if (py >= gd->hsize + gd->sy) { - log_debug("y out of range: %u", py); + log_debug("%s: y out of range: %u", from, py); return (-1); } return (0); @@ -407,7 +407,7 @@ grid_empty_line(struct grid *gd, u_int py, u_int bg) const struct grid_line * grid_peek_line(struct grid *gd, u_int py) { - if (grid_check_y(gd, py) != 0) + if (grid_check_y(gd, __func__, py) != 0) return (NULL); return (&gd->linedata[py]); } @@ -441,7 +441,8 @@ grid_get_cell1(struct grid_line *gl, u_int px, struct grid_cell *gc) void grid_get_cell(struct grid *gd, u_int px, u_int py, struct grid_cell *gc) { - if (grid_check_y(gd, py) != 0 || px >= gd->linedata[py].cellsize) { + if (grid_check_y(gd, __func__, py) != 0 || + px >= gd->linedata[py].cellsize) { memcpy(gc, &grid_default_cell, sizeof *gc); return; } @@ -455,7 +456,7 @@ grid_set_cell(struct grid *gd, u_int px, u_int py, const struct grid_cell *gc) struct grid_line *gl; struct grid_cell_entry *gce; - if (grid_check_y(gd, py) != 0) + if (grid_check_y(gd, __func__, py) != 0) return; grid_expand_line(gd, py, px + 1, 8); @@ -481,7 +482,7 @@ grid_set_cells(struct grid *gd, u_int px, u_int py, const struct grid_cell *gc, struct grid_cell *gcp; u_int i; - if (grid_check_y(gd, py) != 0) + if (grid_check_y(gd, __func__, py) != 0) return; grid_expand_line(gd, py, px + slen, 8); @@ -514,9 +515,9 @@ grid_clear(struct grid *gd, u_int px, u_int py, u_int nx, u_int ny, u_int bg) return; } - if (grid_check_y(gd, py) != 0) + if (grid_check_y(gd, __func__, py) != 0) return; - if (grid_check_y(gd, py + ny - 1) != 0) + if (grid_check_y(gd, __func__, py + ny - 1) != 0) return; for (yy = py; yy < py + ny; yy++) { @@ -543,9 +544,9 @@ grid_clear_lines(struct grid *gd, u_int py, u_int ny, u_int bg) if (ny == 0) return; - if (grid_check_y(gd, py) != 0) + if (grid_check_y(gd, __func__, py) != 0) return; - if (grid_check_y(gd, py + ny - 1) != 0) + if (grid_check_y(gd, __func__, py + ny - 1) != 0) return; for (yy = py; yy < py + ny; yy++) { @@ -563,13 +564,13 @@ grid_move_lines(struct grid *gd, u_int dy, u_int py, u_int ny, u_int bg) if (ny == 0 || py == dy) return; - if (grid_check_y(gd, py) != 0) + if (grid_check_y(gd, __func__, py) != 0) return; - if (grid_check_y(gd, py + ny - 1) != 0) + if (grid_check_y(gd, __func__, py + ny - 1) != 0) return; - if (grid_check_y(gd, dy) != 0) + if (grid_check_y(gd, __func__, dy) != 0) return; - if (grid_check_y(gd, dy + ny - 1) != 0) + if (grid_check_y(gd, __func__, dy + ny - 1) != 0) return; /* Free any lines which are being replaced. */ @@ -603,7 +604,7 @@ grid_move_cells(struct grid *gd, u_int dx, u_int px, u_int py, u_int nx, if (nx == 0 || px == dx) return; - if (grid_check_y(gd, py) != 0) + if (grid_check_y(gd, __func__, py) != 0) return; gl = &gd->linedata[py]; @@ -1776,6 +1776,7 @@ long long args_strtonum(struct args *, u_char, long long, long long, /* cmd-find.c */ int cmd_find_target(struct cmd_find_state *, struct cmdq_item *, const char *, enum cmd_find_type, int); +struct client *cmd_find_best_client(struct session *); struct client *cmd_find_client(struct cmdq_item *, const char *, int); void cmd_find_clear_state(struct cmd_find_state *, int); int cmd_find_empty_state(struct cmd_find_state *); |