]> granicus.if.org Git - vim/commitdiff
patch 8.0.1563: timeout of getwinposx() can be too short v8.0.1563
authorBram Moolenaar <Bram@vim.org>
Sat, 3 Mar 2018 20:29:55 +0000 (21:29 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 3 Mar 2018 20:29:55 +0000 (21:29 +0100)
Problem:    Timeout of getwinposx() can be too short. (lilydjwg)
Solution:   Add getwinpos(). (closes #2689)

runtime/doc/eval.txt
src/evalfunc.c
src/proto/term.pro
src/term.c
src/version.c

index 578e5d327f5e48ff865d4219ef755dc624fcc17d..51f059f4e3c6170278d05232da17351b5a33f78d 100644 (file)
@@ -2192,8 +2192,9 @@ gettabvar({nr}, {varname} [, {def}])
 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
+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}]]])
@@ -4878,16 +4879,24 @@ gettabwinvar({tabnr}, {winnr}, {varname} [, {def}])             *gettabwinvar()*
                        :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.
+               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.
+               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`.
 
index e866f4ce1c6399b591d355d527e9516074c8a859..b02c956132523f13244244f3283dae860ff33ef2 100644 (file)
@@ -197,6 +197,7 @@ static void f_gettabinfo(typval_T *argvars, typval_T *rettv);
 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},
@@ -5526,6 +5528,38 @@ f_win_screenpos(typval_T *argvars, typval_T *rettv)
     list_append_number(rettv->vval.v_list, wp == NULL ? 0 : wp->w_wincol + 1);
 }
 
+/*
+ * "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
  */
@@ -5547,7 +5581,7 @@ f_getwinposx(typval_T *argvars UNUSED, typval_T *rettv)
     {
        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, typval_T *rettv)
     {
        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
index 92cb26d58b4f366ea15cfb3e2f44772ae1ae30a2..42405dda5f2e0e21923e92f9787b3090987b6036 100644 (file)
@@ -24,7 +24,7 @@ void term_cursor_right(int i);
 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);
+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);
index 12c4f2e5bd6c2ffef3b8ef48b625f4b96efeb1fc..7dbbefa49acd61f56087925c420b12fc65fa7bf1 100644 (file)
@@ -2789,7 +2789,7 @@ static int waiting_for_winpos = FALSE;
  * Returns OK or FAIL.
  */
     int
-term_get_winpos(int *x, int *y)
+term_get_winpos(int *x, int *y, varnumber_T timeout)
 {
     int count = 0;
 
@@ -2801,8 +2801,8 @@ term_get_winpos(int *x, int *y)
     OUT_STR(T_CGP);
     out_flush();
 
-    /* Try reading the result for 100 msec. */
-    while (count++ < 10)
+    /* Try reading the result for "timeout" msec. */
+    while (count++ < timeout / 10)
     {
        (void)vpeekc_nomap();
        if (winpos_x >= 0 && winpos_y >= 0)
index 200ed6f2ff048188ef1f3aba6053b24a8486335d..c780826e659ea6d27e698a9af0751484df2b2dfa 100644 (file)
@@ -778,6 +778,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1563,
 /**/
     1562,
 /**/