Skip to content

Commit 16c34c3

Browse files
committed
patch 8.1.1131: getwinpos() does not work in the MS-Windows console
Problem: getwinpos() does not work in the MS-Windows console. Solution: Implement getwinpos().
1 parent 1164023 commit 16c34c3

5 files changed

Lines changed: 33 additions & 16 deletions

File tree

src/evalfunc.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5985,7 +5985,9 @@ f_getwinpos(typval_T *argvars UNUSED, typval_T *rettv)
59855985

59865986
if (rettv_list_alloc(rettv) == FAIL)
59875987
return;
5988-
#if defined(FEAT_GUI) || (defined(HAVE_TGETENT) && defined(FEAT_TERMRESPONSE))
5988+
#if defined(FEAT_GUI) \
5989+
|| (defined(HAVE_TGETENT) && defined(FEAT_TERMRESPONSE)) \
5990+
|| defined(MSWIN)
59895991
{
59905992
varnumber_T timeout = 100;
59915993

@@ -6007,7 +6009,10 @@ f_getwinpos(typval_T *argvars UNUSED, typval_T *rettv)
60076009
f_getwinposx(typval_T *argvars UNUSED, typval_T *rettv)
60086010
{
60096011
rettv->vval.v_number = -1;
6010-
#if defined(FEAT_GUI) || (defined(HAVE_TGETENT) && defined(FEAT_TERMRESPONSE))
6012+
#if defined(FEAT_GUI) \
6013+
|| (defined(HAVE_TGETENT) && defined(FEAT_TERMRESPONSE)) \
6014+
|| defined(MSWIN)
6015+
60116016
{
60126017
int x, y;
60136018

@@ -6024,7 +6029,9 @@ f_getwinposx(typval_T *argvars UNUSED, typval_T *rettv)
60246029
f_getwinposy(typval_T *argvars UNUSED, typval_T *rettv)
60256030
{
60266031
rettv->vval.v_number = -1;
6027-
#if defined(FEAT_GUI) || (defined(HAVE_TGETENT) && defined(FEAT_TERMRESPONSE))
6032+
#if defined(FEAT_GUI) \
6033+
|| (defined(HAVE_TGETENT) && defined(FEAT_TERMRESPONSE)) \
6034+
|| defined(MSWIN)
60286035
{
60296036
int x, y;
60306037

src/terminal.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3868,7 +3868,9 @@ parse_csi(
38683868

38693869
// When getting the window position is not possible or it fails it results
38703870
// in zero/zero.
3871-
#if defined(FEAT_GUI) || (defined(HAVE_TGETENT) && defined(FEAT_TERMRESPONSE))
3871+
#if defined(FEAT_GUI) \
3872+
|| (defined(HAVE_TGETENT) && defined(FEAT_TERMRESPONSE)) \
3873+
|| defined(MSWIN)
38723874
(void)ui_get_winpos(&x, &y, (varnumber_T)100);
38733875
#endif
38743876

src/testdir/test_terminal.vim

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,12 +1889,6 @@ func Test_terminal_statusline()
18891889
endfunc
18901890

18911891
func Test_terminal_getwinpos()
1892-
" getwinpos() does not work in the MS-Windows console, and the GUI runs the
1893-
" console version in the terminal window.
1894-
if has('win32')
1895-
return
1896-
endif
1897-
18981892
" split, go to the bottom-right window
18991893
split
19001894
wincmd j
@@ -1913,10 +1907,17 @@ func Test_terminal_getwinpos()
19131907
let xpos = str2nr(substitute(line, '\[\(\d\+\), \d\+\]', '\1', ''))
19141908
let ypos = str2nr(substitute(line, '\[\d\+, \(\d\+\)\]', '\1', ''))
19151909

1916-
" Position must be bigger than the getwinpos() result of Vim itself.
1917-
let [xroot, yroot] = getwinpos()
1918-
call assert_inrange(xroot + 2, xroot + 1000, xpos)
1919-
call assert_inrange(yroot + 2, yroot + 1000, ypos)
1910+
" getwinpos() in the MS-Windows console returns the screen position of the
1911+
" emulated console.
1912+
if has('win32')
1913+
call assert_inrange(0, 4000, xpos)
1914+
call assert_inrange(0, 2000, ypos)
1915+
else
1916+
" Position must be bigger than the getwinpos() result of Vim itself.
1917+
let [xroot, yroot] = getwinpos()
1918+
call assert_inrange(xroot + 2, xroot + 1000, xpos)
1919+
call assert_inrange(yroot + 2, yroot + 1000, ypos)
1920+
endif
19201921

19211922
call term_wait(buf)
19221923
call term_sendkeys(buf, ":q\<CR>")

src/ui.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,7 @@ ui_new_shellsize(void)
629629

630630
#if ((defined(FEAT_EVAL) || defined(FEAT_TERMINAL)) \
631631
&& (defined(FEAT_GUI) \
632+
|| defined(MSWIN) \
632633
|| (defined(HAVE_TGETENT) && defined(FEAT_TERMRESPONSE)))) \
633634
|| defined(PROTO)
634635
/*
@@ -642,10 +643,14 @@ ui_get_winpos(int *x, int *y, varnumber_T timeout)
642643
if (gui.in_use)
643644
return gui_mch_get_winpos(x, y);
644645
# endif
645-
# if defined(HAVE_TGETENT) && defined(FEAT_TERMRESPONSE)
646-
return term_get_winpos(x, y, timeout);
646+
# if defined(MSWIN) && !defined(FEAT_GUI)
647+
return mch_get_winpos(x, y);
647648
# else
649+
# if defined(HAVE_TGETENT) && defined(FEAT_TERMRESPONSE)
650+
return term_get_winpos(x, y, timeout);
651+
# else
648652
return FAIL;
653+
# endif
649654
# endif
650655
}
651656
#endif

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,8 @@ static char *(features[]) =
771771

772772
static int included_patches[] =
773773
{ /* Add new patch number below this line */
774+
/**/
775+
1131,
774776
/**/
775777
1130,
776778
/**/

0 commit comments

Comments
 (0)