Mercurial > vim
diff src/evalfunc.c @ 13379:0f9dd1b43244
patch 8.0.1563: timeout of getwinposx() can be too short
commit https://github.com/vim/vim/commit/3f54fd319f6641b4bed478bcc90cdb39ede68e31
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Mar 3 21:29:55 2018 +0100
patch 8.0.1563: timeout of getwinposx() can be too short
Problem: Timeout of getwinposx() can be too short. (lilydjwg)
Solution: Add getwinpos(). (closes https://github.com/vim/vim/issues/2689)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 03 Mar 2018 21:30:06 +0100 |
parents | 53f15c99a9fd |
children | 69517d67421f |
line wrap: on
line diff
--- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -197,6 +197,7 @@ static void f_gettabinfo(typval_T *argva static void f_gettabvar(typval_T *argvars, typval_T *rettv); static void f_gettabwinvar(typval_T *argvars, typval_T *rettv); static void f_getwininfo(typval_T *argvars, typval_T *rettv); +static void f_getwinpos(typval_T *argvars, typval_T *rettv); static void f_getwinposx(typval_T *argvars, typval_T *rettv); static void f_getwinposy(typval_T *argvars, typval_T *rettv); static void f_getwinvar(typval_T *argvars, typval_T *rettv); @@ -641,6 +642,7 @@ static struct fst {"gettabvar", 2, 3, f_gettabvar}, {"gettabwinvar", 3, 4, f_gettabwinvar}, {"getwininfo", 0, 1, f_getwininfo}, + {"getwinpos", 0, 1, f_getwinpos}, {"getwinposx", 0, 0, f_getwinposx}, {"getwinposy", 0, 0, f_getwinposy}, {"getwinvar", 2, 3, f_getwinvar}, @@ -5527,6 +5529,38 @@ f_win_screenpos(typval_T *argvars, typva } /* + * "getwinpos({timeout})" function + */ + static void +f_getwinpos(typval_T *argvars UNUSED, typval_T *rettv) +{ + int x = -1; + int y = -1; + + if (rettv_list_alloc(rettv) == FAIL) + return; +#ifdef FEAT_GUI + if (gui.in_use) + gui_mch_get_winpos(&x, &y); +# if defined(HAVE_TGETENT) && defined(FEAT_TERMRESPONSE) + else +# endif +#endif +#if defined(HAVE_TGETENT) && defined(FEAT_TERMRESPONSE) + { + varnumber_T timeout = 100; + + if (argvars[0].v_type != VAR_UNKNOWN) + timeout = get_tv_number(&argvars[0]); + term_get_winpos(&x, &y, timeout); + } +#endif + list_append_number(rettv->vval.v_list, (varnumber_T)x); + list_append_number(rettv->vval.v_list, (varnumber_T)y); +} + + +/* * "getwinposx()" function */ static void @@ -5547,7 +5581,7 @@ f_getwinposx(typval_T *argvars UNUSED, t { int x, y; - if (term_get_winpos(&x, &y) == OK) + if (term_get_winpos(&x, &y, (varnumber_T)100) == OK) rettv->vval.v_number = x; } #endif @@ -5574,7 +5608,7 @@ f_getwinposy(typval_T *argvars UNUSED, t { int x, y; - if (term_get_winpos(&x, &y) == OK) + if (term_get_winpos(&x, &y, (varnumber_T)100) == OK) rettv->vval.v_number = y; } #endif