console: allow resizing the console

Forward resizing requests to the buffer but correctly update our size cache and
the cursor position.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
David Herrmann 2011-12-21 16:39:51 +01:00
parent d75404742b
commit a20e5c3a18
2 changed files with 46 additions and 2 deletions

View File

@ -157,6 +157,45 @@ void kmscon_console_unref(struct kmscon_console *con)
free(con);
}
unsigned int kmscon_console_get_width(struct kmscon_console *con)
{
if (!con)
return 0;
return con->cells_x;
}
unsigned int kmscon_console_get_height(struct kmscon_console *con)
{
if (!con)
return 0;
return con->cells_y;
}
int kmscon_console_resize(struct kmscon_console *con, unsigned int x,
unsigned int y)
{
int ret;
if (!con)
return -EINVAL;
ret = kmscon_buffer_resize(con->cells, x, y);
if (ret)
return ret;
con->cells_x = kmscon_buffer_get_width(con->cells);
con->cells_y = kmscon_buffer_get_height(con->cells);
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;
return 0;
}
/*
* This resets the resolution used for drawing operations. It is recommended to
* set this to the size of your framebuffer, however, you can set this to
@ -302,10 +341,10 @@ void kmscon_console_write(struct kmscon_console *con,
if (!con)
return;
if (con->cursor_x == con->cells_x) {
if (con->cursor_x >= con->cells_x) {
con->cursor_x = 0;
con->cursor_y++;
if (con->cursor_y == con->cells_y) {
if (con->cursor_y >= con->cells_y) {
con->cursor_y--;
kmscon_buffer_rotate(con->cells);
}

View File

@ -92,6 +92,11 @@ int kmscon_console_new(struct kmscon_console **out);
void kmscon_console_ref(struct kmscon_console *con);
void kmscon_console_unref(struct kmscon_console *con);
unsigned int kmscon_console_get_width(struct kmscon_console *con);
unsigned int kmscon_console_get_height(struct kmscon_console *con);
int kmscon_console_resize(struct kmscon_console *con, unsigned int x,
unsigned int y);
int kmscon_console_set_res(struct kmscon_console *con, uint32_t x, uint32_t y);
void kmscon_console_draw(struct kmscon_console *con);
void kmscon_console_map(struct kmscon_console *con);