From 601655fffc54515941e509bc1dd319ddf7d8f8bb Mon Sep 17 00:00:00 2001 From: Hanspeter Portner Date: Sat, 20 May 2023 12:31:15 +0200 Subject: [PATCH] Fix crash in vterm upon non-implemented callbacks --- meson_options.txt | 2 +- src/base_pty.c | 62 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/meson_options.txt b/meson_options.txt index d88a6fa..1bb918c 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -55,4 +55,4 @@ option('use-fontconfig', value : 'disabled', yield : true) -option('version', type : 'string', value : '0.4.0') +option('version', type : 'string', value : '0.5.1') diff --git a/src/base_pty.c b/src/base_pty.c index 0fcb832..fdd8801 100644 --- a/src/base_pty.c +++ b/src/base_pty.c @@ -20,6 +20,8 @@ #include "base_internal.h" +#define UNUSED __attribute__((unused)) + #define DEFAULT_FG 0xddddddff #define DEFAULT_BG 0x222222ff @@ -317,10 +319,62 @@ _screen_bell(void *data) return 0; } +static int +_screen_damage(VTermRect rect UNUSED, void *user UNUSED) +{ + // we don't use it, but must be implemented + return 0; +} + +static int +_screen_moverect(VTermRect dest UNUSED, VTermRect src UNUSED, + void *user UNUSED) +{ + // we don't use it, but must be implemented + return 0; +} + +static int +_screen_movecursor(VTermPos pos UNUSED, VTermPos oldpos UNUSED, + int visible UNUSED, void *user UNUSED) +{ + // we don't use it, but must be implemented + return 0; +} + +static int +_screen_sb_pushline(int cols UNUSED, const VTermScreenCell *cells UNUSED, + void *user UNUSED) +{ + // we don't use it, but must be implemented + return 0; +} + +static int +_screen_sb_popline(int cols UNUSED, VTermScreenCell *cells UNUSED, + void *user UNUSED) +{ + // we don't use it, but must be implemented + return 0; +} + +static int +_screen_sb_clear(void* user UNUSED) +{ + // we don't use it, but must be implemented + return 0; +} + static const VTermScreenCallbacks screen_callbacks = { + .damage = _screen_damage, + .moverect = _screen_moverect, + .movecursor = _screen_movecursor, .settermprop = _screen_settermprop, .bell = _screen_bell, - .resize = _screen_resize + .resize = _screen_resize, + .sb_pushline = _screen_sb_pushline, + .sb_popline = _screen_sb_popline, + .sb_clear = _screen_sb_clear }; static inline __attribute__((always_inline)) int @@ -556,6 +610,7 @@ _term_init(d2tk_atom_body_pty_t *vpty, d2tk_base_pty_cb_t cb, void *data, vpty->screen = vterm_obtain_screen(vpty->vterm); vterm_screen_set_callbacks(vpty->screen, &screen_callbacks, vpty); + vterm_screen_set_damage_merge(vpty->screen, VTERM_DAMAGE_SCROLL); vterm_screen_reset(vpty->screen, 1); return 0; @@ -911,7 +966,10 @@ _term_resize(d2tk_atom_body_pty_t *vpty, d2tk_coord_t ncols, { if( (nrows != vpty->nrows) || (ncols != vpty->ncols) ) { + fprintf(stderr, "%d %d -> %d %d\n", vpty->ncols, vpty->nrows, ncols, nrows); + vterm_set_size(vpty->vterm, nrows, ncols); + vterm_screen_flush_damage(vpty->screen); } } @@ -1240,7 +1298,7 @@ d2tk_pty_not_end(d2tk_pty_t *pty) } D2TK_API d2tk_pty_t * -d2tk_pty_next(d2tk_pty_t *pty __attribute__((unused))) +d2tk_pty_next(d2tk_pty_t *pty UNUSED) { return NULL; } -- 2.38.5