From 46d30aa970bc837a8c71f40235008bae1bb434c2 Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Sun, 4 Jun 2023 20:38:16 +0200 Subject: [PATCH] Fix: [Win32] position window in center of workspace of primary display (#10942) --- src/video/win32_v.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp index b6f278c8eb..2fb04cf2d2 100644 --- a/src/video/win32_v.cpp +++ b/src/video/win32_v.cpp @@ -212,8 +212,13 @@ bool VideoDriver_Win32Base::MakeWindow(bool full_screen, bool resize) if (this->main_wnd != nullptr) { if (!_window_maximize && resize) SetWindowPos(this->main_wnd, 0, 0, 0, w, h, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOMOVE); } else { - int x = (GetSystemMetrics(SM_CXSCREEN) - w) / 2; - int y = (GetSystemMetrics(SM_CYSCREEN) - h) / 2; + /* Center on the workspace of the primary display. */ + MONITORINFO mi; + mi.cbSize = sizeof(mi); + GetMonitorInfo(MonitorFromWindow(0, MONITOR_DEFAULTTOPRIMARY), &mi); + + int x = (mi.rcWork.right - mi.rcWork.left - w) / 2; + int y = (mi.rcWork.bottom - mi.rcWork.top - h) / 2; char window_title[64]; seprintf(window_title, lastof(window_title), "OpenTTD %s", _openttd_revision);