Merge branch 'obsd-master'

pull/1395/head
Thomas Adam 2018-07-04 13:02:25 +01:00
commit 850c26dd46
8 changed files with 43 additions and 24 deletions

View File

@ -563,11 +563,11 @@ format_cb_history_bytes(struct format_tree *ft, struct format_entry *fe)
size = 0; size = 0;
for (i = 0; i < gd->hsize; i++) { for (i = 0; i < gd->hsize; i++) {
gl = &gd->linedata[i]; gl = grid_get_line(gd, i);
size += gl->cellsize * sizeof *gl->celldata; size += gl->cellsize * sizeof *gl->celldata;
size += gl->extdsize * sizeof *gl->extddata; size += gl->extdsize * sizeof *gl->extddata;
} }
size += gd->hsize * sizeof *gd->linedata; size += gd->hsize * sizeof *gl;
xasprintf(&fe->value, "%llu", size); xasprintf(&fe->value, "%llu", size);
} }

View File

@ -64,7 +64,7 @@ grid_view_clear_history(struct grid *gd, u_int bg)
/* Find the last used line. */ /* Find the last used line. */
last = 0; last = 0;
for (yy = 0; yy < gd->sy; yy++) { for (yy = 0; yy < gd->sy; yy++) {
gl = &gd->linedata[grid_view_y(gd, yy)]; gl = grid_get_line(gd, grid_view_y(gd, yy));
if (gl->cellused != 0) if (gl->cellused != 0)
last = yy + 1; last = yy + 1;
} }

12
grid.c
View File

@ -145,6 +145,18 @@ grid_extended_cell(struct grid_line *gl, struct grid_cell_entry *gce,
return (gcp); return (gcp);
} }
struct grid_line *
grid_get_line(struct grid *gd, u_int line)
{
return (&gd->linedata[line]);
}
void
grid_adjust_lines(struct grid *gd, u_int lines)
{
gd->linedata = xreallocarray(gd->linedata, lines, sizeof *gd->linedata);
}
/* Copy default into a cell. */ /* Copy default into a cell. */
static void static void
grid_clear_cell(struct grid *gd, u_int px, u_int py, u_int bg) grid_clear_cell(struct grid *gd, u_int px, u_int py, u_int bg)

View File

@ -408,7 +408,7 @@ screen_write_fast_copy(struct screen_write_ctx *ctx, struct screen *src,
break; break;
cx = s->cx; cx = s->cx;
for (xx = px; xx < px + nx; xx++) { for (xx = px; xx < px + nx; xx++) {
if (xx >= gd->linedata[yy].cellsize) if (xx >= grid_get_line(gd, yy)->cellsize)
break; break;
grid_get_cell(gd, xx, yy, &gc); grid_get_cell(gd, xx, yy, &gc);
if (xx + gc.data.width > px + nx) if (xx + gc.data.width > px + nx)
@ -694,7 +694,7 @@ screen_write_backspace(struct screen_write_ctx *ctx)
if (s->cx == 0) { if (s->cx == 0) {
if (s->cy == 0) if (s->cy == 0)
return; return;
gl = &s->grid->linedata[s->grid->hsize + s->cy - 1]; gl = grid_get_line(s->grid, s->grid->hsize + s->cy - 1);
if (gl->flags & GRID_LINE_WRAPPED) { if (gl->flags & GRID_LINE_WRAPPED) {
s->cy--; s->cy--;
s->cx = screen_size_x(s) - 1; s->cx = screen_size_x(s) - 1;
@ -917,7 +917,7 @@ screen_write_clearline(struct screen_write_ctx *ctx, u_int bg)
struct tty_ctx ttyctx; struct tty_ctx ttyctx;
u_int sx = screen_size_x(s); u_int sx = screen_size_x(s);
gl = &s->grid->linedata[s->grid->hsize + s->cy]; gl = grid_get_line(s->grid, s->grid->hsize + s->cy);
if (gl->cellsize == 0 && bg == 8) if (gl->cellsize == 0 && bg == 8)
return; return;
@ -940,7 +940,7 @@ screen_write_clearendofline(struct screen_write_ctx *ctx, u_int bg)
struct tty_ctx ttyctx; struct tty_ctx ttyctx;
u_int sx = screen_size_x(s); u_int sx = screen_size_x(s);
gl = &s->grid->linedata[s->grid->hsize + s->cy]; gl = grid_get_line(s->grid, s->grid->hsize + s->cy);
if (s->cx > sx - 1 || (s->cx >= gl->cellsize && bg == 8)) if (s->cx > sx - 1 || (s->cx >= gl->cellsize && bg == 8))
return; return;
@ -1043,7 +1043,7 @@ screen_write_linefeed(struct screen_write_ctx *ctx, int wrapped, u_int bg)
struct grid *gd = s->grid; struct grid *gd = s->grid;
struct grid_line *gl; struct grid_line *gl;
gl = &gd->linedata[gd->hsize + s->cy]; gl = grid_get_line(gd, gd->hsize + s->cy);
if (wrapped) if (wrapped)
gl->flags |= GRID_LINE_WRAPPED; gl->flags |= GRID_LINE_WRAPPED;
else else
@ -1433,7 +1433,7 @@ screen_write_cell(struct screen_write_ctx *ctx, const struct grid_cell *gc)
screen_write_initctx(ctx, &ttyctx); screen_write_initctx(ctx, &ttyctx);
/* Handle overwriting of UTF-8 characters. */ /* Handle overwriting of UTF-8 characters. */
gl = &s->grid->linedata[s->grid->hsize + s->cy]; gl = grid_get_line(s->grid, s->grid->hsize + s->cy);
if (gl->flags & GRID_LINE_EXTENDED) { if (gl->flags & GRID_LINE_EXTENDED) {
grid_view_get_cell(gd, s->cx, s->cy, &now_gc); grid_view_get_cell(gd, s->cx, s->cy, &now_gc);
if (screen_write_overwrite(ctx, &now_gc, width)) if (screen_write_overwrite(ctx, &now_gc, width))

View File

@ -280,9 +280,8 @@ screen_resize_y(struct screen *s, u_int sy)
s->cy -= needed; s->cy -= needed;
} }
/* Resize line arrays. */ /* Resize line array. */
gd->linedata = xreallocarray(gd->linedata, gd->hsize + sy, grid_adjust_lines(gd, gd->hsize + sy);
sizeof *gd->linedata);
/* Size increasing. */ /* Size increasing. */
if (sy > oldy) { if (sy > oldy) {
@ -305,7 +304,7 @@ screen_resize_y(struct screen *s, u_int sy)
/* Then fill the rest in with blanks. */ /* Then fill the rest in with blanks. */
for (i = gd->hsize + sy - needed; i < gd->hsize + sy; i++) for (i = gd->hsize + sy - needed; i < gd->hsize + sy; i++)
memset(&gd->linedata[i], 0, sizeof gd->linedata[i]); memset(grid_get_line(gd, i), 0, sizeof(struct grid_line));
} }
/* Set the new size, and reset the scroll region. */ /* Set the new size, and reset the scroll region. */

2
tmux.h
View File

@ -2010,6 +2010,8 @@ char *grid_string_cells(struct grid *, u_int, u_int, u_int,
void grid_duplicate_lines(struct grid *, u_int, struct grid *, u_int, void grid_duplicate_lines(struct grid *, u_int, struct grid *, u_int,
u_int); u_int);
void grid_reflow(struct grid *, u_int, u_int *); void grid_reflow(struct grid *, u_int, u_int *);
struct grid_line *grid_get_line(struct grid *, u_int);
void grid_adjust_lines(struct grid *, u_int);
/* grid-view.c */ /* grid-view.c */
void grid_view_get_cell(struct grid *, u_int, u_int, struct grid_cell *); void grid_view_get_cell(struct grid *, u_int, u_int, struct grid_cell *);

9
tty.c
View File

@ -913,6 +913,7 @@ tty_draw_line(struct tty *tty, const struct window_pane *wp,
int flags, cleared = 0; int flags, cleared = 0;
char buf[512]; char buf[512];
size_t len, old_len; size_t len, old_len;
u_int cellsize;
flags = (tty->flags & TTY_NOCURSOR); flags = (tty->flags & TTY_NOCURSOR);
tty->flags |= TTY_NOCURSOR; tty->flags |= TTY_NOCURSOR;
@ -926,15 +927,17 @@ tty_draw_line(struct tty *tty, const struct window_pane *wp,
* there may be empty background cells after it (from BCE). * there may be empty background cells after it (from BCE).
*/ */
sx = screen_size_x(s); sx = screen_size_x(s);
if (sx > gd->linedata[gd->hsize + py].cellsize)
sx = gd->linedata[gd->hsize + py].cellsize; cellsize = grid_get_line(gd, gd->hsize + py)->cellsize;
if (sx > cellsize)
sx = cellsize;
if (sx > tty->sx) if (sx > tty->sx)
sx = tty->sx; sx = tty->sx;
ux = 0; ux = 0;
if (wp == NULL || if (wp == NULL ||
py == 0 || py == 0 ||
(~gd->linedata[gd->hsize + py - 1].flags & GRID_LINE_WRAPPED) || (~grid_get_line(gd, gd->hsize + py - 1)->flags & GRID_LINE_WRAPPED) ||
ox != 0 || ox != 0 ||
tty->cx < tty->sx || tty->cx < tty->sx ||
screen_size_x(s) < tty->sx) { screen_size_x(s) < tty->sx) {

View File

@ -1755,7 +1755,7 @@ window_copy_copy_line(struct window_pane *wp, char **buf, size_t *off, u_int sy,
* Work out if the line was wrapped at the screen edge and all of it is * Work out if the line was wrapped at the screen edge and all of it is
* on screen. * on screen.
*/ */
gl = &gd->linedata[sy]; gl = grid_get_line(gd, sy);
if (gl->flags & GRID_LINE_WRAPPED && gl->cellsize <= gd->sx) if (gl->flags & GRID_LINE_WRAPPED && gl->cellsize <= gd->sx)
wrapped = 1; wrapped = 1;
@ -1843,7 +1843,7 @@ window_copy_find_length(struct window_pane *wp, u_int py)
* width of the grid, and screen_write_copy treats them as spaces, so * width of the grid, and screen_write_copy treats them as spaces, so
* ignore them here too. * ignore them here too.
*/ */
px = s->grid->linedata[py].cellsize; px = grid_get_line(s->grid, py)->cellsize;
if (px > screen_size_x(s)) if (px > screen_size_x(s))
px = screen_size_x(s); px = screen_size_x(s);
while (px > 0) { while (px > 0) {
@ -1867,7 +1867,7 @@ window_copy_cursor_start_of_line(struct window_pane *wp)
if (data->cx == 0 && s->sel.lineflag == LINE_SEL_NONE) { if (data->cx == 0 && s->sel.lineflag == LINE_SEL_NONE) {
py = screen_hsize(back_s) + data->cy - data->oy; py = screen_hsize(back_s) + data->cy - data->oy;
while (py > 0 && while (py > 0 &&
gd->linedata[py-1].flags & GRID_LINE_WRAPPED) { grid_get_line(gd, py - 1)->flags & GRID_LINE_WRAPPED) {
window_copy_cursor_up(wp, 0); window_copy_cursor_up(wp, 0);
py = screen_hsize(back_s) + data->cy - data->oy; py = screen_hsize(back_s) + data->cy - data->oy;
} }
@ -1907,6 +1907,7 @@ window_copy_cursor_end_of_line(struct window_pane *wp)
struct screen *back_s = data->backing; struct screen *back_s = data->backing;
struct screen *s = &data->screen; struct screen *s = &data->screen;
struct grid *gd = back_s->grid; struct grid *gd = back_s->grid;
struct grid_line *gl;
u_int px, py; u_int px, py;
py = screen_hsize(back_s) + data->cy - data->oy; py = screen_hsize(back_s) + data->cy - data->oy;
@ -1915,12 +1916,14 @@ window_copy_cursor_end_of_line(struct window_pane *wp)
if (data->cx == px && s->sel.lineflag == LINE_SEL_NONE) { if (data->cx == px && s->sel.lineflag == LINE_SEL_NONE) {
if (data->screen.sel.flag && data->rectflag) if (data->screen.sel.flag && data->rectflag)
px = screen_size_x(back_s); px = screen_size_x(back_s);
if (gd->linedata[py].flags & GRID_LINE_WRAPPED) { gl = grid_get_line(gd, py);
while (py < gd->sy + gd->hsize && if (gl->flags & GRID_LINE_WRAPPED) {
gd->linedata[py].flags & GRID_LINE_WRAPPED) { while (py < gd->sy + gd->hsize) {
gl = grid_get_line(gd, py);
if (~gl->flags & GRID_LINE_WRAPPED)
break;
window_copy_cursor_down(wp, 0); window_copy_cursor_down(wp, 0);
py = screen_hsize(back_s) py = screen_hsize(back_s) + data->cy - data->oy;
+ data->cy - data->oy;
} }
px = window_copy_find_length(wp, py); px = window_copy_find_length(wp, py);
} }