Add auto controller count detection and make it default

Note: Existing users have to manually adjust this setting
pull/239/head
Peter Repukat 1 year ago
parent 0745e3684d
commit 50a4ea814d

@ -404,7 +404,7 @@ QVariantMap UIModel::getDefaultConf() const
QJsonValue::fromVariant(QString::fromStdWString(getSteamUserId(false)))},
{"globalModeGameId", ""},
{"globalModeUseGamepadUI", false},
{"controller", QJsonObject{{"maxControllers", 1}, {"emulateDS4", false}, {"allowDesktopConfig", false}}},
{"controller", QJsonObject{{"maxControllers", -1}, {"emulateDS4", false}, {"allowDesktopConfig", false}}},
{"devices",
QJsonObject{
{"hideDevices", true},

@ -261,8 +261,14 @@ CollapsiblePane {
width: 128
editable: true
value: shortcutInfo.controller.maxControllers
from: 0
from: -1
to: 4
textFromValue: function(value) {
if (value == -1) {
return qsTr("auto");
}
return Number(value);
}
onValueChanged: shortcutInfo.controller.maxControllers = value
}
RoundButton {
@ -271,7 +277,12 @@ CollapsiblePane {
helpInfoDialog.text =
qsTr("GlosSI will only provide [NUMBER] of controllers")
+ "\n"
+ qsTr("Required to set to actually connected controller count when using \"real device IDs\" ")
+ qsTr("-1 ^= auto-detect")
+ "\n"
+ qsTr("auto detection only works upon launch")
+ "\n"
+ "\n"
+ qsTr("Required to manuelly set to actually connected controller count when using \"real device IDs\" ")
helpInfoDialog.open()
}
width: 48

@ -49,6 +49,22 @@ InputRedirector::~InputRedirector()
void InputRedirector::run()
{
run_ = vigem_connected_;
max_controllers_ = Settings::controller.maxControllers;
if (max_controllers_ < 0) {
for (int i = 0; i < XUSER_MAX_COUNT; i++) {
XINPUT_STATE state{};
if (XInputGetState(i, &state) == ERROR_SUCCESS) {
max_controllers_ = i + 1;
}
}
if (max_controllers_ < 0) {
max_controllers_ = 1;
spdlog::error("Failed to auto detect controller count. Defaulting to 1");
}
else {
spdlog::info("Auto detected {} controllers", max_controllers_);
}
}
controller_thread_ = std::thread(&InputRedirector::runLoop, this);
#ifdef _WIN32
Overlay::AddOverlayElem([this](bool window_has_focus, ImGuiID dockspace_id) {
@ -58,13 +74,17 @@ void InputRedirector::run()
ImGui::Text("Max. controller count");
ImGui::SameLine();
ImGui::InputInt("##Max. controller count", &countcopy, 1, 1);
ImGui::Text("-1 = Auto-detection (auto-detection only works on launch");
if (countcopy > XUSER_MAX_COUNT) {
countcopy = XUSER_MAX_COUNT;
}
if (countcopy < 0) {
countcopy = 0;
if (countcopy < -1) {
countcopy = -1;
}
Settings::controller.maxControllers = countcopy;
if (Settings::controller.maxControllers > -1) {
max_controllers_ = countcopy;
}
if (ImGui::Checkbox("Emulate DS4 (instead of Xbox360 controller)", &Settings::controller.emulateDS4)) {
controller_settings_changed_ = true;
@ -131,12 +151,12 @@ void InputRedirector::runLoop()
unplugVigemPad(i);
}
}
if (Settings::controller.maxControllers < XUSER_MAX_COUNT) {
for (int i = Settings::controller.maxControllers; i < XUSER_MAX_COUNT; i++) {
if (max_controllers_ < XUSER_MAX_COUNT) {
for (int i = max_controllers_; i < XUSER_MAX_COUNT; i++) {
unplugVigemPad(i);
}
}
for (int i = 0; i < XUSER_MAX_COUNT && i < Settings::controller.maxControllers; i++) {
for (int i = 0; i < XUSER_MAX_COUNT && i < max_controllers_; i++) {
XINPUT_STATE state{};
if (XInputGetState(i, &state) == ERROR_SUCCESS) {
if (vt_pad_[i] != nullptr) {

@ -35,6 +35,7 @@ class InputRedirector {
private:
void runLoop();
int max_controllers_ = -1;
static constexpr int start_delay_ms_ = 2000;
bool run_ = false;
int overlay_elem_id_ = -1;

@ -65,7 +65,7 @@ namespace Settings
inline struct Controller
{
int maxControllers = 1;
int maxControllers = -1;
bool allowDesktopConfig = false;
bool emulateDS4 = false;
} controller;

Loading…
Cancel
Save