selection: mark_selected_region(): use an enum to encode how the cells are to be updated

This commit is contained in:
Daniel Eklöf 2022-08-26 21:07:20 +02:00
parent db2737b96a
commit d5df86f785
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -711,11 +711,26 @@ pixman_region_for_coords(const struct terminal *term,
} }
} }
enum mark_selection_variant {
MARK_SELECTION_MARK_AND_DIRTY,
MARK_SELECTION_UNMARK_AND_DIRTY,
MARK_SELECTION_MARK_FOR_RENDER,
};
static void static void
mark_selected_region(struct terminal *term, pixman_box32_t *boxes, mark_selected_region(struct terminal *term, pixman_box32_t *boxes,
size_t count, bool selected, bool dirty_cells, size_t count, enum mark_selection_variant mark_variant)
bool highlight_empty)
{ {
const bool selected =
mark_variant == MARK_SELECTION_MARK_AND_DIRTY ||
mark_variant == MARK_SELECTION_MARK_FOR_RENDER;
const bool dirty_cells =
mark_variant == MARK_SELECTION_MARK_AND_DIRTY ||
mark_variant == MARK_SELECTION_UNMARK_AND_DIRTY;
const bool highlight_empty =
mark_variant != MARK_SELECTION_MARK_FOR_RENDER ||
term->selection.kind == SELECTION_BLOCK;
for (size_t i = 0; i < count; i++) { for (size_t i = 0; i < count; i++) {
const pixman_box32_t *box = &boxes[i]; const pixman_box32_t *box = &boxes[i];
@ -842,10 +857,10 @@ selection_modify(struct terminal *term, struct coord start, struct coord end)
pixman_box32_t *boxes = NULL; pixman_box32_t *boxes = NULL;
boxes = pixman_region32_rectangles(&no_longer_selected, &n_rects); boxes = pixman_region32_rectangles(&no_longer_selected, &n_rects);
mark_selected_region(term, boxes, n_rects, false, true, true); mark_selected_region(term, boxes, n_rects, MARK_SELECTION_UNMARK_AND_DIRTY);
boxes = pixman_region32_rectangles(&newly_selected, &n_rects); boxes = pixman_region32_rectangles(&newly_selected, &n_rects);
mark_selected_region(term, boxes, n_rects, true, true, true); mark_selected_region(term, boxes, n_rects, MARK_SELECTION_MARK_AND_DIRTY);
pixman_region32_fini(&newly_selected); pixman_region32_fini(&newly_selected);
pixman_region32_fini(&no_longer_selected); pixman_region32_fini(&no_longer_selected);
@ -1110,9 +1125,7 @@ selection_dirty_cells(struct terminal *term)
int n_rects = -1; int n_rects = -1;
pixman_box32_t *boxes = pixman_box32_t *boxes =
pixman_region32_rectangles(&visible_and_selected, &n_rects); pixman_region32_rectangles(&visible_and_selected, &n_rects);
mark_selected_region(term, boxes, n_rects, MARK_SELECTION_MARK_FOR_RENDER);
const bool highlight_empty = term->selection.kind == SELECTION_BLOCK;
mark_selected_region(term, boxes, n_rects, true, false, highlight_empty);
pixman_region32_fini(&visible_and_selected); pixman_region32_fini(&visible_and_selected);
pixman_region32_fini(&view); pixman_region32_fini(&view);