From: Zhiyi Zhang <zzhang@codeweavers.com> set_foreground_window() and NtUserSetActiveWindow() send messages to applications and might cause the window rect to change. Thus, the value in window_rect can be stale and we should wait for the next WM_WINE_WINDOW_STATE_CHANGED message to get the latest window_rect. A WM_WINE_WINDOW_STATE_CHANGED is posted in case there is no more WM_WINE_WINDOW_STATE_CHANGED in the message queue. --- dlls/win32u/message.c | 17 +++++++++++++++-- dlls/winex11.drv/window.c | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/dlls/win32u/message.c b/dlls/win32u/message.c index 02f94837cb6..95494df6905 100644 --- a/dlls/win32u/message.c +++ b/dlls/win32u/message.c @@ -2230,14 +2230,27 @@ static LRESULT handle_internal_message( HWND hwnd, UINT msg, WPARAM wparam, LPAR if (!user_driver->pGetWindowStateUpdates( hwnd, &state_cmd, &swp_flags, &window_rect, &foreground )) return 0; window_rect = map_rect_raw_to_virt( window_rect, get_thread_dpi() ); - if (foreground) set_foreground_window( foreground, FALSE, TRUE ); + if (foreground) + { + set_foreground_window( foreground, FALSE, TRUE ); + /* set_foreground_window() may have changed window_rect, check again later */ + NtUserPostMessage( hwnd, WM_WINE_WINDOW_STATE_CHANGED, 0, 0 ); + return 0; + } + switch (LOWORD(state_cmd)) { case SC_RESTORE: { WND *win; - if (HIWORD(state_cmd)) NtUserSetActiveWindow( hwnd ); + if (HIWORD(state_cmd)) + { + NtUserSetActiveWindow( hwnd ); + /* NtUserSetActiveWindow() may have changed window_rect, check again later */ + NtUserPostMessage( hwnd, WM_WINE_WINDOW_STATE_CHANGED, 0, 0 ); + return 0; + } /* make the win32 window restore to the current host window config */ win = get_win_ptr( hwnd ); diff --git a/dlls/winex11.drv/window.c b/dlls/winex11.drv/window.c index d2d53a40be3..7714fe6bc2b 100644 --- a/dlls/winex11.drv/window.c +++ b/dlls/winex11.drv/window.c @@ -1700,7 +1700,7 @@ static UINT window_update_client_state( struct x11drv_win_data *data ) } else if (old_style & (WS_MINIMIZE | WS_MAXIMIZE)) { - BOOL activate = (old_style & (WS_MINIMIZE | WS_VISIBLE)) == (WS_MINIMIZE | WS_VISIBLE); + BOOL activate = ((old_style & (WS_MINIMIZE | WS_VISIBLE)) == (WS_MINIMIZE | WS_VISIBLE)) && get_active_window() != data->hwnd; TRACE( "restoring win %p/%lx\n", data->hwnd, data->whole_window ); return MAKELONG(SC_RESTORE, activate); } -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10725