Skip to content

Commit 22044dc

Browse files
committed
patch 8.0.1364: there is no easy way to get the window position
Problem: There is no easy way to get the window position. Solution: Add win_screenpos().
1 parent af903e5 commit 22044dc

4 files changed

Lines changed: 42 additions & 0 deletions

File tree

runtime/doc/eval.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2452,6 +2452,7 @@ win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab}
24522452
win_gotoid({expr}) Number go to window with ID {expr}
24532453
win_id2tabwin({expr}) List get tab and window nr from window ID
24542454
win_id2win({expr}) Number get window nr from window ID
2455+
win_screenpos({nr}) List get screen position of window {nr}
24552456
winbufnr({nr}) Number buffer number of window {nr}
24562457
wincol() Number window column of the cursor
24572458
winheight({nr}) Number height of window {nr}
@@ -8633,6 +8634,14 @@ win_id2win({expr}) *win_id2win()*
86338634
Return the window number of window with ID {expr}.
86348635
Return 0 if the window cannot be found in the current tabpage.
86358636

8637+
win_screenpos({nr}) *win_screenpos()*
8638+
Return the screen position of window {nr} as a list with two
8639+
numbers: [row, col]. The first window always has position
8640+
[1, 1].
8641+
{nr} can be the window number or the |window-ID|.
8642+
Return [0, 0] if the window cannot be found in the current
8643+
tabpage.
8644+
86368645
*winbufnr()*
86378646
winbufnr({nr}) The result is a Number, which is the number of the buffer
86388647
associated with window {nr}. {nr} can be the window number or

src/evalfunc.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ static void f_win_getid(typval_T *argvars, typval_T *rettv);
441441
static void f_win_gotoid(typval_T *argvars, typval_T *rettv);
442442
static void f_win_id2tabwin(typval_T *argvars, typval_T *rettv);
443443
static void f_win_id2win(typval_T *argvars, typval_T *rettv);
444+
static void f_win_screenpos(typval_T *argvars, typval_T *rettv);
444445
static void f_winbufnr(typval_T *argvars, typval_T *rettv);
445446
static void f_wincol(typval_T *argvars, typval_T *rettv);
446447
static void f_winheight(typval_T *argvars, typval_T *rettv);
@@ -899,6 +900,7 @@ static struct fst
899900
{"win_gotoid", 1, 1, f_win_gotoid},
900901
{"win_id2tabwin", 1, 1, f_win_id2tabwin},
901902
{"win_id2win", 1, 1, f_win_id2win},
903+
{"win_screenpos", 1, 1, f_win_screenpos},
902904
{"winbufnr", 1, 1, f_winbufnr},
903905
{"wincol", 0, 0, f_wincol},
904906
{"winheight", 1, 1, f_winheight},
@@ -5378,6 +5380,22 @@ f_win_id2win(typval_T *argvars, typval_T *rettv)
53785380
rettv->vval.v_number = win_id2win(argvars);
53795381
}
53805382

5383+
/*
5384+
* "win_screenpos()" function
5385+
*/
5386+
static void
5387+
f_win_screenpos(typval_T *argvars, typval_T *rettv)
5388+
{
5389+
win_T *wp;
5390+
5391+
if (rettv_list_alloc(rettv) == FAIL)
5392+
return;
5393+
5394+
wp = find_win_by_nr(&argvars[0], NULL);
5395+
list_append_number(rettv->vval.v_list, wp == NULL ? 0 : wp->w_winrow + 1);
5396+
list_append_number(rettv->vval.v_list, wp == NULL ? 0 : wp->w_wincol + 1);
5397+
}
5398+
53815399
/*
53825400
* "getwinposx()" function
53835401
*/

src/testdir/test_window_cmd.vim

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,19 @@ func Test_equalalways_on_close()
362362
set equalalways&
363363
endfunc
364364

365+
func Test_win_screenpos()
366+
call assert_equal(1, winnr('$'))
367+
split
368+
vsplit
369+
10wincmd _
370+
30wincmd |
371+
call assert_equal([1, 1], win_screenpos(1))
372+
call assert_equal([1, 32], win_screenpos(2))
373+
call assert_equal([12, 1], win_screenpos(3))
374+
call assert_equal([0, 0], win_screenpos(4))
375+
only
376+
endfunc
377+
365378
func Test_window_jump_tag()
366379
help
367380
/iccf

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+
1364,
774776
/**/
775777
1363,
776778
/**/

0 commit comments

Comments
 (0)