Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for the terminal bell #681

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions elisp.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ emacs_value Flist;
emacs_value Fnth;
emacs_value Ferase_buffer;
emacs_value Finsert;
emacs_value Fding;
emacs_value Fgoto_char;
emacs_value Fforward_char;
emacs_value Fforward_line;
Expand Down Expand Up @@ -120,6 +121,10 @@ void insert(emacs_env *env, emacs_value string) {
env->funcall(env, Finsert, 1, (emacs_value[]){string});
}

void ding(emacs_env *env, emacs_value flag) {
env->funcall(env, Fding, 1, (emacs_value[]){flag});
}

void goto_char(emacs_env *env, int pos) {
emacs_value point = env->make_integer(env, pos);
env->funcall(env, Fgoto_char, 1, (emacs_value[]){point});
Expand Down
2 changes: 2 additions & 0 deletions elisp.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ extern emacs_value Flist;
extern emacs_value Fnth;
extern emacs_value Ferase_buffer;
extern emacs_value Finsert;
extern emacs_value Fding;
extern emacs_value Fgoto_char;
extern emacs_value Fforward_char;
extern emacs_value Fforward_line;
Expand Down Expand Up @@ -74,6 +75,7 @@ void add_text_properties(emacs_env *env, emacs_value string,
emacs_value property);
void erase_buffer(emacs_env *env);
void insert(emacs_env *env, emacs_value string);
void ding(emacs_env *env, emacs_value flag);
void goto_char(emacs_env *env, int pos);
void forward_line(emacs_env *env, int n);
void goto_line(emacs_env *env, int n);
Expand Down
15 changes: 15 additions & 0 deletions vterm-module.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,13 @@ static int term_damage(VTermRect rect, void *data) {
return 1;
}

static int term_bell(void *data) {
Term *term = data;
term->queued_bell = true;
invalidate_terminal(data, -1, -1);
return 1;
}

static int term_moverect(VTermRect dest, VTermRect src, void *data) {
invalidate_terminal(data, MIN(dest.start_row, src.start_row),
MAX(dest.end_row, src.end_row));
Expand Down Expand Up @@ -617,6 +624,10 @@ static void term_redraw(Term *term, emacs_env *env) {
term->linenum_added = term->linenum - oldlinenum;
adjust_topline(term, env);
term->linenum_added = 0;
if (term->queued_bell) {
ding(env, Qt);
term->queued_bell = false;
}
}

if (term->title_changed) {
Expand Down Expand Up @@ -662,6 +673,7 @@ static VTermScreenCallbacks vterm_screen_callbacks = {
.resize = term_resize,
.sb_pushline = term_sb_push,
.sb_popline = term_sb_pop,
.bell = term_bell,
#if !defined(VTermSBClearNotExists)
.sb_clear = term_sb_clear,
#endif
Expand Down Expand Up @@ -1229,6 +1241,8 @@ emacs_value Fvterm_new(emacs_env *env, ptrdiff_t nargs, emacs_value args[],

term->vts = vterm_obtain_screen(term->vt);

term->queued_bell = false;

VTermState *state = vterm_obtain_state(term->vt);
vterm_state_set_unrecognised_fallbacks(state, &parser_callbacks, term);

Expand Down Expand Up @@ -1459,6 +1473,7 @@ int emacs_module_init(struct emacs_runtime *ert) {
Fnth = env->make_global_ref(env, env->intern(env, "nth"));
Ferase_buffer = env->make_global_ref(env, env->intern(env, "erase-buffer"));
Finsert = env->make_global_ref(env, env->intern(env, "vterm--insert"));
Fding = env->make_global_ref(env, env->intern(env, "ding"));
Fgoto_char = env->make_global_ref(env, env->intern(env, "goto-char"));
Fput_text_property =
env->make_global_ref(env, env->intern(env, "put-text-property"));
Expand Down
1 change: 1 addition & 0 deletions vterm-module.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ typedef struct Term {

int invalid_start, invalid_end; // invalid rows in libvterm screen
bool is_invalidated;
bool queued_bell;

Cursor cursor;
char *title;
Expand Down