Strange position when correcting on windows.

261 views
Skip to first unread message

mattn

unread,
Apr 18, 2012, 5:31:08 AM4/18/12
to vim...@googlegroups.com
Hi.

When move taskabr to top of the monitor, corrected position become strange.

1. Move taskbar to top of the monitor.
2. Start gvim.exe
3. :set lines=300

It expected that gvim move up to the bottom of taskbar.

http://go-gyazo.appspot.com/9fa9d351004e3e8a.png

But it has keep space.

http://go-gyazo.appspot.com/6fc3575ca56bfbfb.png

get_work_area() return rect of working area with abstract position.
But GetWindowPlacement()/SetWindowPlacement() treat the position as relative which except taskbar.
To checking both position, it should convert working area to relative. Below is a patch.

https://gist.github.com/2412212

Please check and include.

William E. Skeith III

unread,
Apr 18, 2012, 2:58:55 PM4/18/12
to vim...@googlegroups.com
> Subject: Strange position when correcting on windows.

Hello,

The source of this bug is in revision 3248, which was aiming to fix an
issue on dual-monitor setups.  I noticed this issue a while back, and
produced a similar patch.  Unfortunately, my patch un-fixed what was
done in revision 3248 regarding multiple monitors.  Can you test your
patch on a multi-monitor setup and make sure that it is compatible with
what was done in 3248?  I'm away from my dual monitor setup today...

-WES

mattn

unread,
Apr 19, 2012, 8:18:03 PM4/19/12
to vim...@googlegroups.com, William E. Skeith III
On Thursday, April 19, 2012 3:58:55 AM UTC+9, William E. Skeith III wrote:
> Hello,
>
> The source of this bug is in revision 3248, which was aiming to fix an
> issue on dual-monitor setups.  I noticed this issue a while back, and
> produced a similar patch.  Unfortunately, my patch un-fixed what was
> done in revision 3248 regarding multiple monitors.  Can you test your
> patch on a multi-monitor setup and make sure that it is compatible with
> what was done in 3248?  I'm away from my dual monitor setup today...
>
> -WES

Hi.

I tested on multi-monitor. But my patch have bits bug.
get_work_area() return rect absoluted of working area. So left/top should be considered on multi-monitor.

I updated patch.

https://gist.github.com/2412212

Thanks for your point.

William E. Skeith III

unread,
Apr 20, 2012, 2:39:26 AM4/20/12
to vim...@googlegroups.com
> Hi.
>
> I tested on multi-monitor. But my patch have bits bug.
> get_work_area() return rect absoluted of working area. So left/top should be considered on multi-monitor.
>
> I updated patch.
>
> https://gist.github.com/2412212
>
> Thanks for your point.

Great!  This has been nagging at me for a while.  I'll check out the new
patch over the weekend.

-WES

William E. Skeith III

unread,
Apr 23, 2012, 3:44:44 PM4/23/12
to vim...@googlegroups.com

I've tested out the new patch, and it seems to work just right, without
causing a regression for multiple monitors.

-WES

mattn

unread,
Apr 23, 2012, 9:35:56 PM4/23/12
to vim...@googlegroups.com, William E. Skeith III
What the problem do you have?

William E. Skeith III

unread,
Apr 23, 2012, 10:18:52 PM4/23/12
to vim...@googlegroups.com

??  There's no problem- I think the patch works perfectly.  (Perhaps you
skimmed over the word "without" in my last message?) : )

-WES

mattn

unread,
Apr 24, 2012, 12:58:57 AM4/24/12
to vim...@googlegroups.com, William E. Skeith III
Cool.

> (Perhaps you skimmed over the word "without" in my last message?)

Yes.

Yukihiro Nakadaira

unread,
Jun 19, 2012, 11:33:33 AM6/19/12
to vim...@googlegroups.com
I think that it is better to use GetWindowRect() and MoveWindow()
instead of GetWindowPlacement() so that we can use normal (not relative)
screen coordinates.

diff --git a/src/gui_w32.c b/src/gui_w32.c
--- a/src/gui_w32.c
+++ b/src/gui_w32.c
@@ -1660,28 +1660,21 @@
int direction)
{
RECT workarea_rect;
+ RECT window_rect;
int win_width, win_height;
- WINDOWPLACEMENT wndpl;

/* Try to keep window completely on screen. */
/* Get position of the screen work area. This is the part that is not
* used by the taskbar or appbars. */
get_work_area(&workarea_rect);

- /* Get current posision of our window. Note that the .left and .top are
- * relative to the work area. */
- wndpl.length = sizeof(WINDOWPLACEMENT);
- GetWindowPlacement(s_hwnd, &wndpl);
-
/* Resizing a maximized window looks very strange, unzoom it first.
* But don't do it when still starting up, it may have been requested in
* the shortcut. */
- if (wndpl.showCmd == SW_SHOWMAXIMIZED && starting == 0)
- {
+ if (IsZoomed(s_hwnd) && starting == 0)
ShowWindow(s_hwnd, SW_SHOWNORMAL);
- /* Need to get the settings of the normal window. */
- GetWindowPlacement(s_hwnd, &wndpl);
- }
+
+ GetWindowRect(s_hwnd, &window_rect);

/* compute the size of the outside of the window */
win_width = width + GetSystemMetrics(SM_CXFRAME) * 2;
@@ -1695,34 +1688,24 @@
/* The following should take care of keeping Vim on the same monitor, no
* matter if the secondary monitor is left or right of the primary
* monitor. */
- wndpl.rcNormalPosition.right = wndpl.rcNormalPosition.left + win_width;
- wndpl.rcNormalPosition.bottom = wndpl.rcNormalPosition.top + win_height;
+ window_rect.right = window_rect.left + win_width;
+ window_rect.bottom = window_rect.top + win_height;

/* If the window is going off the screen, move it on to the screen. */
- if ((direction & RESIZE_HOR)
- && wndpl.rcNormalPosition.right > workarea_rect.right)
- OffsetRect(&wndpl.rcNormalPosition,
- workarea_rect.right - wndpl.rcNormalPosition.right, 0);
-
- if ((direction & RESIZE_HOR)
- && wndpl.rcNormalPosition.left < workarea_rect.left)
- OffsetRect(&wndpl.rcNormalPosition,
- workarea_rect.left - wndpl.rcNormalPosition.left, 0);
-
- if ((direction & RESIZE_VERT)
- && wndpl.rcNormalPosition.bottom > workarea_rect.bottom)
- OffsetRect(&wndpl.rcNormalPosition,
- 0, workarea_rect.bottom - wndpl.rcNormalPosition.bottom);
-
- if ((direction & RESIZE_VERT)
- && wndpl.rcNormalPosition.top < workarea_rect.top)
- OffsetRect(&wndpl.rcNormalPosition,
- 0, workarea_rect.top - wndpl.rcNormalPosition.top);
-
- /* set window position - we should use SetWindowPlacement rather than
- * SetWindowPos as the MSDN docs say the coord systems returned by
- * these two are not compatible. */
- SetWindowPlacement(s_hwnd, &wndpl);
+ if ((direction & RESIZE_HOR) && window_rect.right > workarea_rect.right)
+ OffsetRect(&window_rect, workarea_rect.right - window_rect.right, 0);
+
+ if ((direction & RESIZE_HOR) && window_rect.left < workarea_rect.left)
+ OffsetRect(&window_rect, workarea_rect.left - window_rect.left, 0);
+
+ if ((direction & RESIZE_VERT) && window_rect.bottom > workarea_rect.bottom)
+ OffsetRect(&window_rect, 0, workarea_rect.bottom - window_rect.bottom);
+
+ if ((direction & RESIZE_VERT) && window_rect.top < workarea_rect.top)
+ OffsetRect(&window_rect, 0, workarea_rect.top - window_rect.top);
+
+ MoveWindow(s_hwnd, window_rect.left, window_rect.top,
+ win_width, win_height, TRUE);

SetActiveWindow(s_hwnd);
SetFocus(s_hwnd);


--
Yukihiro Nakadaira - yukihiro....@gmail.com

Yukihiro Nakadaira

unread,
Jun 20, 2012, 4:36:00 AM6/20/12
to vim...@googlegroups.com
And I noticed that Yasuhiro's patch doesn't work when using
multi-monitor with different resolution and Vim window is on secondary
monitor.

Bram Moolenaar

unread,
Jun 20, 2012, 6:40:38 AM6/20/12
to Yukihiro Nakadaira, vim...@googlegroups.com

Yukihiro Nakadaira wrote:

> I think that it is better to use GetWindowRect() and MoveWindow()
> instead of GetWindowPlacement() so that we can use normal (not relative)
> screen coordinates.

Does this fix an entry in the todo list? I could not find one.

This window positioning is tricky. I would like to have a few users try
it out on different screen configurations. Especially when splitting
windows or other actions that make the scrollbars appear or disappear.


--
Well, you come from nothing, you go back to nothing... What have you
lost? Nothing!
-- Monty Python: The life of Brian

/// Bram Moolenaar -- Br...@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 ///

Yukihiro Nakadaira

unread,
Jun 20, 2012, 8:34:28 AM6/20/12
to Bram Moolenaar, vim...@googlegroups.com
On Wed, Jun 20, 2012 at 7:40 PM, Bram Moolenaar <Br...@moolenaar.net> wrote:
> Does this fix an entry in the todo list?  I could not find one.
>
> This window positioning is tricky.  I would like to have a few users try
> it out on different screen configurations.  Especially when splitting
> windows or other actions that make the scrollbars appear or disappear.

This problem was reported by mattn on April 18.
And it was not listed in the todo list.
https://groups.google.com/d/msg/vim_dev/xRdOvRDM3-Y/fhlb--KfkTUJ

Recently another related problem was reported.
https://groups.google.com/d/msg/vim_use/s2h1hmw6TZA/iXzhBSamus8J

I think that it is difficult to support window placed across two
monitors. My preference is simply to not adjust window position for
resizing.
Reply all
Reply to author
Forward
0 new messages