diff options
-rw-r--r-- | usr.bin/tmux/cmd-set-option.c | 4 | ||||
-rw-r--r-- | usr.bin/tmux/resize.c | 4 | ||||
-rw-r--r-- | usr.bin/tmux/screen-redraw.c | 4 | ||||
-rw-r--r-- | usr.bin/tmux/server-client.c | 4 | ||||
-rw-r--r-- | usr.bin/tmux/session.c | 4 | ||||
-rw-r--r-- | usr.bin/tmux/status.c | 113 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 9 | ||||
-rw-r--r-- | usr.bin/tmux/window-client.c | 8 |
8 files changed, 85 insertions, 65 deletions
diff --git a/usr.bin/tmux/cmd-set-option.c b/usr.bin/tmux/cmd-set-option.c index 2e6d780ca86..ff6fde83338 100644 --- a/usr.bin/tmux/cmd-set-option.c +++ b/usr.bin/tmux/cmd-set-option.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-set-option.c,v 1.120 2018/10/18 08:38:01 nicm Exp $ */ +/* $OpenBSD: cmd-set-option.c,v 1.121 2019/03/16 17:14:07 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -264,7 +264,7 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item) layout_fix_panes(w); } RB_FOREACH(s, sessions, &sessions) - status_update_saved(s); + status_update_cache(s); /* * Update sizes and redraw. May not always be necessary but do it diff --git a/usr.bin/tmux/resize.c b/usr.bin/tmux/resize.c index 70289b358db..74749147f69 100644 --- a/usr.bin/tmux/resize.c +++ b/usr.bin/tmux/resize.c @@ -1,4 +1,4 @@ -/* $OpenBSD: resize.c,v 1.29 2019/03/12 13:56:30 nicm Exp $ */ +/* $OpenBSD: resize.c,v 1.30 2019/03/16 17:14:07 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -162,7 +162,7 @@ recalculate_sizes(void) */ RB_FOREACH(s, sessions, &sessions) { s->attached = 0; - status_update_saved(s); + status_update_cache(s); } /* diff --git a/usr.bin/tmux/screen-redraw.c b/usr.bin/tmux/screen-redraw.c index 098dd89ed66..dece54490ce 100644 --- a/usr.bin/tmux/screen-redraw.c +++ b/usr.bin/tmux/screen-redraw.c @@ -1,4 +1,4 @@ -/* $OpenBSD: screen-redraw.c,v 1.56 2019/03/12 20:02:47 nicm Exp $ */ +/* $OpenBSD: screen-redraw.c,v 1.57 2019/03/16 17:14:07 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -569,7 +569,7 @@ screen_redraw_draw_status(struct screen_redraw_ctx *ctx) struct client *c = ctx->c; struct window *w = c->session->curw->window; struct tty *tty = &c->tty; - struct screen *s = &c->status.status; + struct screen *s = &c->status.screen; u_int i, y; log_debug("%s: %s @%u", __func__, c->name, w->id); diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c index 3efdc903879..688267e6d11 100644 --- a/usr.bin/tmux/server-client.c +++ b/usr.bin/tmux/server-client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server-client.c,v 1.270 2019/03/15 14:46:58 nicm Exp $ */ +/* $OpenBSD: server-client.c,v 1.271 2019/03/16 17:14:07 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -204,7 +204,7 @@ server_client_create(int fd) c->tty.sx = 80; c->tty.sy = 24; - screen_init(&c->status.status, c->tty.sx, 1, 0); + status_init(c); c->message_string = NULL; TAILQ_INIT(&c->message_log); diff --git a/usr.bin/tmux/session.c b/usr.bin/tmux/session.c index 43e435c2d26..37868f95544 100644 --- a/usr.bin/tmux/session.c +++ b/usr.bin/tmux/session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: session.c,v 1.82 2018/10/18 08:38:01 nicm Exp $ */ +/* $OpenBSD: session.c,v 1.83 2019/03/16 17:14:07 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -136,7 +136,7 @@ session_create(const char *prefix, const char *name, int argc, char **argv, s->options = oo; s->hooks = hooks_create(global_hooks); - status_update_saved(s); + status_update_cache(s); s->tio = NULL; if (tio != NULL) { diff --git a/usr.bin/tmux/status.c b/usr.bin/tmux/status.c index 459149599ce..c8beb5a1c4e 100644 --- a/usr.bin/tmux/status.c +++ b/usr.bin/tmux/status.c @@ -1,4 +1,4 @@ -/* $OpenBSD: status.c,v 1.186 2019/03/15 14:46:58 nicm Exp $ */ +/* $OpenBSD: status.c,v 1.187 2019/03/16 17:14:07 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -194,7 +194,7 @@ status_timer_start_all(void) /* Update status cache. */ void -status_update_saved(struct session *s) +status_update_cache(struct session *s) { if (!options_get_number(s->options, "status")) s->statusat = -1; @@ -296,6 +296,15 @@ status_get_window_at(struct client *c, u_int x) return (NULL); } +/* Initialize status line. */ +void +status_init(struct client *c) +{ + struct status_line *sl = &c->status; + + screen_init(&sl->screen, c->tty.sx, 1, 0); +} + /* Free status line. */ void status_free(struct client *c) @@ -305,10 +314,31 @@ status_free(struct client *c) if (event_initialized(&sl->timer)) evtimer_del(&sl->timer); - screen_free(&sl->status); - if (sl->old_status != NULL) { - screen_free(sl->old_status); - free(sl->old_status); + screen_free(&sl->screen); + if (sl->old_screen != NULL) { + screen_free(sl->old_screen); + free(sl->old_screen); + } +} + +/* Save as old status line. */ +static void +status_save_old(struct status_line *sl) +{ + if (sl->old_screen == NULL) { + sl->old_screen = xmalloc(sizeof *sl->old_screen); + memcpy(sl->old_screen, &sl->screen, sizeof *sl->old_screen); + } +} + +/* Free old status line. */ +static void +status_free_old(struct status_line *sl) +{ + if (sl->old_screen != NULL) { + screen_free(sl->old_screen); + free(sl->old_screen); + sl->old_screen = NULL; } } @@ -316,10 +346,11 @@ status_free(struct client *c) int status_redraw(struct client *c) { + struct status_line *sl = &c->status; struct screen_write_ctx ctx; struct session *s = c->session; struct winlink *wl; - struct screen old_status, window_list; + struct screen old_screen, window_list; struct grid_cell stdgc, lgc, rgc, gc; struct options *oo; char *left, *right; @@ -330,11 +361,7 @@ status_redraw(struct client *c) int larrow, rarrow; /* Delete the saved status line, if any. */ - if (c->status.old_status != NULL) { - screen_free(c->status.old_status); - free(c->status.old_status); - c->status.old_status = NULL; - } + status_free_old(sl); /* No status line? */ lines = status_line_size(c); @@ -347,9 +374,9 @@ status_redraw(struct client *c) style_apply(&stdgc, s->options, "status-style"); /* Create the target screen. */ - memcpy(&old_status, &c->status.status, sizeof old_status); - screen_init(&c->status.status, c->tty.sx, lines, 0); - screen_write_start(&ctx, NULL, &c->status.status); + memcpy(&old_screen, &sl->screen, sizeof old_screen); + screen_init(&sl->screen, c->tty.sx, lines, 0); + screen_write_start(&ctx, NULL, &sl->screen); for (offset = 0; offset < lines * c->tty.sx; offset++) screen_write_putc(&ctx, &stdgc, ' '); screen_write_stop(&ctx); @@ -472,7 +499,7 @@ status_redraw(struct client *c) draw: /* Begin drawing. */ - screen_write_start(&ctx, NULL, &c->status.status); + screen_write_start(&ctx, NULL, &sl->screen); /* Draw the left string and arrow. */ screen_write_cursormove(&ctx, 0, 0, 0); @@ -516,14 +543,14 @@ draw: wloffset++; /* Copy the window list. */ - c->status.window_list_offset = -wloffset + wlstart; + sl->window_list_offset = -wloffset + wlstart; screen_write_cursormove(&ctx, wloffset, 0, 0); screen_write_fast_copy(&ctx, &window_list, wlstart, 0, wlwidth, 1); screen_free(&window_list); /* Save left and right size. */ - c->status.left_size = llen; - c->status.right_size = rlen; + sl->left_size = llen; + sl->right_size = rlen; screen_write_stop(&ctx); @@ -531,11 +558,11 @@ out: free(left); free(right); - if (grid_compare(c->status.status.grid, old_status.grid) == 0) { - screen_free(&old_status); + if (grid_compare(sl->screen.grid, old_screen.grid) == 0) { + screen_free(&old_screen); return (0); } - screen_free(&old_status); + screen_free(&old_screen); return (1); } @@ -603,12 +630,8 @@ status_message_set(struct client *c, const char *fmt, ...) status_message_clear(c); - if (c->status.old_status == NULL) { - c->status.old_status = xmalloc(sizeof *c->status.old_status); - memcpy(c->status.old_status, &c->status.status, - sizeof *c->status.old_status); - screen_init(&c->status.status, c->tty.sx, 1, 0); - } + status_save_old(&c->status); + screen_init(&c->status.screen, c->tty.sx, 1, 0); va_start(ap, fmt); xvasprintf(&c->message_string, fmt, ap); @@ -645,7 +668,7 @@ status_message_clear(struct client *c) c->tty.flags &= ~(TTY_NOCURSOR|TTY_FREEZE); c->flags |= CLIENT_ALLREDRAWFLAGS; /* was frozen and may have changed */ - screen_reinit(&c->status.status); + screen_reinit(&c->status.screen); } /* Clear status line message after timer expires. */ @@ -670,14 +693,14 @@ status_message_redraw(struct client *c) if (c->tty.sx == 0 || c->tty.sy == 0) return (0); - memcpy(&old_status, &c->status.status, sizeof old_status); + memcpy(&old_status, &c->status.screen, sizeof old_status); lines = status_line_size(c); if (lines <= 1) { lines = 1; - screen_init(&c->status.status, c->tty.sx, 1, 0); + screen_init(&c->status.screen, c->tty.sx, 1, 0); } else - screen_init(&c->status.status, c->tty.sx, lines, 0); + screen_init(&c->status.screen, c->tty.sx, lines, 0); len = screen_write_strlen("%s", c->message_string); if (len > c->tty.sx) @@ -685,7 +708,7 @@ status_message_redraw(struct client *c) style_apply(&gc, s->options, "message-style"); - screen_write_start(&ctx, NULL, &c->status.status); + screen_write_start(&ctx, NULL, &c->status.screen); screen_write_cursormove(&ctx, 0, 0, 0); for (offset = 0; offset < lines * c->tty.sx; offset++) screen_write_putc(&ctx, &gc, ' '); @@ -693,7 +716,7 @@ status_message_redraw(struct client *c) screen_write_nputs(&ctx, len, &gc, "%s", c->message_string); screen_write_stop(&ctx); - if (grid_compare(c->status.status.grid, old_status.grid) == 0) { + if (grid_compare(c->status.screen.grid, old_status.grid) == 0) { screen_free(&old_status); return (0); } @@ -722,12 +745,8 @@ status_prompt_set(struct client *c, const char *msg, const char *input, status_message_clear(c); status_prompt_clear(c); - if (c->status.old_status == NULL) { - c->status.old_status = xmalloc(sizeof *c->status.old_status); - memcpy(c->status.old_status, &c->status.status, - sizeof *c->status.old_status); - screen_init(&c->status.status, c->tty.sx, 1, 0); - } + status_save_old(&c->status); + screen_init(&c->status.screen, c->tty.sx, 1, 0); c->prompt_string = format_expand_time(ft, msg); @@ -779,7 +798,7 @@ status_prompt_clear(struct client *c) c->tty.flags &= ~(TTY_NOCURSOR|TTY_FREEZE); c->flags |= CLIENT_ALLREDRAWFLAGS; /* was frozen and may have changed */ - screen_reinit(&c->status.status); + screen_reinit(&c->status.screen); } /* Update status line prompt with a new prompt string. */ @@ -822,14 +841,14 @@ status_prompt_redraw(struct client *c) if (c->tty.sx == 0 || c->tty.sy == 0) return (0); - memcpy(&old_status, &c->status.status, sizeof old_status); + memcpy(&old_status, &c->status.screen, sizeof old_status); lines = status_line_size(c); if (lines <= 1) { lines = 1; - screen_init(&c->status.status, c->tty.sx, 1, 0); + screen_init(&c->status.screen, c->tty.sx, 1, 0); } else - screen_init(&c->status.status, c->tty.sx, lines, 0); + screen_init(&c->status.screen, c->tty.sx, lines, 0); if (c->prompt_mode == PROMPT_COMMAND) style_apply(&gc, s->options, "message-command-style"); @@ -843,7 +862,7 @@ status_prompt_redraw(struct client *c) if (start > c->tty.sx) start = c->tty.sx; - screen_write_start(&ctx, NULL, &c->status.status); + screen_write_start(&ctx, NULL, &c->status.screen); screen_write_cursormove(&ctx, 0, 0, 0); for (offset = 0; offset < lines * c->tty.sx; offset++) screen_write_putc(&ctx, &gc, ' '); @@ -889,14 +908,14 @@ status_prompt_redraw(struct client *c) screen_write_cell(&ctx, &cursorgc); } } - if (c->status.status.cx < screen_size_x(&c->status.status) && + if (c->status.screen.cx < screen_size_x(&c->status.screen) && c->prompt_index >= i) screen_write_putc(&ctx, &cursorgc, ' '); finished: screen_write_stop(&ctx); - if (grid_compare(c->status.status.grid, old_status.grid) == 0) { + if (grid_compare(c->status.screen.grid, old_status.grid) == 0) { screen_free(&old_status); return (0); } diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index e74089b59b6..fd83d2c73c6 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.869 2019/03/15 21:54:47 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.870 2019/03/16 17:14:07 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -1314,8 +1314,8 @@ struct cmd_entry { struct status_line { struct event timer; - struct screen status; - struct screen *old_status; + struct screen screen; + struct screen *old_screen; int window_list_offset; @@ -1967,10 +1967,11 @@ void server_unzoom_window(struct window *); /* status.c */ void status_timer_start(struct client *); void status_timer_start_all(void); -void status_update_saved(struct session *); +void status_update_cache(struct session *); int status_at_line(struct client *); u_int status_line_size(struct client *); struct window *status_get_window_at(struct client *, u_int); +void status_init(struct client *); void status_free(struct client *); int status_redraw(struct client *); void printflike(2, 3) status_message_set(struct client *, const char *, ...); diff --git a/usr.bin/tmux/window-client.c b/usr.bin/tmux/window-client.c index b53cce2b97d..36b3bff240e 100644 --- a/usr.bin/tmux/window-client.c +++ b/usr.bin/tmux/window-client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window-client.c,v 1.17 2019/03/12 20:02:47 nicm Exp $ */ +/* $OpenBSD: window-client.c,v 1.18 2019/03/16 17:14:07 nicm Exp $ */ /* * Copyright (c) 2017 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -229,10 +229,10 @@ window_client_draw(__unused void *modedata, void *itemdata, screen_write_hline(ctx, sx, 0, 0); screen_write_cursormove(ctx, cx, cy + sy - 1, 0); - if (c->status.old_status != NULL) - screen_write_fast_copy(ctx, c->status.old_status, 0, 0, sx, 1); + if (c->status.old_screen != NULL) + screen_write_fast_copy(ctx, c->status.old_screen, 0, 0, sx, 1); else - screen_write_fast_copy(ctx, &c->status.status, 0, 0, sx, 1); + screen_write_fast_copy(ctx, &c->status.screen, 0, 0, sx, 1); } static struct screen * |