From fff3b5f904d3b6d1deb9beec9ae871b135696966 Mon Sep 17 00:00:00 2001 From: Egmont Koblinger Date: Thu, 28 Jan 2016 14:09:55 +0100 Subject: [PATCH] emulation: Track the cursor separately for the two screens This is required to correctly resize the normal screen's contents while the alternate screen is active, fixing a bug introduced by commit 5a434e6c4457bdfe182a13213396e7a66a08f767. https://bugzilla.gnome.org/show_bug.cgi?id=761097 --- src/vte.cc | 160 +++++++++++++++++++++++++---------------------------- src/vteinternal.hh | 4 +- src/vteseq.cc | 152 +++++++++++++++++++++++++------------------------- 3 files changed, 153 insertions(+), 163 deletions(-) diff --git a/src/vte.cc b/src/vte.cc index 3a9a116d1973..701891ba93b3 100644 --- a/src/vte.cc +++ b/src/vte.cc @@ -743,8 +743,8 @@ _vte_invalidate_cursor_once(VteTerminal *terminal, gboolean periodic) if (terminal->pvt->cursor_visible) { preedit_width = vte_terminal_preedit_width(terminal, FALSE); - row = terminal->pvt->cursor.row; - column = terminal->pvt->cursor.col; + row = terminal->pvt->screen->cursor.row; + column = terminal->pvt->screen->cursor.col; columns = 1; column = find_start_column (terminal, column, row); cell = vte_terminal_find_charcell(terminal, column, row); @@ -1843,8 +1843,7 @@ _vte_terminal_adjust_adjustments(VteTerminal *terminal) * area. Leave the scrolling delta alone because it will be updated * when the adjustment changes. */ screen->insert_delta = MAX(screen->insert_delta, delta); - terminal->pvt->cursor.row = MAX(terminal->pvt->cursor.row, - screen->insert_delta); + screen->cursor.row = MAX(screen->cursor.row, screen->insert_delta); if (screen->scroll_delta > screen->insert_delta) { vte_terminal_queue_adjustment_value_changed(terminal, @@ -2137,7 +2136,7 @@ _vte_terminal_ensure_row (VteTerminal *terminal) /* Must make sure we're in a sane area. */ screen = terminal->pvt->screen; - v = terminal->pvt->cursor.row; + v = screen->cursor.row; /* Figure out how many rows we need to add. */ delta = v - _vte_ring_next(screen->row_data) + 1; @@ -2159,7 +2158,7 @@ vte_terminal_ensure_cursor(VteTerminal *terminal) VteRowData *row; row = _vte_terminal_ensure_row (terminal); - _vte_row_data_fill (row, &basic_cell.cell, terminal->pvt->cursor.col); + _vte_row_data_fill (row, &basic_cell.cell, terminal->pvt->screen->cursor.col); return row; } @@ -2177,7 +2176,7 @@ _vte_terminal_update_insert_delta(VteTerminal *terminal) /* The total number of lines. Add one to the cursor offset * because it's zero-based. */ rows = _vte_ring_next (screen->row_data); - delta = terminal->pvt->cursor.row - rows + 1; + delta = screen->cursor.row - rows + 1; if (G_UNLIKELY (delta > 0)) { vte_terminal_insert_rows (terminal, delta); rows = _vte_ring_next (screen->row_data); @@ -2189,7 +2188,7 @@ _vte_terminal_update_insert_delta(VteTerminal *terminal) delta = screen->insert_delta; delta = MIN(delta, rows - terminal->pvt->row_count); delta = MAX(delta, - terminal->pvt->cursor.row - (terminal->pvt->row_count - 1)); + screen->cursor.row - (terminal->pvt->row_count - 1)); delta = MAX(delta, _vte_ring_delta(screen->row_data)); /* Adjust the insert delta and scroll if needed. */ @@ -2921,7 +2920,7 @@ _vte_terminal_cleanup_fragments(VteTerminal *terminal, cell_end->attr.columns = 1; _vte_invalidate_cells(terminal, end, 1, - terminal->pvt->cursor.row, 1); + terminal->pvt->screen->cursor.row, 1); } } @@ -2947,7 +2946,7 @@ _vte_terminal_cleanup_fragments(VteTerminal *terminal, g_assert(start - col == 1); _vte_invalidate_cells(terminal, col, 1, - terminal->pvt->cursor.row, 1); + terminal->pvt->screen->cursor.row, 1); } keep_going = FALSE; } @@ -2974,19 +2973,19 @@ _vte_terminal_cursor_down (VteTerminal *terminal) start = screen->insert_delta; end = start + terminal->pvt->row_count - 1; } - if (terminal->pvt->cursor.row == end) { + if (screen->cursor.row == end) { if (terminal->pvt->scrolling_restricted) { if (start == screen->insert_delta) { /* Scroll this line into the scrollback * buffer by inserting a line at the next * line and scrolling the area up. */ screen->insert_delta++; - terminal->pvt->cursor.row++; + screen->cursor.row++; /* update start and end, as they are relative * to insert_delta. */ start++; end++; - _vte_terminal_ring_insert (terminal, terminal->pvt->cursor.row, FALSE); + _vte_terminal_ring_insert (terminal, screen->cursor.row, FALSE); /* Force the areas below the region to be * redrawn -- they've moved. */ _vte_terminal_scroll_region(terminal, start, @@ -3008,7 +3007,7 @@ _vte_terminal_cursor_down (VteTerminal *terminal) } } else { /* Scroll up with history. */ - terminal->pvt->cursor.row++; + screen->cursor.row++; _vte_terminal_update_insert_delta(terminal); } @@ -3020,7 +3019,7 @@ _vte_terminal_cursor_down (VteTerminal *terminal) } } else { /* Otherwise, just move the cursor down. */ - terminal->pvt->cursor.row++; + screen->cursor.row++; } } @@ -3042,9 +3041,9 @@ _vte_terminal_drop_scrollback (VteTerminal *terminal) void _vte_terminal_restore_cursor (VteTerminal *terminal, VteScreen *screen) { - terminal->pvt->cursor.col = screen->saved.cursor.col; - terminal->pvt->cursor.row = screen->insert_delta + CLAMP(screen->saved.cursor.row, - 0, terminal->pvt->row_count - 1); + screen->cursor.col = screen->saved.cursor.col; + screen->cursor.row = screen->insert_delta + CLAMP(screen->saved.cursor.row, + 0, terminal->pvt->row_count - 1); terminal->pvt->reverse_mode = screen->saved.reverse_mode; terminal->pvt->origin_mode = screen->saved.origin_mode; @@ -3063,8 +3062,8 @@ _vte_terminal_restore_cursor (VteTerminal *terminal, VteScreen *screen) void _vte_terminal_save_cursor (VteTerminal *terminal, VteScreen *screen) { - screen->saved.cursor.col = terminal->pvt->cursor.col; - screen->saved.cursor.row = terminal->pvt->cursor.row - screen->insert_delta; + screen->saved.cursor.col = screen->cursor.col; + screen->saved.cursor.row = screen->cursor.row - screen->insert_delta; screen->saved.reverse_mode = terminal->pvt->reverse_mode; screen->saved.origin_mode = terminal->pvt->origin_mode; @@ -3144,21 +3143,21 @@ _vte_terminal_insert_char(VteTerminal *terminal, gunichar c, columns = _vte_unichar_width(c, terminal->pvt->utf8_ambiguous_width); /* If we're autowrapping here, do it. */ - col = terminal->pvt->cursor.col; + col = screen->cursor.col; if (G_UNLIKELY (columns && col + columns > terminal->pvt->column_count)) { if (terminal->pvt->autowrap) { _vte_debug_print(VTE_DEBUG_ADJ, "Autowrapping before character\n"); /* Wrap. */ /* XXX clear to the end of line */ - col = terminal->pvt->cursor.col = 0; + col = screen->cursor.col = 0; /* Mark this line as soft-wrapped. */ row = _vte_terminal_ensure_row (terminal); row->attr.soft_wrapped = 1; _vte_terminal_cursor_down (terminal); } else { /* Don't wrap, stay at the rightmost column. */ - col = terminal->pvt->cursor.col = + col = screen->cursor.col = terminal->pvt->column_count - columns; } line_wrapped = TRUE; @@ -3169,7 +3168,7 @@ _vte_terminal_insert_char(VteTerminal *terminal, gunichar c, (long)c, c < 256 ? c : ' ', (int)terminal->pvt->color_defaults.attr.fore, (int)terminal->pvt->color_defaults.attr.back, - col, columns, (long)terminal->pvt->cursor.row, + col, columns, (long)screen->cursor.row, (long)screen->insert_delta); @@ -3182,7 +3181,7 @@ _vte_terminal_insert_char(VteTerminal *terminal, gunichar c, _vte_debug_print(VTE_DEBUG_PARSE, "combining U+%04X", c); - row_num = terminal->pvt->cursor.row; + row_num = screen->cursor.row; row = NULL; if (G_UNLIKELY (col == 0)) { /* We are at first column. See if the previous line softwrapped. @@ -3282,10 +3281,10 @@ _vte_terminal_insert_char(VteTerminal *terminal, gunichar c, _vte_invalidate_cells(terminal, col - columns, insert ? terminal->pvt->column_count : columns, - terminal->pvt->cursor.row, 1); + screen->cursor.row, 1); } - terminal->pvt->cursor.col = col; + screen->cursor.col = col; done: /* We added text, so make a note of it. */ @@ -3724,12 +3723,12 @@ vte_terminal_process_incoming(VteTerminal *terminal) bottom = screen->insert_delta == delta; /* Save the current cursor position. */ - cursor = terminal->pvt->cursor; + cursor = screen->cursor; cursor_visible = terminal->pvt->cursor_visible; in_scroll_region = terminal->pvt->scrolling_restricted - && (terminal->pvt->cursor.row >= (screen->insert_delta + terminal->pvt->scrolling_region.start)) - && (terminal->pvt->cursor.row <= (screen->insert_delta + terminal->pvt->scrolling_region.end)); + && (screen->cursor.row >= (screen->insert_delta + terminal->pvt->scrolling_region.start)) + && (screen->cursor.row <= (screen->insert_delta + terminal->pvt->scrolling_region.end)); /* We should only be called when there's data to process. */ g_assert(terminal->pvt->incoming || @@ -3839,8 +3838,8 @@ skip_chunk: modified = TRUE; new_in_scroll_region = terminal->pvt->scrolling_restricted - && (terminal->pvt->cursor.row >= (screen->insert_delta + terminal->pvt->scrolling_region.start)) - && (terminal->pvt->cursor.row <= (screen->insert_delta + terminal->pvt->scrolling_region.end)); + && (screen->cursor.row >= (screen->insert_delta + terminal->pvt->scrolling_region.start)) + && (screen->cursor.row <= (screen->insert_delta + terminal->pvt->scrolling_region.end)); delta = screen->scroll_delta; /* delta may have changed from sequence. */ @@ -3849,10 +3848,10 @@ skip_chunk: */ if (invalidated_text && ((new_in_scroll_region && !in_scroll_region) || - (terminal->pvt->cursor.col > bbox_bottomright.x + VTE_CELL_BBOX_SLACK || - terminal->pvt->cursor.col < bbox_topleft.x - VTE_CELL_BBOX_SLACK || - terminal->pvt->cursor.row > bbox_bottomright.y + VTE_CELL_BBOX_SLACK || - terminal->pvt->cursor.row < bbox_topleft.y - VTE_CELL_BBOX_SLACK))) { + (screen->cursor.col > bbox_bottomright.x + VTE_CELL_BBOX_SLACK || + screen->cursor.col < bbox_topleft.x - VTE_CELL_BBOX_SLACK || + screen->cursor.row > bbox_bottomright.y + VTE_CELL_BBOX_SLACK || + screen->cursor.row < bbox_topleft.y - VTE_CELL_BBOX_SLACK))) { /* Clip off any part of the box which isn't already on-screen. */ bbox_topleft.x = MAX(bbox_topleft.x, 0); bbox_topleft.y = MAX(bbox_topleft.y, delta); @@ -3931,20 +3930,18 @@ skip_chunk: } } - bbox_topleft.x = MIN(bbox_topleft.x, - terminal->pvt->cursor.col); - bbox_topleft.y = MIN(bbox_topleft.y, - terminal->pvt->cursor.row); + bbox_topleft.x = MIN(bbox_topleft.x, screen->cursor.col); + bbox_topleft.y = MIN(bbox_topleft.y, screen->cursor.row); /* Insert the character. */ if (G_UNLIKELY (_vte_terminal_insert_char(terminal, c, FALSE, FALSE))) { /* line wrapped, correct bbox */ if (invalidated_text && - (terminal->pvt->cursor.col > bbox_bottomright.x + VTE_CELL_BBOX_SLACK || - terminal->pvt->cursor.col < bbox_topleft.x - VTE_CELL_BBOX_SLACK || - terminal->pvt->cursor.row > bbox_bottomright.y + VTE_CELL_BBOX_SLACK || - terminal->pvt->cursor.row < bbox_topleft.y - VTE_CELL_BBOX_SLACK)) { + (screen->cursor.col > bbox_bottomright.x + VTE_CELL_BBOX_SLACK || + screen->cursor.col < bbox_topleft.x - VTE_CELL_BBOX_SLACK || + screen->cursor.row > bbox_bottomright.y + VTE_CELL_BBOX_SLACK || + screen->cursor.row < bbox_topleft.y - VTE_CELL_BBOX_SLACK)) { /* Clip off any part of the box which isn't already on-screen. */ bbox_topleft.x = MAX(bbox_topleft.x, 0); bbox_topleft.y = MAX(bbox_topleft.y, delta); @@ -3964,16 +3961,13 @@ skip_chunk: } bbox_topleft.x = MIN(bbox_topleft.x, 0); - bbox_topleft.y = MIN(bbox_topleft.y, - terminal->pvt->cursor.row); + bbox_topleft.y = MIN(bbox_topleft.y, screen->cursor.row); } /* Add the cells over which we have moved to the region * which we need to refresh for the user. */ - bbox_bottomright.x = MAX(bbox_bottomright.x, - terminal->pvt->cursor.col); + bbox_bottomright.x = MAX(bbox_bottomright.x, screen->cursor.col); /* cursor.row + 1 (defer until inv.) */ - bbox_bottomright.y = MAX(bbox_bottomright.y, - terminal->pvt->cursor.row); + bbox_bottomright.y = MAX(bbox_bottomright.y, screen->cursor.row); invalidated_text = TRUE; /* We *don't* emit flush pending signals here. */ @@ -4007,7 +4001,7 @@ skip_chunk: _vte_ring_delta(screen->row_data)); /* The cursor shouldn't be above or below the addressable * part of the display buffer. */ - g_assert(terminal->pvt->cursor.row >= terminal->pvt->screen->insert_delta); + g_assert(screen->cursor.row >= screen->insert_delta); #endif next_match: @@ -4082,8 +4076,8 @@ next_match: } - if ((cursor.col != terminal->pvt->cursor.col) || - (cursor.row != terminal->pvt->cursor.row)) { + if ((cursor.col != terminal->pvt->screen->cursor.col) || + (cursor.row != terminal->pvt->screen->cursor.row)) { /* invalidate the old and new cursor positions */ if (cursor_visible) _vte_invalidate_cell(terminal, cursor.col, cursor.row); @@ -4099,11 +4093,9 @@ next_match: /* Tell the input method where the cursor is. */ if (gtk_widget_get_realized (&terminal->widget)) { GdkRectangle rect; - rect.x = terminal->pvt->cursor.col * - terminal->pvt->char_width + terminal->pvt->padding.left; + rect.x = terminal->pvt->screen->cursor.col * terminal->pvt->char_width + terminal->pvt->padding.left; rect.width = terminal->pvt->char_width; - rect.y = (terminal->pvt->cursor.row - delta) * - terminal->pvt->char_height + terminal->pvt->padding.top; + rect.y = (terminal->pvt->screen->cursor.row - delta) * terminal->pvt->char_height + terminal->pvt->padding.top; rect.height = terminal->pvt->char_height; gtk_im_context_set_cursor_location(terminal->pvt->im_context, &rect); @@ -4830,8 +4822,7 @@ vte_terminal_key_press(GtkWidget *widget, GdkEventKey *event) /* If we're in margin bell mode and on the border of the * margin, bell. */ if (terminal->pvt->margin_bell) { - if ((terminal->pvt->cursor.col + - (glong) terminal->pvt->bell_margin) == + if ((terminal->pvt->screen->cursor.col + (glong) terminal->pvt->bell_margin) == terminal->pvt->column_count) { _vte_terminal_beep (terminal); } @@ -6530,10 +6521,10 @@ vte_terminal_get_cursor_position(VteTerminal *terminal, { g_return_if_fail(VTE_IS_TERMINAL(terminal)); if (column) { - *column = terminal->pvt->cursor.col; + *column = terminal->pvt->screen->cursor.col; } if (row) { - *row = terminal->pvt->cursor.row; + *row = terminal->pvt->screen->cursor.row; } } @@ -8058,14 +8049,14 @@ vte_terminal_screen_set_size(VteTerminal *terminal, VteScreen *screen, glong old " cursor_saved (relative to insert_delta) row=%ld col=%ld\n", screen == &terminal->pvt->normal_screen ? "normal" : "alternate", screen->insert_delta, screen->scroll_delta, - terminal->pvt->cursor.row, terminal->pvt->cursor.row - screen->scroll_delta + 1, terminal->pvt->cursor.col, + screen->cursor.row, screen->cursor.row - screen->scroll_delta + 1, screen->cursor.col, screen->saved.cursor.row, screen->saved.cursor.col); cursor_saved_absolute.row = screen->saved.cursor.row + screen->insert_delta; cursor_saved_absolute.col = screen->saved.cursor.col; below_viewport.row = screen->scroll_delta + old_rows; below_viewport.col = 0; - below_current_paragraph.row = terminal->pvt->cursor.row + 1; + below_current_paragraph.row = screen->cursor.row + 1; while (below_current_paragraph.row < _vte_ring_next(ring) && _vte_ring_index(ring, below_current_paragraph.row - 1)->attr.soft_wrapped) { below_current_paragraph.row++; @@ -8075,15 +8066,12 @@ vte_terminal_screen_set_size(VteTerminal *terminal, VteScreen *screen, glong old markers[0] = &cursor_saved_absolute; markers[1] = &below_viewport; markers[2] = &below_current_paragraph; - if (screen == terminal->pvt->screen) { - /* Tracking the current cursor only makes sense on the active screen. */ - markers[3] = &terminal->pvt->cursor; - if (terminal->pvt->has_selection) { - /* selection_end is inclusive, make it non-inclusive, see bug 722635. */ - terminal->pvt->selection_end.col++; - markers[4] = &terminal->pvt->selection_start; - markers[5] = &terminal->pvt->selection_end; - } + markers[3] = &screen->cursor; + if (terminal->pvt->has_selection) { + /* selection_end is inclusive, make it non-inclusive, see bug 722635. */ + terminal->pvt->selection_end.col++; + markers[4] = &terminal->pvt->selection_start; + markers[5] = &terminal->pvt->selection_end; } old_top_lines = below_current_paragraph.row - screen->insert_delta; @@ -8111,7 +8099,7 @@ vte_terminal_screen_set_size(VteTerminal *terminal, VteScreen *screen, glong old } } - if (screen == terminal->pvt->screen && terminal->pvt->has_selection) { + if (terminal->pvt->has_selection) { /* Make selection_end inclusive again, see above. */ terminal->pvt->selection_end.col--; } @@ -8160,7 +8148,7 @@ vte_terminal_screen_set_size(VteTerminal *terminal, VteScreen *screen, glong old " cursor (absolute) row=%ld (visual line %ld) col=%ld\n" " cursor_saved (relative to insert_delta) row=%ld col=%ld\n\n", screen->insert_delta, new_scroll_delta, - terminal->pvt->cursor.row, terminal->pvt->cursor.row - new_scroll_delta + 1, terminal->pvt->cursor.col, + screen->cursor.row, screen->cursor.row - new_scroll_delta + 1, screen->cursor.col, screen->saved.cursor.row, screen->saved.cursor.col); if (screen == terminal->pvt->screen) @@ -8225,10 +8213,10 @@ vte_terminal_set_size(VteTerminal *terminal, glong columns, glong rows) vte_terminal_set_scrollback_lines(terminal, terminal->pvt->scrollback_lines); /* Ensure the cursor is valid */ - terminal->pvt->cursor.row = CLAMP (terminal->pvt->cursor.row, - _vte_ring_delta (terminal->pvt->screen->row_data), - MAX (_vte_ring_delta (terminal->pvt->screen->row_data), - _vte_ring_next (terminal->pvt->screen->row_data) - 1)); + terminal->pvt->screen->cursor.row = CLAMP (terminal->pvt->screen->cursor.row, + _vte_ring_delta (terminal->pvt->screen->row_data), + MAX (_vte_ring_delta (terminal->pvt->screen->row_data), + _vte_ring_next (terminal->pvt->screen->row_data) - 1)); _vte_terminal_adjust_adjustments_full (terminal); gtk_widget_queue_resize_no_redraw (&terminal->widget); @@ -9963,8 +9951,8 @@ vte_terminal_paint_cursor(VteTerminal *terminal) screen = terminal->pvt->screen; delta = screen->scroll_delta; - col = terminal->pvt->cursor.col; - drow = terminal->pvt->cursor.row; + col = screen->cursor.col; + drow = screen->cursor.row; row = drow - delta; width = terminal->pvt->char_width; height = terminal->pvt->char_height; @@ -10104,7 +10092,7 @@ vte_terminal_paint_im_preedit_string(VteTerminal *terminal) height = terminal->pvt->char_height; delta = screen->scroll_delta; - row = terminal->pvt->cursor.row - delta; + row = screen->cursor.row - delta; /* Find out how many columns the pre-edit string takes up. */ columns = vte_terminal_preedit_width(terminal, FALSE); @@ -10112,7 +10100,7 @@ vte_terminal_paint_im_preedit_string(VteTerminal *terminal) /* If the pre-edit string won't fit on the screen if we start * drawing it at the cursor's position, move it left. */ - col = terminal->pvt->cursor.col; + col = screen->cursor.col; if (col + columns > terminal->pvt->column_count) { col = MAX(0, terminal->pvt->column_count - columns); } @@ -12035,7 +12023,7 @@ vte_terminal_set_scrollback_lines(VteTerminal *terminal, glong lines) /* The main screen gets the full scrollback buffer. */ screen = &terminal->pvt->normal_screen; lines = MAX (lines, terminal->pvt->row_count); - next = MAX (terminal->pvt->cursor.row + 1, + next = MAX (screen->cursor.row + 1, _vte_ring_next (screen->row_data)); _vte_ring_resize (screen->row_data, lines); low = _vte_ring_delta (screen->row_data); @@ -12234,10 +12222,12 @@ vte_terminal_reset(VteTerminal *terminal, pvt->screen = &pvt->normal_screen; pvt->normal_screen.scroll_delta = pvt->normal_screen.insert_delta = _vte_ring_reset(pvt->normal_screen.row_data); + pvt->normal_screen.cursor.row = pvt->normal_screen.insert_delta; + pvt->normal_screen.cursor.col = 0; pvt->alternate_screen.scroll_delta = pvt->alternate_screen.insert_delta = _vte_ring_reset(pvt->alternate_screen.row_data); - pvt->cursor.row = pvt->screen->insert_delta; - pvt->cursor.col = 0; + pvt->alternate_screen.cursor.row = pvt->alternate_screen.insert_delta; + pvt->alternate_screen.cursor.col = 0; /* Adjust the scrollbar to the new location. */ /* Hack: force a change in scroll_delta even if the value remains, so that vte_term_q_adj_val_changed() doesn't shortcut to no-op, see bug 730599. */ diff --git a/src/vteinternal.hh b/src/vteinternal.hh index 04d8104b044d..f2152e6a8853 100644 --- a/src/vteinternal.hh +++ b/src/vteinternal.hh @@ -102,12 +102,13 @@ struct _vte_incoming_chunk{ typedef struct _VteScreen VteScreen; struct _VteScreen { VteRing row_data[1]; /* buffer contents */ + VteVisualPosition cursor; /* absolute value, from the beginning of the terminal history */ long scroll_delta; /* scroll offset */ long insert_delta; /* insertion offset */ /* Stuff saved along with the cursor */ struct { - VteVisualPosition cursor; + VteVisualPosition cursor; /* onscreen coordinate, that is, relative to insert_delta */ gboolean reverse_mode; gboolean origin_mode; gboolean sendrecv_mode; @@ -208,7 +209,6 @@ public: struct _VteScreen normal_screen, alternate_screen, *screen; /* Values we save along with the cursor */ - VteVisualPosition cursor; /* relative to the insertion delta */ gboolean reverse_mode; /* reverse mode */ gboolean origin_mode; /* origin mode */ gboolean sendrecv_mode; /* sendrecv mode */ diff --git a/src/vteseq.cc b/src/vteseq.cc index af27ff5ef277..bf76995165bb 100644 --- a/src/vteseq.cc +++ b/src/vteseq.cc @@ -261,8 +261,8 @@ vte_terminal_emit_resize_window(VteTerminal *terminal, static void _vte_terminal_ensure_cursor_is_onscreen (VteTerminal *terminal) { - if (G_UNLIKELY (terminal->pvt->cursor.col >= terminal->pvt->column_count)) - terminal->pvt->cursor.col = terminal->pvt->column_count - 1; + if (G_UNLIKELY (terminal->pvt->screen->cursor.col >= terminal->pvt->column_count)) + terminal->pvt->screen->cursor.col = terminal->pvt->column_count - 1; } static void @@ -279,8 +279,8 @@ _vte_terminal_home_cursor (VteTerminal *terminal) origin = 0; } - terminal->pvt->cursor.row = screen->insert_delta + origin; - terminal->pvt->cursor.col = 0; + screen->cursor.row = screen->insert_delta + origin; + screen->cursor.col = 0; } /* Clear the entire screen. */ @@ -291,7 +291,7 @@ _vte_terminal_clear_screen (VteTerminal *terminal) VteScreen *screen; screen = terminal->pvt->screen; initial = screen->insert_delta; - row = terminal->pvt->cursor.row - screen->insert_delta; + row = screen->cursor.row - screen->insert_delta; initial = _vte_ring_next(screen->row_data); /* Add a new screen's worth of rows. */ for (i = 0; i < terminal->pvt->row_count; i++) @@ -299,7 +299,7 @@ _vte_terminal_clear_screen (VteTerminal *terminal) /* Move the cursor and insertion delta to the first line in the * newly-cleared area and scroll if need be. */ screen->insert_delta = initial; - terminal->pvt->cursor.row = row + screen->insert_delta; + screen->cursor.row = row + screen->insert_delta; _vte_terminal_adjust_adjustments(terminal); /* Redraw everything. */ _vte_invalidate_all(terminal); @@ -318,9 +318,9 @@ _vte_terminal_clear_current_line (VteTerminal *terminal) /* If the cursor is actually on the screen, clear data in the row * which corresponds to the cursor. */ - if (_vte_ring_next(screen->row_data) > terminal->pvt->cursor.row) { + if (_vte_ring_next(screen->row_data) > screen->cursor.row) { /* Get the data for the row which the cursor points to. */ - rowdata = _vte_ring_index_writable (screen->row_data, terminal->pvt->cursor.row); + rowdata = _vte_ring_index_writable (screen->row_data, screen->cursor.row); g_assert(rowdata != NULL); /* Remove it. */ _vte_row_data_shrink (rowdata, 0); @@ -330,7 +330,7 @@ _vte_terminal_clear_current_line (VteTerminal *terminal) /* Repaint this row. */ _vte_invalidate_cells(terminal, 0, terminal->pvt->column_count, - terminal->pvt->cursor.row, 1); + screen->cursor.row, 1); } /* We've modified the display. Make a note of it. */ @@ -347,7 +347,7 @@ _vte_terminal_clear_above_current (VteTerminal *terminal) screen = terminal->pvt->screen; /* If the cursor is actually on the screen, clear data in the row * which corresponds to the cursor. */ - for (i = screen->insert_delta; i < terminal->pvt->cursor.row; i++) { + for (i = screen->insert_delta; i < screen->cursor.row; i++) { if (_vte_ring_next(screen->row_data) > i) { /* Get the data for the row we're erasing. */ rowdata = _vte_ring_index_writable (screen->row_data, i); @@ -430,9 +430,9 @@ static void vte_sequence_handler_normal_screen (VteTerminal *terminal, GValueArray *params) { /* cursor.row includes insert_delta, adjust accordingly */ - terminal->pvt->cursor.row -= terminal->pvt->screen->insert_delta; + long cr = terminal->pvt->screen->cursor.row - terminal->pvt->screen->insert_delta; terminal->pvt->screen = &terminal->pvt->normal_screen; - terminal->pvt->cursor.row += terminal->pvt->screen->insert_delta; + terminal->pvt->screen->cursor.row = cr + terminal->pvt->screen->insert_delta; /* Make sure the ring is large enough */ _vte_terminal_ensure_row(terminal); @@ -443,9 +443,9 @@ static void vte_sequence_handler_alternate_screen (VteTerminal *terminal, GValueArray *params) { /* cursor.row includes insert_delta, adjust accordingly */ - terminal->pvt->cursor.row -= terminal->pvt->screen->insert_delta; + long cr = terminal->pvt->screen->cursor.row - terminal->pvt->screen->insert_delta; terminal->pvt->screen = &terminal->pvt->alternate_screen; - terminal->pvt->cursor.row += terminal->pvt->screen->insert_delta; + terminal->pvt->screen->cursor.row = cr + terminal->pvt->screen->insert_delta; /* Make sure the ring is large enough */ _vte_terminal_ensure_row(terminal); @@ -591,7 +591,7 @@ vte_sequence_handler_multiple_r(VteTerminal *terminal, VteTerminalSequenceHandler handler) { vte_sequence_handler_multiple_limited(terminal, params, handler, - terminal->pvt->column_count - terminal->pvt->cursor.col); + terminal->pvt->column_count - terminal->pvt->screen->cursor.col); } static void @@ -1035,7 +1035,7 @@ vte_sequence_handler_cursor_back_tab (VteTerminal *terminal, GValueArray *params long newcol; /* Calculate which column is the previous tab stop. */ - newcol = terminal->pvt->cursor.col; + newcol = terminal->pvt->screen->cursor.col; if (terminal->pvt->tabstops != NULL) { /* Find the next tabstop. */ @@ -1051,7 +1051,7 @@ vte_sequence_handler_cursor_back_tab (VteTerminal *terminal, GValueArray *params /* Warp the cursor. */ _vte_debug_print(VTE_DEBUG_PARSE, "Moving cursor to column %ld.\n", (long)newcol); - terminal->pvt->cursor.col = newcol; + terminal->pvt->screen->cursor.col = newcol; } /* Clear from the cursor position (inclusive!) to the beginning of the line. */ @@ -1067,11 +1067,11 @@ _vte_sequence_handler_cb (VteTerminal *terminal, GValueArray *params) /* Get the data for the row which the cursor points to. */ rowdata = _vte_terminal_ensure_row(terminal); /* Clean up Tab/CJK fragments. */ - _vte_terminal_cleanup_fragments (terminal, 0, terminal->pvt->cursor.col + 1); + _vte_terminal_cleanup_fragments (terminal, 0, terminal->pvt->screen->cursor.col + 1); /* Clear the data up to the current column with the default * attributes. If there is no such character cell, we need * to add one. */ - for (i = 0; i <= terminal->pvt->cursor.col; i++) { + for (i = 0; i <= terminal->pvt->screen->cursor.col; i++) { if (i < (glong) _vte_row_data_length (rowdata)) { /* Muck with the cell in this location. */ pcell = _vte_row_data_get_writable (rowdata, i); @@ -1083,8 +1083,8 @@ _vte_sequence_handler_cb (VteTerminal *terminal, GValueArray *params) } /* Repaint this row. */ _vte_invalidate_cells(terminal, - 0, terminal->pvt->cursor.col+1, - terminal->pvt->cursor.row, 1); + 0, terminal->pvt->screen->cursor.col+1, + terminal->pvt->screen->cursor.row, 1); /* We've modified the display. Make a note of it. */ terminal->pvt->text_deleted_flag = TRUE; @@ -1103,19 +1103,19 @@ _vte_sequence_handler_cd (VteTerminal *terminal, GValueArray *params) screen = terminal->pvt->screen; /* If the cursor is actually on the screen, clear the rest of the * row the cursor is on and all of the rows below the cursor. */ - i = terminal->pvt->cursor.row; + i = screen->cursor.row; if (i < _vte_ring_next(screen->row_data)) { /* Get the data for the row we're clipping. */ rowdata = _vte_ring_index_writable (screen->row_data, i); /* Clean up Tab/CJK fragments. */ - if ((glong) _vte_row_data_length (rowdata) > terminal->pvt->cursor.col) - _vte_terminal_cleanup_fragments (terminal, terminal->pvt->cursor.col, _vte_row_data_length (rowdata)); + if ((glong) _vte_row_data_length (rowdata) > screen->cursor.col) + _vte_terminal_cleanup_fragments (terminal, screen->cursor.col, _vte_row_data_length (rowdata)); /* Clear everything to the right of the cursor. */ if (rowdata) - _vte_row_data_shrink (rowdata, terminal->pvt->cursor.col); + _vte_row_data_shrink (rowdata, screen->cursor.col); } /* Now for the rest of the lines. */ - for (i = terminal->pvt->cursor.row + 1; + for (i = screen->cursor.row + 1; i < _vte_ring_next(screen->row_data); i++) { /* Get the data for the row we're removing. */ @@ -1125,7 +1125,7 @@ _vte_sequence_handler_cd (VteTerminal *terminal, GValueArray *params) _vte_row_data_shrink (rowdata, 0); } /* Now fill the cleared areas. */ - for (i = terminal->pvt->cursor.row; + for (i = screen->cursor.row; i < screen->insert_delta + terminal->pvt->row_count; i++) { /* Retrieve the row's data, creating it if necessary. */ @@ -1167,12 +1167,12 @@ _vte_sequence_handler_ce (VteTerminal *terminal, GValueArray *params) /* Get the data for the row which the cursor points to. */ rowdata = _vte_terminal_ensure_row(terminal); g_assert(rowdata != NULL); - if ((glong) _vte_row_data_length (rowdata) > terminal->pvt->cursor.col) { + if ((glong) _vte_row_data_length (rowdata) > terminal->pvt->screen->cursor.col) { /* Clean up Tab/CJK fragments. */ - _vte_terminal_cleanup_fragments (terminal, terminal->pvt->cursor.col, _vte_row_data_length (rowdata)); + _vte_terminal_cleanup_fragments (terminal, terminal->pvt->screen->cursor.col, _vte_row_data_length (rowdata)); /* Remove the data at the end of the array until the current column * is the end of the array. */ - _vte_row_data_shrink (rowdata, terminal->pvt->cursor.col); + _vte_row_data_shrink (rowdata, terminal->pvt->screen->cursor.col); /* We've modified the display. Make a note of it. */ terminal->pvt->text_deleted_flag = TRUE; } @@ -1183,10 +1183,10 @@ _vte_sequence_handler_ce (VteTerminal *terminal, GValueArray *params) rowdata->attr.soft_wrapped = 0; /* Repaint this row. */ _vte_invalidate_cells(terminal, - terminal->pvt->cursor.col, + terminal->pvt->screen->cursor.col, terminal->pvt->column_count - - terminal->pvt->cursor.col, - terminal->pvt->cursor.row, 1); + terminal->pvt->screen->cursor.col, + terminal->pvt->screen->cursor.row, 1); } /* Move the cursor to the given column (horizontal position), 1-based. */ @@ -1206,7 +1206,7 @@ vte_sequence_handler_cursor_character_absolute (VteTerminal *terminal, GValueArr } } - terminal->pvt->cursor.col = val; + terminal->pvt->screen->cursor.col = val; } /* Move the cursor to the given position, 1-based. */ @@ -1244,15 +1244,15 @@ vte_sequence_handler_cursor_position (VteTerminal *terminal, GValueArray *params } } } - terminal->pvt->cursor.row = rowval + screen->insert_delta; - terminal->pvt->cursor.col = colval; + screen->cursor.row = rowval + screen->insert_delta; + screen->cursor.col = colval; } /* Carriage return. */ static void vte_sequence_handler_carriage_return (VteTerminal *terminal, GValueArray *params) { - terminal->pvt->cursor.col = 0; + terminal->pvt->screen->cursor.col = 0; } /* Restrict scrolling and updates to a subset of the visible lines. */ @@ -1316,7 +1316,7 @@ vte_sequence_handler_set_scrolling_region (VteTerminal *terminal, GValueArray *p static void vte_sequence_handler_cursor_next_line (VteTerminal *terminal, GValueArray *params) { - terminal->pvt->cursor.col = 0; + terminal->pvt->screen->cursor.col = 0; vte_sequence_handler_cursor_down (terminal, params); } @@ -1324,7 +1324,7 @@ vte_sequence_handler_cursor_next_line (VteTerminal *terminal, GValueArray *param static void vte_sequence_handler_cursor_preceding_line (VteTerminal *terminal, GValueArray *params) { - terminal->pvt->cursor.col = 0; + terminal->pvt->screen->cursor.col = 0; vte_sequence_handler_cursor_up (terminal, params); } @@ -1356,7 +1356,7 @@ vte_sequence_handler_line_position_absolute (VteTerminal *terminal, GValueArray } val = val - 1 + origin; val = CLAMP(val, origin, rowmax); - terminal->pvt->cursor.row = screen->insert_delta + val; + screen->cursor.row = screen->insert_delta + val; } /* Delete a character at the current cursor position. */ @@ -1371,12 +1371,12 @@ _vte_sequence_handler_dc (VteTerminal *terminal, GValueArray *params) screen = terminal->pvt->screen; - if (_vte_ring_next(screen->row_data) > terminal->pvt->cursor.row) { + if (_vte_ring_next(screen->row_data) > screen->cursor.row) { long len; /* Get the data for the row which the cursor points to. */ - rowdata = _vte_ring_index_writable (screen->row_data, terminal->pvt->cursor.row); + rowdata = _vte_ring_index_writable (screen->row_data, screen->cursor.row); g_assert(rowdata != NULL); - col = terminal->pvt->cursor.col; + col = screen->cursor.col; len = _vte_row_data_length (rowdata); /* Remove the column. */ if (col < len) { @@ -1390,7 +1390,7 @@ _vte_sequence_handler_dc (VteTerminal *terminal, GValueArray *params) /* Repaint this row. */ _vte_invalidate_cells(terminal, col, len - col, - terminal->pvt->cursor.row, 1); + screen->cursor.row, 1); } } @@ -1433,7 +1433,7 @@ vte_sequence_handler_cursor_down (VteTerminal *terminal, GValueArray *params) } } - terminal->pvt->cursor.row = MIN(terminal->pvt->cursor.row + val, end); + screen->cursor.row = MIN(screen->cursor.row + val, end); } /* Erase characters starting at the cursor position (overwriting N with @@ -1462,14 +1462,14 @@ vte_sequence_handler_erase_characters (VteTerminal *terminal, GValueArray *param /* Clear out the given number of characters. */ rowdata = _vte_terminal_ensure_row(terminal); - if (_vte_ring_next(screen->row_data) > terminal->pvt->cursor.row) { + if (_vte_ring_next(screen->row_data) > screen->cursor.row) { g_assert(rowdata != NULL); /* Clean up Tab/CJK fragments. */ - _vte_terminal_cleanup_fragments (terminal, terminal->pvt->cursor.col, terminal->pvt->cursor.col + count); + _vte_terminal_cleanup_fragments (terminal, screen->cursor.col, screen->cursor.col + count); /* Write over the characters. (If there aren't enough, we'll * need to create them.) */ for (i = 0; i < count; i++) { - col = terminal->pvt->cursor.col + i; + col = screen->cursor.col + i; if (col >= 0) { if (col < (glong) _vte_row_data_length (rowdata)) { /* Replace this cell with the current @@ -1484,8 +1484,8 @@ vte_sequence_handler_erase_characters (VteTerminal *terminal, GValueArray *param } /* Repaint this row. */ _vte_invalidate_cells(terminal, - terminal->pvt->cursor.col, count, - terminal->pvt->cursor.row, 1); + screen->cursor.col, count, + screen->cursor.row, 1); } /* We've modified the display. Make a note of it. */ @@ -1507,11 +1507,11 @@ _vte_sequence_handler_insert_character (VteTerminal *terminal, GValueArray *para _vte_terminal_ensure_cursor_is_onscreen(terminal); - save = terminal->pvt->cursor; + save = terminal->pvt->screen->cursor; _vte_terminal_insert_char(terminal, ' ', TRUE, TRUE); - terminal->pvt->cursor = save; + terminal->pvt->screen->cursor = save; } /* Insert N blank characters. */ @@ -1535,9 +1535,9 @@ vte_sequence_handler_backspace (VteTerminal *terminal, GValueArray *params) { _vte_terminal_ensure_cursor_is_onscreen(terminal); - if (terminal->pvt->cursor.col > 0) { + if (terminal->pvt->screen->cursor.col > 0) { /* There's room to move left, so do so. */ - terminal->pvt->cursor.col--; + terminal->pvt->screen->cursor.col--; } } @@ -1557,7 +1557,7 @@ vte_sequence_handler_cursor_backward (VteTerminal *terminal, GValueArray *params val = MAX(g_value_get_long(value), 1); } } - terminal->pvt->cursor.col = MAX(terminal->pvt->cursor.col - val, 0); + terminal->pvt->screen->cursor.col = MAX(terminal->pvt->screen->cursor.col - val, 0); } /* Cursor right N columns. */ @@ -1578,9 +1578,9 @@ vte_sequence_handler_cursor_forward (VteTerminal *terminal, GValueArray *params) } } /* The cursor can be further to the right, don't move in that case. */ - if (terminal->pvt->cursor.col < terminal->pvt->column_count) { + if (terminal->pvt->screen->cursor.col < terminal->pvt->column_count) { /* There's room to move right. */ - terminal->pvt->cursor.col = MIN(terminal->pvt->cursor.col + val, + terminal->pvt->screen->cursor.col = MIN(terminal->pvt->screen->cursor.col + val, terminal->pvt->column_count - 1); } } @@ -1589,7 +1589,7 @@ vte_sequence_handler_cursor_forward (VteTerminal *terminal, GValueArray *params) static void vte_sequence_handler_next_line (VteTerminal *terminal, GValueArray *params) { - terminal->pvt->cursor.col = 0; + terminal->pvt->screen->cursor.col = 0; _vte_terminal_cursor_down (terminal); } @@ -1763,7 +1763,7 @@ vte_sequence_handler_reverse_index (VteTerminal *terminal, GValueArray *params) end = start + terminal->pvt->row_count - 1; } - if (terminal->pvt->cursor.row == start) { + if (screen->cursor.row == start) { /* If we're at the top of the scrolling region, add a * line at the top to scroll the bottom off. */ _vte_terminal_ring_remove (terminal, end); @@ -1775,7 +1775,7 @@ vte_sequence_handler_reverse_index (VteTerminal *terminal, GValueArray *params) start, 2); } else { /* Otherwise, just move the cursor up. */ - terminal->pvt->cursor.row--; + screen->cursor.row--; } /* Adjust the scrollbars if necessary. */ _vte_terminal_adjust_adjustments(terminal); @@ -1791,7 +1791,7 @@ vte_sequence_handler_tab_set (VteTerminal *terminal, GValueArray *params) terminal->pvt->tabstops = g_hash_table_new(NULL, NULL); } _vte_terminal_set_tabstop(terminal, - terminal->pvt->cursor.col); + terminal->pvt->screen->cursor.col); } /* Tab. */ @@ -1801,7 +1801,7 @@ vte_sequence_handler_tab (VteTerminal *terminal, GValueArray *params) long old_len, newcol, col; /* Calculate which column is the next tab stop. */ - newcol = col = terminal->pvt->cursor.col; + newcol = col = terminal->pvt->screen->cursor.col; g_assert (col >= 0); @@ -1873,10 +1873,10 @@ vte_sequence_handler_tab (VteTerminal *terminal, GValueArray *params) } _vte_invalidate_cells (terminal, - terminal->pvt->cursor.col, - newcol - terminal->pvt->cursor.col, - terminal->pvt->cursor.row, 1); - terminal->pvt->cursor.col = newcol; + terminal->pvt->screen->cursor.col, + newcol - terminal->pvt->screen->cursor.col, + terminal->pvt->screen->cursor.row, 1); + terminal->pvt->screen->cursor.col = newcol; } } @@ -1901,7 +1901,7 @@ vte_sequence_handler_tab_clear (VteTerminal *terminal, GValueArray *params) } if (param == 0) { _vte_terminal_clear_tabstop(terminal, - terminal->pvt->cursor.col); + terminal->pvt->screen->cursor.col); } else if (param == 3) { if (terminal->pvt->tabstops != NULL) { @@ -1939,7 +1939,7 @@ vte_sequence_handler_cursor_up (VteTerminal *terminal, GValueArray *params) } } - terminal->pvt->cursor.row = MAX(terminal->pvt->cursor.row - val, start); + screen->cursor.row = MAX(screen->cursor.row - val, start); } /* Vertical tab. */ @@ -2593,7 +2593,7 @@ vte_sequence_handler_insert_lines (VteTerminal *terminal, GValueArray *params) } } /* Find the region we're messing with. */ - row = terminal->pvt->cursor.row; + row = screen->cursor.row; if (terminal->pvt->scrolling_restricted) { end = screen->insert_delta + terminal->pvt->scrolling_region.end; } else { @@ -2612,7 +2612,7 @@ vte_sequence_handler_insert_lines (VteTerminal *terminal, GValueArray *params) _vte_terminal_ring_remove (terminal, end); _vte_terminal_ring_insert (terminal, row, TRUE); } - terminal->pvt->cursor.col = 0; + screen->cursor.col = 0; /* Update the display. */ _vte_terminal_scroll_region(terminal, row, end - row + 1, param); /* Adjust the scrollbars if necessary. */ @@ -2640,7 +2640,7 @@ vte_sequence_handler_delete_lines (VteTerminal *terminal, GValueArray *params) } } /* Find the region we're messing with. */ - row = terminal->pvt->cursor.row; + row = screen->cursor.row; if (terminal->pvt->scrolling_restricted) { end = screen->insert_delta + terminal->pvt->scrolling_region.end; } else { @@ -2660,7 +2660,7 @@ vte_sequence_handler_delete_lines (VteTerminal *terminal, GValueArray *params) _vte_terminal_ring_remove (terminal, row); _vte_terminal_ring_insert (terminal, end, TRUE); } - terminal->pvt->cursor.col = 0; + screen->cursor.col = 0; /* Update the display. */ _vte_terminal_scroll_region(terminal, row, end - row + 1, -param); /* Adjust the scrollbars if necessary. */ @@ -2700,12 +2700,12 @@ vte_sequence_handler_device_status_report (VteTerminal *terminal, GValueArray *p origin = 0; rowmax = terminal->pvt->row_count - 1; } - rowval = terminal->pvt->cursor.row - screen->insert_delta - origin; + rowval = screen->cursor.row - screen->insert_delta - origin; rowval = CLAMP(rowval, 0, rowmax); g_snprintf(buf, sizeof(buf), _VTE_CAP_CSI "%ld;%ldR", rowval + 1, - CLAMP(terminal->pvt->cursor.col + 1, + CLAMP(screen->cursor.col + 1, 1, terminal->pvt->column_count)); vte_terminal_feed_child(terminal, buf, -1); break; @@ -2742,12 +2742,12 @@ vte_sequence_handler_dec_device_status_report (VteTerminal *terminal, GValueArra origin = 0; rowmax = terminal->pvt->row_count - 1; } - rowval = terminal->pvt->cursor.row - screen->insert_delta - origin; + rowval = screen->cursor.row - screen->insert_delta - origin; rowval = CLAMP(rowval, 0, rowmax); g_snprintf(buf, sizeof(buf), _VTE_CAP_CSI "?%ld;%ldR", rowval + 1, - CLAMP(terminal->pvt->cursor.col + 1, + CLAMP(screen->cursor.col + 1, 1, terminal->pvt->column_count)); vte_terminal_feed_child(terminal, buf, -1); break; -- 2.5.0