From 48fb2f721fabe3fb2a2d306fafa2de4f7dbec9d9 Mon Sep 17 00:00:00 2001 From: rdb Date: Thu, 11 Mar 2021 22:19:41 +0100 Subject: [PATCH] windisplay: Fix parented child window being offset This would happen if the undecorated flag is not set; it would receive an additional offset equal to the size of the window decoration. Fixes regression presumably caused by a968caf1d207023b2820cf4c31ae3e7324ffb218 --- panda/src/windisplay/winGraphicsWindow.cxx | 36 ++++++++++++---------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/panda/src/windisplay/winGraphicsWindow.cxx b/panda/src/windisplay/winGraphicsWindow.cxx index 372cfafede..3137045871 100644 --- a/panda/src/windisplay/winGraphicsWindow.cxx +++ b/panda/src/windisplay/winGraphicsWindow.cxx @@ -298,26 +298,28 @@ set_properties_now(WindowProperties &properties) { // When switching undecorated mode, Windows will keep the window at the // current outer size, whereas we want to keep it with the configured // inner size. Store the current size and origin. - LPoint2i top_left = _properties.get_origin(); - LPoint2i bottom_right = top_left + _properties.get_size(); + if (_parent_window_handle == nullptr) { + LPoint2i top_left = _properties.get_origin(); + LPoint2i bottom_right = top_left + _properties.get_size(); - DWORD window_style = make_style(_properties); - SetWindowLong(_hWnd, GWL_STYLE, window_style); + DWORD window_style = make_style(_properties); + SetWindowLong(_hWnd, GWL_STYLE, window_style); - // Now calculate the proper size and origin with the new window style. - RECT view_rect; - SetRect(&view_rect, top_left[0], top_left[1], - bottom_right[0], bottom_right[1]); - WINDOWINFO wi; - GetWindowInfo(_hWnd, &wi); - AdjustWindowRectEx(&view_rect, wi.dwStyle, FALSE, wi.dwExStyle); + // Now calculate the proper size and origin with the new window style. + RECT view_rect; + SetRect(&view_rect, top_left[0], top_left[1], + bottom_right[0], bottom_right[1]); + WINDOWINFO wi; + GetWindowInfo(_hWnd, &wi); + AdjustWindowRectEx(&view_rect, wi.dwStyle, FALSE, wi.dwExStyle); - // We need to call this to ensure that the style change takes effect. - SetWindowPos(_hWnd, HWND_NOTOPMOST, view_rect.left, view_rect.top, - view_rect.right - view_rect.left, - view_rect.bottom - view_rect.top, - SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED | - SWP_NOSENDCHANGING | SWP_SHOWWINDOW); + // We need to call this to ensure that the style change takes effect. + SetWindowPos(_hWnd, HWND_NOTOPMOST, view_rect.left, view_rect.top, + view_rect.right - view_rect.left, + view_rect.bottom - view_rect.top, + SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED | + SWP_NOSENDCHANGING | SWP_SHOWWINDOW); + } } if (properties.has_title()) {