mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-17 05:33:52 -04:00
csi: implement DECOM - switch cursor origin between absolute and relative
The default is absolute mode, where 0,0 is the upper left corner of the screen. In relative mode, the origin is relative the top scroll margin. Internally, we always track the current cursor position in absolute mode. Every time we the client *sets* or *queries* the cursor position in relative mode, we translate it to absolute.
This commit is contained in:
parent
89dbc61a34
commit
95eaad7ce4
3 changed files with 64 additions and 14 deletions
32
terminal.c
32
terminal.c
|
|
@ -486,6 +486,7 @@ term_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl,
|
|||
},
|
||||
.alpha = conf->colors.alpha,
|
||||
},
|
||||
.origin = ORIGIN_ABSOLUTE,
|
||||
.default_cursor_style = conf->cursor.style,
|
||||
.cursor_style = conf->cursor.style,
|
||||
.default_cursor_color = {
|
||||
|
|
@ -991,6 +992,30 @@ 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);
|
||||
}
|
||||
|
||||
struct coord
|
||||
term_cursor_rel_to_abs(const struct terminal *term, int row, int col)
|
||||
{
|
||||
switch (term->origin) {
|
||||
case ORIGIN_ABSOLUTE:
|
||||
return (struct coord) {
|
||||
.col = min(col, term->cols - 1),
|
||||
.row = min(row, term->rows - 1),
|
||||
};
|
||||
break;
|
||||
|
||||
case ORIGIN_RELATIVE: {
|
||||
return (struct coord) {
|
||||
.col = min(col, term->cols - 1),
|
||||
.row = min(row + term->scroll_region.start, term->rows - 1),
|
||||
};
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(false);
|
||||
return (struct coord){-1, -1};
|
||||
}
|
||||
|
||||
void
|
||||
term_cursor_to(struct terminal *term, int row, int col)
|
||||
{
|
||||
|
|
@ -1005,6 +1030,13 @@ term_cursor_to(struct terminal *term, int row, int col)
|
|||
term->grid->cur_row = grid_row(term->grid, row);
|
||||
}
|
||||
|
||||
void
|
||||
term_cursor_home(struct terminal *term)
|
||||
{
|
||||
struct coord new_cursor = term_cursor_rel_to_abs(term, 0, 0);
|
||||
term_cursor_to(term, new_cursor.row, new_cursor.col);
|
||||
}
|
||||
|
||||
void
|
||||
term_cursor_left(struct terminal *term, int count)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue