MonitorFromWindow() may return a different monitor if switching to a smaller display mode.
Fix Railroad Tycoon II crashes.
Signed-off-by: Zhiyi Zhang zzhang@codeweavers.com --- dlls/ddraw/ddraw.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/dlls/ddraw/ddraw.c b/dlls/ddraw/ddraw.c index 6f640ef422a..6256c66e8a6 100644 --- a/dlls/ddraw/ddraw.c +++ b/dlls/ddraw/ddraw.c @@ -4926,9 +4926,7 @@ static void CDECL device_parent_wined3d_device_created(struct wined3d_device_par static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent) { struct ddraw *ddraw = ddraw_from_device_parent(device_parent); - MONITORINFO monitor_info; - HMONITOR monitor; - RECT *r; + struct wined3d_output_desc output_desc;
TRACE("device_parent %p.\n", device_parent);
@@ -4938,19 +4936,20 @@ static void CDECL device_parent_mode_changed(struct wined3d_device_parent *devic return; }
- monitor = MonitorFromWindow(ddraw->swapchain_window, MONITOR_DEFAULTTOPRIMARY); - monitor_info.cbSize = sizeof(monitor_info); - if (!GetMonitorInfoW(monitor, &monitor_info)) + if (FAILED(wined3d_output_get_desc(ddraw->wined3d_output, &output_desc))) { - ERR("Failed to get monitor info.\n"); + ERR("Failed to get output description.\n"); return; }
- r = &monitor_info.rcMonitor; - TRACE("Resizing window %p to %s.\n", ddraw->swapchain_window, wine_dbgstr_rect(r)); + TRACE("Resizing window %p to %s.\n", ddraw->swapchain_window, + wine_dbgstr_rect(&output_desc.desktop_rect));
- if (!SetWindowPos(ddraw->swapchain_window, HWND_TOP, r->left, r->top, - r->right - r->left, r->bottom - r->top, SWP_SHOWWINDOW | SWP_NOACTIVATE)) + if (!SetWindowPos(ddraw->swapchain_window, HWND_TOP, output_desc.desktop_rect.left, + output_desc.desktop_rect.top, + output_desc.desktop_rect.right - output_desc.desktop_rect.left, + output_desc.desktop_rect.bottom - output_desc.desktop_rect.top, + SWP_SHOWWINDOW | SWP_NOACTIVATE)) ERR("Failed to resize window.\n");
InterlockedCompareExchange(&ddraw->device_state, DDRAW_DEVICE_STATE_NOT_RESTORED, DDRAW_DEVICE_STATE_OK);
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=72406
Your paranoid android.
=== debiant (64 bit WoW report) ===
ddraw: ddraw2.c:14449: Test failed: Expect window rect (0,0)-(1024,768), got (0,0)-(1024,739). ddraw2.c:14456: Test failed: Expect window rect (0,0)-(1024,768), got (0,0)-(1024,739).
On Thu, 28 May 2020 at 15:21, Zhiyi Zhang zzhang@codeweavers.com wrote:
- r = &monitor_info.rcMonitor;
- TRACE("Resizing window %p to %s.\n", ddraw->swapchain_window, wine_dbgstr_rect(r));
- TRACE("Resizing window %p to %s.\n", ddraw->swapchain_window,
wine_dbgstr_rect(&output_desc.desktop_rect));
- if (!SetWindowPos(ddraw->swapchain_window, HWND_TOP, r->left, r->top,
r->right - r->left, r->bottom - r->top, SWP_SHOWWINDOW | SWP_NOACTIVATE))
- if (!SetWindowPos(ddraw->swapchain_window, HWND_TOP, output_desc.desktop_rect.left,
output_desc.desktop_rect.top,
output_desc.desktop_rect.right - output_desc.desktop_rect.left,
output_desc.desktop_rect.bottom - output_desc.desktop_rect.top,
SWP_SHOWWINDOW | SWP_NOACTIVATE)) ERR("Failed to resize window.\n");
I'm not sure that's an improvement. Why not simply "r = &output_desc.desktop_rect;"?