win32: Vim window is always moved to primary monitor when resizing Vim
window with ex-command and secondary monitor is on left side.

Steps to reproduce:

Setup monitors as following.

  +---+---+
  |   |   |
  | 2 | 1 |
  |   |   |
  +---+---+
    ^   ^
    |   +- primary monitor
    +----- secondary monitor

Move Vim window to the 2nd monitor.
Resize Vim window with ex-command (e.g. ":set lines=10")
Then, Vim window is moved to the primary monitor.

I wrote the following patch to fix it.
Window position is always adjusted to the nearest monitor (even if
window is placed between two monitors and is completely fit into
screen).


diff --git a/src/gui_w32.c b/src/gui_w32.c
--- a/src/gui_w32.c
+++ b/src/gui_w32.c
@@ -1661,9 +1661,7 @@
 {
     RECT       workarea_rect;
     int                win_width, win_height;
-    int                win_xpos, win_ypos;
     WINDOWPLACEMENT wndpl;
-    int                workarea_left;

     /* Try to keep window completely on screen. */
     /* Get position of the screen work area.  This is the part that is not
@@ -1685,9 +1683,6 @@
        GetWindowPlacement(s_hwnd, &wndpl);
     }

-    win_xpos = wndpl.rcNormalPosition.left;
-    win_ypos = wndpl.rcNormalPosition.top;
-
     /* compute the size of the outside of the window */
     win_width = width + GetSystemMetrics(SM_CXFRAME) * 2;
     win_height = height + GetSystemMetrics(SM_CYFRAME) * 2
@@ -1697,36 +1692,29 @@
 #endif
                        ;

-    /* There is an inconsistency when using two monitors and Vim is on the
-     * second (right) one: win_xpos will be the offset from the workarea of
-     * the left monitor.  While with one monitor it's the offset from the
-     * workarea (including a possible taskbar on the left).  Detect the second
-     * monitor by checking for the left offset to be quite big. */
-    if (workarea_rect.left > 300)
-       workarea_left = 0;
-    else
-       workarea_left = workarea_rect.left;
-
-    /* If the window is going off the screen, move it on to the screen.
-     * win_xpos and win_ypos are relative to the workarea. */
+    wndpl.rcNormalPosition.right = wndpl.rcNormalPosition.left + win_width;
+    wndpl.rcNormalPosition.bottom = wndpl.rcNormalPosition.top + win_height;
+
+    /* If the window is going off the screen, move it on to the screen. */
     if ((direction & RESIZE_HOR)
-           && workarea_left + win_xpos + win_width > workarea_rect.right)
-       win_xpos = workarea_rect.right - win_width - workarea_left;
-
-    if ((direction & RESIZE_HOR) && win_xpos < 0)
-       win_xpos = 0;
+           && 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)
-         && workarea_rect.top + win_ypos + win_height > workarea_rect.bottom)
-       win_ypos = workarea_rect.bottom - win_height - workarea_rect.top;
-
-    if ((direction & RESIZE_VERT) && win_ypos < 0)
-       win_ypos = 0;
-
-    wndpl.rcNormalPosition.left = win_xpos;
-    wndpl.rcNormalPosition.right = win_xpos + win_width;
-    wndpl.rcNormalPosition.top = win_ypos;
-    wndpl.rcNormalPosition.bottom = win_ypos + win_height;
+           && 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


-- 
Yukihiro Nakadaira - [email protected]

-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Raspunde prin e-mail lui