aboutsummaryrefslogtreecommitdiff
path: root/render.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-02-24 17:38:11 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-02-24 17:38:11 +0000
commitd804bc8579c93a57f16214a04b5b625ae380eb78 (patch)
tree3f0409c4233726c8e3a49c86c8cbcee8160e5758 /render.c
parentcsi: delete all sixels on the 'alt' grid when switching back to 'normal' (diff)
term: resize: pre-calculate right/bottom margins
Diffstat (limited to 'render.c')
-rw-r--r--render.c81
1 files changed, 41 insertions, 40 deletions
diff --git a/render.c b/render.c
index 346b5351..179ceb1e 100644
--- a/render.c
+++ b/render.c
@@ -378,8 +378,8 @@ render_cell(struct terminal *term, pixman_image_t *pix,
int width = term->cell_width;
int height = term->cell_height;
- int x = term->x_margin + col * width;
- int y = term->y_margin + row * height;
+ int x = term->margins.left + col * width;
+ int y = term->margins.top + row * height;
assert(cell->attrs.selected == 0 || cell->attrs.selected == 1);
bool is_selected = cell->attrs.selected;
@@ -471,8 +471,8 @@ static void
grid_render_scroll(struct terminal *term, struct buffer *buf,
const struct damage *dmg)
{
- int dst_y = term->y_margin + (dmg->scroll.region.start + 0) * term->cell_height;
- int src_y = term->y_margin + (dmg->scroll.region.start + dmg->scroll.lines) * term->cell_height;
+ int dst_y = term->margins.top + (dmg->scroll.region.start + 0) * term->cell_height;
+ int src_y = term->margins.top + (dmg->scroll.region.start + dmg->scroll.lines) * term->cell_height;
int height = (dmg->scroll.region.end - dmg->scroll.region.start - dmg->scroll.lines) * term->cell_height;
LOG_DBG("damage: SCROLL: %d-%d by %d lines (dst-y: %d, src-y: %d, "
@@ -489,7 +489,7 @@ grid_render_scroll(struct terminal *term, struct buffer *buf,
height * buf->stride);
wl_surface_damage_buffer(
- term->window->surface, term->x_margin, dst_y, term->width - term->x_margin, height);
+ term->window->surface, term->margins.left, dst_y, term->width - term->margins.left - term->margins.right, height);
}
}
@@ -497,8 +497,8 @@ static void
grid_render_scroll_reverse(struct terminal *term, struct buffer *buf,
const struct damage *dmg)
{
- int src_y = term->y_margin + (dmg->scroll.region.start + 0) * term->cell_height;
- int dst_y = term->y_margin + (dmg->scroll.region.start + dmg->scroll.lines) * term->cell_height;
+ int src_y = term->margins.top + (dmg->scroll.region.start + 0) * term->cell_height;
+ int dst_y = term->margins.top + (dmg->scroll.region.start + dmg->scroll.lines) * term->cell_height;
int height = (dmg->scroll.region.end - dmg->scroll.region.start - dmg->scroll.lines) * term->cell_height;
LOG_DBG("damage: SCROLL REVERSE: %d-%d by %d lines (dst-y: %d, src-y: %d, "
@@ -515,7 +515,7 @@ grid_render_scroll_reverse(struct terminal *term, struct buffer *buf,
height * buf->stride);
wl_surface_damage_buffer(
- term->window->surface, term->x_margin, dst_y, term->width - term->x_margin, height);
+ term->window->surface, term->margins.left, dst_y, term->width - term->margins.left - term->margins.right, height);
}
}
@@ -559,21 +559,21 @@ render_sixel(struct terminal *term, pixman_image_t *pix,
(row - term->grid->view + term->grid->num_rows) & (term->grid->num_rows - 1);
/* Translate row/column to x/y pixel values */
- const int x = term->x_margin + sixel->pos.col * term->cell_width;
+ const int x = term->margins.left + sixel->pos.col * term->cell_width;
const int y = max(
- term->y_margin, term->y_margin + view_aligned * term->cell_height);
+ term->margins.top, term->margins.top + view_aligned * term->cell_height);
/* Width/height, in pixels - and don't touch the window margins */
- const int width = min(sixel->width, term->width - x - term->x_margin);
+ const int width = min(sixel->width, term->width - x - term->margins.right);
const int height = min(
sixel->height - first_img_row * term->cell_height,
- term->height - y - term->y_margin);
+ term->height - y - term->margins.bottom);
/* Verify we're not stepping outside the grid */
- assert(x >= term->x_margin);
- assert(y >= term->y_margin);
- assert(x + width <= term->width - term->x_margin);
- assert(y + height <= term->height - term->y_margin);
+ assert(x >= term->margins.left);
+ assert(y >= term->margins.top);
+ assert(x + width <= term->width - term->margins.right);
+ assert(y + height <= term->height - term->margins.bottom);
pixman_image_composite(
PIXMAN_OP_SRC,
@@ -710,10 +710,8 @@ grid_render(struct terminal *term)
else {
/* Fill area outside the cell grid with the default background color */
- int rmargin = term->x_margin + term->cols * term->cell_width;
- int bmargin = term->y_margin + term->rows * term->cell_height;
- int rmargin_width = term->width - rmargin;
- int bmargin_height = term->height - bmargin;
+ int rmargin = term->width - term->margins.right;
+ int bmargin = term->height - term->margins.bottom;
uint32_t _bg = !term->reverse ? term->colors.bg : term->colors.fg;
pixman_color_t bg = color_hex_to_pixman_with_alpha(_bg, term->colors.alpha);
@@ -723,19 +721,19 @@ grid_render(struct terminal *term)
pixman_image_fill_rectangles(
PIXMAN_OP_SRC, pix, &bg, 4,
(pixman_rectangle16_t[]){
- {0, 0, term->width, term->y_margin}, /* Top */
- {0, 0, term->x_margin, term->height}, /* Left */
- {rmargin, 0, rmargin_width, term->height}, /* Right */
- {0, bmargin, term->width, bmargin_height}}); /* Bottom */
+ {0, 0, term->width, term->margins.top}, /* Top */
+ {0, 0, term->margins.left, term->height}, /* Left */
+ {rmargin, 0, term->margins.right, term->height}, /* Right */
+ {0, bmargin, term->width, term->margins.bottom}}); /* Bottom */
wl_surface_damage_buffer(
- term->window->surface, 0, 0, term->width, term->y_margin);
+ term->window->surface, 0, 0, term->width, term->margins.top);
wl_surface_damage_buffer(
- term->window->surface, 0, 0, term->x_margin, term->height);
+ term->window->surface, 0, 0, term->margins.left, term->height);
wl_surface_damage_buffer(
- term->window->surface, rmargin, 0, rmargin_width, term->height);
+ term->window->surface, rmargin, 0, term->margins.right, term->height);
wl_surface_damage_buffer(
- term->window->surface, 0, bmargin, term->width, bmargin_height);
+ term->window->surface, 0, bmargin, term->width, term->margins.bottom);
/* Force a full grid refresh */
term_damage_view(term);
@@ -760,8 +758,8 @@ grid_render(struct terminal *term)
wl_surface_damage_buffer(
term->window->surface,
- term->x_margin + at.col * term->cell_width,
- term->y_margin + at.row * term->cell_height,
+ term->margins.left + at.col * term->cell_width,
+ term->margins.top + at.row * term->cell_height,
cols * term->cell_width, term->cell_height);
}
}
@@ -813,8 +811,8 @@ grid_render(struct terminal *term)
wl_surface_damage_buffer(
term->window->surface,
- term->x_margin, term->y_margin + r * term->cell_height,
- term->width - term->x_margin, term->cell_height);
+ term->margins.left, term->margins.top + r * term->cell_height,
+ term->width - term->margins.left - term->margins.right, term->cell_height);
}
mtx_lock(&term->render.workers.lock);
@@ -834,8 +832,8 @@ grid_render(struct terminal *term)
wl_surface_damage_buffer(
term->window->surface,
- term->x_margin, term->y_margin + r * term->cell_height,
- term->width - term->x_margin, term->cell_height);
+ term->margins.left, term->margins.top + r * term->cell_height,
+ term->width - term->margins.left - term->margins.right, term->cell_height);
}
}
@@ -887,8 +885,8 @@ grid_render(struct terminal *term)
wl_surface_damage_buffer(
term->window->surface,
- term->x_margin + term->cursor.point.col * term->cell_width,
- term->y_margin + view_aligned_row * term->cell_height,
+ term->margins.left + term->cursor.point.col * term->cell_width,
+ term->margins.top + view_aligned_row * term->cell_height,
cols_updated * term->cell_width, term->cell_height);
}
@@ -1110,8 +1108,10 @@ maybe_resize(struct terminal *term, int width, int height, bool force)
assert(new_rows >= 1);
/* Margins */
- term->x_margin = (term->width - new_cols * term->cell_width) / 2;
- term->y_margin = (term->height - new_rows * term->cell_height) / 2;
+ term->margins.left = (term->width - new_cols * term->cell_width) / 2;
+ term->margins.top = (term->height - new_rows * term->cell_height) / 2;
+ term->margins.right = term->width - new_cols * term->cell_width - term->margins.left;
+ term->margins.bottom = term->height - new_rows * term->cell_height - term->margins.top;
if (new_cols == old_cols && new_rows == old_rows) {
LOG_DBG("grid layout unaffected; skipping reflow");
@@ -1132,9 +1132,10 @@ maybe_resize(struct terminal *term, int width, int height, bool force)
term->cols = new_cols;
term->rows = new_rows;
- LOG_INFO("resize: %dx%d, grid: cols=%d, rows=%d (x-margin=%d, y-margin=%d)",
+ LOG_INFO("resize: %dx%d, grid: cols=%d, rows=%d "
+ "(left-margin=%d, right-margin=%d, top-margin=%d, bottom-margin=%d)",
term->width, term->height, term->cols, term->rows,
- term->x_margin, term->y_margin);
+ term->margins.left, term->margins.right, term->margins.top, term->margins.bottom);
/* Signal TIOCSWINSZ */
if (ioctl(term->ptmx, TIOCSWINSZ,