Skip to content

Commit b282cbc

Browse files
AL2009manhyperbx
andauthored
Steam Virtual Gamepad support / Steam Input sharing Device Info with SDL (#1086)
* Experimenting Button Label Experimenting a way to add a hint for Button Labels. It should attempt to fix the Nintendo Layout issue when using a Nintendo Switch controller * Create c-cpp.yml * Create cmake-multi-platform.yml * Create apply-patch.yml * removing the workflows * added experimental Steam Virtual Gamepad support * restoring notes for Button Labels. * Initial Gamepad Hotplug Logic improvements This changes the way how a Controller will be prioritized. By default: it'll always prioritize based on Player 1. It should play nicely with Steam Deck's internal inputs when Steam Input is active * Lightbar detection when using multiple PlayStation controllers at the same time. An attempt to remedy the Lightbar activation. While Player 2/3/4 will override the in-game lightbar event upon connection: it'll later revert back to the in-game event. * Attempt to reduce Input leaking To avoid "the Controller is leaking" situation, there's now a Gamepad stat management that should reset Controller state based on connected controller. * Lightbar active fix when gamepad plugged first prior to game launch Another attempt to fix the lightbar by redoing the controller state mangement. For some reason: the Lightbar gets disabled when a controller is already plugged prior to game launch. It reverts back to normal until the next game event. * Revert "restoring notes for Button Labels." This reverts commit ef4e37c. * Reapply "restoring notes for Button Labels." This reverts commit f3ddd80. * Moving all Gamepad Hotplug changes to separate branch To ensure all Hotplug-related changes don't accidentally get leftover: this commit will revert all the back back to the accidental removal of Button Label's note. * added SDL's GameController naming convention as Fallback If EInputDeviceExplicit doesn't recognize a specific Controller Type or Device: it'll fallback to SDL's naming conventions. This helps troubleshooting Controller-related issues when using the debug console. * Official device naming scheme for EInputDeviceExplicit Changes some of EInputDeviceExplicit's names to match the device's official name (such as Nintendo Switch Pro Controller, Xbox Wireless Controller, Amazon Luna Controller, etc.) * spacing formatting fix * remove "SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS" hint since #1045 will include it: we're gonna get rid of it on this code section to avoid conflicts. * moved EInputDevice Unknown class to the top priority * Replacing EInputDeviceExplicit with SDL_GameControllerName Based on @hyperbx's suggestions: It'll look for SDL's Controller Name as opposed to EInputDevice's naming scheme. * remove hid::GetInputDeviceName() from hid.ccp Now that SDL_GameControllerName handles Controller naming conventions, the hid.ccp portion of GetInputDeviceName is no longer needed. * Fix indentation --------- Co-authored-by: Hyper <[email protected]>
1 parent 6a50f9f commit b282cbc

File tree

3 files changed

+26
-60
lines changed

3 files changed

+26
-60
lines changed

UnleashedRecomp/hid/driver/sdl_hid.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Controller
3838

3939
SDL_GameControllerType GetControllerType() const
4040
{
41-
return SDL_GameControllerTypeForIndex(index);
41+
return SDL_GameControllerGetType(controller);
4242
}
4343

4444
hid::EInputDevice GetInputDevice() const
@@ -49,9 +49,22 @@ class Controller
4949
case SDL_CONTROLLER_TYPE_PS4:
5050
case SDL_CONTROLLER_TYPE_PS5:
5151
return hid::EInputDevice::PlayStation;
52+
case SDL_CONTROLLER_TYPE_XBOX360:
53+
case SDL_CONTROLLER_TYPE_XBOXONE:
54+
return hid::EInputDevice::Xbox;
55+
default:
56+
return hid::EInputDevice::Unknown;
5257
}
58+
}
59+
60+
const char* GetControllerName() const
61+
{
62+
auto result = SDL_GameControllerName(controller);
63+
64+
if (!result)
65+
return "Unknown Device";
5366

54-
return hid::EInputDevice::Xbox;
67+
return result;
5568
}
5669

5770
void Close()
@@ -178,12 +191,21 @@ static void SetControllerInputDevice(Controller* controller)
178191
hid::g_inputDeviceController = hid::g_inputDevice;
179192

180193
auto controllerType = (hid::EInputDeviceExplicit)controller->GetControllerType();
194+
auto controllerName = controller->GetControllerName();
181195

196+
// Only proceed if the controller type changes.
182197
if (hid::g_inputDeviceExplicit != controllerType)
183198
{
184199
hid::g_inputDeviceExplicit = controllerType;
185200

186-
LOGFN("Detected controller: {}", hid::GetInputDeviceName());
201+
if (controllerType == hid::EInputDeviceExplicit::Unknown)
202+
{
203+
LOGFN("Detected controller: {} (Unknown Controller Type)", controllerName);
204+
}
205+
else
206+
{
207+
LOGFN("Detected controller: {}", controllerName);
208+
}
187209
}
188210
}
189211

UnleashedRecomp/hid/hid.cpp

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -27,59 +27,3 @@ bool hid::IsInputDeviceController()
2727
return hid::g_inputDevice != hid::EInputDevice::Keyboard &&
2828
hid::g_inputDevice != hid::EInputDevice::Mouse;
2929
}
30-
31-
std::string hid::GetInputDeviceName()
32-
{
33-
switch (g_inputDevice)
34-
{
35-
case EInputDevice::Keyboard:
36-
return "Keyboard";
37-
38-
case EInputDevice::Mouse:
39-
return "Mouse";
40-
}
41-
42-
switch (g_inputDeviceExplicit)
43-
{
44-
case EInputDeviceExplicit::Xbox360:
45-
return "Xbox 360";
46-
47-
case EInputDeviceExplicit::XboxOne:
48-
return "Xbox One";
49-
50-
case EInputDeviceExplicit::DualShock3:
51-
return "DualShock 3";
52-
53-
case EInputDeviceExplicit::DualShock4:
54-
return "DualShock 4";
55-
56-
case EInputDeviceExplicit::SwitchPro:
57-
return "Nintendo Switch Pro";
58-
59-
case EInputDeviceExplicit::Virtual:
60-
return "Virtual";
61-
62-
case EInputDeviceExplicit::DualSense:
63-
return "DualSense";
64-
65-
case EInputDeviceExplicit::Luna:
66-
return "Amazon Luna";
67-
68-
case EInputDeviceExplicit::Stadia:
69-
return "Google Stadia";
70-
71-
case EInputDeviceExplicit::NvShield:
72-
return "NVIDIA Shield";
73-
74-
case EInputDeviceExplicit::SwitchJCLeft:
75-
return "Nintendo Switch Joy-Con (Left)";
76-
77-
case EInputDeviceExplicit::SwitchJCRight:
78-
return "Nintendo Switch Joy-Con (Right)";
79-
80-
case EInputDeviceExplicit::SwitchJCPair:
81-
return "Nintendo Switch Joy-Con (Pair)";
82-
}
83-
84-
return "Unknown";
85-
}

UnleashedRecomp/hid/hid.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ namespace hid
44
{
55
enum class EInputDevice
66
{
7+
Unknown,
78
Keyboard,
89
Mouse,
910
Xbox,
@@ -45,5 +46,4 @@ namespace hid
4546
void SetProhibitedInputs(uint16_t wButtons = 0, bool leftStick = false, bool rightStick = false);
4647
bool IsInputAllowed();
4748
bool IsInputDeviceController();
48-
std::string GetInputDeviceName();
4949
}

0 commit comments

Comments
 (0)