From a20e5c3a18721850d7937cf9b56b2ca29f98528f Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Wed, 21 Dec 2011 16:39:51 +0100 Subject: [PATCH] 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 --- src/console.c | 43 +++++++++++++++++++++++++++++++++++++++++-- src/console.h | 5 +++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/console.c b/src/console.c index 7533215..93f19ed 100644 --- a/src/console.c +++ b/src/console.c @@ -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); } diff --git a/src/console.h b/src/console.h index 2ddb9b8..e5c62df 100644 --- a/src/console.h +++ b/src/console.h @@ -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);