Add options to control gamepad autoselection heuristics

Also move gamepad type selection to the input tab while we're here
This commit is contained in:
Cameron Gutman 2023-12-31 19:01:37 -06:00
parent 97c921629a
commit 6ea836c511
5 changed files with 133 additions and 36 deletions

View File

@ -170,6 +170,42 @@ ds4_back_as_touchpad_click
ds4_back_as_touchpad_click = enabled
motion_as_ds4
^^^^^^^^^^^^^
**Description**
.. Hint:: Only applies when gamepad is set to auto.
If a client reports that a connected gamepad has motion sensor support, emulate it on the host as a DS4 controller.
When disabled, motion sensors will not be taken into account during gamepad type selection.
**Default**
``enabled``
**Example**
.. code-block:: text
motion_as_ds4 = enabled
touchpad_as_ds4
^^^^^^^^^^^^^^^
**Description**
.. Hint:: Only applies when gamepad is set to auto.
If a client reports that a connected gamepad has a touchpad, emulate it on the host as a DS4 controller.
When disabled, touchpad presence will not be taken into account during gamepad type selection.
**Default**
``enabled``
**Example**
.. code-block:: text
touchpad_as_ds4 = enabled
back_button_timeout
^^^^^^^^^^^^^^^^^^^

View File

@ -420,6 +420,8 @@ namespace config {
platf::supported_gamepads().front().size(),
}, // Default gamepad
true, // back as touchpad click enabled (manual DS4 only)
true, // client gamepads with motion events are emulated as DS4
true, // client gamepads with touchpads are emulated as DS4
true, // keyboard enabled
true, // mouse enabled
@ -1048,6 +1050,8 @@ namespace config {
string_restricted_f(vars, "gamepad"s, input.gamepad, platf::supported_gamepads());
bool_f(vars, "ds4_back_as_touchpad_click", input.ds4_back_as_touchpad_click);
bool_f(vars, "motion_as_ds4", input.motion_as_ds4);
bool_f(vars, "touchpad_as_ds4", input.touchpad_as_ds4);
bool_f(vars, "mouse", input.mouse);
bool_f(vars, "keyboard", input.keyboard);

View File

@ -113,6 +113,8 @@ namespace config {
std::string gamepad;
bool ds4_back_as_touchpad_click;
bool motion_as_ds4;
bool touchpad_as_ds4;
bool keyboard;
bool mouse;

View File

@ -1188,11 +1188,11 @@ namespace platf {
BOOST_LOG(info) << "Gamepad " << id.globalIndex << " will be Xbox 360 controller (auto-selected by client-reported type)"sv;
selectedGamepadType = Xbox360Wired;
}
else if (metadata.capabilities & (LI_CCAP_ACCEL | LI_CCAP_GYRO)) {
else if (config::input.motion_as_ds4 && (metadata.capabilities & (LI_CCAP_ACCEL | LI_CCAP_GYRO))) {
BOOST_LOG(info) << "Gamepad " << id.globalIndex << " will be DualShock 4 controller (auto-selected by motion sensor presence)"sv;
selectedGamepadType = DualShock4Wired;
}
else if (metadata.capabilities & LI_CCAP_TOUCHPAD) {
else if (config::input.touchpad_as_ds4 && (metadata.capabilities & LI_CCAP_TOUCHPAD)) {
BOOST_LOG(info) << "Gamepad " << id.globalIndex << " will be DualShock 4 controller (auto-selected by touchpad presence)"sv;
selectedGamepadType = DualShock4Wired;
}
@ -1201,6 +1201,26 @@ namespace platf {
selectedGamepadType = Xbox360Wired;
}
if (selectedGamepadType == Xbox360Wired) {
if (metadata.capabilities & (LI_CCAP_ACCEL | LI_CCAP_GYRO)) {
BOOST_LOG(warning) << "Gamepad " << id.globalIndex << " has motion sensors, but they are not usable when emulating an Xbox 360 controller"sv;
}
if (metadata.capabilities & LI_CCAP_TOUCHPAD) {
BOOST_LOG(warning) << "Gamepad " << id.globalIndex << " has a touchpad, but it is not usable when emulating an Xbox 360 controller"sv;
}
if (metadata.capabilities & LI_CCAP_RGB_LED) {
BOOST_LOG(warning) << "Gamepad " << id.globalIndex << " has an RGB LED, but it is not usable when emulating an Xbox 360 controller"sv;
}
}
else if (selectedGamepadType == DualShock4Wired) {
if (!(metadata.capabilities & (LI_CCAP_ACCEL | LI_CCAP_GYRO))) {
BOOST_LOG(warning) << "Gamepad " << id.globalIndex << " is emulating a DualShock 4 controller, but the client gamepad doesn't have motion sensors active"sv;
}
if (!(metadata.capabilities & LI_CCAP_TOUCHPAD)) {
BOOST_LOG(warning) << "Gamepad " << id.globalIndex << " is emulating a DualShock 4 controller, but the client gamepad doesn't have a touchpad"sv;
}
}
return raw->vigem->alloc_gamepad_internal(id, feedback_queue, selectedGamepadType);
}

View File

@ -90,40 +90,6 @@
</select>
<div class="form-text">Automatically configure port forwarding</div>
</div>
<!--Gamepads-->
<div class="mb-3" v-if="platform === 'windows'">
<label for="gamepad" class="form-label">Gamepads</label>
<select id="gamepad" class="form-select" v-model="config.gamepad">
<option value="auto">Automatic</option>
<option value="ds4">DS4 (PS4)</option>
<option value="x360">X360 (Xbox 360)</option>
</select>
<div class="form-text">Choose which type of gamepad to emulate on the host</div>
</div>
<div class="accordion" v-if="config.gamepad === 'ds4'">
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button" type="button" data-bs-toggle="collapse"
data-bs-target="#panelsStayOpen-collapseOne">
Manual DS4 options
</button>
</h2>
<div id="panelsStayOpen-collapseOne" class="accordion-collapse collapse show"
aria-labelledby="panelsStayOpen-headingOne">
<div class="accordion-body">
<div>
<label for="ds4_back_as_touchpad_click" class="form-label">Map Back/Select to Touchpad Click</label>
<select id="ds4_back_as_touchpad_click" class="form-select"
v-model="config.ds4_back_as_touchpad_click">
<option value="disabled">Disabled</option>
<option value="enabled">Enabled (default)</option>
</select>
<div class="form-text">When forcing DS4 emulation, map Back/Select to Touchpad Click</div>
</div>
</div>
</div>
</div>
</div>
<!--Ping Timeout-->
<div class="mb-3">
<label for="ping_timeout" class="form-label">Ping Timeout</label>
@ -266,6 +232,73 @@
</div>
</div>
<div v-if="currentTab === 'input'" class="config-page">
<!--Emulated Gamepad Type-->
<div class="mb-3" v-if="platform === 'windows'">
<label for="gamepad" class="form-label">Emulated Gamepad Type</label>
<select id="gamepad" class="form-select" v-model="config.gamepad">
<option value="auto">Automatic</option>
<option value="ds4">DS4 (PS4)</option>
<option value="x360">X360 (Xbox 360)</option>
</select>
<div class="form-text">Choose which type of gamepad to emulate on the host</div>
</div>
<div class="accordion" v-if="config.gamepad === 'ds4'">
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button" type="button" data-bs-toggle="collapse"
data-bs-target="#panelsStayOpen-collapseOne">
Manual DS4 options
</button>
</h2>
<div id="panelsStayOpen-collapseOne" class="accordion-collapse collapse show"
aria-labelledby="panelsStayOpen-headingOne">
<div class="accordion-body">
<div>
<label for="ds4_back_as_touchpad_click" class="form-label">Map Back/Select to Touchpad Click</label>
<select id="ds4_back_as_touchpad_click" class="form-select"
v-model="config.ds4_back_as_touchpad_click">
<option value="disabled">Disabled</option>
<option value="enabled">Enabled (default)</option>
</select>
<div class="form-text">When forcing DS4 emulation, map Back/Select to Touchpad Click</div>
</div>
</div>
</div>
</div>
</div>
<div class="accordion" v-if="config.gamepad === 'auto'">
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button" type="button" data-bs-toggle="collapse"
data-bs-target="#panelsStayOpen-collapseOne">
Automatic selection options
</button>
</h2>
<div id="panelsStayOpen-collapseOne" class="accordion-collapse collapse show"
aria-labelledby="panelsStayOpen-headingOne">
<div class="accordion-body">
<div>
<label for="motion_as_ds4" class="form-label">Emulate a DS4 gamepad if the client gamepad reports motion sensors are present</label>
<select id="motion_as_ds4" class="form-select"
v-model="config.motion_as_ds4">
<option value="disabled">Disabled</option>
<option value="enabled">Enabled (default)</option>
</select>
<div class="form-text">If disabled, motion sensors will not be taken into account during gamepad type selection.</div>
</div>
<div>
<label for="touchpad_as_ds4" class="form-label">Emulate a DS4 gamepad if the client gamepad reports a touchpad is present</label>
<select id="touchpad_as_ds4" class="form-select"
v-model="config.touchpad_as_ds4">
<option value="disabled">Disabled</option>
<option value="enabled">Enabled (default)</option>
</select>
<div class="form-text">If disabled, touchpad presence will not be taken into account during gamepad type selection.</div>
</div>
</div>
</div>
</div>
</div>
<!--Home/Guide Button Emulation Timeout-->
<div class="mb-3">
<label for="back_button_timeout" class="form-label">Home/Guide Button Emulation Timeout</label>
@ -829,6 +862,7 @@
"key_rightalt_to_key_win": "disabled",
"keyboard": "enabled",
"min_log_level": 2,
"motion_as_ds4": "enabled",
"mouse": "enabled",
"nvenc_h264_cavlc": "disabled",
"nvenc_preset": "1",
@ -840,6 +874,7 @@
"resolutions": "[352x240,480x360,858x480,1280x720,1920x1080,2560x1080,3440x1440,1920x1200,3840x2160,3840x1600]",
"sw_preset": "superfast",
"sw_tune": "zerolatency",
"touchpad_as_ds4": "enabled",
"upnp": "disabled",
"vt_coder": "auto",
"vt_realtime": "enabled",