Skip to content

feat(input): implement libvirtualhid#5368

Draft
ReenigneArcher wants to merge 10 commits into
masterfrom
libvirtualhid
Draft

feat(input): implement libvirtualhid#5368
ReenigneArcher wants to merge 10 commits into
masterfrom
libvirtualhid

Conversation

@ReenigneArcher

@ReenigneArcher ReenigneArcher commented Jul 3, 2026

Copy link
Copy Markdown
Member

Description

This PR implements libvirtualhid in Sunshine, replacing inputtino on Linux, vigembus on Windows AMD64, and moves the mouse/keyboard input for macOS as well.

We will still falling back to vigembus on Windows ARM64 or in cases where the user doesn't have libvirtualhid's driver installed.

TODO:

  • CI/CD passing
  • Sonar
  • Test coverage
  • Testing
    • Windows
      • Gamepads
      • Keyboard
      • Mouse
      • Touchscreen
      • Pen
      • Trackpad (not supported on Windows)
    • Linux
      • Gamepads
      • Keyboard
      • Mouse
      • Touchscreen
      • Pen
      • Trackpad
    • FreeBSD
      • Gamepads
      • Keyboard
      • Mouse
      • Touchscreen
      • Pen
      • Trackpad
    • macOS
      • Gamepads (not supported on macOS)
      • Keyboard
      • Mouse
      • Touchscreen (not supported on macOS)
      • Pen (not supported on macOS)
      • Trackpad (not supported on macOS)
  • Remove vigembus helpers from web-ui
  • Create release of libvirtualhid
  • Publish libvirtualhid driver to MSFT store

Screenshot

image

Issues Fixed or Closed

Roadmap Issues

Type of Change

  • feat: New feature (non-breaking change which adds functionality)
  • fix: Bug fix (non-breaking change which fixes an issue)
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semicolons, etc.)
  • refactor: Code change that neither fixes a bug nor adds a feature
  • perf: Code change that improves performance
  • test: Adding missing tests or correcting existing tests
  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Other changes that don't modify src or test files
  • revert: Reverts a previous commit
  • BREAKING CHANGE: Introduces a breaking change (can be combined with any type above)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas
  • Code docstring/documentation-blocks for new or existing methods/components have been added or updated
  • Unit tests have been added or updated for any new or modified functionality

AI Usage

  • None: No AI tools were used in creating this PR
  • Light: AI provided minor assistance (formatting, simple suggestions)
  • Moderate: AI helped with code generation or debugging specific parts
  • Heavy: AI generated most or all of the code changes

@ReenigneArcher ReenigneArcher changed the title feat: implement libvirtualhid feat(input): implement libvirtualhid Jul 3, 2026
@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Bundle Report

Changes will increase total bundle size by 1.31kB (0.05%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
sunshine-esm 855.85kB 1.31kB (0.15%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: sunshine-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
assets/createLucideIcon-*.js 232 bytes 358.69kB 0.06%
assets/config-*.js 969 bytes 70.65kB 1.39%
assets/index-*.js 388 bytes 46.33kB 0.84%
assets/troubleshooting-*.js 135 bytes 9.21kB 1.49%
assets/download-*.js (Deleted) -414 bytes 0 bytes -100.0% 🗑️

@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 29.39262% with 651 lines in your changes missing coverage. Please review.
✅ Project coverage is 27.57%. Comparing base (0a47d3d) to head (e4bd1df).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/platform/virtualhid_input.cpp 31.97% 382 Missing and 3 partials ⚠️
src/confighttp.cpp 38.99% 88 Missing and 9 partials ⚠️
src/platform/windows/input.cpp 1.36% 68 Missing and 4 partials ⚠️
src/platform/linux/input/virtualhid.cpp 6.45% 55 Missing and 3 partials ⚠️
src/platform/macos/input.cpp 38.33% 37 Missing ⚠️
src/config.cpp 0.00% 1 Missing ⚠️
src/input.cpp 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5368      +/-   ##
==========================================
+ Coverage   27.18%   27.57%   +0.38%     
==========================================
  Files         111      105       -6     
  Lines       25412    25096     -316     
  Branches    11214    11108     -106     
==========================================
+ Hits         6909     6920      +11     
- Misses      16570    17230     +660     
+ Partials     1933      946     -987     
Flag Coverage Δ
Archlinux ?
FreeBSD-aarch64 ?
FreeBSD-amd64 12.60% <7.77%> (-0.59%) ⬇️
Homebrew-macos-14 19.80% <14.82%> (-0.56%) ⬇️
Homebrew-macos-15 19.98% <14.95%> (-0.54%) ⬇️
Homebrew-macos-26 20.10% <14.95%> (-0.54%) ⬇️
Homebrew-ubuntu-24.04 13.08% <9.05%> (+0.12%) ⬆️
Linux-AppImage 12.42% <9.05%> (+0.13%) ⬆️
Windows-AMD64 15.25% <7.42%> (+0.04%) ⬆️
Windows-ARM64 13.25% <6.32%> (+0.01%) ⬆️
macOS-arm64 18.33% <15.16%> (-0.52%) ⬇️
macOS-x86_64 17.77% <13.97%> (-0.61%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/config.h 0.00% <ø> (ø)
src/confighttp.h 100.00% <ø> (ø)
src/config.cpp 24.00% <0.00%> (ø)
src/input.cpp 18.86% <0.00%> (+0.11%) ⬆️
src/platform/macos/input.cpp 43.05% <38.33%> (-8.40%) ⬇️
src/platform/linux/input/virtualhid.cpp 6.45% <6.45%> (ø)
src/platform/windows/input.cpp 0.54% <1.36%> (+0.08%) ⬆️
src/confighttp.cpp 45.16% <38.99%> (+1.40%) ⬆️
src/platform/virtualhid_input.cpp 31.97% <31.97%> (ø)

... and 34 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0a47d3d...e4bd1df. Read the comment docs.

Replace the ViGEmBus install/status flow with a unified virtual input driver status endpoint and UI. Update Windows packaging, docs, locale strings, and troubleshooting pages to reflect libvirtualhid as the primary backend, with ViGEmBus shown only as a fallback. Add unit coverage for driver version parsing and status JSON helpers.
Replace Windows-native synthetic pointer/keyboard input implementations with libvirtualhid equivalents:

- Remove keylayout.h and its VK-to-scancode mapping (now handled by libvirtualhid)
- Remove Windows-specific touch/pen device management (HSYNTHETICPOINTERDEVICE, repeat tasks, slot compaction)
- Pass touch_port and flags through to libvirtualhid for keyboard, touch, and pen events
- Add pointer_viewport() and keyboard_event() helpers in virtualhid_input.cpp
- Differentiate LI_TOUCH_EVENT_UP, CANCEL, and HOVER_LEAVE handling for touch contacts
- Add PointerTransition support for pen events
- Update capability detection to use libvirtualhid runtime
- Update libvirtualhid submodule to c1cc7e0
Replace the macOS input implementation with a libvirtualhid-backed backend and route mouse, keyboard, scroll, touch/pen, and gamepad paths through shared virtualhid contexts. Update macOS CMake wiring to build/link libvirtualhid and include the new shared virtualhid input sources, and bump the libvirtualhid submodule to the required revision.
Move libvirtualhid integration from Linux/macOS/Windows compile definition files into common.cmake. This removes duplicated target/library/source wiring, keeps Linux-specific libevdev override variables set before inclusion, and preserves the libevdev -> libvirtualhid build dependency when using the ExternalProject fallback.
Refactor absolute mouse test to use platform-aware touch port helper and account for display origin offsets when verifying expected mouse position. Removes the incorrect `has_input_moved` assertion and updates libvirtualhid submodule.
Implement get_mouse_loc using GetCursorPos on Windows and XQueryPointer on Linux/X11. Remove the GTEST_SKIP for Windows and Linux virtual mouse tests. Replace fixed sleep with polling loop to wait for mouse movement, fix absolute mouse port to use virtual screen metrics on Windows, and relax movement assertions to direction-only checks to account for OS pointer acceleration.
Change `get_mouse_loc()` to return `std::optional<util::point_t>` instead of a sentinel value, properly indicating when the mouse location cannot be observed on a platform. Update all platform implementations (Linux, macOS, Windows) and tests to handle the optional return type. Add libxtst-dev dependency to Linux CI workflow.
@sonarqubecloud

sonarqubecloud Bot commented Jul 8, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
32 New issues
6.6% Duplication on New Code (required ≤ 2%)
32 New Code Smells (required ≤ 0)
2 Duplicated Blocks on New Code (required ≤ 0)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Comment thread src/confighttp.cpp
constexpr auto CSRF_TOKEN_LIFETIME = std::chrono::hours(1); // Tokens valid for 1 hour

constexpr auto LIBVIRTUALHID_MINIMUM_VERSION = ""sv; ///< Minimum supported libvirtualhid driver version; empty means any version.
constexpr auto VIGEMBUS_MINIMUM_VERSION = "1.17.0.0"sv; ///< Minimum supported ViGEmBus fallback driver version.

// Test: driver status JSON includes compatibility and supported version metadata
TEST(ConfigHttpDriverStatusTest, BuildDriverStatus_IncludesExpectedFields) {
const auto status = confighttp::build_driver_status(true, "1.17.0.0", "1.17.0.0");

// Test: driver status JSON includes compatibility and supported version metadata
TEST(ConfigHttpDriverStatusTest, BuildDriverStatus_IncludesExpectedFields) {
const auto status = confighttp::build_driver_status(true, "1.17.0.0", "1.17.0.0");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment