Mercurial > vim
diff src/terminal.c @ 16241:c1698187c482 v8.1.1125
patch 8.1.1125: libvterm does not handle the window position report
commit https://github.com/vim/vim/commit/fa1e90cd4d1bebd66da22df4625f70963f091f17
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Apr 6 17:47:40 2019 +0200
patch 8.1.1125: libvterm does not handle the window position report
Problem: Libvterm does not handle the window position report.
Solution: Let libvterm call the fallback CSI handler when not handling CSI
sequence. Handle the window position report in Vim.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 06 Apr 2019 18:00:05 +0200 |
parents | cd5c83115ec6 |
children | e0a6298bd70f |
line wrap: on
line diff
--- a/src/terminal.c +++ b/src/terminal.c @@ -3842,14 +3842,68 @@ parse_osc(const char *command, size_t cm return 1; } +/* + * Called by libvterm when it cannot recognize a CSI sequence. + * We recognize the window position report. + */ + static int +parse_csi( + const char *leader UNUSED, + const long args[], + int argcount, + const char *intermed UNUSED, + char command, + void *user) +{ + term_T *term = (term_T *)user; + char buf[100]; + int len; + int x = 0; + int y = 0; + win_T *wp; + + // We recognize only CSI 13 t + if (command != 't' || argcount != 1 || args[0] != 13) + return 0; // not handled + + // When getting the window position fails it results in zero/zero. + (void)ui_get_winpos(&x, &y, (varnumber_T)100); + + FOR_ALL_WINDOWS(wp) + if (wp->w_buffer == term->tl_buffer) + break; + if (wp != NULL) + { +#ifdef FEAT_GUI + if (gui.in_use) + { + x += wp->w_wincol * gui.char_width; + y += W_WINROW(wp) * gui.char_height; + } + else +#endif + { + // We roughly estimate the position of the terminal window inside + // the Vim window by assuing a 10 x 7 character cell. + x += wp->w_wincol * 7; + y += W_WINROW(wp) * 10; + } + } + + len = vim_snprintf(buf, 100, "\x1b[3;%d;%dt", x, y); + channel_send(term->tl_job->jv_channel, get_tty_part(term), + (char_u *)buf, len, NULL); + return 1; +} + static VTermParserCallbacks parser_fallbacks = { - NULL, /* text */ - NULL, /* control */ - NULL, /* escape */ - NULL, /* csi */ - parse_osc, /* osc */ - NULL, /* dcs */ - NULL /* resize */ + NULL, // text + NULL, // control + NULL, // escape + parse_csi, // csi + parse_osc, // osc + NULL, // dcs + NULL // resize }; /*