Skip to content

Commit 87f3d20

Browse files
committed
patch 8.0.0113
Problem: MS-Windows: message box to prompt for saving changes may appear on the wrong monitor. Solution: Adjust the CenterWindow function. (Ken Takata)
1 parent eca626f commit 87f3d20

2 files changed

Lines changed: 36 additions & 22 deletions

File tree

src/gui_w32.c

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2297,52 +2297,64 @@ GetTextWidthEnc(HDC hdc, char_u *str, int len)
22972297
# define GetTextWidthEnc(h, s, l) GetTextWidth((h), (s), (l))
22982298
#endif
22992299

2300+
static void get_work_area(RECT *spi_rect);
2301+
23002302
/*
23012303
* A quick little routine that will center one window over another, handy for
2302-
* dialog boxes. Taken from the Win32SDK samples.
2304+
* dialog boxes. Taken from the Win32SDK samples and modified for multiple
2305+
* monitors.
23032306
*/
23042307
static BOOL
23052308
CenterWindow(
23062309
HWND hwndChild,
23072310
HWND hwndParent)
23082311
{
2309-
RECT rChild, rParent;
2310-
int wChild, hChild, wParent, hParent;
2311-
int wScreen, hScreen, xNew, yNew;
2312-
HDC hdc;
2312+
HMONITOR mon;
2313+
MONITORINFO moninfo;
2314+
RECT rChild, rParent, rScreen;
2315+
int wChild, hChild, wParent, hParent;
2316+
int xNew, yNew;
2317+
HDC hdc;
23132318

23142319
GetWindowRect(hwndChild, &rChild);
23152320
wChild = rChild.right - rChild.left;
23162321
hChild = rChild.bottom - rChild.top;
23172322

23182323
/* If Vim is minimized put the window in the middle of the screen. */
23192324
if (hwndParent == NULL || IsMinimized(hwndParent))
2320-
SystemParametersInfo(SPI_GETWORKAREA, 0, &rParent, 0);
2325+
get_work_area(&rParent);
23212326
else
23222327
GetWindowRect(hwndParent, &rParent);
23232328
wParent = rParent.right - rParent.left;
23242329
hParent = rParent.bottom - rParent.top;
23252330

2326-
hdc = GetDC(hwndChild);
2327-
wScreen = GetDeviceCaps (hdc, HORZRES);
2328-
hScreen = GetDeviceCaps (hdc, VERTRES);
2329-
ReleaseDC(hwndChild, hdc);
2330-
2331-
xNew = rParent.left + ((wParent - wChild) /2);
2332-
if (xNew < 0)
2331+
moninfo.cbSize = sizeof(MONITORINFO);
2332+
mon = MonitorFromWindow(hwndChild, MONITOR_DEFAULTTOPRIMARY);
2333+
if (mon != NULL && GetMonitorInfo(mon, &moninfo))
23332334
{
2334-
xNew = 0;
2335+
rScreen = moninfo.rcWork;
23352336
}
2336-
else if ((xNew+wChild) > wScreen)
2337+
else
23372338
{
2338-
xNew = wScreen - wChild;
2339+
hdc = GetDC(hwndChild);
2340+
rScreen.left = 0;
2341+
rScreen.top = 0;
2342+
rScreen.right = GetDeviceCaps(hdc, HORZRES);
2343+
rScreen.bottom = GetDeviceCaps(hdc, VERTRES);
2344+
ReleaseDC(hwndChild, hdc);
23392345
}
23402346

2341-
yNew = rParent.top + ((hParent - hChild) /2);
2342-
if (yNew < 0)
2343-
yNew = 0;
2344-
else if ((yNew+hChild) > hScreen)
2345-
yNew = hScreen - hChild;
2347+
xNew = rParent.left + ((wParent - wChild) / 2);
2348+
if (xNew < rScreen.left)
2349+
xNew = rScreen.left;
2350+
else if ((xNew + wChild) > rScreen.right)
2351+
xNew = rScreen.right - wChild;
2352+
2353+
yNew = rParent.top + ((hParent - hChild) / 2);
2354+
if (yNew < rScreen.top)
2355+
yNew = rScreen.top;
2356+
else if ((yNew + hChild) > rScreen.bottom)
2357+
yNew = rScreen.bottom - hChild;
23462358

23472359
return SetWindowPos(hwndChild, NULL, xNew, yNew, 0, 0,
23482360
SWP_NOSIZE | SWP_NOZORDER);
@@ -5559,7 +5571,7 @@ get_work_area(RECT *spi_rect)
55595571
MONITORINFO moninfo;
55605572

55615573
/* work out which monitor the window is on, and get *it's* work area */
5562-
mon = MonitorFromWindow(s_hwnd, 1 /*MONITOR_DEFAULTTOPRIMARY*/);
5574+
mon = MonitorFromWindow(s_hwnd, MONITOR_DEFAULTTOPRIMARY);
55635575
if (mon != NULL)
55645576
{
55655577
moninfo.cbSize = sizeof(MONITORINFO);

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
113,
767769
/**/
768770
112,
769771
/**/

0 commit comments

Comments
 (0)