From 023eb30b3efa305280e05686a34a0d0eb1832fca Mon Sep 17 00:00:00 2001 From: The Dax Date: Wed, 16 Jul 2014 23:50:46 -0400 Subject: [PATCH 1/3] Win32: Fix a bug in fullscreen. Consolidate the fullscreen code into one function. 99% of the code is the same anyway. --- Windows/WindowsHost.cpp | 5 +-- Windows/WndMainWindow.cpp | 78 +++++++++++++-------------------------- Windows/WndMainWindow.h | 3 +- 3 files changed, 28 insertions(+), 58 deletions(-) diff --git a/Windows/WindowsHost.cpp b/Windows/WindowsHost.cpp index 4fb759a7e1..e023bd69e3 100644 --- a/Windows/WindowsHost.cpp +++ b/Windows/WindowsHost.cpp @@ -336,10 +336,7 @@ bool WindowsHost::CreateDesktopShortcut(std::string argumentPath, std::string ga } void WindowsHost::GoFullscreen(bool viewFullscreen) { - if (viewFullscreen) - MainWindow::SwitchToFullscreen(mainWindow_); - else - MainWindow::SwitchToWindowed(mainWindow_); + MainWindow::ToggleFullscreen(mainWindow_, viewFullscreen); } void WindowsHost::ToggleDebugConsoleVisibility() { diff --git a/Windows/WndMainWindow.cpp b/Windows/WndMainWindow.cpp index 3c5372f30b..f988f1f069 100644 --- a/Windows/WndMainWindow.cpp +++ b/Windows/WndMainWindow.cpp @@ -309,24 +309,39 @@ namespace MainWindow } } - void SwitchToWindowed(HWND hWnd) { + void ToggleFullscreen(HWND hWnd, bool goingFullscreen = false) { // Make sure no rendering is happening during the switch. Core_NotifyWindowHidden(true); g_inModeSwitch = true; // Make sure WM_SIZE doesn't call Core_NotifyWindowHidden(false)... - // Put caption and border styles back. - DWORD dwOldStyle = ::GetWindowLong(hWnd, GWL_STYLE); - DWORD dwNewStyle = dwOldStyle | WS_CAPTION | WS_THICKFRAME | WS_SYSMENU; + DWORD dwOldStyle; + DWORD dwNewStyle; + + if (!goingFullscreen) { + // Put caption and border styles back. + dwOldStyle = ::GetWindowLong(hWnd, GWL_STYLE); + dwNewStyle = dwOldStyle | WS_CAPTION | WS_THICKFRAME | WS_SYSMENU; + + // Put back the menu bar. + ::SetMenu(hWnd, menu); + } else { + // Remember the normal window rectangle. + ::GetWindowRect(hWnd, &g_normalRC); + + // Remove caption and border styles. + dwOldStyle = ::GetWindowLong(hWnd, GWL_STYLE); + dwNewStyle = dwOldStyle & ~(WS_CAPTION | WS_THICKFRAME | WS_SYSMENU); + } + ::SetWindowLong(hWnd, GWL_STYLE, dwNewStyle); - // Put back the menu bar. - ::SetMenu(hWnd, menu); + // Remove the menu bar. + ::SetMenu(hWnd, g_Config.bFullScreen ? NULL : menu); // Resize to normal view. - ShowWindow(hwndMain, SW_RESTORE); + ShowWindow(hwndMain, g_Config.bFullScreen ? SW_MAXIMIZE : SW_RESTORE); - // Reset full screen indicator. - g_Config.bFullScreen = false; + g_Config.bFullScreen = goingFullscreen; CorrectCursor(); bool showOSM = (g_Config.iInternalResolution == RESOLUTION_AUTO); @@ -341,41 +356,6 @@ namespace MainWindow Core_NotifyWindowHidden(false); } - void SwitchToFullscreen(HWND hWnd) { - // Make sure no rendering is happening during the switch. - Core_NotifyWindowHidden(true); - g_inModeSwitch = true; // Make sure WM_SIZE doesn't call Core_NotifyWindowHidden(false)... - - // Remember the normal window rectangle. - ::GetWindowRect(hWnd, &g_normalRC); - - // Remove caption and border styles. - DWORD dwOldStyle = ::GetWindowLong(hWnd, GWL_STYLE); - DWORD dwNewStyle = dwOldStyle & ~(WS_CAPTION | WS_THICKFRAME | WS_SYSMENU); - ::SetWindowLong(hWnd, GWL_STYLE, dwNewStyle); - - // Remove the menu bar. - ::SetMenu(hWnd, NULL); - - // Resize to full screen view. - ShowWindow(hwndMain, SW_MAXIMIZE); - - // Set full screen indicator. - g_Config.bFullScreen = true; - CorrectCursor(); - - bool showOSM = (g_Config.iInternalResolution == RESOLUTION_AUTO); - ResizeDisplay(false); - if (showOSM) { - ShowScreenResolution(); - } - - ShowOwnedPopups(hwndMain, FALSE); - - g_inModeSwitch = false; - Core_NotifyWindowHidden(false); - } - RECT DetermineWindowRectangle() { RECT rc; @@ -819,10 +799,7 @@ namespace MainWindow hideCursor = true; SetTimer(hwndMain, TIMER_CURSORUPDATE, CURSORUPDATE_INTERVAL_MS, 0); - if (g_Config.bFullScreen) - SwitchToFullscreen(hwndMain); - - ShowWindow(hwndMain, nCmdShow); + ToggleFullscreen(hwndMain, g_Config.bFullScreen); W32Util::MakeTopMost(hwndMain, g_Config.bTopMost); @@ -1506,10 +1483,7 @@ namespace MainWindow case ID_OPTIONS_FULLSCREEN: g_Config.bFullScreen = !g_Config.bFullScreen; - if (g_Config.bFullScreen) - SwitchToFullscreen(hWnd); - else - SwitchToWindowed(hWnd); + ToggleFullscreen(hwndMain, g_Config.bFullScreen); break; diff --git a/Windows/WndMainWindow.h b/Windows/WndMainWindow.h index af47c050f5..1f885652e0 100644 --- a/Windows/WndMainWindow.h +++ b/Windows/WndMainWindow.h @@ -63,8 +63,7 @@ namespace MainWindow HWND GetDisplayHWND(); void BrowseAndBoot(std::string defaultPath, bool browseDirectory = false); void SaveStateActionFinished(bool result, void *userdata); - void SwitchToFullscreen(HWND hWnd); - void SwitchToWindowed(HWND hWnd); + void ToggleFullscreen(HWND hWnd, bool goingFullscreen); void ToggleDebugConsoleVisibility(); void TranslateMenus(); void setTexScalingMultiplier(int level); From 61944e2c904ae129838b7f3d0823c5e204e7c2ed Mon Sep 17 00:00:00 2001 From: The Dax Date: Thu, 17 Jul 2014 00:03:41 -0400 Subject: [PATCH 2/3] Typo fix. Should probably be using goingFullscreen too, just for consistency. --- Windows/WndMainWindow.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Windows/WndMainWindow.cpp b/Windows/WndMainWindow.cpp index f988f1f069..43d44afbdc 100644 --- a/Windows/WndMainWindow.cpp +++ b/Windows/WndMainWindow.cpp @@ -336,10 +336,10 @@ namespace MainWindow ::SetWindowLong(hWnd, GWL_STYLE, dwNewStyle); // Remove the menu bar. - ::SetMenu(hWnd, g_Config.bFullScreen ? NULL : menu); + ::SetMenu(hWnd, goingFullscreen ? NULL : menu); // Resize to normal view. - ShowWindow(hwndMain, g_Config.bFullScreen ? SW_MAXIMIZE : SW_RESTORE); + ShowWindow(hwndMain, goingFullscreen ? SW_MAXIMIZE : SW_RESTORE); g_Config.bFullScreen = goingFullscreen; CorrectCursor(); @@ -349,7 +349,7 @@ namespace MainWindow if (showOSM) { ShowScreenResolution(); } - ShowOwnedPopups(hwndMain, TRUE); + ShowOwnedPopups(hwndMain, goingFullscreen ? FALSE : TRUE); W32Util::MakeTopMost(hwndMain, g_Config.bTopMost); g_inModeSwitch = false; From 0f593c7a0f1d63abe3b0483e3a65e07203434811 Mon Sep 17 00:00:00 2001 From: The Dax Date: Thu, 17 Jul 2014 00:06:52 -0400 Subject: [PATCH 3/3] Remove unused parameter. --- Windows/WndMainWindow.cpp | 4 ++-- Windows/WndMainWindow.h | 2 +- Windows/main.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Windows/WndMainWindow.cpp b/Windows/WndMainWindow.cpp index 43d44afbdc..5ca92a273f 100644 --- a/Windows/WndMainWindow.cpp +++ b/Windows/WndMainWindow.cpp @@ -338,7 +338,7 @@ namespace MainWindow // Remove the menu bar. ::SetMenu(hWnd, goingFullscreen ? NULL : menu); - // Resize to normal view. + // Resize to the appropriate view. ShowWindow(hwndMain, goingFullscreen ? SW_MAXIMIZE : SW_RESTORE); g_Config.bFullScreen = goingFullscreen; @@ -757,7 +757,7 @@ namespace MainWindow windowTitle = title; } - BOOL Show(HINSTANCE hInstance, int nCmdShow) { + BOOL Show(HINSTANCE hInstance) { hInst = hInstance; // Store instance handle in our global variable. RECT rc = DetermineWindowRectangle(); diff --git a/Windows/WndMainWindow.h b/Windows/WndMainWindow.h index 1f885652e0..a00d8b7b3d 100644 --- a/Windows/WndMainWindow.h +++ b/Windows/WndMainWindow.h @@ -49,7 +49,7 @@ namespace MainWindow }; void Init(HINSTANCE hInstance); - BOOL Show(HINSTANCE hInstance, int nCmdShow); + BOOL Show(HINSTANCE hInstance); void CreateDebugWindows(); void DestroyDebugWindows(); void Close(); diff --git a/Windows/main.cpp b/Windows/main.cpp index b670b4a564..6f1e88d001 100644 --- a/Windows/main.cpp +++ b/Windows/main.cpp @@ -374,7 +374,7 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin g_hPopupMenus = LoadMenu(_hInstance, (LPCWSTR)IDR_POPUPMENUS); - MainWindow::Show(_hInstance, iCmdShow); + MainWindow::Show(_hInstance); HWND hwndMain = MainWindow::GetHWND(); HWND hwndDisplay = MainWindow::GetDisplayHWND();