Skip to content

Commit

Permalink
Adjust virtual gamepad recognition for new versions of SDL + make bac…
Browse files Browse the repository at this point in the history
…kwards compatible with older versions
  • Loading branch information
streetpea committed Jan 4, 2025
1 parent 0a642c8 commit 9afc7cd
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 18 deletions.
2 changes: 2 additions & 0 deletions gui/include/controllermanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class Controller : public QObject
bool is_dualsense;
bool is_handheld;
bool is_steam_virtual;
bool is_steam_virtual_unmasked;
bool is_dualsense_edge;
bool micbutton_push;

Expand Down Expand Up @@ -124,6 +125,7 @@ class Controller : public QObject
bool IsDualSense();
bool IsHandheld();
bool IsSteamVirtual();
bool IsSteamVirtualUnmasked();
bool IsDualSenseEdge();
void resetMotionControls(bool reset);

Expand Down
53 changes: 39 additions & 14 deletions gui/src/controllermanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,31 @@ static QSet<QString> chiaki_motion_controller_guids({
"030000008f0e00001431000000000000",
});

static QSet<QPair<int16_t, int16_t>> chiaki_dualsense_controller_ids({
static QSet<QPair<uint16_t, uint16_t>> chiaki_dualsense_controller_ids({
// in format (vendor id, product id)
QPair<int16_t, int16_t>(0x054c, 0x0ce6), // DualSense controller
QPair<uint16_t, uint16_t>(0x054c, 0x0ce6), // DualSense controller
});

static QSet<QPair<int16_t, int16_t>> chiaki_dualsense_edge_controller_ids({
static QSet<QPair<uint16_t, uint16_t>> chiaki_dualsense_edge_controller_ids({
// in format (vendor id, product id)
QPair<int16_t, int16_t>(0x054c, 0x0df2), // DualSense Edge controller
QPair<uint16_t, uint16_t>(0x054c, 0x0df2), // DualSense Edge controller
});

static QSet<QPair<int16_t, int16_t>> chiaki_handheld_controller_ids({
static QSet<QPair<uint16_t, uint16_t>> chiaki_handheld_controller_ids({
// in format (vendor id, product id)
QPair<int16_t, int16_t>(0x28de, 0x1205), // Steam Deck
QPair<int16_t, int16_t>(0x0b05, 0x1abe), // Rog Ally
QPair<int16_t, int16_t>(0x17ef, 0x6182), // Legion Go
QPair<int16_t, int16_t>(0x0db0, 0x1901), // MSI Claw
QPair<uint16_t, uint16_t>(0x28de, 0x1205), // Steam Deck
QPair<uint16_t, uint16_t>(0x0b05, 0x1abe), // Rog Ally
QPair<uint16_t, uint16_t>(0x17ef, 0x6182), // Legion Go
QPair<uint16_t, uint16_t>(0x0db0, 0x1901), // MSI Claw
});

static QSet<QPair<int16_t, int16_t>> chiaki_steam_virtual_controller_ids({
static QSet<QPair<uint16_t, uint16_t>> chiaki_steam_virtual_controller_ids({
// in format (vendor id, product id)
QPair<int16_t, int16_t>(0x28de, 0x11ff), // Steam Virtual Controller
#ifdef Q_OS_MACOS
QPair<uint16_t, uint16_t<(0x045e, 0x028e), // Microsoft Xbox 360 Controller
#else
QPair<uint16_t, uint16_t>(0x28de, 0x11ff), // Steam Virtual Controller
#endif
});

static ControllerManager *instance = nullptr;
Expand Down Expand Up @@ -283,7 +287,7 @@ void ControllerManager::ControllerClosed(Controller *controller)
Controller::Controller(int device_id, ControllerManager *manager)
: QObject(manager), ref(0), last_motion_timestamp(0), micbutton_push(false), is_dualsense(false),
is_dualsense_edge(false), updating_mapping_button(false), is_handheld(false),
is_steam_virtual(false), enable_analog_stick_mapping(false)
is_steam_virtual(false), is_steam_virtual_unmasked(false), enable_analog_stick_mapping(false)
{
this->id = device_id;
this->manager = manager;
Expand All @@ -305,11 +309,22 @@ Controller::Controller(int device_id, ControllerManager *manager)
if(SDL_GameControllerHasSensor(controller, SDL_SENSOR_GYRO))
SDL_GameControllerSetSensorEnabled(controller, SDL_SENSOR_GYRO, SDL_TRUE);
#endif
auto controller_id = QPair<int16_t, int16_t>(SDL_GameControllerGetVendor(controller), SDL_GameControllerGetProduct(controller));
auto controller_id = QPair<uint16_t, uint16_t>(SDL_GameControllerGetVendor(controller), SDL_GameControllerGetProduct(controller));
is_dualsense = chiaki_dualsense_controller_ids.contains(controller_id);
is_handheld = chiaki_handheld_controller_ids.contains(controller_id);
is_steam_virtual = chiaki_steam_virtual_controller_ids.contains(controller_id);
is_dualsense_edge = chiaki_dualsense_edge_controller_ids.contains(controller_id);
SDL_Joystick *js = SDL_GameControllerGetJoystick(controller);
SDL_JoystickGUID guid = SDL_JoystickGetGUID(js);
auto guid_controller_id = QPair<uint16_t, uint16_t>(0, 0);
uint16_t guid_version = 0;
SDL_GetJoystickGUIDInfo(guid, &guid_controller_id.first, &guid_controller_id.second, &guid_version, NULL);
#ifdef Q_OS_MACOS
is_steam_virtual = (guid_version == 0 && chiaki_steam_virtual_controller_ids.contains(guid_controller_id));
is_steam_virtual_unmasked = (guid_version == 0 && chiaki_steam_virtual_controller_ids.contains(controller_id));
#else
is_steam_virtual = chiaki_steam_virtual_controller_ids.contains(guid_controller_id);
is_steam_virtual_unmasked = chiaki_steam_virtual_controller_ids.contains(controller_id);
#endif
break;
}
}
Expand Down Expand Up @@ -893,6 +908,16 @@ bool Controller::IsSteamVirtual()
return false;
}

bool Controller::IsSteamVirtualUnmasked()
{
#ifdef CHIAKI_GUI_ENABLE_SDL_GAMECONTROLLER
if(!controller)
return false;
return is_steam_virtual_unmasked;
#endif
return false;
}

void Controller::resetMotionControls(bool reset)
{
#ifdef CHIAKI_GUI_ENABLE_SDL_GAMECONTROLLER
Expand Down
2 changes: 1 addition & 1 deletion gui/src/qml/SettingsDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -2266,7 +2266,7 @@ DialogView {
Label {
id: steamLabel
wrapMode: TextEdit.Wrap
text: qsTr("This controller is managed by Steam. Please use Steam to map controller or disable Steam Input for the controller before mapping here.")
text: qsTr("This controller is managed by Steam.\nPlease use Steam to map controller or disable Steam Input for the controller before mapping here.")
Keys.onReturnPressed: steamControllerMappingDialog.close();
Keys.onEscapePressed: steamControllerMappingDialog.close();
}
Expand Down
6 changes: 3 additions & 3 deletions gui/src/streamsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ void StreamSession::UpdateGamepads()
{
DisconnectHaptics();
}
if (!controller->IsHandheld() && !controller->IsSteamVirtual())
if (!controller->IsHandheld() && !controller->IsSteamVirtualUnmasked())
{
haptics_handheld++;
}
Expand Down Expand Up @@ -920,7 +920,7 @@ void StreamSession::UpdateGamepads()
haptics_handheld++;
#endif
}
if (!controller->IsHandheld() && !controller->IsSteamVirtual())
if (!controller->IsHandheld() && !controller->IsSteamVirtualUnmasked())
{
haptics_handheld--;
}
Expand Down Expand Up @@ -1624,7 +1624,7 @@ void StreamSession::PushHapticsFrame(uint8_t *buf, size_t buf_size)
for(auto controller : controllers)
{
#if CHIAKI_GUI_ENABLE_STEAMDECK_NATIVE
if(haptics_handheld < 1 && (controller->IsHandheld() || (sdeck && controller->IsSteamVirtual())))
if(haptics_handheld < 1 && (controller->IsHandheld() || (sdeck && controller->IsSteamVirtualUnmasked())))
#else
if(haptics_handheld < 1 && controller->IsHandheld())
#endif
Expand Down

0 comments on commit 9afc7cd

Please sign in to comment.