console: add *_move_to() function
*_move_to() can be used to position the pointer at an arbitrary position inside the buffer. If in relative-addressing mode, you cannot position it outside the scroll-region, though. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
parent
5a0ba19d91
commit
497d3840dc
@ -59,12 +59,26 @@ struct kmscon_console {
|
||||
unsigned int cells_y;
|
||||
unsigned int margin_top; /* idx of first scroll line */
|
||||
unsigned int margin_bottom; /* idx of last scroll line */
|
||||
bool rel_addr; /* is relative addressing used? */
|
||||
|
||||
/* cursor */
|
||||
unsigned int cursor_x;
|
||||
unsigned int cursor_y;
|
||||
};
|
||||
|
||||
static inline unsigned int to_abs_x(struct kmscon_console *con, unsigned int x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
static inline unsigned int to_abs_y(struct kmscon_console *con, unsigned int y)
|
||||
{
|
||||
if (!con->rel_addr)
|
||||
return y;
|
||||
|
||||
return con->margin_top + y;
|
||||
}
|
||||
|
||||
int kmscon_console_new(struct kmscon_console **out,
|
||||
struct kmscon_font_factory *ff, struct kmscon_compositor *comp)
|
||||
{
|
||||
@ -202,10 +216,7 @@ int kmscon_console_resize(struct kmscon_console *con, unsigned int x,
|
||||
num = kmscon_buffer_get_mbottom(con->cells);
|
||||
con->margin_bottom = con->cells_y - 1 - num;
|
||||
|
||||
if (con->cursor_x > con->cells_x)
|
||||
con->cursor_x = con->cells_x;
|
||||
if (con->cursor_y > con->cells_y)
|
||||
con->cursor_y = con->cells_y;
|
||||
kmscon_console_move_to(con, con->cursor_x, con->cursor_y);
|
||||
|
||||
ret = kmscon_font_factory_load(con->ff, &font, 0,
|
||||
height / con->cells_y);
|
||||
@ -271,3 +282,22 @@ void kmscon_console_newline(struct kmscon_console *con)
|
||||
kmscon_buffer_scroll_up(con->cells, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void kmscon_console_move_to(struct kmscon_console *con, unsigned int x,
|
||||
unsigned int y)
|
||||
{
|
||||
if (!con)
|
||||
return;
|
||||
|
||||
con->cursor_x = to_abs_x(con, x);
|
||||
if (con->cursor_x >= con->cells_x)
|
||||
con->cursor_x = con->cells_x - 1;
|
||||
|
||||
con->cursor_y = to_abs_y(con, y);
|
||||
if (con->cursor_y > con->margin_bottom) {
|
||||
if (con->rel_addr)
|
||||
con->cursor_y = con->margin_bottom;
|
||||
else if (con->cursor_y >= con->cells_y)
|
||||
con->cursor_y = con->cells_y - 1;
|
||||
}
|
||||
}
|
||||
|
@ -89,5 +89,7 @@ void kmscon_console_map(struct kmscon_console *con);
|
||||
|
||||
void kmscon_console_write(struct kmscon_console *con, kmscon_symbol_t ch);
|
||||
void kmscon_console_newline(struct kmscon_console *con);
|
||||
void kmscon_console_move_to(struct kmscon_console *con, unsigned int x,
|
||||
unsigned int y);
|
||||
|
||||
#endif /* KMSCON_CONSOLE_H */
|
||||
|
Loading…
x
Reference in New Issue
Block a user