diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2019-03-16 19:12:14 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2019-03-16 19:12:14 +0000 |
commit | 464bf283b240714008ea933bad497bced2c1406d (patch) | |
tree | 2b86d2c7071b9d18c17f880b1c8fd6b3a802fd7f /usr.bin/tmux | |
parent | 38f9e3e9e140c3733ce243f1ce820b51410606a2 (diff) |
Use a pointer for the active screen in the status line instead of
copying them around all the time.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r-- | usr.bin/tmux/screen-redraw.c | 4 | ||||
-rw-r--r-- | usr.bin/tmux/status.c | 141 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 5 | ||||
-rw-r--r-- | usr.bin/tmux/window-client.c | 7 |
4 files changed, 77 insertions, 80 deletions
diff --git a/usr.bin/tmux/screen-redraw.c b/usr.bin/tmux/screen-redraw.c index dece54490ce..c7bc2a0be95 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.57 2019/03/16 17:14:07 nicm Exp $ */ +/* $OpenBSD: screen-redraw.c,v 1.58 2019/03/16 19:12:13 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.screen; + struct screen *s = c->status.active; u_int i, y; log_debug("%s: %s @%u", __func__, c->name, w->id); diff --git a/usr.bin/tmux/status.c b/usr.bin/tmux/status.c index 06656f6db2a..eafc0088b70 100644 --- a/usr.bin/tmux/status.c +++ b/usr.bin/tmux/status.c @@ -1,4 +1,4 @@ -/* $OpenBSD: status.c,v 1.188 2019/03/16 17:53:55 nicm Exp $ */ +/* $OpenBSD: status.c,v 1.189 2019/03/16 19:12:13 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -296,6 +296,32 @@ status_get_window_at(struct client *c, u_int x) return (NULL); } +/* Save old status line. */ +static void +status_push_screen(struct client *c) +{ + struct status_line *sl = &c->status; + + if (sl->active == &sl->screen) { + sl->active = xmalloc(sizeof *sl->active); + screen_init(sl->active, c->tty.sx, status_line_size(c), 0); + } + sl->references++; +} + +/* Restore old status line. */ +static void +status_pop_screen(struct client *c) +{ + struct status_line *sl = &c->status; + + if (--sl->references == 0) { + screen_free(sl->active); + free(sl->active); + sl->active = &sl->screen; + } +} + /* Initialize status line. */ void status_init(struct client *c) @@ -303,6 +329,7 @@ status_init(struct client *c) struct status_line *sl = &c->status; screen_init(&sl->screen, c->tty.sx, 1, 0); + sl->active = &sl->screen; } /* Free status line. */ @@ -314,37 +341,11 @@ status_free(struct client *c) if (event_initialized(&sl->timer)) evtimer_del(&sl->timer); - 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 client *c) -{ - struct status_line *sl = &c->status; - - if (sl->old_screen == NULL) { - sl->old_screen = xmalloc(sizeof *sl->old_screen); - memcpy(sl->old_screen, &sl->screen, sizeof *sl->old_screen); - screen_init(&c->status.screen, c->tty.sx, 1, 0); - } -} - -/* Free old status line. */ -static void -status_free_old(struct client *c) -{ - struct status_line *sl = &c->status; - - if (sl->old_screen != NULL) { - screen_free(sl->old_screen); - free(sl->old_screen); - sl->old_screen = NULL; + if (sl->active != &sl->screen) { + screen_free(sl->active); + free(sl->active); } + screen_free(&sl->screen); } /* Draw status line for client. */ @@ -365,8 +366,9 @@ status_redraw(struct client *c) size_t llen, rlen, seplen; int larrow, rarrow; - /* Delete the saved status line, if any. */ - status_free_old(c); + /* Shouldn't get here if not the active screen. */ + if (sl->active != &sl->screen) + fatalx("not the active screen"); /* No status line? */ lines = status_line_size(c); @@ -379,9 +381,9 @@ status_redraw(struct client *c) style_apply(&stdgc, s->options, "status-style"); /* Create the target screen. */ - memcpy(&old_screen, &sl->screen, sizeof old_screen); - screen_init(&sl->screen, c->tty.sx, lines, 0); - screen_write_start(&ctx, NULL, &sl->screen); + memcpy(&old_screen, sl->active, sizeof old_screen); + screen_init(sl->active, c->tty.sx, lines, 0); + screen_write_start(&ctx, NULL, sl->active); for (offset = 0; offset < lines * c->tty.sx; offset++) screen_write_putc(&ctx, &stdgc, ' '); screen_write_stop(&ctx); @@ -504,7 +506,7 @@ status_redraw(struct client *c) draw: /* Begin drawing. */ - screen_write_start(&ctx, NULL, &sl->screen); + screen_write_start(&ctx, NULL, sl->active); /* Draw the left string and arrow. */ screen_write_cursormove(&ctx, 0, 0, 0); @@ -563,7 +565,7 @@ out: free(left); free(right); - if (grid_compare(sl->screen.grid, old_screen.grid) == 0) { + if (grid_compare(sl->active->grid, old_screen.grid) == 0) { screen_free(&old_screen); return (0); } @@ -634,7 +636,7 @@ status_message_set(struct client *c, const char *fmt, ...) int delay; status_message_clear(c); - status_save_old(c); + status_push_screen(c); va_start(ap, fmt); xvasprintf(&c->message_string, fmt, ap); @@ -671,7 +673,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.screen); + status_pop_screen(c); } /* Clear status line message after timer expires. */ @@ -687,23 +689,22 @@ status_message_callback(__unused int fd, __unused short event, void *data) int status_message_redraw(struct client *c) { - struct screen_write_ctx ctx; - struct session *s = c->session; - struct screen old_status; - size_t len; - struct grid_cell gc; - u_int lines, offset; + struct status_line *sl = &c->status; + struct screen_write_ctx ctx; + struct session *s = c->session; + struct screen old_screen; + size_t len; + u_int lines, offset; + struct grid_cell gc; if (c->tty.sx == 0 || c->tty.sy == 0) return (0); - memcpy(&old_status, &c->status.screen, sizeof old_status); + memcpy(&old_screen, sl->active, sizeof old_screen); lines = status_line_size(c); - if (lines <= 1) { + if (lines <= 1) lines = 1; - screen_init(&c->status.screen, c->tty.sx, 1, 0); - } else - screen_init(&c->status.screen, c->tty.sx, lines, 0); + screen_init(sl->active, c->tty.sx, 1, 0); len = screen_write_strlen("%s", c->message_string); if (len > c->tty.sx) @@ -711,7 +712,7 @@ status_message_redraw(struct client *c) style_apply(&gc, s->options, "message-style"); - screen_write_start(&ctx, NULL, &c->status.screen); + screen_write_start(&ctx, NULL, sl->active); screen_write_cursormove(&ctx, 0, 0, 0); for (offset = 0; offset < lines * c->tty.sx; offset++) screen_write_putc(&ctx, &gc, ' '); @@ -719,11 +720,11 @@ 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.screen.grid, old_status.grid) == 0) { - screen_free(&old_status); + if (grid_compare(sl->active->grid, old_screen.grid) == 0) { + screen_free(&old_screen); return (0); } - screen_free(&old_status); + screen_free(&old_screen); return (1); } @@ -747,7 +748,7 @@ status_prompt_set(struct client *c, const char *msg, const char *input, status_message_clear(c); status_prompt_clear(c); - status_save_old(c); + status_push_screen(c); c->prompt_string = format_expand_time(ft, msg); @@ -799,7 +800,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.screen); + status_pop_screen(c); } /* Update status line prompt with a new prompt string. */ @@ -833,23 +834,22 @@ status_prompt_update(struct client *c, const char *msg, const char *input) int status_prompt_redraw(struct client *c) { + struct status_line *sl = &c->status; struct screen_write_ctx ctx; struct session *s = c->session; - struct screen old_status; - u_int i, offset, left, start, pcursor, pwidth, width; - u_int lines; + struct screen old_screen; + u_int i, lines, offset, left, start, width; + u_int pcursor, pwidth; struct grid_cell gc, cursorgc; if (c->tty.sx == 0 || c->tty.sy == 0) return (0); - memcpy(&old_status, &c->status.screen, sizeof old_status); + memcpy(&old_screen, sl->active, sizeof old_screen); lines = status_line_size(c); - if (lines <= 1) { + if (lines <= 1) lines = 1; - screen_init(&c->status.screen, c->tty.sx, 1, 0); - } else - screen_init(&c->status.screen, c->tty.sx, lines, 0); + screen_init(sl->active, c->tty.sx, lines, 0); if (c->prompt_mode == PROMPT_COMMAND) style_apply(&gc, s->options, "message-command-style"); @@ -863,7 +863,7 @@ status_prompt_redraw(struct client *c) if (start > c->tty.sx) start = c->tty.sx; - screen_write_start(&ctx, NULL, &c->status.screen); + screen_write_start(&ctx, NULL, sl->active); screen_write_cursormove(&ctx, 0, 0, 0); for (offset = 0; offset < lines * c->tty.sx; offset++) screen_write_putc(&ctx, &gc, ' '); @@ -909,18 +909,17 @@ status_prompt_redraw(struct client *c) screen_write_cell(&ctx, &cursorgc); } } - if (c->status.screen.cx < screen_size_x(&c->status.screen) && - c->prompt_index >= i) + if (sl->active->cx < screen_size_x(sl->active) && c->prompt_index >= i) screen_write_putc(&ctx, &cursorgc, ' '); finished: screen_write_stop(&ctx); - if (grid_compare(c->status.screen.grid, old_status.grid) == 0) { - screen_free(&old_status); + if (grid_compare(sl->active->grid, old_screen.grid) == 0) { + screen_free(&old_screen); return (0); } - screen_free(&old_status); + screen_free(&old_screen); return (1); } diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index fd83d2c73c6..faf60868f0a 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.870 2019/03/16 17:14:07 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.871 2019/03/16 19:12:13 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -1315,7 +1315,8 @@ struct status_line { struct event timer; struct screen screen; - struct screen *old_screen; + struct screen *active; + int references; int window_list_offset; diff --git a/usr.bin/tmux/window-client.c b/usr.bin/tmux/window-client.c index 36b3bff240e..588933205ac 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.18 2019/03/16 17:14:07 nicm Exp $ */ +/* $OpenBSD: window-client.c,v 1.19 2019/03/16 19:12:13 nicm Exp $ */ /* * Copyright (c) 2017 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -229,10 +229,7 @@ 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_screen != NULL) - screen_write_fast_copy(ctx, c->status.old_screen, 0, 0, sx, 1); - else - screen_write_fast_copy(ctx, &c->status.screen, 0, 0, sx, 1); + screen_write_fast_copy(ctx, &c->status.screen, 0, 0, sx, 1); } static struct screen * |