From 2da25c0a29aa574a2d1ea752c6ef844758de5404 Mon Sep 17 00:00:00 2001 From: driver1998 Date: Wed, 20 Mar 2019 07:39:04 +0800 Subject: [PATCH] Attempt to fix the UI gliches on Windows Clang build Where the main window keeps getting smaller while moving around, and the mouse can get out of the guest when grabbed. --- src/win/win_ui.c | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/src/win/win_ui.c b/src/win/win_ui.c index fa06e4c26..190535aac 100644 --- a/src/win/win_ui.c +++ b/src/win/win_ui.c @@ -8,7 +8,7 @@ * * user Interface module for WinAPI on Windows. * - * Version: @(#)win_ui.c 1.0.38 2018/11/18 + * Version: @(#)win_ui.c 1.0.39 2019/3/20 * * Authors: Sarah Walker, * Miran Grca, @@ -17,6 +17,7 @@ * Copyright 2008-2018 Sarah Walker. * Copyright 2016-2018 Miran Grca. * Copyright 2017,2018 Fred N. van Kempen. + * Copyright 2019 GH Cao. */ #define UNICODE #include @@ -50,6 +51,7 @@ HWND hwndMain, /* application main window */ HMENU menuMain; /* application main menu */ HICON hIcon[256]; /* icon data loaded from resources */ RECT oldclip; /* mouse rect */ +int sbar_height = 23; /* statusbar height */ int infocus = 1; int rctrl_is_lalt = 0; int user_resize = 0; @@ -273,9 +275,10 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) HMENU hmenu; int sb_borders[3]; - RECT rect; + RECT rect, rc; int temp_x, temp_y; + int non_client_width, non_client_height; switch (message) { case WM_CREATE: @@ -337,7 +340,6 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) case IDM_VID_RESIZE: vid_resize = !vid_resize; CheckMenuItem(hmenu, IDM_VID_RESIZE, (vid_resize)? MF_CHECKED : MF_UNCHECKED); - GetWindowRect(hwnd, &rect); if (vid_resize) SetWindowLongPtr(hwnd, GWL_STYLE, (WS_OVERLAPPEDWINDOW) | WS_VISIBLE); @@ -346,10 +348,15 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) SendMessage(hwndSBAR, SB_GETBORDERS, 0, (LPARAM) sb_borders); + GetWindowRect(hwnd, &rect); + GetClientRect(hwnd, &rc); + non_client_width = (rect.right-rect.left) - (rc.right-rc.left); + non_client_height = (rect.bottom-rect.top) - (rc.bottom-rc.top); + /* Main Window. */ - MoveWindow(hwnd, rect.left, rect.top, - unscaled_size_x + (GetSystemMetrics(vid_resize ? SM_CXSIZEFRAME : SM_CXFIXEDFRAME) * 2), -unscaled_size_y + (GetSystemMetrics(SM_CYEDGE) * 2) + (GetSystemMetrics(vid_resize ? SM_CYSIZEFRAME : SM_CYFIXEDFRAME) * 2) + GetSystemMetrics(SM_CYMENUSIZE) + GetSystemMetrics(SM_CYCAPTION) + 17 + sb_borders[1] + 1, + MoveWindow(hwnd, rect.left, rect.top, + unscaled_size_x + non_client_width, + unscaled_size_y + non_client_height + sbar_height, TRUE); /* Render window. */ @@ -556,7 +563,7 @@ unscaled_size_y + (GetSystemMetrics(SM_CYEDGE) * 2) + (GetSystemMetrics(vid_resi SendMessage(hwndSBAR, SB_GETBORDERS, 0, (LPARAM) sb_borders); temp_x = (lParam & 0xFFFF); - temp_y = (lParam >> 16) - (21 + sb_borders[1]); + temp_y = (lParam >> 16) - sbar_height; if (temp_x < 1) temp_x = 1; if (temp_y < 1) @@ -728,6 +735,7 @@ ui_init(int nCmdShow) MSG messages; /* received-messages buffer */ HWND hwnd = NULL; /* handle for our window */ HACCEL haccel; /* handle to accelerator table */ + RECT sbar_rect; /* RECT of the status bar */ int bRet; if (settings_only) { @@ -838,6 +846,12 @@ ui_init(int nCmdShow) /* Create the status bar window. */ StatusBarCreate(hwndMain, IDC_STATUS, hinstance); + /* Get the actual height of the statusbar, + * since that is not something we can change. + */ + GetWindowRect(hwndSBAR, &sbar_rect); + sbar_height = sbar_rect.bottom - sbar_rect.top; + /* * Before we can create the Render window, we first have * to prepare some other things that it depends on. @@ -1002,7 +1016,9 @@ void plat_resize(int x, int y) { int sb_borders[3]; - RECT r; + RECT r, rc; + int non_client_width; + int non_client_height; /* First, see if we should resize the UI window. */ if (!vid_resize) { @@ -1011,11 +1027,14 @@ plat_resize(int x, int y) SendMessage(hwndSBAR, SB_GETBORDERS, 0, (LPARAM) sb_borders); GetWindowRect(hwndMain, &r); + GetClientRect(hwndMain, &rc); + non_client_width = (r.right-r.left) - (rc.right-rc.left); + non_client_height = (r.bottom-r.top) - (rc.bottom-rc.top); + MoveWindow(hwndMain, r.left, r.top, - x + (GetSystemMetrics(vid_resize ? SM_CXSIZEFRAME : SM_CXFIXEDFRAME) * 2), - y + (GetSystemMetrics(SM_CYEDGE) * 2) + (GetSystemMetrics(vid_resize ? SM_CYSIZEFRAME : SM_CYFIXEDFRAME) * 2) + GetSystemMetrics(SM_CYMENUSIZE) + GetSystemMetrics(SM_CYCAPTION) + 17 + sb_borders[1] + 1, + x + non_client_width, + y + non_client_height + sbar_height, TRUE); - GetWindowRect(hwndMain, &r); MoveWindow(hwndRender, 0, 0, x, y, TRUE); GetWindowRect(hwndRender, &r);