Skip to content

Commit

Permalink
Only process device msgs if using controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
Aemony committed Jun 26, 2024
1 parent bcc194a commit beee9bb
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 51 deletions.
48 changes: 26 additions & 22 deletions src/SKIF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4367,32 +4367,36 @@ SKIF_WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
case DBT_DEVICEARRIVAL:
case DBT_DEVICEREMOVECOMPLETE:
{
DEV_BROADCAST_HDR* pDevHdr =
(DEV_BROADCAST_HDR *)lParam;
if (pDevHdr->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
// Only process these if controller support is enabled
if (_registry.bControllers)
{
DEV_BROADCAST_DEVICEINTERFACE_W *pDev =
(DEV_BROADCAST_DEVICEINTERFACE_W *)pDevHdr;

static constexpr GUID GUID_DEVINTERFACE_HID =
{ 0x4D1E55B2L, 0xF16F, 0x11CF, { 0x88, 0xCB, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30 } };

if (IsEqualGUID (pDev->dbcc_classguid, GUID_DEVINTERFACE_HID))
DEV_BROADCAST_HDR* pDevHdr =
(DEV_BROADCAST_HDR *)lParam;
if (pDevHdr->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
{
// Check for changes in case any device has arrived
if (wParam == DBT_DEVICEARRIVAL)
{
PLOG_VERBOSE << "A HID device has arrived, and we need to refresh gamepad connectivity...";
_gamepad.InvalidateGamePads( );
_gamepad.WakeThread ( );
}
DEV_BROADCAST_DEVICEINTERFACE_W *pDev =
(DEV_BROADCAST_DEVICEINTERFACE_W *)pDevHdr;

static constexpr GUID GUID_DEVINTERFACE_HID =
{ 0x4D1E55B2L, 0xF16F, 0x11CF, { 0x88, 0xCB, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30 } };

// Only check for changes if a device was removed if we actually had a connected gamepad
else if (wParam == DBT_DEVICEREMOVECOMPLETE && _gamepad.HasGamePad())
if (IsEqualGUID (pDev->dbcc_classguid, GUID_DEVINTERFACE_HID))
{
PLOG_VERBOSE << "A HID device was removed, and we need to refresh gamepad connectivity...";
_gamepad.InvalidateGamePads( );
_gamepad.WakeThread ( );
// Check for changes in case any device has arrived
if (wParam == DBT_DEVICEARRIVAL)
{
PLOG_VERBOSE << "A HID device has arrived, and we need to refresh gamepad connectivity...";
_gamepad.InvalidateGamePads( );
_gamepad.WakeThread ( );
}

// Only check for changes if a device was removed if we actually had a connected gamepad
else if (wParam == DBT_DEVICEREMOVECOMPLETE && _gamepad.HasGamePad ( ))
{
PLOG_VERBOSE << "A HID device was removed, and we need to refresh gamepad connectivity...";
_gamepad.InvalidateGamePads( );
_gamepad.WakeThread ( );
}
}
}
}
Expand Down
67 changes: 39 additions & 28 deletions src/tabs/common_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ void SKIF_UI_DrawComponentVersion (void)
void SKIF_UI_DrawPlatformStatus (void)
{
static SKIF_GamePadInputHelper& _gamepad = SKIF_GamePadInputHelper::GetInstance ( );
static SKIF_RegistrySettings& _registry = SKIF_RegistrySettings ::GetInstance ( );

ImGui::BeginGroup ( );
ImGui::Spacing ( );
Expand Down Expand Up @@ -479,44 +480,54 @@ void SKIF_UI_DrawPlatformStatus (void)
}

SKIF_ImGui_Spacing ( );

ImGui::Text ("Connected XInput gamepads:");
ImGui::SameLine ( );

std::vector<bool> slots = _gamepad.GetGamePads ( );

ImGui::BeginGroup ( );
for (auto slot : slots)

if (! _registry.bControllers)
{
ImGui::SameLine ( );

if (slot)
ImGui::TextColored (ImGui::GetStyleColorVec4 (ImGuiCol_SKIF_Success), ICON_FA_CHECK);
else
ImGui::TextColored (ImGui::GetStyleColorVec4 (ImGuiCol_SKIF_Yellow ), ICON_FA_XMARK);
ImGui::TextDisabled ("Disabled");
SKIF_ImGui_SetHoverTip ("Please re-enable controller support in the Settings tab.");
}
ImGui::EndGroup ( );
SKIF_ImGui_SetHoverTip ("Indicates which Xbox (XInput) controller slots are currently in use/connected.");

// If the primary slot is false and one of the other are true, show a warning
if (slots[0] == false &&
(slots[1] == true ||
slots[2] == true ||
slots[3] == true ))
else
{
ImGui::Spacing ( );
std::vector<bool> slots = _gamepad.GetGamePads ( );

ImGui::PushStyleColor (ImGuiCol_Text, ImGui::GetStyleColorVec4 (ImGuiCol_SKIF_Yellow));
ImGui::BeginGroup ( );
ImGui::Spacing ( );
ImGui::SameLine ( );
ImGui::Text (ICON_FA_TRIANGLE_EXCLAMATION " ");
ImGui::SameLine ( );
ImGui::Text ("Some games may not detect the gamepad!");
for (auto slot : slots)
{
ImGui::SameLine ( );

if (slot)
ImGui::TextColored (ImGui::GetStyleColorVec4 (ImGuiCol_SKIF_Success), ICON_FA_CHECK);
else
ImGui::TextColored (ImGui::GetStyleColorVec4 (ImGuiCol_SKIF_Yellow ), ICON_FA_XMARK);
}
ImGui::EndGroup ( );
ImGui::PopStyleColor ( );
SKIF_ImGui_SetHoverTip ("Indicates which Xbox (XInput) controller slots are currently in use/connected.");

// If the primary slot is false and one of the other are true, show a warning
if (slots[0] == false &&
(slots[1] == true ||
slots[2] == true ||
slots[3] == true ))
{
ImGui::Spacing ( );

SKIF_ImGui_SetHoverTip ("Some games may not be able to detect the controller if it is not connected to the first slot.\n"
"Disconnect and reconnect the controller to the system usually takes care of the issue.");
ImGui::PushStyleColor (ImGuiCol_Text, ImGui::GetStyleColorVec4 (ImGuiCol_SKIF_Yellow));
ImGui::BeginGroup ( );
ImGui::Spacing ( );
ImGui::SameLine ( );
ImGui::Text (ICON_FA_TRIANGLE_EXCLAMATION " ");
ImGui::SameLine ( );
ImGui::Text ("Some games may not detect the gamepad!");
ImGui::EndGroup ( );
ImGui::PopStyleColor ( );

SKIF_ImGui_SetHoverTip ("Some games may not be able to detect the controller if it is not connected to the first slot.\n"
"Disconnect and reconnect the controller to the system usually takes care of the issue.");
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/tabs/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1438,8 +1438,10 @@ SKIF_UI_Tab_DrawSettings (void)
SKIF_GamePadInputHelper::GetInstance ( );

if (_registry.bControllers)
{
_gamepad.InvalidateGamePads ( );
_gamepad.WakeThread ( );
else
} else
_gamepad.SleepThread ( );
}

Expand Down

0 comments on commit beee9bb

Please sign in to comment.