From 69c3e744983e37662fa7b4f61482fb1d142e257c Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 1 May 2020 11:46:24 +0200 Subject: util.h: new header file defining commonly used macros --- selection.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'selection.c') diff --git a/selection.c b/selection.c index 534a0888..4ed24dca 100644 --- a/selection.c +++ b/selection.c @@ -17,11 +17,9 @@ #include "grid.h" #include "misc.h" #include "render.h" +#include "util.h" #include "vt.h" -#define min(x, y) ((x) < (y) ? (x) : (y)) -#define max(x, y) ((x) > (y) ? (x) : (y)) - bool selection_enabled(const struct terminal *term) { -- cgit v1.3 From 623329cf23dc1309eec1338c52417d25141f44d6 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 1 May 2020 11:59:09 +0200 Subject: selection: extract text: also copy combining characters --- selection.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'selection.c') diff --git a/selection.c b/selection.c index 4ed24dca..b84f4228 100644 --- a/selection.c +++ b/selection.c @@ -46,7 +46,7 @@ selection_on_row_in_view(const struct terminal *term, int row_no) static void foreach_selected_normal( struct terminal *term, struct coord _start, struct coord _end, - void (*cb)(struct terminal *term, struct row *row, struct cell *cell, void *data), + void (*cb)(struct terminal *term, struct row *row, struct cell *cell, int col, void *data), void *data) { const struct coord *start = &_start; @@ -80,7 +80,7 @@ foreach_selected_normal( c <= (r == end_row ? end_col : term->cols - 1); c++) { - cb(term, row, &row->cells[c], data); + cb(term, row, &row->cells[c], c, data); } start_col = 0; @@ -90,7 +90,7 @@ foreach_selected_normal( static void foreach_selected_block( struct terminal *term, struct coord _start, struct coord _end, - void (*cb)(struct terminal *term, struct row *row, struct cell *cell, void *data), + void (*cb)(struct terminal *term, struct row *row, struct cell *cell, int col, void *data), void *data) { const struct coord *start = &_start; @@ -112,14 +112,14 @@ foreach_selected_block( assert(row != NULL); for (int c = top_left.col; c <= bottom_right.col; c++) - cb(term, row, &row->cells[c], data); + cb(term, row, &row->cells[c], c, data); } } static void foreach_selected( struct terminal *term, struct coord start, struct coord end, - void (*cb)(struct terminal *term, struct row *row, struct cell *cell, void *data), + void (*cb)(struct terminal *term, struct row *row, struct cell *cell, int col, void *data), void *data) { switch (term->selection.kind) { @@ -142,6 +142,8 @@ min_bufsize_for_extraction(const struct terminal *term) { const struct coord *start = &term->selection.start; const struct coord *end = &term->selection.end; + const size_t chars_per_cell + = 1 + ALEN(term->grid->cur_row->comb_chars[0].chars); switch (term->selection.kind) { case SELECTION_NONE: @@ -160,7 +162,7 @@ min_bufsize_for_extraction(const struct terminal *term) } if (start->row == end->row) - return end->col - start->col + 1; + return (end->col - start->col + 1) * chars_per_cell; else { size_t cells = 0; @@ -169,7 +171,7 @@ min_bufsize_for_extraction(const struct terminal *term) cells += term->cols - start->col + 1; cells += (term->cols + 1) * (end->row - start->row - 1); cells += end->col + 1 + 1; - return cells; + return cells * chars_per_cell; } case SELECTION_BLOCK: { @@ -186,7 +188,7 @@ min_bufsize_for_extraction(const struct terminal *term) /* Add one extra column on each row, for \n */ int cols = bottom_right.col - top_left.col + 1 + 1; int rows = bottom_right.row - top_left.row + 1; - return rows * cols; + return rows * cols * chars_per_cell; } } @@ -199,13 +201,13 @@ struct extract { size_t size; size_t idx; size_t empty_count; - struct row *last_row; - struct cell *last_cell; + const struct row *last_row; + const struct cell *last_cell; }; static void extract_one(struct terminal *term, struct row *row, struct cell *cell, - void *data) + int col, void *data) { struct extract *ctx = data; @@ -235,6 +237,13 @@ extract_one(struct terminal *term, struct row *row, struct cell *cell, assert(ctx->idx + 1 <= ctx->size); ctx->buf[ctx->idx++] = cell->wc; + const struct combining_chars *comb_chars = &row->comb_chars[col]; + + assert(cell->wc != 0); + assert(ctx->idx + comb_chars->count <= ctx->size); + for (size_t i = 0; i < comb_chars->count; i++) + ctx->buf[ctx->idx++] = comb_chars->chars[i]; + ctx->last_row = row; ctx->last_cell = cell; } @@ -299,7 +308,7 @@ selection_start(struct terminal *term, int col, int row, static void unmark_selected(struct terminal *term, struct row *row, struct cell *cell, - void *data) + int col, void *data) { if (cell->attrs.selected == 0 || (cell->attrs.selected & 2)) { /* Ignore if already deselected, or if premarked for updated selection */ @@ -313,7 +322,7 @@ unmark_selected(struct terminal *term, struct row *row, struct cell *cell, static void premark_selected(struct terminal *term, struct row *row, struct cell *cell, - void *data) + int col, void *data) { /* Tell unmark to leave this be */ cell->attrs.selected |= 2; @@ -321,7 +330,7 @@ premark_selected(struct terminal *term, struct row *row, struct cell *cell, static void mark_selected(struct terminal *term, struct row *row, struct cell *cell, - void *data) + int col, void *data) { if (cell->attrs.selected & 1) { cell->attrs.selected = 1; /* Clear the pre-mark bit */ -- cgit v1.3 From 3474624c2c17058f0fd9f3f1821971e7213d285b Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 1 May 2020 12:05:38 +0200 Subject: unicode-combining: completely remove unicode combining characters when feature is disabled --- grid.c | 8 ++++++++ render.c | 2 ++ selection.c | 10 ++++++++-- terminal.c | 3 +++ terminal.h | 5 +++++ 5 files changed, 26 insertions(+), 2 deletions(-) (limited to 'selection.c') diff --git a/grid.c b/grid.c index 2a6b1073..22e4ecaf 100644 --- a/grid.c +++ b/grid.c @@ -34,12 +34,16 @@ grid_row_alloc(int cols, bool initialize) if (initialize) { row->cells = calloc(cols, sizeof(row->cells[0])); +#if FOOT_UNICODE_COMBINING row->comb_chars = calloc(cols, sizeof(row->comb_chars[0])); +#endif for (size_t c = 0; c < cols; c++) row->cells[c].attrs.clean = 1; } else { row->cells = malloc(cols * sizeof(row->cells[0])); +#if FOOT_UNICODE_COMBINING row->comb_chars = malloc(cols * sizeof(row->comb_chars[0])); +#endif } return row; @@ -51,7 +55,9 @@ grid_row_free(struct row *row) if (row == NULL) return; +#if FOOT_UNICODE_COMBINING free(row->comb_chars); +#endif free(row->cells); free(row); } @@ -208,6 +214,7 @@ grid_reflow(struct grid *grid, int new_rows, int new_cols, new_row->cells[new_col_idx] = *old_cell; new_row->cells[new_col_idx].attrs.clean = 1; +#if FOOT_UNICODE_COMBINING struct combining_chars *old_comb_chars = &old_row->comb_chars[c - empty_count + i]; struct combining_chars *new_comb_chars @@ -216,6 +223,7 @@ grid_reflow(struct grid *grid, int new_rows, int new_cols, new_comb_chars->count = old_comb_chars->count; for (size_t j = 0; j < ALEN(new_comb_chars->chars); j++) new_comb_chars->chars[j] = old_comb_chars->chars[j]; +#endif /* Translate tracking point(s) */ if (is_tracking_point && i >= empty_count) { diff --git a/render.c b/render.c index a87601d2..41b5c5b7 100644 --- a/render.c +++ b/render.c @@ -442,6 +442,7 @@ render_cell(struct terminal *term, pixman_image_t *pix, } } + #if FOOT_UNICODE_COMBINING /* Combining characters */ const struct combining_chars *comb_chars = &row->comb_chars[col]; for (size_t i = 0; i < comb_chars->count; i++) { @@ -461,6 +462,7 @@ render_cell(struct terminal *term, pixman_image_t *pix, g->width, g->height); pixman_image_unref(src); } +#endif /* Underline */ if (cell->attrs.underline) { diff --git a/selection.c b/selection.c index b84f4228..f9f7f6cd 100644 --- a/selection.c +++ b/selection.c @@ -142,8 +142,12 @@ min_bufsize_for_extraction(const struct terminal *term) { const struct coord *start = &term->selection.start; const struct coord *end = &term->selection.end; - const size_t chars_per_cell - = 1 + ALEN(term->grid->cur_row->comb_chars[0].chars); + const size_t chars_per_cell = +#if FOOT_UNICODE_COMBINING + 1 + ALEN(term->grid->cur_row->comb_chars[0].chars); +#else + 1; +#endif switch (term->selection.kind) { case SELECTION_NONE: @@ -237,12 +241,14 @@ extract_one(struct terminal *term, struct row *row, struct cell *cell, assert(ctx->idx + 1 <= ctx->size); ctx->buf[ctx->idx++] = cell->wc; +#if FOOT_UNICODE_COMBINING const struct combining_chars *comb_chars = &row->comb_chars[col]; assert(cell->wc != 0); assert(ctx->idx + comb_chars->count <= ctx->size); for (size_t i = 0; i < comb_chars->count; i++) ctx->buf[ctx->idx++] = comb_chars->chars[i]; +#endif ctx->last_row = row; ctx->last_cell = cell; diff --git a/terminal.c b/terminal.c index bbbf2127..9c3c24e8 100644 --- a/terminal.c +++ b/terminal.c @@ -2295,7 +2295,10 @@ term_print(struct terminal *term, wchar_t wc, int width) cell->wc = term->vt.last_printed = wc; cell->attrs = term->vt.attrs; +#if FOOT_UNICODE_COMBINING row->comb_chars[term->grid->cursor.point.col].count = 0; +#endif + row->dirty = true; cell->attrs.clean = 0; diff --git a/terminal.h b/terminal.h index b1f7ac8e..62c7e707 100644 --- a/terminal.h +++ b/terminal.h @@ -77,16 +77,21 @@ struct damage { int lines; }; +#if FOOT_UNICODE_COMBINING struct combining_chars { uint8_t count; wchar_t chars[2]; /* TODO: how many do we need? */ }; +#endif struct row { struct cell *cells; bool dirty; bool linebreak; + +#if FOOT_UNICODE_COMBINING struct combining_chars *comb_chars; +#endif }; struct sixel { -- cgit v1.3