Skip to content

Commit

Permalink
Added additional checks to make sure gamepad input is not processed o…
Browse files Browse the repository at this point in the history
…n spurious wakeup in focus check thread
  • Loading branch information
Kaldaien committed Nov 4, 2024
1 parent 7053f08 commit 7bdf319
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
27 changes: 11 additions & 16 deletions src/utility/gamepad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ SKIF_GamePadInputHelper::UpdateXInputState (void)

static std::array<gamepad_state_s, XUSER_MAX_COUNT> history;

DWORD dwActivePid = 0x0;
GetWindowThreadProcessId (GetForegroundWindow (), &dwActivePid);

static DWORD dwLastActivePid = dwActivePid;

for ( auto idx : XUSER_INDEXES )
{
// Load the static object
Expand All @@ -193,7 +198,8 @@ SKIF_GamePadInputHelper::UpdateXInputState (void)
if (dwResult == ERROR_DEVICE_NOT_CONNECTED)
m_bGamepads [idx].store (false);

else if (dwResult == ERROR_SUCCESS)
else if (dwResult == ERROR_SUCCESS && GetCurrentProcessId () == dwActivePid &&
dwLastActivePid == dwActivePid)
{
// If button state is different, this controller is active...
if ( xinput_state.dwPacketNumber != local.last_state.dwPacketNumber )
Expand Down Expand Up @@ -261,17 +267,15 @@ SKIF_GamePadInputHelper::UpdateXInputState (void)
if (newest.slot == INFINITE)
newest.state = XSTATE_EMPTY;

DWORD dwPidOfMe = GetCurrentProcessId (),
dwPidOfFG = 0x0;

if (!(GetWindowThreadProcessId (GetForegroundWindow (), &dwPidOfFG) &&
dwPidOfMe == dwPidOfFG) ||
!IsWindowVisible (SKIF_ImGui_hWnd))
if (dwActivePid != GetCurrentProcessId () ||
!IsWindowVisible (SKIF_ImGui_hWnd))
{
// Neutralize input because SKIF is not in the foreground
newest.state = XSTATE_EMPTY;
}

dwLastActivePid = dwActivePid;

m_xisGamepad.store (newest.state);

return newest.state;
Expand All @@ -280,15 +284,6 @@ SKIF_GamePadInputHelper::UpdateXInputState (void)
bool
SKIF_GamePadInputHelper::RegisterDevNotification (HWND hWnd)
{
DWORD dwProcId = 0x0;
GetWindowThreadProcessId (hWnd, &dwProcId);

if (dwProcId != GetProcessId (GetCurrentProcess ()))
{
m_hWindowHandle = 0;
return false;
}

GUID GUID_DEVINTERFACE_HID =
{ 0x4D1E55B2L, 0xF16F, 0x11CF,
{ 0x88, 0xCB, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30 } };
Expand Down
2 changes: 1 addition & 1 deletion version.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#define SKIF_MAJOR 1
#define SKIF_MINOR 1
#define SKIF_BUILD 9
#define SKIF_BUILD 10
#define SKIF_REV 0


Expand Down

0 comments on commit 7bdf319

Please sign in to comment.