console: allow resizing the console
authorDavid Herrmann <dh.herrmann@googlemail.com>
Wed, 21 Dec 2011 15:39:51 +0000 (16:39 +0100)
committerDavid Herrmann <dh.herrmann@googlemail.com>
Wed, 21 Dec 2011 15:39:51 +0000 (16:39 +0100)
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>
src/console.c
src/console.h

index 7533215..93f19ed 100644 (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);
                }
index 2ddb9b8..e5c62df 100644 (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);