2019-07-05 10:16:56 +02:00
|
|
|
#include "render.h"
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
|
2019-07-05 10:44:09 +02:00
|
|
|
#include <wayland-cursor.h>
|
2019-07-05 10:16:56 +02:00
|
|
|
#include <xdg-shell.h>
|
|
|
|
|
|
|
|
|
|
#define LOG_MODULE "render"
|
|
|
|
|
#define LOG_ENABLE_DBG 0
|
|
|
|
|
#include "log.h"
|
|
|
|
|
#include "shm.h"
|
2019-07-08 13:57:31 +02:00
|
|
|
#include "grid.h"
|
2019-07-05 10:16:56 +02:00
|
|
|
|
|
|
|
|
#define min(x, y) ((x) < (y) ? (x) : (y))
|
|
|
|
|
#define max(x, y) ((x) > (y) ? (x) : (y))
|
|
|
|
|
|
|
|
|
|
cairo_scaled_font_t *
|
|
|
|
|
attrs_to_font(struct terminal *term, const struct attributes *attrs)
|
|
|
|
|
{
|
|
|
|
|
int idx = attrs->italic << 1 | attrs->bold;
|
|
|
|
|
return term->fonts[idx];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct glyph_sequence {
|
|
|
|
|
cairo_glyph_t glyphs[100000];
|
|
|
|
|
cairo_glyph_t *g;
|
|
|
|
|
int count;
|
|
|
|
|
|
|
|
|
|
struct attributes attrs;
|
2019-07-08 15:56:15 +02:00
|
|
|
struct rgb foreground;
|
2019-07-05 10:16:56 +02:00
|
|
|
};
|
|
|
|
|
|
2019-07-06 18:31:14 +02:00
|
|
|
static struct glyph_sequence gseq;
|
|
|
|
|
|
2019-07-08 13:57:31 +02:00
|
|
|
static void
|
|
|
|
|
render_cell(struct terminal *term, struct buffer *buf, const struct cell *cell,
|
|
|
|
|
int col, int row)
|
|
|
|
|
{
|
|
|
|
|
/* Cursor here? */
|
|
|
|
|
bool has_cursor
|
|
|
|
|
= (!term->hide_cursor &&
|
|
|
|
|
(term->cursor.col == col && term->cursor.row == row));
|
|
|
|
|
|
2019-07-08 15:28:33 +02:00
|
|
|
double width = term->cell_width;
|
|
|
|
|
double height = term->cell_height;
|
|
|
|
|
double x = col * width;
|
|
|
|
|
double y = row * height;
|
2019-07-08 13:57:31 +02:00
|
|
|
|
2019-07-08 15:56:15 +02:00
|
|
|
const struct rgb *foreground = cell->attrs.have_foreground
|
2019-07-08 15:27:44 +02:00
|
|
|
? &cell->attrs.foreground
|
|
|
|
|
: !term->reverse ? &term->foreground : &term->background;
|
2019-07-08 15:56:15 +02:00
|
|
|
const struct rgb *background = cell->attrs.have_background
|
2019-07-08 15:27:44 +02:00
|
|
|
? &cell->attrs.background
|
|
|
|
|
: !term->reverse ? &term->background : &term->foreground;
|
2019-07-08 13:57:31 +02:00
|
|
|
|
2019-07-08 15:56:15 +02:00
|
|
|
/* If *one* is set, we reverse */
|
2019-07-08 20:25:41 +02:00
|
|
|
if (has_cursor ^ cell->attrs.reverse) {
|
2019-07-08 15:56:15 +02:00
|
|
|
const struct rgb *swap = foreground;
|
2019-07-08 13:57:31 +02:00
|
|
|
foreground = background;
|
|
|
|
|
background = swap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Background */
|
2019-07-08 15:56:15 +02:00
|
|
|
cairo_set_source_rgb(buf->cairo, background->r, background->g, background->b);
|
2019-07-08 13:57:31 +02:00
|
|
|
cairo_rectangle(buf->cairo, x, y, width, height);
|
|
|
|
|
cairo_fill(buf->cairo);
|
|
|
|
|
|
|
|
|
|
if (cell->c[0] == '\0' || cell->c[0] == ' ')
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (cell->attrs.conceal)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* cairo_show_glyphs() apparently works *much* faster when
|
|
|
|
|
* called once with a large array of glyphs, compared to
|
|
|
|
|
* multiple calls with a single glyph.
|
|
|
|
|
*
|
|
|
|
|
* So, collect glyphs until cell attributes change, then we
|
|
|
|
|
* 'flush' (render) the glyphs.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (memcmp(&cell->attrs, &gseq.attrs, sizeof(cell->attrs)) != 0 ||
|
|
|
|
|
gseq.count >= sizeof(gseq.glyphs) / sizeof(gseq.glyphs[0]) - 10 ||
|
2019-07-08 15:27:44 +02:00
|
|
|
memcmp(&gseq.foreground, foreground, sizeof(*foreground)) != 0)
|
2019-07-08 13:57:31 +02:00
|
|
|
{
|
|
|
|
|
if (gseq.count >= sizeof(gseq.glyphs) / sizeof(gseq.glyphs[0]) - 10)
|
|
|
|
|
LOG_WARN("hit glyph limit");
|
2019-07-08 15:27:44 +02:00
|
|
|
|
2019-07-08 13:57:31 +02:00
|
|
|
cairo_set_scaled_font(buf->cairo, attrs_to_font(term, &gseq.attrs));
|
2019-07-08 15:56:15 +02:00
|
|
|
cairo_set_source_rgb(
|
2019-07-08 13:57:31 +02:00
|
|
|
buf->cairo, gseq.foreground.r, gseq.foreground.g,
|
2019-07-08 15:56:15 +02:00
|
|
|
gseq.foreground.b);
|
2019-07-08 13:57:31 +02:00
|
|
|
|
|
|
|
|
cairo_show_glyphs(buf->cairo, gseq.glyphs, gseq.count);
|
|
|
|
|
|
|
|
|
|
gseq.g = gseq.glyphs;
|
|
|
|
|
gseq.count = 0;
|
|
|
|
|
gseq.attrs = cell->attrs;
|
2019-07-08 15:27:44 +02:00
|
|
|
gseq.foreground = *foreground;
|
2019-07-08 13:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int new_glyphs
|
|
|
|
|
= sizeof(gseq.glyphs) / sizeof(gseq.glyphs[0]) - gseq.count;
|
|
|
|
|
|
|
|
|
|
cairo_status_t status = cairo_scaled_font_text_to_glyphs(
|
|
|
|
|
attrs_to_font(term, &cell->attrs), x, y + term->fextents.ascent,
|
|
|
|
|
cell->c, strlen(cell->c), &gseq.g, &new_glyphs,
|
|
|
|
|
NULL, NULL, NULL);
|
|
|
|
|
|
|
|
|
|
if (status != CAIRO_STATUS_SUCCESS)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
gseq.g += new_glyphs;
|
|
|
|
|
gseq.count += new_glyphs;
|
|
|
|
|
assert(gseq.count <= sizeof(gseq.glyphs) / sizeof(gseq.glyphs[0]));
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-05 10:16:56 +02:00
|
|
|
static void
|
|
|
|
|
grid_render_scroll(struct terminal *term, struct buffer *buf,
|
|
|
|
|
const struct damage *dmg)
|
|
|
|
|
{
|
|
|
|
|
int dst_y = (dmg->scroll.region.start + 0) * term->cell_height;
|
|
|
|
|
int src_y = (dmg->scroll.region.start + dmg->scroll.lines) * term->cell_height;
|
|
|
|
|
int width = buf->width;
|
|
|
|
|
int height = (dmg->scroll.region.end - dmg->scroll.region.start - dmg->scroll.lines) * term->cell_height;
|
|
|
|
|
|
|
|
|
|
const uint32_t stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);
|
|
|
|
|
|
|
|
|
|
LOG_DBG("damage: SCROLL: %d-%d by %d lines (dst-y: %d, src-y: %d, "
|
|
|
|
|
"height: %d, stride: %d, mmap-size: %zu)",
|
|
|
|
|
dmg->scroll.region.start, dmg->scroll.region.end,
|
|
|
|
|
dmg->scroll.lines,
|
|
|
|
|
dst_y, src_y, height, stride,
|
|
|
|
|
buf->size);
|
|
|
|
|
|
|
|
|
|
if (height > 0) {
|
|
|
|
|
cairo_surface_flush(buf->cairo_surface);
|
|
|
|
|
uint8_t *raw = cairo_image_surface_get_data(buf->cairo_surface);
|
|
|
|
|
|
|
|
|
|
memmove(raw + dst_y * stride, raw + src_y * stride, height * stride);
|
|
|
|
|
cairo_surface_mark_dirty(buf->cairo_surface);
|
|
|
|
|
|
|
|
|
|
wl_surface_damage_buffer(term->wl.surface, 0, dst_y, width, height);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
grid_render_scroll_reverse(struct terminal *term, struct buffer *buf,
|
|
|
|
|
const struct damage *dmg)
|
|
|
|
|
{
|
|
|
|
|
int src_y = (dmg->scroll.region.start + 0) * term->cell_height;
|
|
|
|
|
int dst_y = (dmg->scroll.region.start + dmg->scroll.lines) * term->cell_height;
|
|
|
|
|
int width = buf->width;
|
|
|
|
|
int height = (dmg->scroll.region.end - dmg->scroll.region.start - dmg->scroll.lines) * term->cell_height;
|
|
|
|
|
|
|
|
|
|
const uint32_t stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);
|
|
|
|
|
|
|
|
|
|
LOG_DBG("damage: SCROLL REVERSE: %d-%d by %d lines (dst-y: %d, src-y: %d, "
|
|
|
|
|
"height: %d, stride: %d, mmap-size: %zu)",
|
|
|
|
|
dmg->scroll.region.start, dmg->scroll.region.end,
|
|
|
|
|
dmg->scroll.lines,
|
|
|
|
|
dst_y, src_y, height, stride,
|
|
|
|
|
buf->size);
|
|
|
|
|
|
|
|
|
|
if (height > 0) {
|
|
|
|
|
cairo_surface_flush(buf->cairo_surface);
|
|
|
|
|
uint8_t *raw = cairo_image_surface_get_data(buf->cairo_surface);
|
|
|
|
|
|
|
|
|
|
memmove(raw + dst_y * stride, raw + src_y * stride, height * stride);
|
|
|
|
|
cairo_surface_mark_dirty(buf->cairo_surface);
|
|
|
|
|
|
|
|
|
|
wl_surface_damage_buffer(term->wl.surface, 0, dst_y, width, height);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void frame_callback(
|
|
|
|
|
void *data, struct wl_callback *wl_callback, uint32_t callback_data);
|
|
|
|
|
|
|
|
|
|
static const struct wl_callback_listener frame_listener = {
|
|
|
|
|
.done = &frame_callback,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
grid_render(struct terminal *term)
|
|
|
|
|
{
|
|
|
|
|
static int last_cursor;
|
|
|
|
|
|
|
|
|
|
assert(term->width > 0);
|
|
|
|
|
assert(term->height > 0);
|
|
|
|
|
|
|
|
|
|
struct buffer *buf = shm_get_buffer(term->wl.shm, term->width, term->height);
|
|
|
|
|
cairo_set_operator(buf->cairo, CAIRO_OPERATOR_SOURCE);
|
|
|
|
|
|
|
|
|
|
static struct buffer *last_buf = NULL;
|
|
|
|
|
if (last_buf != buf || false) {
|
|
|
|
|
if (last_buf != NULL) {
|
|
|
|
|
LOG_WARN("new buffer");
|
|
|
|
|
|
2019-07-05 15:53:53 +02:00
|
|
|
/* Fill area outside the cell grid with the default background color */
|
|
|
|
|
int rmargin = term->cols * term->cell_width;
|
|
|
|
|
int bmargin = term->rows * term->cell_height;
|
|
|
|
|
int rmargin_width = term->width - rmargin;
|
|
|
|
|
int bmargin_height = term->height - bmargin;
|
|
|
|
|
|
2019-07-08 15:56:15 +02:00
|
|
|
const struct rgb *bg = !term->reverse ?
|
2019-07-05 20:12:40 +02:00
|
|
|
&term->background : &term->foreground;
|
2019-07-08 15:56:15 +02:00
|
|
|
cairo_set_source_rgb(buf->cairo, bg->r, bg->g, bg->b);
|
2019-07-05 15:53:53 +02:00
|
|
|
|
|
|
|
|
cairo_rectangle(buf->cairo, rmargin, 0, rmargin_width, term->height);
|
|
|
|
|
cairo_rectangle(buf->cairo, 0, bmargin, term->width, bmargin_height);
|
|
|
|
|
cairo_fill(buf->cairo);
|
|
|
|
|
|
|
|
|
|
wl_surface_damage_buffer(
|
|
|
|
|
term->wl.surface, rmargin, 0, rmargin_width, term->height);
|
|
|
|
|
wl_surface_damage_buffer(
|
|
|
|
|
term->wl.surface, 0, bmargin, term->width, bmargin_height);
|
|
|
|
|
|
|
|
|
|
/* Force a full grid refresh */
|
2019-07-05 10:16:56 +02:00
|
|
|
term_damage_all(term);
|
|
|
|
|
}
|
|
|
|
|
last_buf = buf;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-08 13:57:31 +02:00
|
|
|
bool all_clean = tll_length(term->grid->scroll_damage) == 0;
|
|
|
|
|
|
2019-07-05 10:16:56 +02:00
|
|
|
tll_foreach(term->grid->scroll_damage, it) {
|
|
|
|
|
switch (it->item.type) {
|
|
|
|
|
case DAMAGE_SCROLL:
|
|
|
|
|
grid_render_scroll(term, buf, &it->item);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DAMAGE_SCROLL_REVERSE:
|
|
|
|
|
grid_render_scroll_reverse(term, buf, &it->item);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tll_remove(term->grid->scroll_damage, it);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-07 21:55:31 +02:00
|
|
|
gseq.g = gseq.glyphs;
|
|
|
|
|
gseq.count = 0;
|
2019-07-08 13:57:31 +02:00
|
|
|
|
|
|
|
|
for (int r = 0; r < term->rows; r++) {
|
2019-07-09 16:26:36 +02:00
|
|
|
struct row *row = grid_row_in_view(term->grid, r);
|
2019-07-08 13:57:31 +02:00
|
|
|
|
|
|
|
|
if (!row->dirty)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
//LOG_WARN("rendering line: %d", r);
|
|
|
|
|
|
|
|
|
|
for (int col = 0; col < term->cols; col++)
|
|
|
|
|
render_cell(term, buf, &row->cells[col], col, r);
|
|
|
|
|
|
|
|
|
|
row->dirty = false;
|
|
|
|
|
all_clean = false;
|
|
|
|
|
|
|
|
|
|
wl_surface_damage_buffer(term->wl.surface, 0, r * term->cell_height, term->width, term->cell_height);
|
|
|
|
|
}
|
2019-07-05 10:16:56 +02:00
|
|
|
|
|
|
|
|
/* TODO: break out to function */
|
|
|
|
|
/* Re-render last cursor cell and current cursor cell */
|
|
|
|
|
/* Make sure previous cursor is refreshed (to avoid "ghost" cursors) */
|
2019-07-08 13:57:31 +02:00
|
|
|
int cursor_as_linear
|
|
|
|
|
= (term->grid->offset + term->cursor.row) * term->cols + term->cursor.col;
|
|
|
|
|
|
|
|
|
|
if (last_cursor != cursor_as_linear) {
|
2019-07-09 16:26:36 +02:00
|
|
|
int row = last_cursor / term->cols - term->grid->view;
|
2019-07-08 13:57:31 +02:00
|
|
|
int col = last_cursor % term->cols;
|
|
|
|
|
if (row >= 0 && row < term->rows) {
|
2019-07-09 16:26:36 +02:00
|
|
|
render_cell(term, buf, &grid_row_in_view(term->grid, row)->cells[col], col, row);
|
2019-07-08 13:57:31 +02:00
|
|
|
all_clean = false;
|
|
|
|
|
|
|
|
|
|
wl_surface_damage_buffer(
|
|
|
|
|
term->wl.surface, col * term->cell_width, row * term->cell_height,
|
|
|
|
|
term->cell_width, term->cell_height);
|
|
|
|
|
}
|
|
|
|
|
last_cursor = cursor_as_linear;
|
2019-07-05 10:16:56 +02:00
|
|
|
}
|
|
|
|
|
|
2019-07-08 13:57:31 +02:00
|
|
|
if (all_clean) {
|
|
|
|
|
buf->busy = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render_cell(
|
|
|
|
|
term, buf,
|
2019-07-09 16:26:36 +02:00
|
|
|
&grid_row_in_view(term->grid, term->cursor.row)->cells[term->cursor.col],
|
2019-07-08 13:57:31 +02:00
|
|
|
term->cursor.col, term->cursor.row);
|
|
|
|
|
|
|
|
|
|
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);
|
2019-07-05 10:16:56 +02:00
|
|
|
|
2019-07-07 21:55:31 +02:00
|
|
|
if (gseq.count > 0) {
|
|
|
|
|
cairo_set_scaled_font(buf->cairo, attrs_to_font(term, &gseq.attrs));
|
2019-07-08 15:56:15 +02:00
|
|
|
cairo_set_source_rgb(
|
2019-07-07 21:55:31 +02:00
|
|
|
buf->cairo, gseq.foreground.r, gseq.foreground.g,
|
2019-07-08 15:56:15 +02:00
|
|
|
gseq.foreground.b);
|
2019-07-07 21:55:31 +02:00
|
|
|
cairo_show_glyphs(buf->cairo, gseq.glyphs, gseq.count);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-08 15:27:44 +02:00
|
|
|
assert(term->grid->offset >= 0 && term->grid->offset < term->grid->num_rows);
|
2019-07-09 16:26:36 +02:00
|
|
|
assert(term->grid->view >= 0 && term->grid->view < term->grid->num_rows);
|
2019-07-05 10:16:56 +02:00
|
|
|
|
2019-07-09 09:17:24 +02:00
|
|
|
cairo_surface_flush(buf->cairo_surface);
|
2019-07-05 10:16:56 +02:00
|
|
|
wl_surface_attach(term->wl.surface, buf->wl_buf, 0, 0);
|
|
|
|
|
|
2019-07-09 09:23:32 +02:00
|
|
|
assert(term->frame_callback == NULL);
|
|
|
|
|
term->frame_callback = wl_surface_frame(term->wl.surface);
|
|
|
|
|
wl_callback_add_listener(term->frame_callback, &frame_listener, term);
|
2019-07-05 10:16:56 +02:00
|
|
|
|
|
|
|
|
wl_surface_commit(term->wl.surface);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
frame_callback(void *data, struct wl_callback *wl_callback, uint32_t callback_data)
|
|
|
|
|
{
|
|
|
|
|
struct terminal *term = data;
|
|
|
|
|
|
2019-07-09 09:23:32 +02:00
|
|
|
assert(term->frame_callback == wl_callback);
|
2019-07-05 10:16:56 +02:00
|
|
|
wl_callback_destroy(wl_callback);
|
2019-07-09 09:23:32 +02:00
|
|
|
term->frame_callback = NULL;
|
2019-07-05 10:16:56 +02:00
|
|
|
grid_render(term);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-09 09:12:41 +02:00
|
|
|
static void
|
|
|
|
|
reflow(struct row **new_grid, int new_cols, int new_rows,
|
|
|
|
|
struct row *const *old_grid, int old_cols, int old_rows)
|
|
|
|
|
{
|
|
|
|
|
/* TODO: actually reflow */
|
|
|
|
|
for (int r = 0; r < min(new_rows, old_rows); r++) {
|
|
|
|
|
size_t copy_cols = min(new_cols, old_cols);
|
|
|
|
|
size_t clear_cols = new_cols - copy_cols;
|
|
|
|
|
|
|
|
|
|
struct cell *new_cells = new_grid[r]->cells;
|
|
|
|
|
const struct cell *old_cells = old_grid[r]->cells;
|
|
|
|
|
|
2019-07-09 16:26:36 +02:00
|
|
|
new_grid[r]->initialized = old_grid[r]->initialized;
|
|
|
|
|
new_grid[r]->dirty = old_grid[r]->dirty;
|
|
|
|
|
|
2019-07-09 09:12:41 +02:00
|
|
|
memcpy(new_cells, old_cells, copy_cols * sizeof(new_cells[0]));
|
|
|
|
|
memset(&new_cells[copy_cols], 0, clear_cols * sizeof(new_cells[0]));
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-09 16:26:36 +02:00
|
|
|
for (int r = min(new_rows, old_rows); r < new_rows; r++) {
|
|
|
|
|
new_grid[r]->initialized = false;
|
|
|
|
|
new_grid[r]->dirty = false;
|
2019-07-09 09:12:41 +02:00
|
|
|
memset(new_grid[r]->cells, 0, new_cols * sizeof(new_grid[r]->cells[0]));
|
2019-07-09 16:26:36 +02:00
|
|
|
}
|
2019-07-09 09:12:41 +02:00
|
|
|
}
|
|
|
|
|
|
2019-07-05 10:16:56 +02:00
|
|
|
/* Move to terminal.c? */
|
|
|
|
|
void
|
|
|
|
|
render_resize(struct terminal *term, int width, int height)
|
|
|
|
|
{
|
|
|
|
|
if (width == term->width && height == term->height)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
term->width = width;
|
|
|
|
|
term->height = height;
|
|
|
|
|
|
2019-07-09 16:26:36 +02:00
|
|
|
const int scrollback_lines = 10000;
|
|
|
|
|
|
2019-07-09 09:12:41 +02:00
|
|
|
const int old_cols = term->cols;
|
2019-07-08 13:57:31 +02:00
|
|
|
const int old_rows = term->rows;
|
2019-07-09 09:12:41 +02:00
|
|
|
const int old_normal_grid_rows = term->normal.num_rows;
|
|
|
|
|
const int old_alt_grid_rows = term->alt.num_rows;
|
|
|
|
|
|
2019-07-08 13:57:31 +02:00
|
|
|
const int new_cols = term->width / term->cell_width;
|
|
|
|
|
const int new_rows = term->height / term->cell_height;
|
2019-07-09 16:26:36 +02:00
|
|
|
const int new_normal_grid_rows = new_rows + scrollback_lines;
|
2019-07-09 09:12:41 +02:00
|
|
|
const int new_alt_grid_rows = new_rows;
|
|
|
|
|
|
|
|
|
|
/* Allocate new 'normal' grid */
|
|
|
|
|
struct row **normal = malloc(new_normal_grid_rows * sizeof(normal[0]));
|
|
|
|
|
for (int r = 0; r < new_normal_grid_rows; r++) {
|
|
|
|
|
struct row *row = malloc(sizeof(*row));
|
|
|
|
|
row->cells = malloc(new_cols * sizeof(row->cells[0]));
|
|
|
|
|
normal[r] = row;
|
|
|
|
|
}
|
2019-07-08 13:57:31 +02:00
|
|
|
|
2019-07-09 09:12:41 +02:00
|
|
|
/* Allocate new 'alt' grid */
|
|
|
|
|
struct row **alt = malloc(new_alt_grid_rows * sizeof(alt[0]));
|
|
|
|
|
for (int r = 0; r < new_alt_grid_rows; r++) {
|
|
|
|
|
struct row *row = malloc(sizeof(*row));
|
|
|
|
|
row->cells = malloc(new_cols * sizeof(row->cells[0]));
|
|
|
|
|
alt[r] = row;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Reflow content */
|
|
|
|
|
reflow(normal, new_cols, new_normal_grid_rows,
|
|
|
|
|
term->normal.rows, old_cols, old_normal_grid_rows);
|
|
|
|
|
reflow(alt, new_cols, new_alt_grid_rows,
|
|
|
|
|
term->alt.rows, old_cols, old_alt_grid_rows);
|
|
|
|
|
|
2019-07-09 16:26:36 +02:00
|
|
|
for (int r = 0; r < new_rows; r++) {
|
|
|
|
|
normal[r]->initialized = true;
|
|
|
|
|
alt[r]->initialized = true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-09 09:12:41 +02:00
|
|
|
/* Free old 'normal' grid */
|
2019-07-08 13:57:31 +02:00
|
|
|
for (int r = 0; r < term->normal.num_rows; r++) {
|
|
|
|
|
free(term->normal.rows[r]->cells);
|
|
|
|
|
free(term->normal.rows[r]);
|
|
|
|
|
}
|
|
|
|
|
free(term->normal.rows);
|
|
|
|
|
|
2019-07-09 09:12:41 +02:00
|
|
|
/* Free old 'alt' grid */
|
2019-07-08 13:57:31 +02:00
|
|
|
for (int r = 0; r < term->alt.num_rows; r++) {
|
|
|
|
|
free(term->alt.rows[r]->cells);
|
|
|
|
|
free(term->alt.rows[r]);
|
|
|
|
|
}
|
|
|
|
|
free(term->alt.rows);
|
|
|
|
|
|
|
|
|
|
term->cols = new_cols;
|
|
|
|
|
term->rows = new_rows;
|
2019-07-05 10:16:56 +02:00
|
|
|
|
2019-07-09 09:12:41 +02:00
|
|
|
term->normal.rows = normal;
|
|
|
|
|
term->normal.num_rows = new_normal_grid_rows;
|
|
|
|
|
term->alt.rows = alt;
|
|
|
|
|
term->alt.num_rows = new_alt_grid_rows;
|
|
|
|
|
|
2019-07-05 10:16:56 +02:00
|
|
|
LOG_INFO("resize: %dx%d, grid: cols=%d, rows=%d",
|
|
|
|
|
term->width, term->height, term->cols, term->rows);
|
|
|
|
|
|
|
|
|
|
/* Signal TIOCSWINSZ */
|
|
|
|
|
if (ioctl(term->ptmx, TIOCSWINSZ,
|
|
|
|
|
&(struct winsize){
|
|
|
|
|
.ws_row = term->rows,
|
|
|
|
|
.ws_col = term->cols,
|
|
|
|
|
.ws_xpixel = term->width,
|
|
|
|
|
.ws_ypixel = term->height}) == -1)
|
|
|
|
|
{
|
|
|
|
|
LOG_ERRNO("TIOCSWINSZ");
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-09 09:12:41 +02:00
|
|
|
if (term->scroll_region.start >= term->rows)
|
|
|
|
|
term->scroll_region.start = 0;
|
|
|
|
|
|
|
|
|
|
if (term->scroll_region.end >= old_rows)
|
2019-07-05 10:16:56 +02:00
|
|
|
term->scroll_region.end = term->rows;
|
|
|
|
|
|
2019-07-09 16:26:36 +02:00
|
|
|
term->normal.offset %= term->normal.num_rows;
|
|
|
|
|
term->normal.view %= term->alt.num_rows;
|
|
|
|
|
|
|
|
|
|
term->alt.offset %= term->alt.num_rows;
|
|
|
|
|
term->alt.view %= term->alt.num_rows;
|
|
|
|
|
|
2019-07-05 10:16:56 +02:00
|
|
|
term_cursor_to(
|
|
|
|
|
term,
|
|
|
|
|
min(term->cursor.row, term->rows - 1),
|
|
|
|
|
min(term->cursor.col, term->cols - 1));
|
2019-07-09 16:26:36 +02:00
|
|
|
|
|
|
|
|
/* TODO: damage view */
|
2019-07-05 10:16:56 +02:00
|
|
|
term_damage_all(term);
|
|
|
|
|
|
2019-07-09 09:23:32 +02:00
|
|
|
if (term->frame_callback == NULL)
|
2019-07-05 10:16:56 +02:00
|
|
|
grid_render(term);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
render_set_title(struct terminal *term, const char *title)
|
|
|
|
|
{
|
|
|
|
|
xdg_toplevel_set_title(term->wl.xdg_toplevel, title);
|
|
|
|
|
}
|
2019-07-05 10:44:09 +02:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
render_update_cursor_surface(struct terminal *term)
|
|
|
|
|
{
|
|
|
|
|
if (term->wl.pointer.cursor == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
//const int scale = backend->monitor->scale;
|
|
|
|
|
const int scale = 1;
|
|
|
|
|
|
|
|
|
|
struct wl_cursor_image *image = term->wl.pointer.cursor->images[0];
|
|
|
|
|
|
|
|
|
|
wl_surface_set_buffer_scale(term->wl.pointer.surface, scale);
|
|
|
|
|
|
|
|
|
|
wl_surface_attach(
|
|
|
|
|
term->wl.pointer.surface, wl_cursor_image_get_buffer(image), 0, 0);
|
|
|
|
|
|
|
|
|
|
wl_pointer_set_cursor(
|
|
|
|
|
term->wl.pointer.pointer, term->wl.pointer.serial,
|
|
|
|
|
term->wl.pointer.surface,
|
|
|
|
|
image->hotspot_x / scale, image->hotspot_y / scale);
|
|
|
|
|
|
|
|
|
|
wl_surface_damage_buffer(
|
|
|
|
|
term->wl.pointer.surface, 0, 0, INT32_MAX, INT32_MAX);
|
|
|
|
|
|
|
|
|
|
wl_surface_commit(term->wl.pointer.surface);
|
|
|
|
|
}
|