Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
[submodule "third-party/glad"]
path = third-party/glad
url = https://github.com/Dav1dde/glad.git
[submodule "third-party/inputtino"]
path = third-party/inputtino
url = https://github.com/games-on-whales/inputtino.git
branch = stable
[submodule "third-party/libdisplaydevice"]
path = third-party/libdisplaydevice
url = https://github.com/LizardByte/libdisplaydevice.git
branch = master
[submodule "third-party/libvirtualhid"]
path = third-party/libvirtualhid
url = https://github.com/LizardByte/libvirtualhid.git
branch = master
[submodule "third-party/lizardbyte-common"]
path = third-party/lizardbyte-common
url = https://github.com/LizardByte/lizardbyte-common.git
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.24)
# `CMAKE_CUDA_ARCHITECTURES` requires 3.18
# `set_source_files_properties` requires 3.18
# `cmake_path(CONVERT ... TO_NATIVE_PATH_LIST ...)` requires 3.20
# `third-party/libvirtualhid` requires 3.24
# todo - set this conditionally

project(Sunshine VERSION 0.0.0
Expand Down
23 changes: 10 additions & 13 deletions cmake/compile_definitions/linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -297,23 +297,20 @@ if(NOT ${CUDA_FOUND}
message(FATAL_ERROR "Couldn't find either cuda, libdrm, libva, kwin, pipewire, portal, wayland or x11")
endif()

# These need to be set before adding the inputtino subdirectory in order for them to be picked up
# These need to be set before adding the libvirtualhid subdirectory in order for them to be picked up
set(LIBEVDEV_CUSTOM_INCLUDE_DIR "${EVDEV_INCLUDE_DIR}")
set(LIBEVDEV_CUSTOM_LIBRARY "${EVDEV_LIBRARY}")
if(FREEBSD)
set(USE_UHID OFF)
endif()

add_subdirectory("${CMAKE_SOURCE_DIR}/third-party/inputtino")
list(APPEND SUNSHINE_EXTERNAL_LIBRARIES inputtino::libinputtino)
file(GLOB_RECURSE INPUTTINO_SOURCES
${CMAKE_SOURCE_DIR}/src/platform/linux/input/inputtino*.h
${CMAKE_SOURCE_DIR}/src/platform/linux/input/inputtino*.cpp)
list(APPEND PLATFORM_TARGET_FILES ${INPUTTINO_SOURCES})
add_subdirectory("${CMAKE_SOURCE_DIR}/third-party/libvirtualhid")
list(APPEND SUNSHINE_EXTERNAL_LIBRARIES libvirtualhid::libvirtualhid)
list(APPEND PLATFORM_TARGET_FILES
"${CMAKE_SOURCE_DIR}/src/platform/virtualhid_input.h"
"${CMAKE_SOURCE_DIR}/src/platform/virtualhid_input.cpp"
"${CMAKE_SOURCE_DIR}/src/platform/linux/input/virtualhid.cpp")

# build libevdev before the libinputtino target
if(EXTERNAL_PROJECT_LIBEVDEV_USED)
add_dependencies(libinputtino libevdev)
# build libevdev before the libvirtualhid target when using the ExternalProject fallback
if(EXTERNAL_PROJECT_LIBEVDEV_USED AND TARGET libvirtualhid)
add_dependencies(libvirtualhid libevdev)
endif()

# AppImage and Flatpak
Expand Down
7 changes: 7 additions & 0 deletions cmake/compile_definitions/windows.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ file(GLOB NVPREFS_FILES CONFIGURE_DEPENDS
# vigem
include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/third-party/ViGEmClient/include")

# libvirtualhid
add_subdirectory("${CMAKE_SOURCE_DIR}/third-party/libvirtualhid")

# sunshine icon
if(NOT DEFINED SUNSHINE_ICON_PATH)
set(SUNSHINE_ICON_PATH "${CMAKE_SOURCE_DIR}/sunshine.ico")
Expand Down Expand Up @@ -73,6 +76,8 @@ set(PLATFORM_TARGET_FILES
"${CMAKE_SOURCE_DIR}/src/platform/windows/audio.cpp"
"${CMAKE_SOURCE_DIR}/src/platform/windows/utf_utils.cpp"
"${CMAKE_SOURCE_DIR}/src/platform/windows/utf_utils.h"
"${CMAKE_SOURCE_DIR}/src/platform/virtualhid_input.h"
"${CMAKE_SOURCE_DIR}/src/platform/virtualhid_input.cpp"
"${CMAKE_SOURCE_DIR}/third-party/ViGEmClient/src/ViGEmClient.cpp"
"${CMAKE_SOURCE_DIR}/third-party/ViGEmClient/include/ViGEm/Client.h"
"${CMAKE_SOURCE_DIR}/third-party/ViGEmClient/include/ViGEm/Common.h"
Expand Down Expand Up @@ -105,3 +110,5 @@ list(PREPEND PLATFORM_LIBRARIES
ws2_32
wsock32
)

list(APPEND SUNSHINE_EXTERNAL_LIBRARIES libvirtualhid::libvirtualhid)
29 changes: 19 additions & 10 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,30 +332,40 @@ editing the `conf` file in a text editor. Use the examples as reference.
@endcode</td>
</tr>
<tr>
<td rowspan="6">Choices</td>
<td rowspan="7">Choices</td>
<td>generic</td>
<td>Generic HID gamepad
@note{This option applies to FreeBSD, Linux, and Windows.}</td>
</tr>
<tr>
<td>ds4</td>
<td>DualShock 4 controller (PS4)
@note{This option applies to Windows only.}</td>
@note{This option applies to FreeBSD, Linux, and Windows.}</td>
</tr>
<tr>
<td>ds5</td>
<td>DualShock 5 controller (PS5)
@note{This option applies to FreeBSD and Linux only.}</td>
@note{This option applies to FreeBSD, Linux, and Windows.}</td>
</tr>
<tr>
<td>switch</td>
<td>Switch Pro controller
@note{This option applies to FreeBSD and Linux only.}</td>
@note{This option applies to FreeBSD, Linux, and Windows.}</td>
</tr>
<tr>
<td>x360</td>
<td>Xbox 360 controller
@note{This option applies to Windows only.}</td>
@note{This option applies to FreeBSD, Linux, and Windows.}</td>
</tr>
<tr>
<td>xone</td>
<td>Xbox One controller
@note{This option applies to FreeBSD and Linux only.}</td>
@note{This option applies to FreeBSD, Linux, and Windows.}</td>
</tr>
<tr>
<td>xseries</td>
<td>Xbox Series controller
@note{This option applies to FreeBSD, Linux, and Windows.}</td>
</tr>
</table>

Expand Down Expand Up @@ -440,14 +450,13 @@ editing the `conf` file in a text editor. Use the examples as reference.
</tr>
</table>

### ds5_inputtino_randomize_mac
### virtualhid_randomize_mac

<table>
<tr>
<td>Description</td>
<td colspan="2">
Randomize the MAC-Address for the generated virtual controller.
@hint{Only applies on linux for gamepads created as PS5-style controllers}
Randomize the MAC address for PlayStation-style virtual controllers created by libvirtualhid.
</td>
</tr>
<tr>
Expand All @@ -459,7 +468,7 @@ editing the `conf` file in a text editor. Use the examples as reference.
<tr>
<td>Example</td>
<td colspan="2">@code{}
ds5_inputtino_randomize_mac = enabled
virtualhid_randomize_mac = enabled
@endcode</td>
</tr>
</table>
Expand Down
3 changes: 2 additions & 1 deletion docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,8 @@ and enter its device name in the [audio_sink](configuration.md#audio_sink) field
> Gamepads are not currently supported.

### Windows
In order for virtual gamepads to work, you must install ViGEmBus. You can do this from the troubleshooting tab
Sunshine uses libvirtualhid for virtual gamepads on Windows. ViGEmBus is only used as a fallback for Xbox 360
and DualShock 4 gamepads when libvirtualhid is unavailable. You can install ViGEmBus from the troubleshooting tab
in the web UI, as long as you are running Sunshine as a service or as an administrator. After installation, it is
recommended to restart your computer.

Expand Down
4 changes: 3 additions & 1 deletion docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ launchctl load -w /Library/LaunchAgents/org.freedesktop.dbus-session.plist
## Windows
### No gamepad detected
You must install ViGEmBus to use virtual gamepads. You can install this from the troubleshooting tab of the web UI.
Sunshine uses libvirtualhid for virtual gamepads on Windows. ViGEmBus is only needed as a fallback for Xbox 360
and DualShock 4 gamepads when libvirtualhid is unavailable. You can install ViGEmBus from the troubleshooting tab
of the web UI.
Alternatively, you can manually install it from
[ViGEmBus releases](https://github.com/nefarius/ViGEmBus/releases/latest). You must use version 1.17 or newer.
Expand Down
1 change: 0 additions & 1 deletion gh-pages-template/_data/features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
Sunshine emulates an Xbox, PlayStation, or Nintendo Switch controller.
Use nearly any controller on your Moonlight client!
<br><small><ul>
<li>Nintendo Switch emulation is only available on Linux.</li>
<li>Gamepad emulation is not currently supported on macOS.</li>
</ul></small>
Expand Down
4 changes: 2 additions & 2 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ namespace config {
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, // ds5_inputtino_randomize_mac
true, // virtualhid_randomize_mac

true, // keyboard enabled
true, // mouse enabled
Expand Down Expand Up @@ -1690,7 +1690,7 @@ namespace config {
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, "ds5_inputtino_randomize_mac", input.ds5_inputtino_randomize_mac);
bool_f(vars, "virtualhid_randomize_mac", input.virtualhid_randomize_mac);

bool_f(vars, "mouse", input.mouse);
bool_f(vars, "keyboard", input.keyboard);
Expand Down
2 changes: 1 addition & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ namespace config {
bool ds4_back_as_touchpad_click; ///< Map the DS4 Back button to a touchpad click.
bool motion_as_ds4; ///< Expose motion controls through the DS4 protocol.
bool touchpad_as_ds4; ///< Expose touchpad input through the DS4 protocol.
bool ds5_inputtino_randomize_mac; ///< Randomize the inputtino DualSense MAC address.
bool virtualhid_randomize_mac; ///< Randomize the libvirtualhid virtual controller MAC address.

bool keyboard; ///< Enable keyboard input from clients.
bool key_rightalt_to_key_win; ///< Map the client Right Alt key to the Windows key.
Expand Down
8 changes: 4 additions & 4 deletions src/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ extern "C" {
#include <chrono>
#include <cmath>
#include <list>
#include <memory>
#include <thread>
#include <unordered_map>

Expand Down Expand Up @@ -610,8 +611,8 @@ namespace input {
This final operation is a bit weird and has been brought about with lots of trial and error. A better
way to do this may exist.

Basically, this is what makes the touchscreen map to the coordinates inputtino expects properly.
Since inputtino's dimensions are now logical (because scaling breaks everything otherwise), using the previous
Basically, this is what makes the touchscreen map to the logical virtual input coordinates properly.
Since the virtual input dimensions are logical (because scaling breaks everything otherwise), using the previous
x and y coordinates would be incorrect when screens are scaled, because the touch port is smaller (or larger)
by a factor (that factor is touch_port.scalar_tpcoords), and that factor must be used to account for that difference
when moving the cursor. Otherwise, it will move either slower or faster than your finger proportionally to
Expand Down Expand Up @@ -1880,8 +1881,7 @@ namespace input {
* @brief Probe connected gamepads and update input capability state.
*/
bool probe_gamepads() {
auto input = static_cast<platf::input_t *>(platf_input.get());
const auto gamepads = platf::supported_gamepads(input);
const auto gamepads = platf::supported_gamepads(std::addressof(platf_input));
for (auto &gamepad : gamepads) {
if (gamepad.is_enabled && gamepad.name != "auto") {
return false;
Expand Down
Loading
Loading