Mercurial > vim
comparison src/gui_w32.c @ 21351:a4f213630151 v8.2.1226
patch 8.2.1226: MS-Windows: windows positioning wrong depending on taskbar
Commit: https://github.com/vim/vim/commit/98af99f2d79b310e81003f5e27862a7b522d8372
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Jul 16 22:30:31 2020 +0200
patch 8.2.1226: MS-Windows: windows positioning wrong depending on taskbar
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)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 16 Jul 2020 22:45:04 +0200 |
parents | 8590a462ad46 |
children | fcccc29bd386 |
comparison
equal
deleted
inserted
replaced
21350:e5e32c9f711f | 21351:a4f213630151 |
---|---|
1427 } | 1427 } |
1428 | 1428 |
1429 /* | 1429 /* |
1430 * Find the scrollbar with the given hwnd. | 1430 * Find the scrollbar with the given hwnd. |
1431 */ | 1431 */ |
1432 static scrollbar_T * | 1432 static scrollbar_T * |
1433 gui_mswin_find_scrollbar(HWND hwnd) | 1433 gui_mswin_find_scrollbar(HWND hwnd) |
1434 { | 1434 { |
1435 win_T *wp; | 1435 win_T *wp; |
1436 | 1436 |
1437 if (gui.bottom_sbar.id == hwnd) | 1437 if (gui.bottom_sbar.id == hwnd) |
5393 int base_width UNUSED, | 5393 int base_width UNUSED, |
5394 int base_height UNUSED, | 5394 int base_height UNUSED, |
5395 int direction) | 5395 int direction) |
5396 { | 5396 { |
5397 RECT workarea_rect; | 5397 RECT workarea_rect; |
5398 RECT window_rect; | |
5398 int win_width, win_height; | 5399 int win_width, win_height; |
5399 WINDOWPLACEMENT wndpl; | |
5400 | 5400 |
5401 // Try to keep window completely on screen. | 5401 // Try to keep window completely on screen. |
5402 // Get position of the screen work area. This is the part that is not | 5402 // Get position of the screen work area. This is the part that is not |
5403 // used by the taskbar or appbars. | 5403 // used by the taskbar or appbars. |
5404 get_work_area(&workarea_rect); | 5404 get_work_area(&workarea_rect); |
5405 | 5405 |
5406 // Get current position of our window. Note that the .left and .top are | |
5407 // relative to the work area. | |
5408 wndpl.length = sizeof(WINDOWPLACEMENT); | |
5409 GetWindowPlacement(s_hwnd, &wndpl); | |
5410 | |
5411 // Resizing a maximized window looks very strange, unzoom it first. | 5406 // Resizing a maximized window looks very strange, unzoom it first. |
5412 // But don't do it when still starting up, it may have been requested in | 5407 // But don't do it when still starting up, it may have been requested in |
5413 // the shortcut. | 5408 // the shortcut. |
5414 if (wndpl.showCmd == SW_SHOWMAXIMIZED && starting == 0) | 5409 if (IsZoomed(s_hwnd) && starting == 0) |
5415 { | |
5416 ShowWindow(s_hwnd, SW_SHOWNORMAL); | 5410 ShowWindow(s_hwnd, SW_SHOWNORMAL); |
5417 // Need to get the settings of the normal window. | 5411 |
5418 GetWindowPlacement(s_hwnd, &wndpl); | 5412 GetWindowRect(s_hwnd, &window_rect); |
5419 } | |
5420 | 5413 |
5421 // compute the size of the outside of the window | 5414 // compute the size of the outside of the window |
5422 win_width = width + (GetSystemMetrics(SM_CXFRAME) + | 5415 win_width = width + (GetSystemMetrics(SM_CXFRAME) + |
5423 GetSystemMetrics(SM_CXPADDEDBORDER)) * 2; | 5416 GetSystemMetrics(SM_CXPADDEDBORDER)) * 2; |
5424 win_height = height + (GetSystemMetrics(SM_CYFRAME) + | 5417 win_height = height + (GetSystemMetrics(SM_CYFRAME) + |
5430 ; | 5423 ; |
5431 | 5424 |
5432 // The following should take care of keeping Vim on the same monitor, no | 5425 // The following should take care of keeping Vim on the same monitor, no |
5433 // matter if the secondary monitor is left or right of the primary | 5426 // matter if the secondary monitor is left or right of the primary |
5434 // monitor. | 5427 // monitor. |
5435 wndpl.rcNormalPosition.right = wndpl.rcNormalPosition.left + win_width; | 5428 window_rect.right = window_rect.left + win_width; |
5436 wndpl.rcNormalPosition.bottom = wndpl.rcNormalPosition.top + win_height; | 5429 window_rect.bottom = window_rect.top + win_height; |
5437 | 5430 |
5438 // If the window is going off the screen, move it on to the screen. | 5431 // If the window is going off the screen, move it on to the screen. |
5439 if ((direction & RESIZE_HOR) | 5432 if ((direction & RESIZE_HOR) && window_rect.right > workarea_rect.right) |
5440 && wndpl.rcNormalPosition.right > workarea_rect.right) | 5433 OffsetRect(&window_rect, workarea_rect.right - window_rect.right, 0); |
5441 OffsetRect(&wndpl.rcNormalPosition, | 5434 |
5442 workarea_rect.right - wndpl.rcNormalPosition.right, 0); | 5435 if ((direction & RESIZE_HOR) && window_rect.left < workarea_rect.left) |
5443 | 5436 OffsetRect(&window_rect, workarea_rect.left - window_rect.left, 0); |
5444 if ((direction & RESIZE_HOR) | 5437 |
5445 && wndpl.rcNormalPosition.left < workarea_rect.left) | 5438 if ((direction & RESIZE_VERT) && window_rect.bottom > workarea_rect.bottom) |
5446 OffsetRect(&wndpl.rcNormalPosition, | 5439 OffsetRect(&window_rect, 0, workarea_rect.bottom - window_rect.bottom); |
5447 workarea_rect.left - wndpl.rcNormalPosition.left, 0); | 5440 |
5448 | 5441 if ((direction & RESIZE_VERT) && window_rect.top < workarea_rect.top) |
5449 if ((direction & RESIZE_VERT) | 5442 OffsetRect(&window_rect, 0, workarea_rect.top - window_rect.top); |
5450 && wndpl.rcNormalPosition.bottom > workarea_rect.bottom) | 5443 |
5451 OffsetRect(&wndpl.rcNormalPosition, | 5444 MoveWindow(s_hwnd, window_rect.left, window_rect.top, |
5452 0, workarea_rect.bottom - wndpl.rcNormalPosition.bottom); | 5445 win_width, win_height, TRUE); |
5453 | |
5454 if ((direction & RESIZE_VERT) | |
5455 && wndpl.rcNormalPosition.top < workarea_rect.top) | |
5456 OffsetRect(&wndpl.rcNormalPosition, | |
5457 0, workarea_rect.top - wndpl.rcNormalPosition.top); | |
5458 | |
5459 // set window position - we should use SetWindowPlacement rather than | |
5460 // SetWindowPos as the MSDN docs say the coord systems returned by | |
5461 // these two are not compatible. | |
5462 SetWindowPlacement(s_hwnd, &wndpl); | |
5463 | 5446 |
5464 SetActiveWindow(s_hwnd); | 5447 SetActiveWindow(s_hwnd); |
5465 SetFocus(s_hwnd); | 5448 SetFocus(s_hwnd); |
5466 | 5449 |
5467 #ifdef FEAT_MENU | 5450 #ifdef FEAT_MENU |