From 8c9d07b26b140d8424abcf8393014861d2643814 Mon Sep 17 00:00:00 2001 From: John Peterson Date: Sun, 1 Feb 2009 16:29:35 +0000 Subject: [PATCH] nJoy: Don't allow input when Dolphin is not in focus (supports both the rendering to main window and render to separate window options) git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2062 8ced0084-cf51-0410-be5f-012b33b47a6e --- .../Plugin_nJoy_SDL/Src/GUI/ConfigBox.cpp | 2 +- Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.cpp | 36 +++++++++++++++++-- Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.h | 1 + 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigBox.cpp b/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigBox.cpp index 4c9a830d0d..f34fec2ed1 100644 --- a/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigBox.cpp +++ b/Source/Plugins/Plugin_nJoy_SDL/Src/GUI/ConfigBox.cpp @@ -462,7 +462,7 @@ void ConfigBox::UpdateGUI(int _notebookpage) m_textDpadLeft[_notebookpage]->Show(!Hat); m_textDpadRight[_notebookpage]->Show(!Hat); - m_textDpadDown[_notebookpage]->SetLabel(Hat ? wxT("Select hat") : wxT("Up")); + m_textDpadDown[_notebookpage]->SetLabel(Hat ? wxT("Select hat") : wxT("Down")); m_bJoyDpadDown[_notebookpage]->SetToolTip(Hat ? wxT("Select a hat by pressing the hat in any direction") : wxT("")); diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.cpp b/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.cpp index 3bb6c759f9..60bf8c3939 100644 --- a/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.cpp +++ b/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.cpp @@ -90,6 +90,7 @@ CONTROLLER_MAPPING PadMapping[4]; bool emulator_running = false; int NumPads = 0, NumGoodPads = 0; HWND m_hWnd; // Handle to window +SPADInitialize *g_PADInitialize; // TODO: fix this dirty hack to stop missing symbols void __Log(int log, const char *format, ...) {} @@ -239,7 +240,7 @@ void Initialize(void *init) // Debugging //Console::Open(); Console::Print("Initialize: %i\n", SDL_WasInit(0)); - SPADInitialize *_PADInitialize = (SPADInitialize*)init; + g_PADInitialize = (SPADInitialize*)init; emulator_running = true; #ifdef _DEBUG @@ -247,7 +248,7 @@ void Initialize(void *init) #endif #ifdef _WIN32 - m_hWnd = (HWND)_PADInitialize->hWnd; + m_hWnd = (HWND)g_PADInitialize->hWnd; #endif NumPads = Search_Devices(); // Populate joyinfo for all attached devices @@ -259,7 +260,7 @@ void Initialize(void *init) || (PadMapping[2].enabled && PadState[2].joy == NULL) || (PadMapping[3].enabled && PadState[3].joy == NULL)) { - _PADInitialize->padNumber = -1; + g_PADInitialize->padNumber = -1; Console::Print("%s\n", SDL_GetError()); } } @@ -398,6 +399,9 @@ void Shutdown() // ŻŻŻŻŻŻŻŻŻŻŻŻŻŻ void PAD_Input(u16 _Key, u8 _UpDown) { + // Check that Dolphin is in focus, otherwise don't update the pad status + if (!IsFocus()) return; + // Check if the keys are interesting, and then update it for(int i = 0; i < 4; i++) { @@ -606,6 +610,29 @@ unsigned int PAD_GetAttachedPads() +//****************************************************************************** +// Supporting functions +//****************************************************************************** + +////////////////////////////////////////////////////////////////////////////////////////// +// Check if Dolphin is in focus +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ +bool IsFocus() +{ +#ifdef _WIN32 + HWND Parent = GetParent(g_PADInitialize->hWnd); + HWND TopLevel = GetParent(Parent); + // Support both rendering to main window and not + if (GetForegroundWindow() == TopLevel || GetForegroundWindow() == g_PADInitialize->hWnd) + return true; + else + return false; +#else + return true; +#endif +} + + ////////////////////////////////////////////////////////////////////////////////////////// // Convert stick values // ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ @@ -747,6 +774,9 @@ void ReadButton(int controller, int button) for a virtual controller 0 to 3. */ void GetJoyState(int controller) { + // Check that Dolphin is in focus, otherwise don't update the pad status + if (!IsFocus()) return; + // Update the gamepad status SDL_JoystickUpdate(); diff --git a/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.h b/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.h index b4835ff6a9..9295304e7e 100644 --- a/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.h +++ b/Source/Plugins/Plugin_nJoy_SDL/Src/nJoy.h @@ -243,6 +243,7 @@ void GetJoyState(int controller); int Search_Devices(); void DEBUG_INIT(); void DEBUG_QUIT(); +bool IsFocus(); void Pad_Use_Rumble(u8 _numPAD, SPADStatus* _pPADStatus); // Rumble int Pad_Convert(int _val); // Value conversion