aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--vterm-module.c36
-rw-r--r--vterm-module.h2
2 files changed, 17 insertions, 21 deletions
diff --git a/vterm-module.c b/vterm-module.c
index 7a39aff..775d724 100644
--- a/vterm-module.c
+++ b/vterm-module.c
@@ -194,20 +194,16 @@ static void refresh_lines(Term *term, emacs_env *env, int start_row,
// Refresh the screen (visible part of the buffer when the terminal is
// focused) of a invalidated terminal
static void refresh_screen(Term *term, emacs_env *env) {
- int height;
- int width;
-
// Term height may have decreased before `invalid_end` reflects it.
- term->invalid_end = MIN(term->invalid_end, height);
+ term->invalid_end = MIN(term->invalid_end, term->height);
if (term->invalid_end >= term->invalid_start) {
- vterm_get_size(term->vt, &height, &width);
-
int line_start = row_to_linenr(term, term->invalid_start);
goto_line(env, line_start);
delete_lines(env, line_start, term->invalid_end - term->invalid_start,
true);
- refresh_lines(term, env, term->invalid_start, term->invalid_end, width);
+ refresh_lines(term, env, term->invalid_start, term->invalid_end,
+ term->width);
}
term->invalid_start = INT_MAX;
@@ -221,16 +217,16 @@ static int term_resize(int rows, int cols, void *user_data) {
Term *term = (Term *)user_data;
term->invalid_start = 0;
term->invalid_end = rows;
- invalidate_terminal(term,-1,-1);
+ term->width = cols;
+ term->height = rows;
+ invalidate_terminal(term, -1, -1);
return 1;
}
// Refresh the scrollback of an invalidated terminal.
static void refresh_scrollback(Term *term, emacs_env *env) {
- int width, height;
int buffer_lnum;
- vterm_get_size(term->vt, &height, &width);
if (term->sb_pending > 0) {
// This means that either the window height has decreased or the screen
@@ -239,17 +235,18 @@ static void refresh_scrollback(Term *term, emacs_env *env) {
// section of the buffer
buffer_lnum = env->extract_integer(env, buffer_line_number(env));
- int del_cnt = buffer_lnum - height - (int)term->sb_size + term->sb_pending;
+ int del_cnt =
+ buffer_lnum - term->height - (int)term->sb_size + term->sb_pending;
if (del_cnt > 0) {
delete_lines(env, 1, del_cnt, true);
buffer_lnum = env->extract_integer(env, buffer_line_number(env));
}
- int buf_index = buffer_lnum - height + 1;
+ int buf_index = buffer_lnum - term->height + 1;
goto_line(env, buf_index);
- refresh_lines(term, env, -term->sb_pending, 0, width);
+ refresh_lines(term, env, -term->sb_pending, 0, term->width);
term->sb_pending = 0;
}
- int max_line_count = (int)term->sb_current + height;
+ int max_line_count = (int)term->sb_current + term->height;
buffer_lnum = env->extract_integer(env, buffer_line_number(env));
// Remove extra lines at the bottom
@@ -260,9 +257,6 @@ static void refresh_scrollback(Term *term, emacs_env *env) {
}
static void adjust_topline(Term *term, emacs_env *env, long added) {
- int height, width;
- vterm_get_size(term->vt, &height, &width);
-
int buffer_lnum = env->extract_integer(env, buffer_line_number(env));
VTermState *state = vterm_obtain_state(term->vt);
VTermPos pos;
@@ -603,6 +597,9 @@ static emacs_value Fvterm_new(emacs_env *env, ptrdiff_t nargs,
term->sb_buffer = malloc(sizeof(ScrollbackLine *) * term->sb_size);
term->invalid_start = 0;
term->invalid_end = rows;
+ term->width = cols;
+ term->height = rows;
+
term->cursor.visible = true;
term->cursor.blinking = false;
term->title = NULL;
@@ -660,10 +657,7 @@ static emacs_value Fvterm_set_size(emacs_env *env, ptrdiff_t nargs,
int rows = env->extract_integer(env, args[1]);
int cols = env->extract_integer(env, args[2]);
- int old_rows, old_cols;
- vterm_get_size(term->vt, &old_rows, &old_cols);
-
- if (cols != old_cols || rows != old_rows) {
+ if (cols != term->width || rows != term->height) {
vterm_set_size(term->vt, rows, cols);
vterm_screen_flush_damage(term->vts);
diff --git a/vterm-module.h b/vterm-module.h
index 9f809b3..d985033 100644
--- a/vterm-module.h
+++ b/vterm-module.h
@@ -50,6 +50,8 @@ typedef struct Term {
Cursor cursor;
char *title;
bool is_title_changed;
+
+ int width, height;
} Term;
// Faces