To: vim_dev@googlegroups.com Subject: Patch 8.0.1563 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.1563 Problem: Timeout of getwinposx() can be too short. (lilydjwg) Solution: Add getwinpos(). (closes #2689) Files: src/evalfunc.c, src/term.c, src/proto/term.pro, runtime/doc/eval.txt *** ../vim-8.0.1562/src/evalfunc.c 2018-03-03 15:06:48.379228997 +0100 --- src/evalfunc.c 2018-03-03 21:25:23.480527237 +0100 *************** *** 197,202 **** --- 197,203 ---- 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,646 **** --- 642,648 ---- {"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,5532 **** --- 5529,5566 ---- } /* + * "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,5553 **** { int x, y; ! if (term_get_winpos(&x, &y) == OK) rettv->vval.v_number = x; } #endif --- 5581,5587 ---- { int x, y; ! if (term_get_winpos(&x, &y, (varnumber_T)100) == OK) rettv->vval.v_number = x; } #endif *************** *** 5574,5580 **** { int x, y; ! if (term_get_winpos(&x, &y) == OK) rettv->vval.v_number = y; } #endif --- 5608,5614 ---- { int x, y; ! if (term_get_winpos(&x, &y, (varnumber_T)100) == OK) rettv->vval.v_number = y; } #endif *** ../vim-8.0.1562/src/term.c 2018-03-02 20:58:36.282811968 +0100 --- src/term.c 2018-03-03 21:24:19.112946095 +0100 *************** *** 2789,2795 **** * Returns OK or FAIL. */ int ! term_get_winpos(int *x, int *y) { int count = 0; --- 2789,2795 ---- * Returns OK or FAIL. */ int ! term_get_winpos(int *x, int *y, varnumber_T timeout) { int count = 0; *************** *** 2801,2808 **** OUT_STR(T_CGP); out_flush(); ! /* Try reading the result for 100 msec. */ ! while (count++ < 10) { (void)vpeekc_nomap(); if (winpos_x >= 0 && winpos_y >= 0) --- 2801,2808 ---- OUT_STR(T_CGP); out_flush(); ! /* Try reading the result for "timeout" msec. */ ! while (count++ < timeout / 10) { (void)vpeekc_nomap(); if (winpos_x >= 0 && winpos_y >= 0) *** ../vim-8.0.1562/src/proto/term.pro 2018-02-22 21:06:44.562818983 +0100 --- src/proto/term.pro 2018-03-03 21:24:22.172926182 +0100 *************** *** 24,30 **** void term_append_lines(int line_count); void term_delete_lines(int line_count); void term_set_winpos(int x, int y); ! int term_get_winpos(int *x, int *y); void term_set_winsize(int height, int width); void term_fg_color(int n); void term_bg_color(int n); --- 24,30 ---- void term_append_lines(int line_count); void term_delete_lines(int line_count); void term_set_winpos(int x, int y); ! int term_get_winpos(int *x, int *y, varnumber_T timeout); void term_set_winsize(int height, int width); void term_fg_color(int n); void term_bg_color(int n); *** ../vim-8.0.1562/runtime/doc/eval.txt 2018-02-24 19:53:09.150750442 +0100 --- runtime/doc/eval.txt 2018-03-03 21:26:45.711992269 +0100 *************** *** 2189,2196 **** gettabwinvar({tabnr}, {winnr}, {name} [, {def}]) any {name} in {winnr} in tab page {tabnr} getwininfo([{winid}]) List list of windows ! getwinposx() Number X coord in pixels of GUI Vim window ! getwinposy() Number Y coord in pixels of GUI Vim window getwinvar({nr}, {varname} [, {def}]) any variable {varname} in window {nr} glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) --- 2192,2200 ---- gettabwinvar({tabnr}, {winnr}, {name} [, {def}]) any {name} in {winnr} in tab page {tabnr} getwininfo([{winid}]) List list of windows ! getwinpos([{tmeout}]) List X and Y coord in pixels of the Vim window ! getwinposx() Number X coord in pixels of the Vim window ! getwinposy() Number Y coord in pixels of the Vim window getwinvar({nr}, {varname} [, {def}]) any variable {varname} in window {nr} glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *************** *** 4864,4879 **** :let list_is_on = gettabwinvar(1, 2, '&list') :echo "myvar = " . gettabwinvar(3, 1, 'myvar') < *getwinposx()* getwinposx() The result is a Number, which is the X coordinate in pixels of the left hand side of the GUI Vim window. Also works for an ! xterm. The result will be -1 if the information is not available. The value can be used with `:winpos`. *getwinposy()* getwinposy() The result is a Number, which is the Y coordinate in pixels of ! the top of the GUI Vim window. Also works for an xterm. The result will be -1 if the information is not available. The value can be used with `:winpos`. --- 4879,4902 ---- :let list_is_on = gettabwinvar(1, 2, '&list') :echo "myvar = " . gettabwinvar(3, 1, 'myvar') < + getwinpos([{timeout}]) *getwinpos()* + The result is a list with two numbers, the result of + getwinposx() and getwinposy() combined: + [x-pos, y-pos] + {timeout} can be used to specify how long to wait in msec for + a response from the terminal. When omitted 100 msec is used. + *getwinposx()* getwinposx() The result is a Number, which is the X coordinate in pixels of the left hand side of the GUI Vim window. Also works for an ! xterm (uses a timeout of 100 msec). The result will be -1 if the information is not available. The value can be used with `:winpos`. *getwinposy()* getwinposy() The result is a Number, which is the Y coordinate in pixels of ! the top of the GUI Vim window. Also works for an xterm (uses ! a timeout of 100 msec). The result will be -1 if the information is not available. The value can be used with `:winpos`. *** ../vim-8.0.1562/src/version.c 2018-03-03 20:46:28.759725294 +0100 --- src/version.c 2018-03-03 21:28:40.395246437 +0100 *************** *** 780,781 **** --- 780,783 ---- { /* Add new patch number below this line */ + /**/ + 1563, /**/ -- We apologise again for the fault in the subtitles. Those responsible for sacking the people who have just been sacked have been sacked. "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///