diff options
Diffstat (limited to 'render.c')
| -rw-r--r-- | render.c | 72 |
1 files changed, 52 insertions, 20 deletions
@@ -35,13 +35,8 @@ static struct glyph_sequence gseq; static void render_cell(struct terminal *term, struct buffer *buf, const struct cell *cell, - int col, int row) + int col, int row, bool has_cursor) { - /* Cursor here? */ - bool has_cursor - = (!term->hide_cursor && - (term->cursor.col == col && term->cursor.row == row)); - double width = term->cell_width; double height = term->cell_height; double x = col * width; @@ -243,7 +238,7 @@ grid_render(struct terminal *term) gseq.count = 0; for (int r = 0; r < term->rows; r++) { - struct row *row = grid_row(term->grid, r); + struct row *row = grid_row_in_view(term->grid, r); if (!row->dirty) continue; @@ -251,7 +246,7 @@ grid_render(struct terminal *term) //LOG_WARN("rendering line: %d", r); for (int col = 0; col < term->cols; col++) - render_cell(term, buf, &row->cells[col], col, r); + render_cell(term, buf, &row->cells[col], col, r, false); row->dirty = false; all_clean = false; @@ -269,7 +264,7 @@ grid_render(struct terminal *term) int row = last_cursor / term->cols - term->grid->offset; int col = last_cursor % term->cols; if (row >= 0 && row < term->rows) { - render_cell(term, buf, &grid_row(term->grid, row)->cells[col], col, row); + render_cell(term, buf, &grid_row_in_view(term->grid, row)->cells[col], col, row, false); all_clean = false; wl_surface_damage_buffer( @@ -284,16 +279,31 @@ grid_render(struct terminal *term) return; } - render_cell( - term, buf, - &grid_row(term->grid, term->cursor.row)->cells[term->cursor.col], - term->cursor.col, term->cursor.row); + bool cursor_is_visible = false; + int view_end = (term->grid->view + term->rows - 1) % term->grid->num_rows; + int cursor_row = (term->grid->offset + term->cursor.row) % term->grid->num_rows; + if (view_end >= term->grid->view) { + /* Not wrapped */ + if (cursor_row >= term->grid->view && cursor_row <= view_end) + cursor_is_visible = true; + } else { + /* Wrapped */ + if (cursor_row >= term->grid->view || cursor_row <= view_end) + cursor_is_visible = true; + } - wl_surface_damage_buffer( - term->wl.surface, - term->cursor.col * term->cell_width, - term->cursor.row * term->cell_height, - term->cell_width, term->cell_height); + if (cursor_is_visible) { + render_cell( + term, buf, + &grid_row_in_view(term->grid, term->cursor.row)->cells[term->cursor.col], + term->cursor.col, term->cursor.row, true); + + wl_surface_damage_buffer( + term->wl.surface, + term->cursor.col * term->cell_width, + term->cursor.row * term->cell_height, + term->cell_width, term->cell_height); + } if (gseq.count > 0) { cairo_set_scaled_font(buf->cairo, attrs_to_font(term, &gseq.attrs)); @@ -304,6 +314,7 @@ grid_render(struct terminal *term) } assert(term->grid->offset >= 0 && term->grid->offset < term->grid->num_rows); + assert(term->grid->view >= 0 && term->grid->view < term->grid->num_rows); cairo_surface_flush(buf->cairo_surface); wl_surface_attach(term->wl.surface, buf->wl_buf, 0, 0); @@ -338,12 +349,18 @@ reflow(struct row **new_grid, int new_cols, int new_rows, struct cell *new_cells = new_grid[r]->cells; const struct cell *old_cells = old_grid[r]->cells; + new_grid[r]->initialized = old_grid[r]->initialized; + new_grid[r]->dirty = old_grid[r]->dirty; + memcpy(new_cells, old_cells, copy_cols * sizeof(new_cells[0])); memset(&new_cells[copy_cols], 0, clear_cols * sizeof(new_cells[0])); } - for (int r = min(new_rows, old_rows); r < new_rows; r++) + for (int r = min(new_rows, old_rows); r < new_rows; r++) { + new_grid[r]->initialized = false; + new_grid[r]->dirty = false; memset(new_grid[r]->cells, 0, new_cols * sizeof(new_grid[r]->cells[0])); + } } /* Move to terminal.c? */ @@ -356,6 +373,8 @@ render_resize(struct terminal *term, int width, int height) term->width = width; term->height = height; + const int scrollback_lines = 10000; + const int old_cols = term->cols; const int old_rows = term->rows; const int old_normal_grid_rows = term->normal.num_rows; @@ -363,7 +382,7 @@ render_resize(struct terminal *term, int width, int height) const int new_cols = term->width / term->cell_width; const int new_rows = term->height / term->cell_height; - const int new_normal_grid_rows = new_rows; + const int new_normal_grid_rows = new_rows + scrollback_lines; const int new_alt_grid_rows = new_rows; /* Allocate new 'normal' grid */ @@ -388,6 +407,11 @@ render_resize(struct terminal *term, int width, int height) reflow(alt, new_cols, new_alt_grid_rows, term->alt.rows, old_cols, old_alt_grid_rows); + for (int r = 0; r < new_rows; r++) { + normal[r]->initialized = true; + alt[r]->initialized = true; + } + /* Free old 'normal' grid */ for (int r = 0; r < term->normal.num_rows; r++) { free(term->normal.rows[r]->cells); @@ -430,11 +454,19 @@ render_resize(struct terminal *term, int width, int height) if (term->scroll_region.end >= old_rows) term->scroll_region.end = term->rows; + term->normal.offset %= term->normal.num_rows; + term->normal.view %= term->normal.num_rows; + + term->alt.offset %= term->alt.num_rows; + term->alt.view %= term->alt.num_rows; + term_cursor_to( term, min(term->cursor.row, term->rows - 1), min(term->cursor.col, term->cols - 1)); + term_damage_all(term); + term_damage_view(term); if (term->frame_callback == NULL) grid_render(term); |
