diff --git a/Core/Config.cpp b/Core/Config.cpp index fb7b743df6..99668d9215 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -540,6 +540,7 @@ static ConfigSetting controlSettings[] = { #endif ConfigSetting("DisableDpadDiagonals", &g_Config.bDisableDpadDiagonals, false, true, true), + ConfigSetting("GamepadOnlyFocused", &g_Config.bGamepadOnlyFocused, false, true, true), ConfigSetting("TouchButtonStyle", &g_Config.iTouchButtonStyle, 1, true, true), ConfigSetting("TouchButtonOpacity", &g_Config.iTouchButtonOpacity, 65, true, true), diff --git a/Core/Config.h b/Core/Config.h index 33274e1636..ec02c11f8f 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -234,6 +234,7 @@ public: // Disable diagonals bool bDisableDpadDiagonals; + bool bGamepadOnlyFocused; // Control Style int iTouchButtonStyle; // Control Positions diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index f402af511d..8d67a5e7a4 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -369,6 +369,10 @@ void GameSettingsScreen::CreateViews() { controlsSettings->Add(new ItemHeader(ms->T("Controls"))); controlsSettings->Add(new Choice(c->T("Control Mapping")))->OnClick.Handle(this, &GameSettingsScreen::OnControlMapping); +#if defined(USING_WIN_UI) + controlsSettings->Add(new CheckBox(&g_Config.bGamepadOnlyFocused, c->T("Ignore gamepads when not focused"))); +#endif + #if defined(MOBILE_DEVICE) controlsSettings->Add(new CheckBox(&g_Config.bHapticFeedback, c->T("HapticFeedback", "Haptic Feedback (vibration)"))); static const char *tiltTypes[] = { "None (Disabled)", "Analog Stick", "D-PAD", "PSP Action Buttons"}; diff --git a/Windows/InputDevice.cpp b/Windows/InputDevice.cpp index 3e781102fb..be9f240ed5 100644 --- a/Windows/InputDevice.cpp +++ b/Windows/InputDevice.cpp @@ -21,6 +21,7 @@ #include "input/input_state.h" #include "thread/thread.h" #include "thread/threadutil.h" +#include "Core/Config.h" #include "Core/Host.h" #include "Windows/InputDevice.h" #include "Windows/XinputDevice.h" @@ -33,6 +34,7 @@ static volatile bool inputThreadEnabled = false; static std::thread *inputThread = NULL; static recursive_mutex inputMutex; static condition_variable inputEndCond; +static bool focused = true; extern InputState input_state; @@ -46,7 +48,7 @@ inline static void ExecuteInputPoll() { input_state.pad_lstick_y = 0; input_state.pad_rstick_x = 0; input_state.pad_rstick_y = 0; - if (host) { + if (host && (focused || !g_Config.bGamepadOnlyFocused)) { host->PollControllers(input_state); } UpdateInputState(&input_state); @@ -87,3 +89,11 @@ void InputDevice::StopPolling() { delete inputThread; inputThread = NULL; } + +void InputDevice::GainFocus() { + focused = true; +} + +void InputDevice::LoseFocus() { + focused = false; +} diff --git a/Windows/InputDevice.h b/Windows/InputDevice.h index a2bc3bf842..fd48e3f2e5 100644 --- a/Windows/InputDevice.h +++ b/Windows/InputDevice.h @@ -32,4 +32,7 @@ public: static void BeginPolling(); static void StopPolling(); + + static void GainFocus(); + static void LoseFocus(); }; diff --git a/Windows/WndMainWindow.cpp b/Windows/WndMainWindow.cpp index 63a04511b6..323bb96b3b 100644 --- a/Windows/WndMainWindow.cpp +++ b/Windows/WndMainWindow.cpp @@ -1083,6 +1083,7 @@ namespace MainWindow { bool pause = true; if (wParam == WA_ACTIVE || wParam == WA_CLICKACTIVE) { + InputDevice::GainFocus(); g_activeWindow = WINDOW_MAINWINDOW; pause = false; } @@ -1097,6 +1098,7 @@ namespace MainWindow if (wParam == WA_INACTIVE) { WindowsRawInput::LoseFocus(); + InputDevice::LoseFocus(); } } break;