From 624d5e0a48b3c21746e76887d9dccdbca01b6014 Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Wed, 30 May 2012 19:02:17 +0200 Subject: [PATCH] console/vte: draw cursor If HIDE_CURSOR mode is not set, we draw the cursor at the current position. Signed-off-by: David Herrmann --- src/console.c | 40 +++++++++++++++++++++++++++++++++------- src/console.h | 1 + src/vte.c | 6 ++++++ 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/src/console.c b/src/console.c index b02ff77..4288389 100644 --- a/src/console.c +++ b/src/console.c @@ -713,13 +713,17 @@ static int kmscon_buffer_set_margins(struct kmscon_buffer *buf, } static void kmscon_buffer_draw(struct kmscon_buffer *buf, - struct font_screen *fscr) + struct font_screen *fscr, + unsigned int cur_x, + unsigned int cur_y) { - unsigned int i, j, k, num; + unsigned int i, j, k, num, o; struct line *iter, *line = NULL; struct cell *cell; int idx; float m[16]; + bool cursor_done = false; + struct font_char_attr attr; if (!buf || !fscr) return; @@ -729,6 +733,7 @@ static void kmscon_buffer_draw(struct kmscon_buffer *buf, iter = buf->position; k = 0; idx = 0; + o = 0; for (i = 0; i < buf->size_y; ++i) { if (iter) { line = iter; @@ -757,6 +762,7 @@ static void kmscon_buffer_draw(struct kmscon_buffer *buf, break; } k++; + o++; } if (!line) @@ -769,17 +775,30 @@ static void kmscon_buffer_draw(struct kmscon_buffer *buf, for (j = 0; j < num; ++j) { cell = &line->cells[j]; + memcpy(&attr, &cell->attr, sizeof(attr)); + + if (o == cur_y + 1 && + j == cur_x) { + cursor_done = true; + attr.inverse = !attr.inverse; + } /* TODO: do some more sophisticated inverse here. When * INVERSE mode is set, we should instead just select * inverse colors instead of switching background and * foreground */ if (buf->flags & KMSCON_CONSOLE_INVERSE) - cell->attr.inverse = !cell->attr.inverse; - font_screen_draw_char(fscr, cell->ch, &cell->attr, + attr.inverse = !attr.inverse; + font_screen_draw_char(fscr, cell->ch, &attr, j, i, 1, 1); - if (buf->flags & KMSCON_CONSOLE_INVERSE) - cell->attr.inverse = !cell->attr.inverse; + } + + if (o == cur_y + 1 && !cursor_done) { + cursor_done = true; + if (!(buf->flags & KMSCON_CONSOLE_INVERSE)) + attr.inverse = !attr.inverse; + font_screen_draw_char(fscr, 0, &attr, + cur_x, i, 1, 1); } } @@ -1086,10 +1105,17 @@ unsigned int kmscon_console_get_flags(struct kmscon_console *con) void kmscon_console_draw(struct kmscon_console *con, struct font_screen *fscr) { + unsigned int cur_x, cur_y; + if (!con) return; - kmscon_buffer_draw(con->cells, fscr); + cur_x = con->cursor_x; + if (con->cursor_x >= con->cells->size_x) + cur_x = con->cells->size_x - 1; + cur_y = con->cursor_y; + + kmscon_buffer_draw(con->cells, fscr, cur_x, cur_y); } void kmscon_console_write(struct kmscon_console *con, kmscon_symbol_t ch, diff --git a/src/console.h b/src/console.h index bdeefba..f425139 100644 --- a/src/console.h +++ b/src/console.h @@ -50,6 +50,7 @@ struct kmscon_console; /* modes for kmscon_console_re/set() */ #define KMSCON_CONSOLE_REL_ORIGIN 0x04 #define KMSCON_CONSOLE_INVERSE 0x08 +#define KMSCON_CONSOLE_HIDE_CURSOR 0x10 int kmscon_console_new(struct kmscon_console **out); void kmscon_console_ref(struct kmscon_console *con); diff --git a/src/vte.c b/src/vte.c index cee8f9f..344df9b 100644 --- a/src/vte.c +++ b/src/vte.c @@ -943,6 +943,12 @@ static void csi_mode(struct kmscon_vte *vte, bool set) continue; case 25: /* DECTCEM */ set_reset_flag(vte, set, FLAG_TEXT_CURSOR_MODE); + if (set) + kmscon_console_reset_flags(vte->con, + KMSCON_CONSOLE_HIDE_CURSOR); + else + kmscon_console_set_flags(vte->con, + KMSCON_CONSOLE_HIDE_CURSOR); continue; case 42: /* DECNRCM */ set_reset_flag(vte, set, FLAG_NATIONAL_CHARSET_MODE); -- 2.7.4