diff --git a/src/console.c b/src/console.c index 5501775..7b459e4 100644 --- a/src/console.c +++ b/src/console.c @@ -1,5 +1,5 @@ /* - * kmscon - Console Management + * kmscon - Screen Management * * Copyright (c) 2011-2012 David Herrmann * Copyright (c) 2011 University of Tuebingen @@ -25,8 +25,8 @@ */ /* - * Console Management - * This provides the console drawing and manipulation functions. It does not + * Screen Management + * This provides the screen drawing and manipulation functions. It does not * provide the terminal emulation. It is just an abstraction layer to draw text * to a framebuffer as used by terminals and consoles. */ @@ -41,11 +41,11 @@ #include "shl_timer.h" #include "tsm_unicode.h" -#define LOG_SUBSYSTEM "console" +#define LOG_SUBSYSTEM "tsm_screen" struct cell { tsm_symbol_t ch; - struct kmscon_console_attr attr; + struct tsm_screen_attr attr; }; struct line { @@ -56,13 +56,13 @@ struct line { struct cell *cells; }; -struct kmscon_console { +struct tsm_screen { size_t ref; unsigned int flags; struct shl_timer *timer; /* default attributes for new cells */ - struct kmscon_console_attr def_attr; + struct tsm_screen_attr def_attr; /* current buffer */ unsigned int size_x; @@ -87,13 +87,13 @@ struct kmscon_console { bool *tab_ruler; }; -static void cell_init(struct kmscon_console *con, struct cell *cell) +static void cell_init(struct tsm_screen *con, struct cell *cell) { cell->ch = 0; memcpy(&cell->attr, &con->def_attr, sizeof(cell->attr)); } -static int line_new(struct kmscon_console *con, struct line **out, +static int line_new(struct tsm_screen *con, struct line **out, unsigned int width) { struct line *line; @@ -128,7 +128,7 @@ static void line_free(struct line *line) free(line); } -static int line_resize(struct kmscon_console *con, struct line *line, +static int line_resize(struct tsm_screen *con, struct line *line, unsigned int width) { struct cell *tmp; @@ -154,7 +154,7 @@ static int line_resize(struct kmscon_console *con, struct line *line, } /* This links the given line into the scrollback-buffer */ -static void link_to_scrollback(struct kmscon_console *con, struct line *line) +static void link_to_scrollback(struct tsm_screen *con, struct line *line) { struct line *tmp; @@ -185,7 +185,7 @@ static void link_to_scrollback(struct kmscon_console *con, struct line *line) * next inserted line, which can be "line", too. */ if (con->sb_pos) { if (con->sb_pos == tmp || - !(con->flags & KMSCON_CONSOLE_FIXED_POS)) { + !(con->flags & TSM_SCREEN_FIXED_POS)) { if (con->sb_pos->next) con->sb_pos = con->sb_pos->next; else @@ -206,7 +206,7 @@ static void link_to_scrollback(struct kmscon_console *con, struct line *line) } /* Unlinks last line from the scrollback buffer, Returns NULL if it is empty */ -static struct line *get_from_scrollback(struct kmscon_console *con) +static struct line *get_from_scrollback(struct tsm_screen *con) { struct line *line; @@ -223,7 +223,7 @@ static struct line *get_from_scrollback(struct kmscon_console *con) /* correctly move the current position if it is set in the sb */ if (con->sb_pos) { - if (con->flags & KMSCON_CONSOLE_FIXED_POS || + if (con->flags & TSM_SCREEN_FIXED_POS || !con->sb_pos->prev) { if (con->sb_pos == line) con->sb_pos = NULL; @@ -237,7 +237,7 @@ static struct line *get_from_scrollback(struct kmscon_console *con) return line; } -static void console_scroll_up(struct kmscon_console *con, unsigned int num) +static void screen_scroll_up(struct tsm_screen *con, unsigned int num) { unsigned int i, j, max; int ret; @@ -255,8 +255,8 @@ static void console_scroll_up(struct kmscon_console *con, unsigned int num) * 128 seems to be a sane limit that should never be reached but should * also be small enough so we do not get stack overflows. */ if (num > 128) { - console_scroll_up(con, 128); - return console_scroll_up(con, num - 128); + screen_scroll_up(con, 128); + return screen_scroll_up(con, num - 128); } struct line *cache[num]; @@ -282,7 +282,7 @@ static void console_scroll_up(struct kmscon_console *con, unsigned int num) cache, num * sizeof(struct line*)); } -static void console_scroll_down(struct kmscon_console *con, unsigned int num) +static void screen_scroll_down(struct tsm_screen *con, unsigned int num) { unsigned int i, j, max; @@ -293,10 +293,10 @@ static void console_scroll_down(struct kmscon_console *con, unsigned int num) if (num > max) num = max; - /* see console_scroll_up() for an explanation */ + /* see screen_scroll_up() for an explanation */ if (num > 128) { - console_scroll_down(con, 128); - return console_scroll_down(con, num - 128); + screen_scroll_down(con, 128); + return screen_scroll_down(con, num - 128); } struct line *cache[num]; @@ -316,9 +316,9 @@ static void console_scroll_down(struct kmscon_console *con, unsigned int num) cache, num * sizeof(struct line*)); } -static void console_write(struct kmscon_console *con, unsigned int x, +static void screen_write(struct tsm_screen *con, unsigned int x, unsigned int y, tsm_symbol_t ch, - const struct kmscon_console_attr *attr) + const struct tsm_screen_attr *attr) { struct line *line; @@ -329,14 +329,14 @@ static void console_write(struct kmscon_console *con, unsigned int x, line = con->lines[y]; - if ((con->flags & KMSCON_CONSOLE_INSERT_MODE) && x < (con->size_x - 1)) + if ((con->flags & TSM_SCREEN_INSERT_MODE) && x < (con->size_x - 1)) memmove(&line->cells[x + 1], &line->cells[x], sizeof(struct cell) * (con->size_x - 1 - x)); line->cells[x].ch = ch; memcpy(&line->cells[x].attr, attr, sizeof(*attr)); } -static void console_erase_region(struct kmscon_console *con, +static void screen_erase_region(struct tsm_screen *con, unsigned int x_from, unsigned int y_from, unsigned int x_to, @@ -372,22 +372,22 @@ static void console_erase_region(struct kmscon_console *con, } } -static inline unsigned int to_abs_x(struct kmscon_console *con, unsigned int x) +static inline unsigned int to_abs_x(struct tsm_screen *con, unsigned int x) { return x; } -static inline unsigned int to_abs_y(struct kmscon_console *con, unsigned int y) +static inline unsigned int to_abs_y(struct tsm_screen *con, unsigned int y) { - if (!(con->flags & KMSCON_CONSOLE_REL_ORIGIN)) + if (!(con->flags & TSM_SCREEN_REL_ORIGIN)) return y; return con->margin_top + y; } -int kmscon_console_new(struct kmscon_console **out) +int tsm_screen_new(struct tsm_screen **out) { - struct kmscon_console *con; + struct tsm_screen *con; int ret; unsigned int i; @@ -408,11 +408,11 @@ int kmscon_console_new(struct kmscon_console **out) if (ret) goto err_free; - ret = kmscon_console_resize(con, 80, 24); + ret = tsm_screen_resize(con, 80, 24); if (ret) goto err_timer; - log_debug("new console"); + log_debug("new screen"); *out = con; return 0; @@ -428,7 +428,7 @@ err_free: return ret; } -void kmscon_console_ref(struct kmscon_console *con) +void tsm_screen_ref(struct tsm_screen *con) { if (!con) return; @@ -436,14 +436,14 @@ void kmscon_console_ref(struct kmscon_console *con) ++con->ref; } -void kmscon_console_unref(struct kmscon_console *con) +void tsm_screen_unref(struct tsm_screen *con) { unsigned int i; if (!con || !con->ref || --con->ref) return; - log_debug("destroying console"); + log_debug("destroying screen"); for (i = 0; i < con->line_num; ++i) line_free(con->lines[i]); @@ -453,7 +453,7 @@ void kmscon_console_unref(struct kmscon_console *con) free(con); } -unsigned int kmscon_console_get_width(struct kmscon_console *con) +unsigned int tsm_screen_get_width(struct tsm_screen *con) { if (!con) return 0; @@ -461,7 +461,7 @@ unsigned int kmscon_console_get_width(struct kmscon_console *con) return con->size_x; } -unsigned int kmscon_console_get_height(struct kmscon_console *con) +unsigned int tsm_screen_get_height(struct tsm_screen *con) { if (!con) return 0; @@ -469,7 +469,7 @@ unsigned int kmscon_console_get_height(struct kmscon_console *con) return con->size_y; } -int kmscon_console_resize(struct kmscon_console *con, unsigned int x, +int tsm_screen_resize(struct tsm_screen *con, unsigned int x, unsigned int y) { struct line **cache; @@ -483,9 +483,9 @@ int kmscon_console_resize(struct kmscon_console *con, unsigned int x, if (con->size_x == x && con->size_y == y) return 0; - /* First make sure the line buffer is big enough for our new console. + /* First make sure the line buffer is big enough for our new screen. * That is, allocate all new lines and make sure each line has enough - * cells to hold the new console or the current console. If we fail, we + * cells to hold the new screen or the current screen. If we fail, we * can safely return -ENOMEM and the buffer is still valid. We must * allocate the new lines to at least the same size as the current * lines. Otherwise, if this function fails in later turns, we will have @@ -509,7 +509,7 @@ int kmscon_console_resize(struct kmscon_console *con, unsigned int x, } } - /* Resize all lines in the buffer if we increase console width. This + /* Resize all lines in the buffer if we increase screen width. This * will guarantee that all lines are big enough so we can resize the * buffer without reallocating them later. */ if (x > con->size_x) { @@ -536,9 +536,9 @@ int kmscon_console_resize(struct kmscon_console *con, unsigned int x, con->margin_top = 0; con->margin_bottom = con->size_y - 1; - /* scroll buffer if console height shrinks */ + /* scroll buffer if screen height shrinks */ if (con->size_y != 0 && y < con->size_y) - console_scroll_up(con, con->size_y - y); + screen_scroll_up(con, con->size_y - y); /* reset tabs */ for (i = 0; i < x; ++i) { @@ -561,7 +561,7 @@ int kmscon_console_resize(struct kmscon_console *con, unsigned int x, return 0; } -int kmscon_console_set_margins(struct kmscon_console *con, +int tsm_screen_set_margins(struct tsm_screen *con, unsigned int top, unsigned int bottom) { unsigned int upper, lower; @@ -589,7 +589,7 @@ int kmscon_console_set_margins(struct kmscon_console *con, } /* set maximum scrollback buffer size */ -void kmscon_console_set_max_sb(struct kmscon_console *con, +void tsm_screen_set_max_sb(struct tsm_screen *con, unsigned int max) { struct line *line; @@ -618,7 +618,7 @@ void kmscon_console_set_max_sb(struct kmscon_console *con, } /* clear scrollback buffer */ -void kmscon_console_clear_sb(struct kmscon_console *con) +void tsm_screen_clear_sb(struct tsm_screen *con) { struct line *iter, *tmp; @@ -637,7 +637,7 @@ void kmscon_console_clear_sb(struct kmscon_console *con) con->sb_pos = NULL; } -void kmscon_console_sb_up(struct kmscon_console *con, unsigned int num) +void tsm_screen_sb_up(struct tsm_screen *con, unsigned int num) { if (!con || !num) return; @@ -656,7 +656,7 @@ void kmscon_console_sb_up(struct kmscon_console *con, unsigned int num) } } -void kmscon_console_sb_down(struct kmscon_console *con, unsigned int num) +void tsm_screen_sb_down(struct tsm_screen *con, unsigned int num) { if (!con || !num) return; @@ -672,23 +672,23 @@ void kmscon_console_sb_down(struct kmscon_console *con, unsigned int num) } } -void kmscon_console_sb_page_up(struct kmscon_console *con, unsigned int num) +void tsm_screen_sb_page_up(struct tsm_screen *con, unsigned int num) { if (!con || !num) return; - kmscon_console_sb_up(con, num * con->size_y); + tsm_screen_sb_up(con, num * con->size_y); } -void kmscon_console_sb_page_down(struct kmscon_console *con, unsigned int num) +void tsm_screen_sb_page_down(struct tsm_screen *con, unsigned int num) { if (!con || !num) return; - kmscon_console_sb_down(con, num * con->size_y); + tsm_screen_sb_down(con, num * con->size_y); } -void kmscon_console_sb_reset(struct kmscon_console *con) +void tsm_screen_sb_reset(struct tsm_screen *con) { if (!con) return; @@ -696,8 +696,8 @@ void kmscon_console_sb_reset(struct kmscon_console *con) con->sb_pos = NULL; } -void kmscon_console_set_def_attr(struct kmscon_console *con, - const struct kmscon_console_attr *attr) +void tsm_screen_set_def_attr(struct tsm_screen *con, + const struct tsm_screen_attr *attr) { if (!con || !attr) return; @@ -705,7 +705,7 @@ void kmscon_console_set_def_attr(struct kmscon_console *con, memcpy(&con->def_attr, attr, sizeof(*attr)); } -void kmscon_console_reset(struct kmscon_console *con) +void tsm_screen_reset(struct tsm_screen *con) { unsigned int i; @@ -724,7 +724,7 @@ void kmscon_console_reset(struct kmscon_console *con) } } -void kmscon_console_set_flags(struct kmscon_console *con, unsigned int flags) +void tsm_screen_set_flags(struct tsm_screen *con, unsigned int flags) { if (!con || !flags) return; @@ -732,7 +732,7 @@ void kmscon_console_set_flags(struct kmscon_console *con, unsigned int flags) con->flags |= flags; } -void kmscon_console_reset_flags(struct kmscon_console *con, unsigned int flags) +void tsm_screen_reset_flags(struct tsm_screen *con, unsigned int flags) { if (!con || !flags) return; @@ -740,7 +740,7 @@ void kmscon_console_reset_flags(struct kmscon_console *con, unsigned int flags) con->flags &= ~flags; } -unsigned int kmscon_console_get_flags(struct kmscon_console *con) +unsigned int tsm_screen_get_flags(struct tsm_screen *con) { if (!con) return 0; @@ -748,7 +748,7 @@ unsigned int kmscon_console_get_flags(struct kmscon_console *con) return con->flags; } -unsigned int kmscon_console_get_cursor_x(struct kmscon_console *con) +unsigned int tsm_screen_get_cursor_x(struct tsm_screen *con) { if (!con) return 0; @@ -756,7 +756,7 @@ unsigned int kmscon_console_get_cursor_x(struct kmscon_console *con) return con->cursor_x; } -unsigned int kmscon_console_get_cursor_y(struct kmscon_console *con) +unsigned int tsm_screen_get_cursor_y(struct tsm_screen *con) { if (!con) return 0; @@ -764,7 +764,7 @@ unsigned int kmscon_console_get_cursor_y(struct kmscon_console *con) return con->cursor_y; } -void kmscon_console_set_tabstop(struct kmscon_console *con) +void tsm_screen_set_tabstop(struct tsm_screen *con) { if (!con || con->cursor_x >= con->size_x) return; @@ -772,7 +772,7 @@ void kmscon_console_set_tabstop(struct kmscon_console *con) con->tab_ruler[con->cursor_x] = true; } -void kmscon_console_reset_tabstop(struct kmscon_console *con) +void tsm_screen_reset_tabstop(struct tsm_screen *con) { if (!con || con->cursor_x >= con->size_x) return; @@ -780,7 +780,7 @@ void kmscon_console_reset_tabstop(struct kmscon_console *con) con->tab_ruler[con->cursor_x] = false; } -void kmscon_console_reset_all_tabstops(struct kmscon_console *con) +void tsm_screen_reset_all_tabstops(struct tsm_screen *con) { unsigned int i; @@ -791,8 +791,8 @@ void kmscon_console_reset_all_tabstops(struct kmscon_console *con) con->tab_ruler[i] = false; } -void kmscon_console_write(struct kmscon_console *con, tsm_symbol_t ch, - const struct kmscon_console_attr *attr) +void tsm_screen_write(struct tsm_screen *con, tsm_symbol_t ch, + const struct tsm_screen_attr *attr) { unsigned int last; @@ -806,7 +806,7 @@ void kmscon_console_write(struct kmscon_console *con, tsm_symbol_t ch, last = con->size_y - 1; if (con->cursor_x >= con->size_x) { - if (con->flags & KMSCON_CONSOLE_AUTO_WRAP) { + if (con->flags & TSM_SCREEN_AUTO_WRAP) { con->cursor_x = 0; ++con->cursor_y; } else { @@ -816,39 +816,39 @@ void kmscon_console_write(struct kmscon_console *con, tsm_symbol_t ch, if (con->cursor_y > last) { con->cursor_y = last; - console_scroll_up(con, 1); + screen_scroll_up(con, 1); } - console_write(con, con->cursor_x, con->cursor_y, ch, attr); + screen_write(con, con->cursor_x, con->cursor_y, ch, attr); ++con->cursor_x; } -void kmscon_console_newline(struct kmscon_console *con) +void tsm_screen_newline(struct tsm_screen *con) { if (!con) return; - kmscon_console_move_down(con, 1, true); - kmscon_console_move_line_home(con); + tsm_screen_move_down(con, 1, true); + tsm_screen_move_line_home(con); } -void kmscon_console_scroll_up(struct kmscon_console *con, unsigned int num) +void tsm_screen_scroll_up(struct tsm_screen *con, unsigned int num) { if (!con || !num) return; - console_scroll_up(con, num); + screen_scroll_up(con, num); } -void kmscon_console_scroll_down(struct kmscon_console *con, unsigned int num) +void tsm_screen_scroll_down(struct tsm_screen *con, unsigned int num) { if (!con || !num) return; - console_scroll_down(con, num); + screen_scroll_down(con, num); } -void kmscon_console_move_to(struct kmscon_console *con, unsigned int x, +void tsm_screen_move_to(struct tsm_screen *con, unsigned int x, unsigned int y) { unsigned int last; @@ -856,7 +856,7 @@ void kmscon_console_move_to(struct kmscon_console *con, unsigned int x, if (!con) return; - if (con->flags & KMSCON_CONSOLE_REL_ORIGIN) + if (con->flags & TSM_SCREEN_REL_ORIGIN) last = con->margin_bottom; else last = con->size_y - 1; @@ -870,7 +870,7 @@ void kmscon_console_move_to(struct kmscon_console *con, unsigned int x, con->cursor_y = last; } -void kmscon_console_move_up(struct kmscon_console *con, unsigned int num, +void tsm_screen_move_up(struct tsm_screen *con, unsigned int num, bool scroll) { unsigned int diff, size; @@ -887,14 +887,14 @@ void kmscon_console_move_up(struct kmscon_console *con, unsigned int num, if (num > diff) { num -= diff; if (scroll) - console_scroll_down(con, num); + screen_scroll_down(con, num); con->cursor_y = size; } else { con->cursor_y -= num; } } -void kmscon_console_move_down(struct kmscon_console *con, unsigned int num, +void tsm_screen_move_down(struct tsm_screen *con, unsigned int num, bool scroll) { unsigned int diff, size; @@ -911,14 +911,14 @@ void kmscon_console_move_down(struct kmscon_console *con, unsigned int num, if (num > diff) { num -= diff; if (scroll) - console_scroll_up(con, num); + screen_scroll_up(con, num); con->cursor_y = size - 1; } else { con->cursor_y += num; } } -void kmscon_console_move_left(struct kmscon_console *con, unsigned int num) +void tsm_screen_move_left(struct tsm_screen *con, unsigned int num) { if (!con || !num) return; @@ -935,7 +935,7 @@ void kmscon_console_move_left(struct kmscon_console *con, unsigned int num) con->cursor_x -= num; } -void kmscon_console_move_right(struct kmscon_console *con, unsigned int num) +void tsm_screen_move_right(struct tsm_screen *con, unsigned int num) { if (!con || !num) return; @@ -949,7 +949,7 @@ void kmscon_console_move_right(struct kmscon_console *con, unsigned int num) con->cursor_x += num; } -void kmscon_console_move_line_end(struct kmscon_console *con) +void tsm_screen_move_line_end(struct tsm_screen *con) { if (!con) return; @@ -957,7 +957,7 @@ void kmscon_console_move_line_end(struct kmscon_console *con) con->cursor_x = con->size_x - 1; } -void kmscon_console_move_line_home(struct kmscon_console *con) +void tsm_screen_move_line_home(struct tsm_screen *con) { if (!con) return; @@ -965,7 +965,7 @@ void kmscon_console_move_line_home(struct kmscon_console *con) con->cursor_x = 0; } -void kmscon_console_tab_right(struct kmscon_console *con, unsigned int num) +void tsm_screen_tab_right(struct tsm_screen *con, unsigned int num) { unsigned int i, j; @@ -988,7 +988,7 @@ void kmscon_console_tab_right(struct kmscon_console *con, unsigned int num) con->cursor_x = con->size_x - 1; } -void kmscon_console_tab_left(struct kmscon_console *con, unsigned int num) +void tsm_screen_tab_left(struct tsm_screen *con, unsigned int num) { unsigned int i; int j; @@ -1010,7 +1010,7 @@ void kmscon_console_tab_left(struct kmscon_console *con, unsigned int num) } } -void kmscon_console_insert_lines(struct kmscon_console *con, unsigned int num) +void tsm_screen_insert_lines(struct tsm_screen *con, unsigned int num) { unsigned int i, j, max; @@ -1045,7 +1045,7 @@ void kmscon_console_insert_lines(struct kmscon_console *con, unsigned int num) con->cursor_x = 0; } -void kmscon_console_delete_lines(struct kmscon_console *con, unsigned int num) +void tsm_screen_delete_lines(struct tsm_screen *con, unsigned int num) { unsigned int i, j, max; @@ -1080,7 +1080,7 @@ void kmscon_console_delete_lines(struct kmscon_console *con, unsigned int num) con->cursor_x = 0; } -void kmscon_console_insert_chars(struct kmscon_console *con, unsigned int num) +void tsm_screen_insert_chars(struct tsm_screen *con, unsigned int num) { struct cell *cells; unsigned int max, mv, i; @@ -1109,7 +1109,7 @@ void kmscon_console_insert_chars(struct kmscon_console *con, unsigned int num) } } -void kmscon_console_delete_chars(struct kmscon_console *con, unsigned int num) +void tsm_screen_delete_chars(struct tsm_screen *con, unsigned int num) { struct cell *cells; unsigned int max, mv, i; @@ -1138,7 +1138,7 @@ void kmscon_console_delete_chars(struct kmscon_console *con, unsigned int num) } } -void kmscon_console_erase_cursor(struct kmscon_console *con) +void tsm_screen_erase_cursor(struct tsm_screen *con) { unsigned int x; @@ -1150,10 +1150,10 @@ void kmscon_console_erase_cursor(struct kmscon_console *con) else x = con->cursor_x; - console_erase_region(con, x, con->cursor_y, x, con->cursor_y, false); + screen_erase_region(con, x, con->cursor_y, x, con->cursor_y, false); } -void kmscon_console_erase_chars(struct kmscon_console *con, unsigned int num) +void tsm_screen_erase_chars(struct tsm_screen *con, unsigned int num) { unsigned int x; @@ -1165,11 +1165,11 @@ void kmscon_console_erase_chars(struct kmscon_console *con, unsigned int num) else x = con->cursor_x; - console_erase_region(con, x, con->cursor_y, x + num - 1, con->cursor_y, + screen_erase_region(con, x, con->cursor_y, x + num - 1, con->cursor_y, false); } -void kmscon_console_erase_cursor_to_end(struct kmscon_console *con, +void tsm_screen_erase_cursor_to_end(struct tsm_screen *con, bool protect) { unsigned int x; @@ -1182,40 +1182,40 @@ void kmscon_console_erase_cursor_to_end(struct kmscon_console *con, else x = con->cursor_x; - console_erase_region(con, x, con->cursor_y, con->size_x - 1, + screen_erase_region(con, x, con->cursor_y, con->size_x - 1, con->cursor_y, protect); } -void kmscon_console_erase_home_to_cursor(struct kmscon_console *con, +void tsm_screen_erase_home_to_cursor(struct tsm_screen *con, bool protect) { if (!con) return; - console_erase_region(con, 0, con->cursor_y, con->cursor_x, + screen_erase_region(con, 0, con->cursor_y, con->cursor_x, con->cursor_y, protect); } -void kmscon_console_erase_current_line(struct kmscon_console *con, +void tsm_screen_erase_current_line(struct tsm_screen *con, bool protect) { if (!con) return; - console_erase_region(con, 0, con->cursor_y, con->size_x - 1, + screen_erase_region(con, 0, con->cursor_y, con->size_x - 1, con->cursor_y, protect); } -void kmscon_console_erase_screen_to_cursor(struct kmscon_console *con, +void tsm_screen_erase_screen_to_cursor(struct tsm_screen *con, bool protect) { if (!con) return; - console_erase_region(con, 0, 0, con->cursor_x, con->cursor_y, protect); + screen_erase_region(con, 0, 0, con->cursor_x, con->cursor_y, protect); } -void kmscon_console_erase_cursor_to_screen(struct kmscon_console *con, +void tsm_screen_erase_cursor_to_screen(struct tsm_screen *con, bool protect) { unsigned int x; @@ -1228,30 +1228,30 @@ void kmscon_console_erase_cursor_to_screen(struct kmscon_console *con, else x = con->cursor_x; - console_erase_region(con, x, con->cursor_y, con->size_x - 1, + screen_erase_region(con, x, con->cursor_y, con->size_x - 1, con->size_y - 1, protect); } -void kmscon_console_erase_screen(struct kmscon_console *con, bool protect) +void tsm_screen_erase_screen(struct tsm_screen *con, bool protect) { if (!con) return; - console_erase_region(con, 0, 0, con->size_x - 1, con->size_y - 1, + screen_erase_region(con, 0, 0, con->size_x - 1, con->size_y - 1, protect); } -void kmscon_console_draw(struct kmscon_console *con, - kmscon_console_prepare_cb prepare_cb, - kmscon_console_draw_cb draw_cb, - kmscon_console_render_cb render_cb, +void tsm_screen_draw(struct tsm_screen *con, + tsm_screen_prepare_cb prepare_cb, + tsm_screen_draw_cb draw_cb, + tsm_screen_render_cb render_cb, void *data) { unsigned int cur_x, cur_y; unsigned int i, j, k; struct line *iter, *line = NULL; struct cell *cell; - struct kmscon_console_attr attr; + struct tsm_screen_attr attr; bool cursor_done = false; int ret, warned = 0; uint64_t time_prep = 0, time_draw = 0, time_rend = 0; @@ -1309,7 +1309,7 @@ void kmscon_console_draw(struct kmscon_console *con, if (k == cur_y + 1 && j == cur_x) { cursor_done = true; - if (!(con->flags & KMSCON_CONSOLE_HIDE_CURSOR)) + if (!(con->flags & TSM_SCREEN_HIDE_CURSOR)) attr.inverse = !attr.inverse; } @@ -1317,7 +1317,7 @@ void kmscon_console_draw(struct kmscon_console *con, * INVERSE mode is set, we should instead just select * inverse colors instead of switching background and * foreground */ - if (con->flags & KMSCON_CONSOLE_INVERSE) + if (con->flags & TSM_SCREEN_INVERSE) attr.inverse = !attr.inverse; ch = tsm_symbol_get(NULL, &cell->ch, &len); @@ -1335,8 +1335,8 @@ void kmscon_console_draw(struct kmscon_console *con, if (k == cur_y + 1 && !cursor_done) { cursor_done = true; - if (!(con->flags & KMSCON_CONSOLE_HIDE_CURSOR)) { - if (!(con->flags & KMSCON_CONSOLE_INVERSE)) + if (!(con->flags & TSM_SCREEN_HIDE_CURSOR)) { + if (!(con->flags & TSM_SCREEN_INVERSE)) attr.inverse = !attr.inverse; draw_cb(con, 0, NULL, 0, cur_x, i, &attr, data); } diff --git a/src/console.h b/src/console.h index b49c590..7bdc218 100644 --- a/src/console.h +++ b/src/console.h @@ -1,5 +1,5 @@ /* - * kmscon - Console Management + * kmscon - Screen Management * * Copyright (c) 2011-2012 David Herrmann * Copyright (c) 2011 University of Tuebingen @@ -25,32 +25,32 @@ */ /* - * Console Management - * This console does not emulate any terminal at all. This subsystem just - * provides functions to draw a console to a framebuffer and modifying the state + * Screen Management + * This screen does not emulate any terminal at all. This subsystem just + * provides functions to draw a screen to a framebuffer and modifying the state * of it. */ -#ifndef KMSCON_CONSOLE_H -#define KMSCON_CONSOLE_H +#ifndef TSM_SCREEN_H +#define TSM_SCREEN_H #include #include #include #include "tsm_unicode.h" -struct kmscon_console; +struct tsm_screen; -/* console objects */ +/* screen objects */ -#define KMSCON_CONSOLE_INSERT_MODE 0x01 -#define KMSCON_CONSOLE_AUTO_WRAP 0x02 -#define KMSCON_CONSOLE_REL_ORIGIN 0x04 -#define KMSCON_CONSOLE_INVERSE 0x08 -#define KMSCON_CONSOLE_HIDE_CURSOR 0x10 -#define KMSCON_CONSOLE_FIXED_POS 0x20 +#define TSM_SCREEN_INSERT_MODE 0x01 +#define TSM_SCREEN_AUTO_WRAP 0x02 +#define TSM_SCREEN_REL_ORIGIN 0x04 +#define TSM_SCREEN_INVERSE 0x08 +#define TSM_SCREEN_HIDE_CURSOR 0x10 +#define TSM_SCREEN_FIXED_POS 0x20 -struct kmscon_console_attr { +struct tsm_screen_attr { int8_t fccode; /* foreground color code or <0 for rgb */ int8_t bccode; /* background color code or <0 for rgb */ uint8_t fr; /* foreground red */ @@ -65,91 +65,91 @@ struct kmscon_console_attr { unsigned int protect : 1; /* cannot be erased */ }; -typedef int (*kmscon_console_prepare_cb) (struct kmscon_console *con, - void *data); -typedef int (*kmscon_console_draw_cb) (struct kmscon_console *con, - uint32_t id, - const uint32_t *ch, - size_t len, - unsigned int posx, - unsigned int posy, - const struct kmscon_console_attr *attr, - void *data); -typedef int (*kmscon_console_render_cb) (struct kmscon_console *con, - void *data); +typedef int (*tsm_screen_prepare_cb) (struct tsm_screen *con, + void *data); +typedef int (*tsm_screen_draw_cb) (struct tsm_screen *con, + uint32_t id, + const uint32_t *ch, + size_t len, + unsigned int posx, + unsigned int posy, + const struct tsm_screen_attr *attr, + void *data); +typedef int (*tsm_screen_render_cb) (struct tsm_screen *con, + void *data); -int kmscon_console_new(struct kmscon_console **out); -void kmscon_console_ref(struct kmscon_console *con); -void kmscon_console_unref(struct kmscon_console *con); +int tsm_screen_new(struct tsm_screen **out); +void tsm_screen_ref(struct tsm_screen *con); +void tsm_screen_unref(struct tsm_screen *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_margins(struct kmscon_console *con, - unsigned int top, unsigned int bottom); -void kmscon_console_set_max_sb(struct kmscon_console *con, unsigned int max); -void kmscon_console_clear_sb(struct kmscon_console *con); +unsigned int tsm_screen_get_width(struct tsm_screen *con); +unsigned int tsm_screen_get_height(struct tsm_screen *con); +int tsm_screen_resize(struct tsm_screen *con, unsigned int x, + unsigned int y); +int tsm_screen_set_margins(struct tsm_screen *con, + unsigned int top, unsigned int bottom); +void tsm_screen_set_max_sb(struct tsm_screen *con, unsigned int max); +void tsm_screen_clear_sb(struct tsm_screen *con); -void kmscon_console_sb_up(struct kmscon_console *con, unsigned int num); -void kmscon_console_sb_down(struct kmscon_console *con, unsigned int num); -void kmscon_console_sb_page_up(struct kmscon_console *con, unsigned int num); -void kmscon_console_sb_page_down(struct kmscon_console *con, unsigned int num); -void kmscon_console_sb_reset(struct kmscon_console *con); +void tsm_screen_sb_up(struct tsm_screen *con, unsigned int num); +void tsm_screen_sb_down(struct tsm_screen *con, unsigned int num); +void tsm_screen_sb_page_up(struct tsm_screen *con, unsigned int num); +void tsm_screen_sb_page_down(struct tsm_screen *con, unsigned int num); +void tsm_screen_sb_reset(struct tsm_screen *con); -void kmscon_console_set_def_attr(struct kmscon_console *con, - const struct kmscon_console_attr *attr); -void kmscon_console_reset(struct kmscon_console *con); -void kmscon_console_set_flags(struct kmscon_console *con, unsigned int flags); -void kmscon_console_reset_flags(struct kmscon_console *con, unsigned int flags); -unsigned int kmscon_console_get_flags(struct kmscon_console *con); +void tsm_screen_set_def_attr(struct tsm_screen *con, + const struct tsm_screen_attr *attr); +void tsm_screen_reset(struct tsm_screen *con); +void tsm_screen_set_flags(struct tsm_screen *con, unsigned int flags); +void tsm_screen_reset_flags(struct tsm_screen *con, unsigned int flags); +unsigned int tsm_screen_get_flags(struct tsm_screen *con); -unsigned int kmscon_console_get_cursor_x(struct kmscon_console *con); -unsigned int kmscon_console_get_cursor_y(struct kmscon_console *con); +unsigned int tsm_screen_get_cursor_x(struct tsm_screen *con); +unsigned int tsm_screen_get_cursor_y(struct tsm_screen *con); -void kmscon_console_set_tabstop(struct kmscon_console *con); -void kmscon_console_reset_tabstop(struct kmscon_console *con); -void kmscon_console_reset_all_tabstops(struct kmscon_console *con); +void tsm_screen_set_tabstop(struct tsm_screen *con); +void tsm_screen_reset_tabstop(struct tsm_screen *con); +void tsm_screen_reset_all_tabstops(struct tsm_screen *con); -void kmscon_console_write(struct kmscon_console *con, tsm_symbol_t ch, - const struct kmscon_console_attr *attr); -void kmscon_console_newline(struct kmscon_console *con); -void kmscon_console_scroll_up(struct kmscon_console *con, unsigned int num); -void kmscon_console_scroll_down(struct kmscon_console *con, unsigned int num); -void kmscon_console_move_to(struct kmscon_console *con, unsigned int x, - unsigned int y); -void kmscon_console_move_up(struct kmscon_console *con, unsigned int num, - bool scroll); -void kmscon_console_move_down(struct kmscon_console *con, unsigned int num, - bool scroll); -void kmscon_console_move_left(struct kmscon_console *con, unsigned int num); -void kmscon_console_move_right(struct kmscon_console *con, unsigned int num); -void kmscon_console_move_line_end(struct kmscon_console *con); -void kmscon_console_move_line_home(struct kmscon_console *con); -void kmscon_console_tab_right(struct kmscon_console *con, unsigned int num); -void kmscon_console_tab_left(struct kmscon_console *con, unsigned int num); -void kmscon_console_insert_lines(struct kmscon_console *con, unsigned int num); -void kmscon_console_delete_lines(struct kmscon_console *con, unsigned int num); -void kmscon_console_insert_chars(struct kmscon_console *con, unsigned int num); -void kmscon_console_delete_chars(struct kmscon_console *con, unsigned int num); -void kmscon_console_erase_cursor(struct kmscon_console *con); -void kmscon_console_erase_chars(struct kmscon_console *con, unsigned int num); -void kmscon_console_erase_cursor_to_end(struct kmscon_console *con, - bool protect); -void kmscon_console_erase_home_to_cursor(struct kmscon_console *con, - bool protect); -void kmscon_console_erase_current_line(struct kmscon_console *con, +void tsm_screen_write(struct tsm_screen *con, tsm_symbol_t ch, + const struct tsm_screen_attr *attr); +void tsm_screen_newline(struct tsm_screen *con); +void tsm_screen_scroll_up(struct tsm_screen *con, unsigned int num); +void tsm_screen_scroll_down(struct tsm_screen *con, unsigned int num); +void tsm_screen_move_to(struct tsm_screen *con, unsigned int x, + unsigned int y); +void tsm_screen_move_up(struct tsm_screen *con, unsigned int num, + bool scroll); +void tsm_screen_move_down(struct tsm_screen *con, unsigned int num, + bool scroll); +void tsm_screen_move_left(struct tsm_screen *con, unsigned int num); +void tsm_screen_move_right(struct tsm_screen *con, unsigned int num); +void tsm_screen_move_line_end(struct tsm_screen *con); +void tsm_screen_move_line_home(struct tsm_screen *con); +void tsm_screen_tab_right(struct tsm_screen *con, unsigned int num); +void tsm_screen_tab_left(struct tsm_screen *con, unsigned int num); +void tsm_screen_insert_lines(struct tsm_screen *con, unsigned int num); +void tsm_screen_delete_lines(struct tsm_screen *con, unsigned int num); +void tsm_screen_insert_chars(struct tsm_screen *con, unsigned int num); +void tsm_screen_delete_chars(struct tsm_screen *con, unsigned int num); +void tsm_screen_erase_cursor(struct tsm_screen *con); +void tsm_screen_erase_chars(struct tsm_screen *con, unsigned int num); +void tsm_screen_erase_cursor_to_end(struct tsm_screen *con, + bool protect); +void tsm_screen_erase_home_to_cursor(struct tsm_screen *con, + bool protect); +void tsm_screen_erase_current_line(struct tsm_screen *con, + bool protect); +void tsm_screen_erase_screen_to_cursor(struct tsm_screen *con, bool protect); -void kmscon_console_erase_screen_to_cursor(struct kmscon_console *con, - bool protect); -void kmscon_console_erase_cursor_to_screen(struct kmscon_console *con, - bool protect); -void kmscon_console_erase_screen(struct kmscon_console *con, bool protect); +void tsm_screen_erase_cursor_to_screen(struct tsm_screen *con, + bool protect); +void tsm_screen_erase_screen(struct tsm_screen *con, bool protect); -void kmscon_console_draw(struct kmscon_console *con, - kmscon_console_prepare_cb prepare_cb, - kmscon_console_draw_cb draw_cb, - kmscon_console_render_cb render_cb, - void *data); +void tsm_screen_draw(struct tsm_screen *con, + tsm_screen_prepare_cb prepare_cb, + tsm_screen_draw_cb draw_cb, + tsm_screen_render_cb render_cb, + void *data); -#endif /* KMSCON_CONSOLE_H */ +#endif /* TSM_SCREEN_H */ diff --git a/src/terminal.c b/src/terminal.c index 903af4a..ff25956 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -68,7 +68,7 @@ struct kmscon_terminal { unsigned int fps; unsigned int redraw; struct ev_timer *redraw_timer; - struct kmscon_console *console; + struct tsm_screen *console; struct kmscon_vte *vte; struct kmscon_pty *pty; @@ -89,7 +89,7 @@ static void redraw(struct kmscon_terminal *term) ent = shl_dlist_entry(iter, struct screen, list); screen = ent->screen; - kmscon_console_draw(term->console, + tsm_screen_draw(term->console, kmscon_text_prepare_cb, kmscon_text_draw_cb, kmscon_text_render_cb, @@ -173,7 +173,7 @@ static void terminal_resize(struct kmscon_terminal *term, return; /* shrinking always succeeds */ - kmscon_console_resize(term->console, term->min_cols, term->min_rows); + tsm_screen_resize(term->console, term->min_cols, term->min_rows); kmscon_pty_resize(term->pty, term->min_cols, term->min_rows); } @@ -348,32 +348,32 @@ static void input_event(struct uterm_input *input, if (UTERM_INPUT_HAS_MODS(ev, kmscon_conf.grab_scroll_up->mods) && ev->keysym == kmscon_conf.grab_scroll_up->keysym) { - kmscon_console_sb_up(term->console, 1); + tsm_screen_sb_up(term->console, 1); schedule_redraw(term); return; } if (UTERM_INPUT_HAS_MODS(ev, kmscon_conf.grab_scroll_down->mods) && ev->keysym == kmscon_conf.grab_scroll_down->keysym) { - kmscon_console_sb_down(term->console, 1); + tsm_screen_sb_down(term->console, 1); schedule_redraw(term); return; } if (UTERM_INPUT_HAS_MODS(ev, kmscon_conf.grab_page_up->mods) && ev->keysym == kmscon_conf.grab_page_up->keysym) { - kmscon_console_sb_page_up(term->console, 1); + tsm_screen_sb_page_up(term->console, 1); schedule_redraw(term); return; } if (UTERM_INPUT_HAS_MODS(ev, kmscon_conf.grab_page_down->mods) && ev->keysym == kmscon_conf.grab_page_down->keysym) { - kmscon_console_sb_page_down(term->console, 1); + tsm_screen_sb_page_down(term->console, 1); schedule_redraw(term); return; } if (kmscon_vte_handle_keyboard(term->vte, ev->keysym, ev->mods, ev->unicode)) { - kmscon_console_sb_reset(term->console); + tsm_screen_sb_reset(term->console); schedule_redraw(term); } } @@ -421,10 +421,10 @@ int kmscon_terminal_new(struct kmscon_terminal **out, term->fps = 1000000000ULL / fps; log_debug("FPS: %lu TIMER: %lu", term->fps, fps); - ret = kmscon_console_new(&term->console); + ret = tsm_screen_new(&term->console); if (ret) goto err_free; - kmscon_console_set_max_sb(term->console, kmscon_conf.sb_size); + tsm_screen_set_max_sb(term->console, kmscon_conf.sb_size); ret = kmscon_vte_new(&term->vte, term->console, write_event, term); if (ret) @@ -468,7 +468,7 @@ err_pty: err_vte: kmscon_vte_unref(term->vte); err_con: - kmscon_console_unref(term->console); + tsm_screen_unref(term->console); err_free: free(term); return ret; @@ -498,7 +498,7 @@ void kmscon_terminal_unref(struct kmscon_terminal *term) uterm_input_unregister_cb(term->input, input_event, term); kmscon_pty_unref(term->pty); kmscon_vte_unref(term->vte); - kmscon_console_unref(term->console); + tsm_screen_unref(term->console); uterm_input_unref(term->input); ev_eloop_unref(term->eloop); free(term); @@ -514,8 +514,8 @@ int kmscon_terminal_open(struct kmscon_terminal *term, return -EINVAL; kmscon_pty_close(term->pty); - width = kmscon_console_get_width(term->console); - height = kmscon_console_get_height(term->console); + width = tsm_screen_get_width(term->console); + height = tsm_screen_get_height(term->console); ret = kmscon_pty_open(term->pty, width, height); if (ret) return ret; diff --git a/src/text.c b/src/text.c index f39d255..eab35de 100644 --- a/src/text.c +++ b/src/text.c @@ -448,7 +448,7 @@ int kmscon_text_prepare(struct kmscon_text *txt) int kmscon_text_draw(struct kmscon_text *txt, uint32_t id, const uint32_t *ch, size_t len, unsigned int posx, unsigned int posy, - const struct kmscon_console_attr *attr) + const struct tsm_screen_attr *attr) { if (!txt || !txt->rendering) return -EINVAL; @@ -501,20 +501,20 @@ void kmscon_text_abort(struct kmscon_text *txt) txt->rendering = false; } -int kmscon_text_prepare_cb(struct kmscon_console *con, void *data) +int kmscon_text_prepare_cb(struct tsm_screen *con, void *data) { return kmscon_text_prepare(data); } -int kmscon_text_draw_cb(struct kmscon_console *con, +int kmscon_text_draw_cb(struct tsm_screen *con, uint32_t id, const uint32_t *ch, size_t len, unsigned int posx, unsigned int posy, - const struct kmscon_console_attr *attr, void *data) + const struct tsm_screen_attr *attr, void *data) { return kmscon_text_draw(data, id, ch, len, posx, posy, attr); } -int kmscon_text_render_cb(struct kmscon_console *con, void *data) +int kmscon_text_render_cb(struct tsm_screen *con, void *data) { return kmscon_text_render(data); } diff --git a/src/text.h b/src/text.h index 6a3ca74..f0e2589 100644 --- a/src/text.h +++ b/src/text.h @@ -139,7 +139,7 @@ struct kmscon_text_ops { int (*draw) (struct kmscon_text *txt, uint32_t id, const uint32_t *ch, size_t len, unsigned int posx, unsigned int posy, - const struct kmscon_console_attr *attr); + const struct tsm_screen_attr *attr); int (*render) (struct kmscon_text *txt); void (*abort) (struct kmscon_text *txt); }; @@ -162,16 +162,16 @@ int kmscon_text_prepare(struct kmscon_text *txt); int kmscon_text_draw(struct kmscon_text *txt, uint32_t id, const uint32_t *ch, size_t len, unsigned int posx, unsigned int posy, - const struct kmscon_console_attr *attr); + const struct tsm_screen_attr *attr); int kmscon_text_render(struct kmscon_text *txt); void kmscon_text_abort(struct kmscon_text *txt); -int kmscon_text_prepare_cb(struct kmscon_console *con, void *data); -int kmscon_text_draw_cb(struct kmscon_console *con, +int kmscon_text_prepare_cb(struct tsm_screen *con, void *data); +int kmscon_text_draw_cb(struct tsm_screen *con, uint32_t id, const uint32_t *ch, size_t len, unsigned int posx, unsigned int posy, - const struct kmscon_console_attr *attr, void *data); -int kmscon_text_render_cb(struct kmscon_console *con, void *data); + const struct tsm_screen_attr *attr, void *data); +int kmscon_text_render_cb(struct tsm_screen *con, void *data); /* modularized backends */ diff --git a/src/text_bblit.c b/src/text_bblit.c index af5ee5b..3082b32 100644 --- a/src/text_bblit.c +++ b/src/text_bblit.c @@ -60,7 +60,7 @@ static int bblit_set(struct kmscon_text *txt) static int bblit_draw(struct kmscon_text *txt, uint32_t id, const uint32_t *ch, size_t len, unsigned int posx, unsigned int posy, - const struct kmscon_console_attr *attr) + const struct tsm_screen_attr *attr) { const struct kmscon_glyph *glyph; int ret; diff --git a/src/text_bbulk.c b/src/text_bbulk.c index b6a42b5..9732d96 100644 --- a/src/text_bbulk.c +++ b/src/text_bbulk.c @@ -112,7 +112,7 @@ static void bbulk_unset(struct kmscon_text *txt) static int bbulk_draw(struct kmscon_text *txt, uint32_t id, const uint32_t *ch, size_t len, unsigned int posx, unsigned int posy, - const struct kmscon_console_attr *attr) + const struct tsm_screen_attr *attr) { struct bbulk *bb = txt->data; const struct kmscon_glyph *glyph; diff --git a/src/text_gltex.c b/src/text_gltex.c index ce028ba..c3ffcbd 100644 --- a/src/text_gltex.c +++ b/src/text_gltex.c @@ -523,7 +523,7 @@ static int gltex_prepare(struct kmscon_text *txt) static int gltex_draw(struct kmscon_text *txt, uint32_t id, const uint32_t *ch, size_t len, unsigned int posx, unsigned int posy, - const struct kmscon_console_attr *attr) + const struct tsm_screen_attr *attr) { struct gltex *gt = txt->data; struct atlas *atlas; diff --git a/src/vte.c b/src/vte.c index b5c02ba..6c5bc07 100644 --- a/src/vte.c +++ b/src/vte.c @@ -139,7 +139,7 @@ enum parser_action { struct vte_saved_state { unsigned int cursor_x; unsigned int cursor_y; - struct kmscon_console_attr cattr; + struct tsm_screen_attr cattr; kmscon_vte_charset *gl; kmscon_vte_charset *gr; bool wrap_mode; @@ -148,7 +148,7 @@ struct vte_saved_state { struct kmscon_vte { unsigned long ref; - struct kmscon_console *con; + struct tsm_screen *con; kmscon_vte_write_cb write_cb; void *data; @@ -161,8 +161,8 @@ struct kmscon_vte { unsigned int csi_flags; uint8_t (*palette)[3]; - struct kmscon_console_attr def_attr; - struct kmscon_console_attr cattr; + struct tsm_screen_attr def_attr; + struct tsm_screen_attr cattr; unsigned int flags; kmscon_vte_charset *gl; @@ -310,7 +310,7 @@ static uint8_t (*get_palette(void))[3] * be called before passing the attribute to the console layer so the console * layer can always work with RGB values and does not have to care for color * codes. */ -static void to_rgb(struct kmscon_vte *vte, struct kmscon_console_attr *attr) +static void to_rgb(struct kmscon_vte *vte, struct tsm_screen_attr *attr) { int8_t code; @@ -338,8 +338,8 @@ static void to_rgb(struct kmscon_vte *vte, struct kmscon_console_attr *attr) } } -static void copy_fcolor(struct kmscon_console_attr *dest, - const struct kmscon_console_attr *src) +static void copy_fcolor(struct tsm_screen_attr *dest, + const struct tsm_screen_attr *src) { dest->fccode = src->fccode; dest->fr = src->fr; @@ -347,8 +347,8 @@ static void copy_fcolor(struct kmscon_console_attr *dest, dest->fb = src->fb; } -static void copy_bcolor(struct kmscon_console_attr *dest, - const struct kmscon_console_attr *src) +static void copy_bcolor(struct tsm_screen_attr *dest, + const struct tsm_screen_attr *src) { dest->bccode = src->bccode; dest->br = src->br; @@ -356,7 +356,7 @@ static void copy_bcolor(struct kmscon_console_attr *dest, dest->bb = src->bb; } -int kmscon_vte_new(struct kmscon_vte **out, struct kmscon_console *con, +int kmscon_vte_new(struct kmscon_vte **out, struct tsm_screen *con, kmscon_vte_write_cb write_cb, void *data) { struct kmscon_vte *vte; @@ -384,10 +384,10 @@ int kmscon_vte_new(struct kmscon_vte **out, struct kmscon_console *con, goto err_free; kmscon_vte_reset(vte); - kmscon_console_erase_screen(vte->con, false); + tsm_screen_erase_screen(vte->con, false); log_debug("new vte object"); - kmscon_console_ref(vte->con); + tsm_screen_ref(vte->con); *out = vte; return 0; @@ -413,7 +413,7 @@ void kmscon_vte_unref(struct kmscon_vte *vte) return; log_debug("destroying vte object"); - kmscon_console_unref(vte->con); + tsm_screen_unref(vte->con); tsm_utf8_mach_free(vte->mach); free(vte); } @@ -490,7 +490,7 @@ static void vte_write_debug(struct kmscon_vte *vte, const char *u8, size_t len, static void write_console(struct kmscon_vte *vte, tsm_symbol_t sym) { to_rgb(vte, &vte->cattr); - kmscon_console_write(vte->con, sym, &vte->cattr); + tsm_screen_write(vte->con, sym, &vte->cattr); } static void reset_state(struct kmscon_vte *vte) @@ -512,8 +512,8 @@ static void reset_state(struct kmscon_vte *vte) static void save_state(struct kmscon_vte *vte) { - vte->saved_state.cursor_x = kmscon_console_get_cursor_x(vte->con); - vte->saved_state.cursor_y = kmscon_console_get_cursor_y(vte->con); + vte->saved_state.cursor_x = tsm_screen_get_cursor_x(vte->con); + vte->saved_state.cursor_y = tsm_screen_get_cursor_y(vte->con); vte->saved_state.cattr = vte->cattr; vte->saved_state.gl = vte->gl; vte->saved_state.gr = vte->gr; @@ -523,33 +523,29 @@ static void save_state(struct kmscon_vte *vte) static void restore_state(struct kmscon_vte *vte) { - kmscon_console_move_to(vte->con, vte->saved_state.cursor_x, + tsm_screen_move_to(vte->con, vte->saved_state.cursor_x, vte->saved_state.cursor_y); vte->cattr = vte->saved_state.cattr; to_rgb(vte, &vte->cattr); if (vte->flags & FLAG_BACKGROUND_COLOR_ERASE_MODE) - kmscon_console_set_def_attr(vte->con, &vte->cattr); + tsm_screen_set_def_attr(vte->con, &vte->cattr); vte->gl = vte->saved_state.gl; vte->gr = vte->saved_state.gr; if (vte->saved_state.wrap_mode) { vte->flags |= FLAG_AUTO_WRAP_MODE; - kmscon_console_set_flags(vte->con, - KMSCON_CONSOLE_AUTO_WRAP); + tsm_screen_set_flags(vte->con, TSM_SCREEN_AUTO_WRAP); } else { vte->flags &= ~FLAG_AUTO_WRAP_MODE; - kmscon_console_reset_flags(vte->con, - KMSCON_CONSOLE_AUTO_WRAP); + tsm_screen_reset_flags(vte->con, TSM_SCREEN_AUTO_WRAP); } if (vte->saved_state.origin_mode) { vte->flags |= FLAG_ORIGIN_MODE; - kmscon_console_set_flags(vte->con, - KMSCON_CONSOLE_REL_ORIGIN); + tsm_screen_set_flags(vte->con, TSM_SCREEN_REL_ORIGIN); } else { vte->flags &= ~FLAG_ORIGIN_MODE; - kmscon_console_reset_flags(vte->con, - KMSCON_CONSOLE_REL_ORIGIN); + tsm_screen_reset_flags(vte->con, TSM_SCREEN_REL_ORIGIN); } } @@ -570,8 +566,8 @@ void kmscon_vte_reset(struct kmscon_vte *vte) vte->flags |= FLAG_SEND_RECEIVE_MODE; vte->flags |= FLAG_AUTO_WRAP_MODE; vte->flags |= FLAG_BACKGROUND_COLOR_ERASE_MODE; - kmscon_console_reset(vte->con); - kmscon_console_set_flags(vte->con, KMSCON_CONSOLE_AUTO_WRAP); + tsm_screen_reset(vte->con); + tsm_screen_set_flags(vte->con, TSM_SCREEN_AUTO_WRAP); tsm_utf8_mach_reset(vte->mach); vte->state = STATE_GROUND; @@ -586,7 +582,7 @@ void kmscon_vte_reset(struct kmscon_vte *vte) memcpy(&vte->cattr, &vte->def_attr, sizeof(vte->cattr)); to_rgb(vte, &vte->cattr); - kmscon_console_set_def_attr(vte->con, &vte->def_attr); + tsm_screen_set_def_attr(vte->con, &vte->def_attr); reset_state(vte); } @@ -594,9 +590,9 @@ void kmscon_vte_reset(struct kmscon_vte *vte) static void hard_reset(struct kmscon_vte *vte) { kmscon_vte_reset(vte); - kmscon_console_erase_screen(vte->con, false); - kmscon_console_clear_sb(vte->con); - kmscon_console_move_to(vte->con, 0, 0); + tsm_screen_erase_screen(vte->con, false); + tsm_screen_clear_sb(vte->con); + tsm_screen_move_to(vte->con, 0, 0); } static void send_primary_da(struct kmscon_vte *vte) @@ -625,24 +621,24 @@ static void do_execute(struct kmscon_vte *vte, uint32_t ctrl) break; case 0x08: /* BS */ /* Move cursor one position left */ - kmscon_console_move_left(vte->con, 1); + tsm_screen_move_left(vte->con, 1); break; case 0x09: /* HT */ /* Move to next tab stop or end of line */ - kmscon_console_tab_right(vte->con, 1); + tsm_screen_tab_right(vte->con, 1); break; case 0x0a: /* LF */ case 0x0b: /* VT */ case 0x0c: /* FF */ /* Line feed or newline (CR/NL mode) */ if (vte->flags & FLAG_LINE_FEED_NEW_LINE_MODE) - kmscon_console_newline(vte->con); + tsm_screen_newline(vte->con); else - kmscon_console_move_down(vte->con, 1, true); + tsm_screen_move_down(vte->con, 1, true); break; case 0x0d: /* CR */ /* Move cursor to left margin */ - kmscon_console_move_line_home(vte->con); + tsm_screen_move_line_home(vte->con); break; case 0x0e: /* SO */ /* Map G1 character set into GL */ @@ -677,19 +673,19 @@ static void do_execute(struct kmscon_vte *vte, uint32_t ctrl) break; case 0x84: /* IND */ /* Move down one row, perform scroll-up if needed */ - kmscon_console_move_down(vte->con, 1, true); + tsm_screen_move_down(vte->con, 1, true); break; case 0x85: /* NEL */ /* CR/NL with scroll-up if needed */ - kmscon_console_newline(vte->con); + tsm_screen_newline(vte->con); break; case 0x88: /* HTS */ /* Set tab stop at current position */ - kmscon_console_set_tabstop(vte->con); + tsm_screen_set_tabstop(vte->con); break; case 0x8d: /* RI */ /* Move up one row, perform scroll-down if needed */ - kmscon_console_move_up(vte->con, 1, true); + tsm_screen_move_up(vte->con, 1, true); break; case 0x8e: /* SS2 */ /* Temporarily map G2 into GL for next char only */ @@ -904,19 +900,19 @@ static void do_esc(struct kmscon_vte *vte, uint32_t data) switch (data) { case 'D': /* IND */ /* Move down one row, perform scroll-up if needed */ - kmscon_console_move_down(vte->con, 1, true); + tsm_screen_move_down(vte->con, 1, true); break; case 'E': /* NEL */ /* CR/NL with scroll-up if needed */ - kmscon_console_newline(vte->con); + tsm_screen_newline(vte->con); break; case 'H': /* HTS */ /* Set tab stop at current position */ - kmscon_console_set_tabstop(vte->con); + tsm_screen_set_tabstop(vte->con); break; case 'M': /* RI */ /* Move up one row, perform scroll-down if needed */ - kmscon_console_move_up(vte->con, 1, true); + tsm_screen_move_up(vte->con, 1, true); break; case 'N': /* SS2 */ /* Temporarily map G2 into GL for next char only */ @@ -1179,7 +1175,7 @@ static void csi_attribute(struct kmscon_vte *vte) to_rgb(vte, &vte->cattr); if (vte->flags & FLAG_BACKGROUND_COLOR_ERASE_MODE) - kmscon_console_set_def_attr(vte->con, &vte->cattr); + tsm_screen_set_def_attr(vte->con, &vte->cattr); } static void csi_soft_reset(struct kmscon_vte *vte) @@ -1254,11 +1250,11 @@ static void csi_mode(struct kmscon_vte *vte, bool set) set_reset_flag(vte, set, FLAG_INSERT_REPLACE_MODE); if (set) - kmscon_console_set_flags(vte->con, - KMSCON_CONSOLE_INSERT_MODE); + tsm_screen_set_flags(vte->con, + TSM_SCREEN_INSERT_MODE); else - kmscon_console_reset_flags(vte->con, - KMSCON_CONSOLE_INSERT_MODE); + tsm_screen_reset_flags(vte->con, + TSM_SCREEN_INSERT_MODE); continue; case 12: /* SRM */ set_reset_flag(vte, set, @@ -1312,29 +1308,29 @@ static void csi_mode(struct kmscon_vte *vte, bool set) case 5: /* DECSCNM */ set_reset_flag(vte, set, FLAG_INVERSE_SCREEN_MODE); if (set) - kmscon_console_set_flags(vte->con, - KMSCON_CONSOLE_INVERSE); + tsm_screen_set_flags(vte->con, + TSM_SCREEN_INVERSE); else - kmscon_console_reset_flags(vte->con, - KMSCON_CONSOLE_INVERSE); + tsm_screen_reset_flags(vte->con, + TSM_SCREEN_INVERSE); continue; case 6: /* DECOM */ set_reset_flag(vte, set, FLAG_ORIGIN_MODE); if (set) - kmscon_console_set_flags(vte->con, - KMSCON_CONSOLE_REL_ORIGIN); + tsm_screen_set_flags(vte->con, + TSM_SCREEN_REL_ORIGIN); else - kmscon_console_reset_flags(vte->con, - KMSCON_CONSOLE_REL_ORIGIN); + tsm_screen_reset_flags(vte->con, + TSM_SCREEN_REL_ORIGIN); continue; case 7: /* DECAWN */ set_reset_flag(vte, set, FLAG_AUTO_WRAP_MODE); if (set) - kmscon_console_set_flags(vte->con, - KMSCON_CONSOLE_AUTO_WRAP); + tsm_screen_set_flags(vte->con, + TSM_SCREEN_AUTO_WRAP); else - kmscon_console_reset_flags(vte->con, - KMSCON_CONSOLE_AUTO_WRAP); + tsm_screen_reset_flags(vte->con, + TSM_SCREEN_AUTO_WRAP); continue; case 8: /* DECARM */ set_reset_flag(vte, set, FLAG_AUTO_REPEAT_MODE); @@ -1353,11 +1349,11 @@ static void csi_mode(struct kmscon_vte *vte, bool set) case 25: /* DECTCEM */ set_reset_flag(vte, set, FLAG_TEXT_CURSOR_MODE); if (set) - kmscon_console_reset_flags(vte->con, - KMSCON_CONSOLE_HIDE_CURSOR); + tsm_screen_reset_flags(vte->con, + TSM_SCREEN_HIDE_CURSOR); else - kmscon_console_set_flags(vte->con, - KMSCON_CONSOLE_HIDE_CURSOR); + tsm_screen_set_flags(vte->con, + TSM_SCREEN_HIDE_CURSOR); continue; case 42: /* DECNRCM */ set_reset_flag(vte, set, FLAG_NATIONAL_CHARSET_MODE); @@ -1394,8 +1390,8 @@ static void csi_dsr(struct kmscon_vte *vte) if (vte->csi_argv[0] == 5) { vte_write(vte, "\e[0n", 4); } else if (vte->csi_argv[0] == 6) { - x = kmscon_console_get_cursor_x(vte->con); - y = kmscon_console_get_cursor_y(vte->con); + x = tsm_screen_get_cursor_x(vte->con); + y = tsm_screen_get_cursor_y(vte->con); len = snprintf(buf, sizeof(buf), "\e[%u;%uR", x, y); if (len >= sizeof(buf)) vte_write(vte, "\e[0;0R", 6); @@ -1418,45 +1414,45 @@ static void do_csi(struct kmscon_vte *vte, uint32_t data) num = vte->csi_argv[0]; if (num <= 0) num = 1; - kmscon_console_move_up(vte->con, num, false); + tsm_screen_move_up(vte->con, num, false); break; case 'B': /* CUD */ /* move cursor down */ num = vte->csi_argv[0]; if (num <= 0) num = 1; - kmscon_console_move_down(vte->con, num, false); + tsm_screen_move_down(vte->con, num, false); break; case 'C': /* CUF */ /* move cursor forward */ num = vte->csi_argv[0]; if (num <= 0) num = 1; - kmscon_console_move_right(vte->con, num); + tsm_screen_move_right(vte->con, num); break; case 'D': /* CUB */ /* move cursor backward */ num = vte->csi_argv[0]; if (num <= 0) num = 1; - kmscon_console_move_left(vte->con, num); + tsm_screen_move_left(vte->con, num); break; case 'd': /* VPA */ /* Vertical Line Position Absolute */ num = vte->csi_argv[0]; if (num <= 0) num = 1; - x = kmscon_console_get_cursor_x(vte->con); - kmscon_console_move_to(vte->con, x, num - 1); + x = tsm_screen_get_cursor_x(vte->con); + tsm_screen_move_to(vte->con, x, num - 1); break; case 'e': /* VPR */ /* Vertical Line Position Relative */ num = vte->csi_argv[0]; if (num <= 0) num = 1; - x = kmscon_console_get_cursor_x(vte->con); - y = kmscon_console_get_cursor_y(vte->con); - kmscon_console_move_to(vte->con, x, y + num); + x = tsm_screen_get_cursor_x(vte->con); + y = tsm_screen_get_cursor_y(vte->con); + tsm_screen_move_to(vte->con, x, y + num); break; case 'H': /* CUP */ case 'f': /* HVP */ @@ -1467,15 +1463,15 @@ static void do_csi(struct kmscon_vte *vte, uint32_t data) y = vte->csi_argv[1]; if (y <= 0) y = 1; - kmscon_console_move_to(vte->con, y - 1, x - 1); + tsm_screen_move_to(vte->con, y - 1, x - 1); break; case 'G': /* CHA */ /* Cursor Character Absolute */ num = vte->csi_argv[0]; if (num <= 0) num = 1; - y = kmscon_console_get_cursor_y(vte->con); - kmscon_console_move_to(vte->con, num - 1, y); + y = tsm_screen_get_cursor_y(vte->con); + tsm_screen_move_to(vte->con, num - 1, y); break; case 'J': if (vte->csi_flags & CSI_WHAT) @@ -1484,13 +1480,13 @@ static void do_csi(struct kmscon_vte *vte, uint32_t data) protect = false; if (vte->csi_argv[0] <= 0) - kmscon_console_erase_cursor_to_screen(vte->con, + tsm_screen_erase_cursor_to_screen(vte->con, protect); else if (vte->csi_argv[0] == 1) - kmscon_console_erase_screen_to_cursor(vte->con, + tsm_screen_erase_screen_to_cursor(vte->con, protect); else if (vte->csi_argv[0] == 2) - kmscon_console_erase_screen(vte->con, protect); + tsm_screen_erase_screen(vte->con, protect); else log_debug("unknown parameter to CSI-J: %d", vte->csi_argv[0]); @@ -1502,11 +1498,11 @@ static void do_csi(struct kmscon_vte *vte, uint32_t data) protect = false; if (vte->csi_argv[0] <= 0) - kmscon_console_erase_cursor_to_end(vte->con, protect); + tsm_screen_erase_cursor_to_end(vte->con, protect); else if (vte->csi_argv[0] == 1) - kmscon_console_erase_home_to_cursor(vte->con, protect); + tsm_screen_erase_home_to_cursor(vte->con, protect); else if (vte->csi_argv[0] == 2) - kmscon_console_erase_current_line(vte->con, protect); + tsm_screen_erase_current_line(vte->con, protect); else log_debug("unknown parameter to CSI-K: %d", vte->csi_argv[0]); @@ -1516,7 +1512,7 @@ static void do_csi(struct kmscon_vte *vte, uint32_t data) num = vte->csi_argv[0]; if (num <= 0) num = 1; - kmscon_console_erase_chars(vte->con, num); + tsm_screen_erase_chars(vte->con, num); break; case 'm': csi_attribute(vte); @@ -1553,7 +1549,7 @@ static void do_csi(struct kmscon_vte *vte, uint32_t data) lower = vte->csi_argv[1]; if (lower < 0) lower = 0; - kmscon_console_set_margins(vte->con, upper, lower); + tsm_screen_set_margins(vte->con, upper, lower); break; case 'c': /* DA */ /* device attributes */ @@ -1564,22 +1560,22 @@ static void do_csi(struct kmscon_vte *vte, uint32_t data) num = vte->csi_argv[0]; if (num <= 0) num = 1; - kmscon_console_insert_lines(vte->con, num); + tsm_screen_insert_lines(vte->con, num); break; case 'M': /* DL */ /* delete lines */ num = vte->csi_argv[0]; if (num <= 0) num = 1; - kmscon_console_delete_lines(vte->con, num); + tsm_screen_delete_lines(vte->con, num); break; case 'g': /* TBC */ /* tabulation clear */ num = vte->csi_argv[0]; if (num <= 0) - kmscon_console_reset_tabstop(vte->con); + tsm_screen_reset_tabstop(vte->con); else if (num == 3) - kmscon_console_reset_all_tabstops(vte->con); + tsm_screen_reset_all_tabstops(vte->con); else log_debug("invalid parameter %d to TBC CSI", num); break; @@ -1588,28 +1584,28 @@ static void do_csi(struct kmscon_vte *vte, uint32_t data) num = vte->csi_argv[0]; if (num <= 0) num = 1; - kmscon_console_insert_chars(vte->con, num); + tsm_screen_insert_chars(vte->con, num); break; case 'P': /* DCH */ /* delete characters */ num = vte->csi_argv[0]; if (num <= 0) num = 1; - kmscon_console_delete_chars(vte->con, num); + tsm_screen_delete_chars(vte->con, num); break; case 'Z': /* CBT */ /* cursor horizontal backwards tab */ num = vte->csi_argv[0]; if (num <= 0) num = 1; - kmscon_console_tab_left(vte->con, num); + tsm_screen_tab_left(vte->con, num); break; case 'I': /* CHT */ /* cursor horizontal forward tab */ num = vte->csi_argv[0]; if (num <= 0) num = 1; - kmscon_console_tab_right(vte->con, num); + tsm_screen_tab_right(vte->con, num); break; case 'n': /* DSR */ /* device status reports */ @@ -1620,14 +1616,14 @@ static void do_csi(struct kmscon_vte *vte, uint32_t data) num = vte->csi_argv[0]; if (num <= 0) num = 1; - kmscon_console_scroll_up(vte->con, num); + tsm_screen_scroll_up(vte->con, num); break; case 'T': /* SD */ /* scroll down */ num = vte->csi_argv[0]; if (num <= 0) num = 1; - kmscon_console_scroll_down(vte->con, num); + tsm_screen_scroll_down(vte->con, num); break; default: log_debug("unhandled CSI sequence %c", data); diff --git a/src/vte.h b/src/vte.h index 59d9e1a..a6a00d0 100644 --- a/src/vte.h +++ b/src/vte.h @@ -62,7 +62,7 @@ typedef void (*kmscon_vte_write_cb) (struct kmscon_vte *vte, size_t len, void *data); -int kmscon_vte_new(struct kmscon_vte **out, struct kmscon_console *con, +int kmscon_vte_new(struct kmscon_vte **out, struct tsm_screen *con, kmscon_vte_write_cb write_cb, void *data); void kmscon_vte_ref(struct kmscon_vte *vte); void kmscon_vte_unref(struct kmscon_vte *vte);