mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-04 04:06:06 -05:00
cleanup
This commit is contained in:
parent
0f14b5298e
commit
d7bb83022d
4 changed files with 14 additions and 589 deletions
2
main.c
2
main.c
|
|
@ -10,8 +10,6 @@
|
|||
#include <poll.h>
|
||||
#include <errno.h>
|
||||
|
||||
//#include <termios.h>
|
||||
|
||||
#include <wayland-client.h>
|
||||
#include <wayland-cursor.h>
|
||||
#include <xdg-shell.h>
|
||||
|
|
|
|||
303
render.c
303
render.c
|
|
@ -117,226 +117,6 @@ render_cell(struct terminal *term, struct buffer *buf, const struct cell *cell,
|
|||
assert(gseq.count <= sizeof(gseq.glyphs) / sizeof(gseq.glyphs[0]));
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void
|
||||
grid_render_update(struct terminal *term, struct buffer *buf, const struct damage *dmg)
|
||||
{
|
||||
LOG_DBG("damage: UPDATE: %d -> %d (offset = %d)",
|
||||
(dmg->range.start - term->grid->offset) % term->grid->size,
|
||||
(dmg->range.start - term->grid->offset) % term->grid->size + dmg->range.length,
|
||||
term->grid->offset);
|
||||
|
||||
int start = dmg->range.start;
|
||||
int length = dmg->range.length;
|
||||
|
||||
if (start < term->grid->offset) {
|
||||
int end = start + length;
|
||||
if (end >= term->grid->offset) {
|
||||
start = term->grid->offset;
|
||||
length = end - start;
|
||||
} else
|
||||
return;
|
||||
}
|
||||
|
||||
const int cols = term->cols;
|
||||
|
||||
for (int linear_cursor = start,
|
||||
row = ((start - term->grid->offset) % term->grid->size) / cols,
|
||||
col = ((start - term->grid->offset) % term->grid->size) % cols;
|
||||
linear_cursor < start + length;
|
||||
linear_cursor++,
|
||||
col = col + 1 >= term->cols ? 0 : col + 1,
|
||||
row += col == 0 ? 1 : 0)
|
||||
{
|
||||
|
||||
assert(row >= 0);
|
||||
assert(row < term->rows);
|
||||
assert(col >= 0);
|
||||
assert(col < term->cols);
|
||||
|
||||
int cell_idx = linear_cursor % term->grid->size;
|
||||
if (cell_idx < 0)
|
||||
cell_idx += term->grid->size;
|
||||
|
||||
assert(cell_idx >= 0);
|
||||
assert(cell_idx < term->rows * term->cols);
|
||||
|
||||
const struct cell *cell = &term->grid->cells[cell_idx];
|
||||
|
||||
/* Cursor here? */
|
||||
bool has_cursor
|
||||
= (!term->hide_cursor &&
|
||||
(term->cursor.linear == linear_cursor - term->grid->offset));
|
||||
|
||||
int x = col * term->cell_width;
|
||||
int y = row * term->cell_height;
|
||||
int width = term->cell_width;
|
||||
int height = term->cell_height;
|
||||
|
||||
struct rgba foreground = cell->attrs.have_foreground
|
||||
? cell->attrs.foreground
|
||||
: !term->reverse ? term->foreground : term->background;
|
||||
struct rgba background = cell->attrs.have_background
|
||||
? cell->attrs.background
|
||||
: !term->reverse ? term->background : term->foreground;
|
||||
|
||||
if (has_cursor) {
|
||||
struct rgba swap = foreground;
|
||||
foreground = background;
|
||||
background = swap;
|
||||
}
|
||||
|
||||
if (cell->attrs.reverse) {
|
||||
struct rgba swap = foreground;
|
||||
foreground = background;
|
||||
background = swap;
|
||||
}
|
||||
|
||||
/* Background */
|
||||
cairo_set_source_rgba(
|
||||
buf->cairo, background.r, background.g, background.b, background.a);
|
||||
cairo_rectangle(buf->cairo, x, y, width, height);
|
||||
cairo_fill(buf->cairo);
|
||||
|
||||
if (cell->c[0] == '\0' || cell->c[0] == ' ')
|
||||
continue;
|
||||
|
||||
if (cell->attrs.conceal)
|
||||
continue;
|
||||
|
||||
/*
|
||||
* 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 ||
|
||||
memcmp(&gseq.foreground, &foreground, sizeof(foreground)) != 0)
|
||||
{
|
||||
if (gseq.count >= sizeof(gseq.glyphs) / sizeof(gseq.glyphs[0]) - 10)
|
||||
LOG_WARN("hit glyph limit");
|
||||
cairo_set_scaled_font(buf->cairo, attrs_to_font(term, &gseq.attrs));
|
||||
cairo_set_source_rgba(
|
||||
buf->cairo, gseq.foreground.r, gseq.foreground.g,
|
||||
gseq.foreground.b, gseq.foreground.a);
|
||||
|
||||
cairo_set_operator(buf->cairo, CAIRO_OPERATOR_OVER);
|
||||
cairo_show_glyphs(buf->cairo, gseq.glyphs, gseq.count);
|
||||
|
||||
gseq.g = gseq.glyphs;
|
||||
gseq.count = 0;
|
||||
gseq.attrs = cell->attrs;
|
||||
gseq.foreground = foreground;
|
||||
}
|
||||
|
||||
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)
|
||||
continue;
|
||||
|
||||
gseq.g += new_glyphs;
|
||||
gseq.count += new_glyphs;
|
||||
assert(gseq.count <= sizeof(gseq.glyphs) / sizeof(gseq.glyphs[0]));
|
||||
}
|
||||
|
||||
wl_surface_damage_buffer(
|
||||
term->wl.surface,
|
||||
0, ((dmg->range.start - term->grid->offset) / cols) * term->cell_height,
|
||||
buf->width, (dmg->range.length + cols - 1) / cols * term->cell_height);
|
||||
}
|
||||
|
||||
static void
|
||||
grid_render_erase(struct terminal *term, struct buffer *buf, const struct damage *dmg)
|
||||
{
|
||||
LOG_DBG("damage: ERASE: %d -> %d (offset = %d)",
|
||||
(dmg->range.start - term->grid->offset) % term->grid->size,
|
||||
(dmg->range.start - term->grid->offset) % term->grid->size + dmg->range.length,
|
||||
term->grid->offset);
|
||||
|
||||
assert(dmg->range.start >= term->grid->offset);
|
||||
|
||||
const struct rgba *bg = !term->reverse ?
|
||||
&term->background : &term->foreground;
|
||||
|
||||
cairo_set_source_rgba(buf->cairo, bg->r, bg->g, bg->b, bg->a);
|
||||
|
||||
const int cols = term->cols;
|
||||
|
||||
int start = (dmg->range.start - term->grid->offset) % term->grid->size;
|
||||
int left = dmg->range.length;
|
||||
|
||||
int row = start / cols;
|
||||
int col = start % cols;
|
||||
|
||||
/* Partial initial line */
|
||||
if (col != 0) {
|
||||
int cell_count = min(left, cols - col);
|
||||
|
||||
int x = col * term->cell_width;
|
||||
int y = row * term->cell_height;
|
||||
int width = cell_count * term->cell_width;
|
||||
int height = term->cell_height;
|
||||
|
||||
cairo_rectangle(buf->cairo, x, y, width, height);
|
||||
cairo_fill(buf->cairo);
|
||||
wl_surface_damage_buffer(term->wl.surface, x, y, width, height);
|
||||
|
||||
start += cell_count;
|
||||
left -= cell_count;
|
||||
|
||||
row = start / cols;
|
||||
col = start % cols;
|
||||
}
|
||||
|
||||
assert(left == 0 || col == 0);
|
||||
|
||||
/* One or more full lines left */
|
||||
if (left >= cols) {
|
||||
int line_count = left / cols;
|
||||
|
||||
int x = 0;
|
||||
int y = row * term->cell_height;
|
||||
int width = buf->width;
|
||||
int height = line_count * term->cell_height;
|
||||
|
||||
cairo_rectangle(buf->cairo, x, y, width, height);
|
||||
cairo_fill(buf->cairo);
|
||||
wl_surface_damage_buffer(term->wl.surface, x, y, width, height);
|
||||
|
||||
start += line_count * cols;
|
||||
left -= line_count * cols;
|
||||
|
||||
row += line_count;
|
||||
col = 0;
|
||||
}
|
||||
|
||||
assert(left == 0 || col == 0);
|
||||
assert(left < cols);
|
||||
|
||||
/* Partial last line */
|
||||
if (left > 0) {
|
||||
int x = 0;
|
||||
int y = row * term->cell_height;
|
||||
int width = left * term->cell_width;
|
||||
int height = term->cell_height;
|
||||
|
||||
cairo_rectangle(buf->cairo, x, y, width, height);
|
||||
cairo_fill(buf->cairo);
|
||||
wl_surface_damage_buffer(term->wl.surface, x, y, width, height);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
grid_render_scroll(struct terminal *term, struct buffer *buf,
|
||||
const struct damage *dmg)
|
||||
|
|
@ -364,21 +144,6 @@ grid_render_scroll(struct terminal *term, struct buffer *buf,
|
|||
|
||||
wl_surface_damage_buffer(term->wl.surface, 0, dst_y, width, height);
|
||||
}
|
||||
|
||||
#if 0
|
||||
const int cols = term->cols;
|
||||
|
||||
struct damage erase = {
|
||||
.type = DAMAGE_ERASE,
|
||||
.range = {
|
||||
.start = term->grid->offset + max(dmg->scroll.region.end - dmg->scroll.lines,
|
||||
dmg->scroll.region.start) * cols,
|
||||
.length = min(dmg->scroll.region.end - dmg->scroll.region.start,
|
||||
dmg->scroll.lines) * cols,
|
||||
},
|
||||
};
|
||||
grid_render_erase(term, buf, &erase);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -408,20 +173,6 @@ grid_render_scroll_reverse(struct terminal *term, struct buffer *buf,
|
|||
|
||||
wl_surface_damage_buffer(term->wl.surface, 0, dst_y, width, height);
|
||||
}
|
||||
|
||||
#if 0
|
||||
const int cols = term->cols;
|
||||
|
||||
struct damage erase = {
|
||||
.type = DAMAGE_ERASE,
|
||||
.range = {
|
||||
.start = term->grid->offset + dmg->scroll.region.start * cols,
|
||||
.length = min(dmg->scroll.region.end - dmg->scroll.region.start,
|
||||
dmg->scroll.lines) * cols,
|
||||
},
|
||||
};
|
||||
grid_render_erase(term, buf, &erase);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void frame_callback(
|
||||
|
|
@ -436,19 +187,9 @@ grid_render(struct terminal *term)
|
|||
{
|
||||
static int last_cursor;
|
||||
|
||||
#if 0
|
||||
if (tll_length(term->grid->damage) == 0 &&
|
||||
tll_length(term->grid->scroll_damage) == 0 &&
|
||||
last_cursor == term->grid->offset + term->cursor.linear)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
assert(term->width > 0);
|
||||
assert(term->height > 0);
|
||||
|
||||
//LOG_WARN("RENDER");
|
||||
|
||||
struct buffer *buf = shm_get_buffer(term->wl.shm, term->width, term->height);
|
||||
cairo_set_operator(buf->cairo, CAIRO_OPERATOR_SOURCE);
|
||||
|
||||
|
|
@ -493,11 +234,6 @@ grid_render(struct terminal *term)
|
|||
case DAMAGE_SCROLL_REVERSE:
|
||||
grid_render_scroll_reverse(term, buf, &it->item);
|
||||
break;
|
||||
|
||||
case DAMAGE_UPDATE:
|
||||
case DAMAGE_ERASE:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
|
||||
tll_remove(term->grid->scroll_damage, it);
|
||||
|
|
@ -505,21 +241,6 @@ grid_render(struct terminal *term)
|
|||
|
||||
gseq.g = gseq.glyphs;
|
||||
gseq.count = 0;
|
||||
#if 0
|
||||
tll_foreach(term->grid->damage, it) {
|
||||
switch (it->item.type) {
|
||||
case DAMAGE_ERASE: grid_render_erase(term, buf, &it->item); break;
|
||||
case DAMAGE_UPDATE: grid_render_update(term, buf, &it->item); break;
|
||||
|
||||
case DAMAGE_SCROLL:
|
||||
case DAMAGE_SCROLL_REVERSE:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
|
||||
tll_remove(term->grid->damage, it);
|
||||
}
|
||||
#endif
|
||||
|
||||
for (int r = 0; r < term->rows; r++) {
|
||||
struct row *row = grid_row(term->grid, r);
|
||||
|
|
@ -545,14 +266,6 @@ grid_render(struct terminal *term)
|
|||
= (term->grid->offset + term->cursor.row) * term->cols + term->cursor.col;
|
||||
|
||||
if (last_cursor != cursor_as_linear) {
|
||||
#if 0
|
||||
struct damage prev_cursor = {
|
||||
.type = DAMAGE_UPDATE,
|
||||
.range = {.start = last_cursor, .length = 1},
|
||||
};
|
||||
grid_render_update(term, buf, &prev_cursor);
|
||||
#endif
|
||||
#if 1
|
||||
int row = last_cursor / term->cols - term->grid->offset;
|
||||
int col = last_cursor % term->cols;
|
||||
if (row >= 0 && row < term->rows) {
|
||||
|
|
@ -564,7 +277,6 @@ grid_render(struct terminal *term)
|
|||
term->cell_width, term->cell_height);
|
||||
}
|
||||
last_cursor = cursor_as_linear;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (all_clean) {
|
||||
|
|
@ -572,14 +284,6 @@ grid_render(struct terminal *term)
|
|||
return;
|
||||
}
|
||||
|
||||
#if 0
|
||||
struct damage cursor = {
|
||||
.type = DAMAGE_UPDATE,
|
||||
.range = {.start = term->grid->offset + term->cursor.linear, .length = 1},
|
||||
};
|
||||
grid_render_update(term, buf, &cursor);
|
||||
#endif
|
||||
|
||||
render_cell(
|
||||
term, buf,
|
||||
&grid_row(term->grid, term->cursor.row)->cells[term->cursor.col],
|
||||
|
|
@ -600,13 +304,8 @@ grid_render(struct terminal *term)
|
|||
}
|
||||
|
||||
assert(term->grid->offset >= 0 && term->grid->offset < term->grid->num_rows);
|
||||
#if 0
|
||||
term->grid->offset %= term->grid->size;
|
||||
if (term->grid->offset < 0)
|
||||
term->grid->offset += term->grid->size;
|
||||
#endif
|
||||
|
||||
//cairo_surface_flush(buf->cairo_surface);
|
||||
cairo_surface_flush(buf->cairo_surface);
|
||||
wl_surface_attach(term->wl.surface, buf->wl_buf, 0, 0);
|
||||
|
||||
struct wl_callback *cb = wl_surface_frame(term->wl.surface);
|
||||
|
|
|
|||
271
terminal.c
271
terminal.c
|
|
@ -4,6 +4,8 @@
|
|||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <linux/input-event-codes.h>
|
||||
|
||||
#define LOG_MODULE "terminal"
|
||||
#define LOG_ENABLE_DBG 0
|
||||
#include "log.h"
|
||||
|
|
@ -12,142 +14,17 @@
|
|||
#define min(x, y) ((x) < (y) ? (x) : (y))
|
||||
#define max(x, y) ((x) > (y) ? (x) : (y))
|
||||
|
||||
#if 0
|
||||
static bool
|
||||
damage_merge_range(struct terminal *term, const struct damage *dmg)
|
||||
{
|
||||
if (tll_length(term->grid->damage) == 0)
|
||||
return false;
|
||||
|
||||
struct damage *old = &tll_back(term->grid->damage);
|
||||
if (old->type != dmg->type)
|
||||
return false;
|
||||
|
||||
const int start = dmg->range.start;
|
||||
const int end = start + dmg->range.length;
|
||||
|
||||
const int prev_start = old->range.start;
|
||||
const int prev_end = prev_start + old->range.length;
|
||||
|
||||
if ((start >= prev_start && start <= prev_end) ||
|
||||
(end >= prev_start && end <= prev_end) ||
|
||||
(start <= prev_start && end >= prev_end))
|
||||
{
|
||||
/* The two damage ranges intersect */
|
||||
int new_start = min(start, prev_start);
|
||||
int new_end = max(end, prev_end);
|
||||
|
||||
old->range.start = new_start;
|
||||
old->range.length = new_end - new_start;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void
|
||||
term_damage_update_or_erase(struct terminal *term, enum damage_type damage_type,
|
||||
int start, int length)
|
||||
{
|
||||
#if 1
|
||||
if (tll_length(term->grid->damage) > 1024) {
|
||||
term_damage_all(term);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
struct damage dmg = {
|
||||
.type = damage_type,
|
||||
.range = {.start = term->grid->offset + start, .length = length},
|
||||
};
|
||||
|
||||
if (damage_merge_range(term, &dmg))
|
||||
return;
|
||||
|
||||
tll_push_back(term->grid->damage, dmg);
|
||||
}
|
||||
#endif
|
||||
void
|
||||
term_damage_update(struct terminal *term, int start, int length)
|
||||
{
|
||||
#if 0
|
||||
assert(start + length <= term->rows * term->cols);
|
||||
term_damage_update_or_erase(term, DAMAGE_UPDATE, start, length);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
term_damage_erase(struct terminal *term, int start, int length)
|
||||
{
|
||||
#if 0
|
||||
assert(start + length <= term->rows * term->cols);
|
||||
term_damage_update_or_erase(term, DAMAGE_ERASE, start, length);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
term_damage_all(struct terminal *term)
|
||||
{
|
||||
#if 0
|
||||
tll_free(term->grid->damage);
|
||||
tll_free(term->grid->scroll_damage);
|
||||
term_damage_update(term, 0, term->rows * term->cols);
|
||||
#else
|
||||
for (int i = 0; i < term->rows; i++)
|
||||
grid_row(term->grid, i)->dirty = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void
|
||||
damage_adjust_after_scroll(struct terminal *term, enum damage_type damage_type,
|
||||
struct scroll_region region, int lines)
|
||||
{
|
||||
tll_foreach(term->grid->damage, it) {
|
||||
#if 0
|
||||
if (it->item.range.start < term->grid->offset) {
|
||||
int end = it->item.range.start + it->item.range.length;
|
||||
if (end >= term->grid->offset) {
|
||||
it->item.range.start = term->grid->offset;
|
||||
it->item.range.length = end - it->item.range.start;
|
||||
} else {
|
||||
tll_remove(term->grid->damage, it);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int start = it->item.range.start;
|
||||
int end = start + it->item.range.length;
|
||||
|
||||
if (start -
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
term_damage_scroll(struct terminal *term, enum damage_type damage_type,
|
||||
struct scroll_region region, int lines)
|
||||
{
|
||||
#if 0
|
||||
//damage_adjust_after_scroll(term, damage_type, region, lines);
|
||||
if (damage_type == DAMAGE_SCROLL) {
|
||||
tll_foreach(term->grid->damage, it) {
|
||||
int start = it->item.range.start;
|
||||
int length = it->item.range.length;
|
||||
|
||||
if (start < term->grid->offset) {
|
||||
int end = start + length;
|
||||
if (end >= term->grid->offset) {
|
||||
it->item.range.start = term->grid->offset;
|
||||
it->item.range.length = end - it->item.range.start;
|
||||
} else
|
||||
tll_remove(term->grid->damage, it);
|
||||
} else
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (tll_length(term->grid->scroll_damage) > 0) {
|
||||
struct damage *dmg = &tll_back(term->grid->scroll_damage);
|
||||
|
||||
|
|
@ -166,40 +43,6 @@ term_damage_scroll(struct terminal *term, enum damage_type damage_type,
|
|||
tll_push_back(term->grid->scroll_damage, dmg);
|
||||
}
|
||||
|
||||
#if 0
|
||||
void
|
||||
term_erase(struct terminal *term, int start, int end)
|
||||
{
|
||||
LOG_DBG("erase: %d-%d", start, end);
|
||||
assert(end >= start);
|
||||
assert(end <= term->rows * term->cols);
|
||||
|
||||
if (term->vt.attrs.have_background) {
|
||||
int erase_start = start;
|
||||
int left = end - erase_start;
|
||||
|
||||
while (left > 0) {
|
||||
int len = left;
|
||||
struct cell *cells = grid_get_range(term->grid, erase_start, &len);
|
||||
|
||||
memset(cells, 0, len * sizeof(cells[0]));
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
cells[i].attrs.background = term->vt.attrs.background;
|
||||
cells[i].attrs.have_background = true;
|
||||
}
|
||||
|
||||
erase_start += len;
|
||||
left -= len;
|
||||
}
|
||||
|
||||
term_damage_update(term, start, end - start);
|
||||
} else {
|
||||
grid_memclear(term->grid, start, end - start);
|
||||
term_damage_erase(term, start, end - start);
|
||||
}
|
||||
}
|
||||
#else
|
||||
static inline void
|
||||
erase_cell_range(struct terminal *term, struct row *row, int start, int end)
|
||||
{
|
||||
|
|
@ -246,7 +89,6 @@ term_erase(struct terminal *term, const struct coord *start, const struct coord
|
|||
|
||||
erase_cell_range(term, grid_row(term->grid, end->row), 0, end->col);
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
term_cursor_to(struct terminal *term, int row, int col)
|
||||
|
|
@ -301,72 +143,23 @@ term_scroll_partial(struct terminal *term, struct scroll_region region, int rows
|
|||
|
||||
assert(rows < term->rows && "unimplemented");
|
||||
|
||||
/* Top non-scrolling region */
|
||||
for (int i = region.start - 1; i >= 0; i--)
|
||||
grid_swap_row(term->grid, i, i + rows);
|
||||
|
||||
if (region.start > 0) {
|
||||
#if 0
|
||||
tll_foreach(term->grid->damage, it) {
|
||||
int start = it->item.range.start - term->grid->offset;
|
||||
int end __attribute__((unused)) = start + it->item.range.length;
|
||||
|
||||
if (start < region.start * term->cols) {
|
||||
assert(end <= region.start * term->cols);
|
||||
it->item.range.start += rows * term->cols;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Bottom non-scrolling region */
|
||||
for (int i = term->rows - 1; i >= region.end; i--)
|
||||
grid_swap_row(term->grid, i, i + rows);
|
||||
|
||||
if (region.end < term->rows) {
|
||||
#if 0
|
||||
grid_memmove(
|
||||
term->grid,
|
||||
(region.end + rows) * term->cols,
|
||||
region.end * term->cols,
|
||||
(term->rows - region.end) * term->cols);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
tll_foreach(term->grid->damage, it) {
|
||||
int start = it->item.range.start - term->grid->offset;
|
||||
int end = start + it->item.range.length;
|
||||
|
||||
if (end > region.end * term->cols) {
|
||||
assert(start >= region.end * term->cols);
|
||||
it->item.range.start += rows * term->cols;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Offset grid origin */
|
||||
term->grid->offset += rows;
|
||||
term->grid->offset %= term->grid->num_rows;
|
||||
|
||||
#if 0
|
||||
term_erase(
|
||||
term,
|
||||
&(struct coord){0, max(region.end - rows, 0)},
|
||||
&(struct coord){term->cols - 1, region.end - 1});
|
||||
#else
|
||||
for (int r = max(region.end - rows, 0); r < region.end; r++)
|
||||
erase_line(term, grid_row(term->grid, r));
|
||||
#endif
|
||||
|
||||
term_damage_scroll(term, DAMAGE_SCROLL, region, rows);
|
||||
|
||||
term->grid->cur_row = grid_row(term->grid, term->cursor.row);
|
||||
#if 0
|
||||
int len = term->cols;
|
||||
term->grid->cur_line = grid_get_range(
|
||||
term->grid, term->cursor.linear - term->cursor.col, &len);
|
||||
|
||||
assert(len == term->cols);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -381,55 +174,14 @@ term_scroll_reverse_partial(struct terminal *term,
|
|||
{
|
||||
assert(rows < term->rows && "unimplemented");
|
||||
|
||||
if (region.end < term->rows) {
|
||||
//assert(false);
|
||||
#if 0
|
||||
grid_memmove(
|
||||
term->grid,
|
||||
(region.end - rows) * term->cols,
|
||||
region.end * term->cols,
|
||||
(term->rows - region.end) * term->cols);
|
||||
|
||||
tll_foreach(term->grid->damage, it) {
|
||||
int start = it->item.range.start - term->grid->offset;
|
||||
int end = start + it->item.range.length;
|
||||
|
||||
if (end > region.end * term->cols) {
|
||||
assert(start >= region.end * term->cols);
|
||||
it->item.range.start -= rows * term->cols;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (region.start > 0) {
|
||||
//assert(false);
|
||||
#if 0
|
||||
grid_memmove(
|
||||
term->grid, -rows * term->cols, 0, region.start * term->cols);
|
||||
|
||||
tll_foreach(term->grid->damage, it) {
|
||||
int start = it->item.range.start - term->grid->offset;
|
||||
int end __attribute__((unused)) = start + it->item.range.length;
|
||||
|
||||
if (start < region.start * term->cols) {
|
||||
if (end > region.start * term->cols) {
|
||||
LOG_ERR("region.start = %d, rows = %d, damage.start = %d, damage.end = %d (%s)",
|
||||
region.start, rows, start, end, it->item.type == DAMAGE_UPDATE ? "UPDATE" : "ERASE");
|
||||
abort();
|
||||
}
|
||||
assert(end <= region.start * term->cols);
|
||||
it->item.range.start -= rows * term->cols;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
term->grid->offset += term->grid->num_rows - rows;
|
||||
term->grid->offset %= term->grid->num_rows;
|
||||
|
||||
/* Bottom non-scrolling region */
|
||||
for (int i = region.end + rows; i < term->rows + rows; i++)
|
||||
grid_swap_row(term->grid, i, i - rows);
|
||||
|
||||
/* Top non-scrolling region */
|
||||
for (int i = 0 + rows; i < region.start + rows; i++)
|
||||
grid_swap_row(term->grid, i, i - rows);
|
||||
|
||||
|
|
@ -440,13 +192,6 @@ term_scroll_reverse_partial(struct terminal *term,
|
|||
|
||||
term_damage_scroll(term, DAMAGE_SCROLL_REVERSE, region, rows);
|
||||
term->grid->cur_row = grid_row(term->grid, term->cursor.row);
|
||||
#if 0
|
||||
int len = term->cols;
|
||||
term->grid->cur_line = grid_get_range(
|
||||
term->grid, term->cursor.linear - term->cursor.col, &len);
|
||||
|
||||
assert(len == term->cols);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -455,8 +200,6 @@ term_scroll_reverse(struct terminal *term, int rows)
|
|||
term_scroll_reverse_partial(term, term->scroll_region, rows);
|
||||
}
|
||||
|
||||
#include <linux/input-event-codes.h>
|
||||
|
||||
static int
|
||||
linux_mouse_button_to_x(int button)
|
||||
{
|
||||
|
|
|
|||
27
terminal.h
27
terminal.h
|
|
@ -80,24 +80,14 @@ struct coord {
|
|||
int row;
|
||||
};
|
||||
|
||||
enum damage_type {DAMAGE_UPDATE, DAMAGE_ERASE, DAMAGE_SCROLL, DAMAGE_SCROLL_REVERSE};
|
||||
enum damage_type {DAMAGE_SCROLL, DAMAGE_SCROLL_REVERSE};
|
||||
struct damage {
|
||||
enum damage_type type;
|
||||
union {
|
||||
/* DAMAGE_UPDATE, DAMAGE_ERASE */
|
||||
#if 0
|
||||
struct {
|
||||
int start;
|
||||
int length;
|
||||
} range;
|
||||
#endif
|
||||
|
||||
/* DAMAGE_SCROLL, DAMAGE_SCROLL_REVERSE */
|
||||
struct {
|
||||
struct scroll_region region;
|
||||
int lines;
|
||||
} scroll;
|
||||
};
|
||||
/* DAMAGE_SCROLL, DAMAGE_SCROLL_REVERSE */
|
||||
struct {
|
||||
struct scroll_region region;
|
||||
int lines;
|
||||
} scroll;
|
||||
};
|
||||
|
||||
struct row {
|
||||
|
|
@ -109,8 +99,6 @@ struct grid {
|
|||
int num_rows;
|
||||
int offset;
|
||||
|
||||
//struct cell *cells;
|
||||
//struct cell *cur_line;
|
||||
struct row **rows;
|
||||
struct row *cur_row;
|
||||
|
||||
|
|
@ -257,13 +245,10 @@ struct terminal {
|
|||
};
|
||||
|
||||
void term_damage_all(struct terminal *term);
|
||||
void term_damage_update(struct terminal *term, int start, int length);
|
||||
void term_damage_erase(struct terminal *term, int start, int length);
|
||||
void term_damage_scroll(
|
||||
struct terminal *term, enum damage_type damage_type,
|
||||
struct scroll_region region, int lines);
|
||||
|
||||
//void term_erase(struct terminal *term, int start, int end);
|
||||
void term_erase(
|
||||
struct terminal *term, const struct coord *start, const struct coord *end);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue