To: vim_dev@googlegroups.com Subject: Patch 8.2.1226 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1226 Problem: MS-Windows: windows positioning wrong when the taskbar is placed at the top or left of the screen. Solution: Use GetWindowRect and MoveWindow APIs. (Yukihiro Nakadaira, Ken Takata, closes #6455) Files: src/gui_w32.c *** ../vim-8.2.1225/src/gui_w32.c 2020-05-16 14:01:48.117547771 +0200 --- src/gui_w32.c 2020-07-16 22:28:53.374676682 +0200 *************** *** 1429,1435 **** /* * Find the scrollbar with the given hwnd. */ ! static scrollbar_T * gui_mswin_find_scrollbar(HWND hwnd) { win_T *wp; --- 1429,1435 ---- /* * Find the scrollbar with the given hwnd. */ ! static scrollbar_T * gui_mswin_find_scrollbar(HWND hwnd) { win_T *wp; *************** *** 5395,5422 **** int direction) { RECT workarea_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 position 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) ! { ShowWindow(s_hwnd, SW_SHOWNORMAL); ! // Need to get the settings of the normal window. ! GetWindowPlacement(s_hwnd, &wndpl); ! } // compute the size of the outside of the window win_width = width + (GetSystemMetrics(SM_CXFRAME) + --- 5395,5415 ---- int direction) { RECT workarea_rect; + RECT window_rect; int win_width, win_height; // 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); // 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 (IsZoomed(s_hwnd) && starting == 0) ShowWindow(s_hwnd, SW_SHOWNORMAL); ! ! GetWindowRect(s_hwnd, &window_rect); // compute the size of the outside of the window win_width = width + (GetSystemMetrics(SM_CXFRAME) + *************** *** 5432,5465 **** // 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; // 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); SetActiveWindow(s_hwnd); SetFocus(s_hwnd); --- 5425,5448 ---- // 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. ! 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) && 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); *** ../vim-8.2.1225/src/version.c 2020-07-16 22:15:48.944513013 +0200 --- src/version.c 2020-07-16 22:28:49.714685249 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 1226, /**/ -- If you put 7 of the most talented OSS developers in a room for a week and asked them to fix a bug in a spreadsheet program, in 1 week you'd have 2 new mail readers and a text-based web browser. /// Bram Moolenaar -- Bram@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 ///