Skip to content
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
574afdf
Experimenting Button Label
AL2009man Mar 4, 2025
07d193e
Create c-cpp.yml
AL2009man Mar 5, 2025
176bb62
Create cmake-multi-platform.yml
AL2009man Mar 5, 2025
9a181e0
Create apply-patch.yml
AL2009man Mar 5, 2025
90b35bc
removing the workflows
AL2009man Mar 5, 2025
4309183
Merge branch 'hedge-dev:main' into main
AL2009man Mar 6, 2025
bec2cf6
added experimental Steam Virtual Gamepad support
AL2009man Mar 6, 2025
ef4e37c
restoring notes for Button Labels.
AL2009man Mar 6, 2025
a8cac87
Merge branch 'hedge-dev:main' into SDL2-Steam
AL2009man Mar 6, 2025
c9b3a5e
Initial Gamepad Hotplug Logic improvements
AL2009man Mar 6, 2025
a96fc60
Lightbar detection when using multiple PlayStation controllers at the…
AL2009man Mar 7, 2025
458938c
Attempt to reduce Input leaking
AL2009man Mar 7, 2025
75dacf5
Lightbar active fix when gamepad plugged first prior to game launch
AL2009man Mar 7, 2025
f3ddd80
Revert "restoring notes for Button Labels."
AL2009man Mar 7, 2025
bd07101
Reapply "restoring notes for Button Labels."
AL2009man Mar 7, 2025
7291987
Moving all Gamepad Hotplug changes to separate branch
AL2009man Mar 7, 2025
d95aad2
Merge branch 'hedge-dev:main' into SteamVirtualGamepad-Prompts
AL2009man Mar 7, 2025
22b2ba8
added SDL's GameController naming convention as Fallback
AL2009man Mar 9, 2025
31b2544
Official device naming scheme for EInputDeviceExplicit
AL2009man Mar 9, 2025
df2f95c
spacing formatting fix
AL2009man Mar 9, 2025
50fc64f
Merge branch 'hedge-dev:main' into SteamVirtualGamepad-Prompts
AL2009man Mar 12, 2025
570fab6
remove "SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS" hint
AL2009man Mar 20, 2025
5a57de3
moved EInputDevice Unknown class to the top priority
AL2009man Mar 20, 2025
c77ce2b
Replacing EInputDeviceExplicit with SDL_GameControllerName
AL2009man Mar 20, 2025
95d4917
remove hid::GetInputDeviceName() from hid.ccp
AL2009man Mar 20, 2025
a404f16
Fix indentation
hyperbx Mar 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 93 additions & 74 deletions UnleashedRecomp/hid/driver/sdl_hid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,23 @@ class Controller

SDL_GameControllerType GetControllerType() const
{
return SDL_GameControllerTypeForIndex(index);
return SDL_GameControllerGetType(controller);
}

hid::EInputDevice GetInputDevice() const
{
switch (GetControllerType())
{
case SDL_CONTROLLER_TYPE_PS3:
case SDL_CONTROLLER_TYPE_PS4:
case SDL_CONTROLLER_TYPE_PS5:
return hid::EInputDevice::PlayStation;
case SDL_CONTROLLER_TYPE_PS3:
case SDL_CONTROLLER_TYPE_PS4:
case SDL_CONTROLLER_TYPE_PS5:
return hid::EInputDevice::PlayStation;
case SDL_CONTROLLER_TYPE_XBOX360:
case SDL_CONTROLLER_TYPE_XBOXONE:
return hid::EInputDevice::Xbox;
default:
return hid::EInputDevice::Unknown;
}

return hid::EInputDevice::Xbox;
}

void Close()
Expand Down Expand Up @@ -134,6 +137,7 @@ class Controller
}
};


std::array<Controller, 4> g_controllers;
Controller* g_activeController;

Expand Down Expand Up @@ -179,14 +183,26 @@ static void SetControllerInputDevice(Controller* controller)

auto controllerType = (hid::EInputDeviceExplicit)controller->GetControllerType();

// Only proceed if the controller type changes
if (hid::g_inputDeviceExplicit != controllerType)
{
hid::g_inputDeviceExplicit = controllerType;

LOGFN("Detected controller: {}", hid::GetInputDeviceName());
// Handle Unknown Type specifically
if (controllerType == hid::EInputDeviceExplicit::Unknown)
{
const char* controllerName = SDL_GameControllerName(controller->controller);
LOGFN("Controller connected: {} (Unknown Controller Type)", controllerName ? controllerName : "Unknown Device");
}
else
{
// For known types, only use the EInputDeviceExplicit name
LOGFN("Controller connected: {}", hid::GetInputDeviceName());
}
}
Comment thread
hyperbx marked this conversation as resolved.
}


static void SetControllerTimeOfDayLED(Controller& controller, bool isNight)
{
auto r = isNight ? 22 : 0;
Expand All @@ -200,99 +216,99 @@ int HID_OnSDLEvent(void*, SDL_Event* event)
{
switch (event->type)
{
case SDL_CONTROLLERDEVICEADDED:
{
const auto freeIndex = FindFreeController();

if (freeIndex != -1)
{
auto controller = Controller(event->cdevice.which);
case SDL_CONTROLLERDEVICEADDED:
{
const auto freeIndex = FindFreeController();

g_controllers[freeIndex] = controller;
if (freeIndex != -1)
{
auto controller = Controller(event->cdevice.which);

SetControllerTimeOfDayLED(controller, App::s_isWerehog);
}
g_controllers[freeIndex] = controller;

break;
SetControllerTimeOfDayLED(controller, App::s_isWerehog);
}

case SDL_CONTROLLERDEVICEREMOVED:
{
auto* controller = FindController(event->cdevice.which);
break;
}

if (controller)
controller->Close();
case SDL_CONTROLLERDEVICEREMOVED:
{
auto* controller = FindController(event->cdevice.which);

break;
}
if (controller)
controller->Close();

case SDL_CONTROLLERBUTTONDOWN:
case SDL_CONTROLLERBUTTONUP:
case SDL_CONTROLLERAXISMOTION:
case SDL_CONTROLLERTOUCHPADDOWN:
{
auto* controller = FindController(event->cdevice.which);
break;
}

if (!controller)
break;
case SDL_CONTROLLERBUTTONDOWN:
case SDL_CONTROLLERBUTTONUP:
case SDL_CONTROLLERAXISMOTION:
case SDL_CONTROLLERTOUCHPADDOWN:
{
auto* controller = FindController(event->cdevice.which);

if (event->type == SDL_CONTROLLERAXISMOTION)
{
if (abs(event->caxis.value) > 8000)
{
SDL_ShowCursor(SDL_DISABLE);
SetControllerInputDevice(controller);
}
if (!controller)
break;

controller->PollAxis();
}
else
if (event->type == SDL_CONTROLLERAXISMOTION)
{
if (abs(event->caxis.value) > 8000)
{
SDL_ShowCursor(SDL_DISABLE);
SetControllerInputDevice(controller);

controller->Poll();
}

break;
controller->PollAxis();
}
else
{
SDL_ShowCursor(SDL_DISABLE);
SetControllerInputDevice(controller);

case SDL_KEYDOWN:
case SDL_KEYUP:
hid::g_inputDevice = hid::EInputDevice::Keyboard;
break;
controller->Poll();
}

case SDL_MOUSEMOTION:
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
{
if (!GameWindow::IsFullscreen() || GameWindow::s_isFullscreenCursorVisible)
SDL_ShowCursor(SDL_ENABLE);
break;
}

hid::g_inputDevice = hid::EInputDevice::Mouse;
case SDL_KEYDOWN:
case SDL_KEYUP:
hid::g_inputDevice = hid::EInputDevice::Keyboard;
break;

break;
}
case SDL_MOUSEMOTION:
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
{
if (!GameWindow::IsFullscreen() || GameWindow::s_isFullscreenCursorVisible)
SDL_ShowCursor(SDL_ENABLE);

case SDL_WINDOWEVENT:
{
if (event->window.event == SDL_WINDOWEVENT_FOCUS_LOST)
{
// Stop vibrating controllers on focus lost.
for (auto& controller : g_controllers)
controller.SetVibration({ 0, 0 });
}
hid::g_inputDevice = hid::EInputDevice::Mouse;

break;
}
break;
}

case SDL_USER_EVILSONIC:
case SDL_WINDOWEVENT:
{
if (event->window.event == SDL_WINDOWEVENT_FOCUS_LOST)
{
// Stop vibrating controllers on focus lost.
for (auto& controller : g_controllers)
SetControllerTimeOfDayLED(controller, event->user.code);

break;
controller.SetVibration({ 0, 0 });
}

break;
}

case SDL_USER_EVILSONIC:
{
for (auto& controller : g_controllers)
SetControllerTimeOfDayLED(controller, event->user.code);

break;
}
}

return 0;
Expand All @@ -311,12 +327,15 @@ void hid::Init()
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_WII, "1");
SDL_SetHint(SDL_HINT_XINPUT_ENABLED, "1");

SDL_SetHint(SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS, "0"); // Uses Button Labels. This hint is disabled for Nintendo Controllers.

Comment thread
AL2009man marked this conversation as resolved.
Outdated
SDL_InitSubSystem(SDL_INIT_EVENTS);
SDL_AddEventWatch(HID_OnSDLEvent, nullptr);

SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
}


uint32_t hid::GetState(uint32_t dwUserIndex, XAMINPUT_STATE* pState)
{
static uint32_t packet;
Expand Down
14 changes: 7 additions & 7 deletions UnleashedRecomp/hid/hid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ std::string hid::GetInputDeviceName()
switch (g_inputDeviceExplicit)
{
case EInputDeviceExplicit::Xbox360:
return "Xbox 360";
return "Xbox 360 Controller";

case EInputDeviceExplicit::XboxOne:
return "Xbox One";
return "Xbox Wireless Controller";

case EInputDeviceExplicit::DualShock3:
return "DualShock 3";
Expand All @@ -54,22 +54,22 @@ std::string hid::GetInputDeviceName()
return "DualShock 4";

case EInputDeviceExplicit::SwitchPro:
return "Nintendo Switch Pro";
return "Nintendo Switch Pro Controller";

case EInputDeviceExplicit::Virtual:
return "Virtual";
return "Virtual Controller";

case EInputDeviceExplicit::DualSense:
return "DualSense";

case EInputDeviceExplicit::Luna:
return "Amazon Luna";
return "Amazon Luna Controller";

case EInputDeviceExplicit::Stadia:
return "Google Stadia";
return "Google Stadia Controller";

case EInputDeviceExplicit::NvShield:
return "NVIDIA Shield";
return "NVIDIA SHIELD Controller";

case EInputDeviceExplicit::SwitchJCLeft:
return "Nintendo Switch Joy-Con (Left)";
Expand Down
3 changes: 2 additions & 1 deletion UnleashedRecomp/hid/hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ namespace hid
Keyboard,
Mouse,
Xbox,
PlayStation
PlayStation,
Unknown
Comment thread
AL2009man marked this conversation as resolved.
Outdated
};

enum class EInputDeviceExplicit
Expand Down