From 6ea836c511f3ffffffdff72dfd885644401a99d2 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 31 Dec 2023 19:01:37 -0600 Subject: [PATCH] Add options to control gamepad autoselection heuristics Also move gamepad type selection to the input tab while we're here --- docs/source/about/advanced_usage.rst | 36 ++++++++ src/config.cpp | 4 + src/config.h | 2 + src/platform/windows/input.cpp | 24 +++++- src_assets/common/assets/web/config.html | 103 +++++++++++++++-------- 5 files changed, 133 insertions(+), 36 deletions(-) diff --git a/docs/source/about/advanced_usage.rst b/docs/source/about/advanced_usage.rst index 0b4a687b..72926557 100644 --- a/docs/source/about/advanced_usage.rst +++ b/docs/source/about/advanced_usage.rst @@ -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 ^^^^^^^^^^^^^^^^^^^ diff --git a/src/config.cpp b/src/config.cpp index 74bb6121..030bdb1d 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -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); diff --git a/src/config.h b/src/config.h index 6e481a1f..9df7a144 100644 --- a/src/config.h +++ b/src/config.h @@ -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; diff --git a/src/platform/windows/input.cpp b/src/platform/windows/input.cpp index ab4d7262..5559719b 100644 --- a/src/platform/windows/input.cpp +++ b/src/platform/windows/input.cpp @@ -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); } diff --git a/src_assets/common/assets/web/config.html b/src_assets/common/assets/web/config.html index ccf2b6aa..d49bee69 100644 --- a/src_assets/common/assets/web/config.html +++ b/src_assets/common/assets/web/config.html @@ -90,40 +90,6 @@
Automatically configure port forwarding
- -
- - -
Choose which type of gamepad to emulate on the host
-
-
-
-

- -

-
-
-
- - -
When forcing DS4 emulation, map Back/Select to Touchpad Click
-
-
-
-
-
@@ -266,6 +232,73 @@
+ +
+ + +
Choose which type of gamepad to emulate on the host
+
+
+
+

+ +

+
+
+
+ + +
When forcing DS4 emulation, map Back/Select to Touchpad Click
+
+
+
+
+
+
+
+

+ +

+
+
+
+ + +
If disabled, motion sensors will not be taken into account during gamepad type selection.
+
+
+ + +
If disabled, touchpad presence will not be taken into account during gamepad type selection.
+
+
+
+
+
@@ -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",