From 4f52fab65ac9d0625b1ff9f7cfe2dd72c36d2863 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 11 Nov 2005 21:22:18 +0000 Subject: [PATCH] In OpenGL (not D3D), it's our job to unset and reset the full-screen video mode when we lose focus. --- stepmania/src/RageDisplay_D3D.cpp | 2 +- .../LowLevelWindow/LowLevelWindow_Win32.cpp | 2 +- .../src/archutils/Win32/GraphicsWindow.cpp | 32 ++++++++++++++++++- .../src/archutils/Win32/GraphicsWindow.h | 2 +- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/stepmania/src/RageDisplay_D3D.cpp b/stepmania/src/RageDisplay_D3D.cpp index 3db3e5b15e..6bea5c6455 100644 --- a/stepmania/src/RageDisplay_D3D.cpp +++ b/stepmania/src/RageDisplay_D3D.cpp @@ -213,7 +213,7 @@ RageDisplay_D3D::RageDisplay_D3D() CString RageDisplay_D3D::Init( VideoModeParams p ) { - GraphicsWindow::Initialize(); + GraphicsWindow::Initialize( true ); LOG->Trace( "RageDisplay_D3D::RageDisplay_D3D()" ); LOG->MapLog("renderer", "Current renderer: Direct3D"); diff --git a/stepmania/src/arch/LowLevelWindow/LowLevelWindow_Win32.cpp b/stepmania/src/arch/LowLevelWindow/LowLevelWindow_Win32.cpp index 50a3303437..67e04a89fa 100644 --- a/stepmania/src/arch/LowLevelWindow/LowLevelWindow_Win32.cpp +++ b/stepmania/src/arch/LowLevelWindow/LowLevelWindow_Win32.cpp @@ -35,7 +35,7 @@ LowLevelWindow_Win32::LowLevelWindow_Win32() { ASSERT( g_HGLRC == NULL ); - GraphicsWindow::Initialize(); + GraphicsWindow::Initialize( false ); } LowLevelWindow_Win32::~LowLevelWindow_Win32() diff --git a/stepmania/src/archutils/Win32/GraphicsWindow.cpp b/stepmania/src/archutils/Win32/GraphicsWindow.cpp index ff5577f55f..8fadcfd14c 100644 --- a/stepmania/src/archutils/Win32/GraphicsWindow.cpp +++ b/stepmania/src/archutils/Win32/GraphicsWindow.cpp @@ -22,6 +22,10 @@ static bool g_bHasFocus = true; static bool g_bLastHasFocus = true; static HICON g_hIcon = NULL; static bool m_bWideWindowClass; +static bool g_bD3D = false; + +/* If we're fullscreen, this is the mode we set. */ +static DEVMODE g_FullScreenDevMode; static CString GetNewWindow() { @@ -48,6 +52,7 @@ LRESULT CALLBACK GraphicsWindow::GraphicsWindow_WndProc( HWND hWnd, UINT msg, WP { const bool bInactive = (LOWORD(wParam) == WA_INACTIVE); const bool bMinimized = (HIWORD(wParam) != 0); + const bool bHadFocus = g_bHasFocus; LOG->Trace("WM_ACTIVATE (%i, %i)", bInactive, bMinimized ); g_bHasFocus = !bInactive && !bMinimized; @@ -62,8 +67,29 @@ LRESULT CALLBACK GraphicsWindow::GraphicsWindow_WndProc( HWND hWnd, UINT msg, WP LOG->MapLog( "LOST_FOCUS", "Lost focus to: %s", sStr.c_str() ); } + + if( !g_bD3D && !g_CurrentParams.windowed ) + { + /* In OpenGL (not D3D), it's our job to unset and reset the full-screen video mode + * when we focus changes, and to hide and show the window. Hiding is done in WM_KILLFOCUS, + * because that's where most other apps seem to do it. */ + if( g_bHasFocus && !bHadFocus ) + { + ChangeDisplaySettings( &g_FullScreenDevMode, CDS_FULLSCREEN ); + ShowWindow( g_hWndMain, SW_SHOWNORMAL ); + } + else if( !g_bHasFocus && bHadFocus ) + { + ChangeDisplaySettings( NULL, 0 ); + } + } + return 0; } + case WM_KILLFOCUS: + if( !g_bD3D && !g_CurrentParams.windowed ) + ShowWindow( g_hWndMain, SW_SHOWMINNOACTIVE ); + break; /* Is there any reason we should care what size the user resizes the window to? */ // case WM_GETMINMAXINFO: @@ -170,6 +196,7 @@ CString GraphicsWindow::SetScreenMode( const VideoModeParams &p ) if( ret != DISP_CHANGE_SUCCESSFUL ) return "Couldn't set screen mode"; + g_FullScreenDevMode = DevMode; return CString(); } @@ -318,8 +345,11 @@ void GraphicsWindow::DestroyGraphicsWindow() } -void GraphicsWindow::Initialize() +void GraphicsWindow::Initialize( bool bD3D ) { + /* A few things need to be handled differently for D3D. */ + g_bD3D = bD3D; + AppInstance inst; do { diff --git a/stepmania/src/archutils/Win32/GraphicsWindow.h b/stepmania/src/archutils/Win32/GraphicsWindow.h index f69ad4d44e..35ddb816b7 100644 --- a/stepmania/src/archutils/Win32/GraphicsWindow.h +++ b/stepmania/src/archutils/Win32/GraphicsWindow.h @@ -8,7 +8,7 @@ struct VideoModeParams; // for VideoModeParams namespace GraphicsWindow { /* Set up, and create a hidden window. This only needs to be called once. */ - void Initialize(); + void Initialize( bool bD3D ); /* Shut down completely. */ void Shutdown();