diff options
| -rw-r--r-- | elisp.c | 5 | ||||
| -rw-r--r-- | elisp.h | 2 | ||||
| -rw-r--r-- | vterm-module.c | 11 | ||||
| -rw-r--r-- | vterm-module.h | 1 | ||||
| -rw-r--r-- | vterm.el | 9 |
5 files changed, 28 insertions, 0 deletions
@@ -127,6 +127,11 @@ void toggle_cursor(emacs_env *env, bool visible) { env->funcall(env, Fset, 2, (emacs_value[]){Qcursor_type, Qvisible}); } +void toggle_mouse(emacs_env *env, bool mouse) { + emacs_value Qvisible = mouse ? Qt : Qnil; + env->funcall(env, Fvterm_toggle_mouse, 1, (emacs_value[]){Qvisible}); +}; + void toggle_cursor_blinking(emacs_env *env, bool blinking) { blinking = false; emacs_value Qfalse = env->make_integer(env, -1); @@ -39,6 +39,7 @@ emacs_value Fvterm_flush_output; emacs_value Fblink_cursor_mode; emacs_value Fget_buffer_window; emacs_value Fselected_window; +emacs_value Fvterm_toggle_mouse; // Utils void bind_function(emacs_env *env, const char *name, emacs_value Sfun); @@ -59,6 +60,7 @@ void forward_line(emacs_env *env, int n); void goto_line(emacs_env *env, int n); void toggle_cursor(emacs_env *env, bool visible); void toggle_cursor_blinking(emacs_env *env, bool visible); +void toggle_mouse(emacs_env *env, bool mouse); void delete_lines(emacs_env *env, int linenum, int count, bool del_whole_line); emacs_value get_hex_color_fg(emacs_env *env, emacs_value face); emacs_value get_hex_color_bg(emacs_env *env, emacs_value face); diff --git a/vterm-module.c b/vterm-module.c index 24ac1e6..bc65d40 100644 --- a/vterm-module.c +++ b/vterm-module.c @@ -313,6 +313,7 @@ static void term_redraw(Term *term, emacs_env *env) { if (term->is_invalidated) { toggle_cursor_blinking(env, term->cursor.blinking); toggle_cursor(env, term->cursor.visible); + toggle_mouse(env, term->mouse); long bufline_before = env->extract_integer(env, buffer_line_number(env)); refresh_scrollback(term, env); refresh_screen(term, env); @@ -364,6 +365,10 @@ static int term_settermprop(VTermProp prop, VTermValue *val, void *user_data) { break; case VTERM_PROP_CURSORBLINK: term->cursor.blinking = val->boolean; + break; + case VTERM_PROP_MOUSE: + term->mouse = val->boolean; + break; default: return 0; } @@ -518,6 +523,10 @@ static void term_process_key(Term *term, unsigned char *key, size_t len, vterm_keyboard_key(term->vt, VTERM_KEY_FUNCTION(12), modifier); } else if (is_key(key, len, "SPC")) { vterm_keyboard_unichar(term->vt, ' ', modifier); + } else if (is_key(key, len, "<mouse-4>")) { + vterm_mouse_button(term->vt, 4, true, modifier); + } else if (is_key(key, len, "<mouse-5>")) { + vterm_mouse_button(term->vt, 5, true, modifier); } else if (len <= 4) { uint32_t codepoint; if (utf8_to_codepoint(key, len, &codepoint)) { @@ -571,6 +580,7 @@ static emacs_value Fvterm_new(emacs_env *env, ptrdiff_t nargs, term->invalid_end = rows; term->cursor.visible = true; term->cursor.blinking = false; + term->mouse = false; return env->make_user_ptr(env, term_finalize, term); } @@ -682,6 +692,7 @@ int emacs_module_init(struct emacs_runtime *ert) { env->make_global_ref(env, env->intern(env, "get-buffer-window")); Fselected_window = env->make_global_ref(env, env->intern(env, "selected-window")); + Fvterm_toggle_mouse = env->make_global_ref(env, env->intern(env, "vterm--toggle-mouse")); // Faces Qterm = env->make_global_ref(env, env->intern(env, "vterm")); diff --git a/vterm-module.h b/vterm-module.h index 0934087..3380f95 100644 --- a/vterm-module.h +++ b/vterm-module.h @@ -48,6 +48,7 @@ typedef struct Term { bool is_invalidated; Cursor cursor; + bool mouse; // Send mouse events to the shell } Term; // Faces @@ -267,5 +267,14 @@ Feeds the size change to the virtual terminal." "Return the maximum line number." (line-number-at-pos (point-max))) +(defun vterm--toggle-mouse (bool) + (if bool + (progn + (define-key vterm-mode-map [mouse-4] #'vterm--self-insert) + (define-key vterm-mode-map [mouse-5] #'vterm--self-insert)) + (local-set-key [mouse-4] nil) + (local-set-key [mouse-5] nil))) + + (provide 'vterm) ;;; vterm.el ends here |
