Definitions for input handling on Windows. More...
#include <array>#include <Windows.h>#include <memory>#include <thread>#include <vector>#include <libvirtualhid/license.hpp>#include <ViGEm/Client.h>#include "input.h"#include "misc.h"#include "src/config.h"#include "src/globals.h"#include "src/logging.h"#include "src/platform/common.h"#include "src/platform/virtualhid_input.h"Classes | |
| struct | platf::client_input_raw_t |
| Per-client virtual devices for touch and pen input. More... | |
| struct | platf::gamepad_context_t |
| ViGEm target and report buffers for one virtual gamepad. More... | |
| struct | platf::gp_touch_context_t |
| Last touch coordinates reported by a virtual gamepad. More... | |
| struct | platf::input_raw_t |
| Global virtual input device handles shared by clients. More... | |
| class | platf::vigem_t |
| ViGEm client connection and virtual gamepad collection. More... | |
Macros | |
| #define | APPLY_CALIBRATION(val, bias, scale) |
| Macro for APPLY CALIBRATION. | |
| #define | CALLBACK |
| Windows callback calling convention marker. | |
| #define | DPS_TO_DS4_GYRO(x) |
| Macro for DPS TO DS4 GYRO. | |
| #define | MPS2_TO_DS4_ACCEL(x) |
| Macro for MPS2 TO DS4 ACCEL. | |
Typedefs | |
| using | platf::client_t = util::safe_ptr<_VIGEM_CLIENT_T, &vigem_free> |
| ViGEm client pointer released with vigem_free. | |
| using | platf::target_t = util::safe_ptr<_VIGEM_TARGET_T, &vigem_target_free> |
| ViGEm target pointer released with vigem_target_free. | |
Functions | |
| int | platf::alloc_gamepad (input_t &input, const gamepad_id_t &id, const gamepad_arrival_t &metadata, feedback_queue_t feedback_queue) |
| Create a new virtual gamepad. | |
| std::unique_ptr< client_input_t > | platf::allocate_client_input_context (input_t &input) |
| Allocate a context to store per-client input data. | |
| void | platf::ds4_notify (client_t::pointer client, target_t::pointer target, std::uint8_t largeMotor, std::uint8_t smallMotor, DS4_LIGHTBAR_COLOR, void *userdata) |
| Handle DualShock 4 virtual gamepad notification events. | |
| void | platf::ds4_update_ts_and_send (vigem_t *vigem, int nr) |
| Sends DS4 input with updated timestamps and repeats to keep timestamp updated. | |
| bool | platf::ensure_vigem (input_raw_t *raw) |
| Create the ViGEm fallback context if it is not already available. | |
| void | platf::free_gamepad (input_t &input, int nr) |
| Release gamepad resources. | |
| void | platf::freeInput (input_raw_t *input) |
| Release a platform input backend created by input(). | |
| void | platf::gamepad_battery (input_t &input, const gamepad_battery_t &battery) |
| Send a gamepad battery event to the OS. | |
| void | platf::gamepad_motion (input_t &input, const gamepad_motion_t &motion) |
| Send a gamepad motion event to the OS. | |
| void | platf::gamepad_touch (input_t &input, const gamepad_touch_t &touch) |
| Send a gamepad touch event to the OS. | |
| void | platf::gamepad_update (input_t &input, int nr, const gamepad_state_t &gamepad_state) |
| Submit updated Sunshine gamepad state to the virtual device. | |
| platform_caps::caps_t | platf::get_capabilities () |
| Get the supported platform capabilities to advertise to the client. | |
| std::optional< util::point_t > | platf::get_mouse_loc (input_t &input) |
| Get the current mouse position for platform input tests. | |
| input_t | platf::input () |
| Create the platform input backend for a stream. | |
| int | platf::rebind_gamepad (input_t &input, const gamepad_id_t &id, feedback_queue_t feedback_queue) |
| Rebind an existing virtual gamepad to a resumed client session. | |
| bool | platf::should_allocate_vigembus_gamepad (const bool virtualhid_selected) |
| Check and explain whether a gamepad allocation may use ViGEmBus. | |
| bool | platf::should_use_virtualhid_gamepads (const input_raw_t &raw) |
| Check whether the libvirtualhid runtime should receive gamepad allocations. | |
| std::vector< supported_gamepad_t > & | platf::supported_gamepads (input_t *input) |
| Gets the supported gamepads for this platform backend. | |
| std::vector< supported_gamepad_t > | platf::vigembus_supported_gamepads (const bool available) |
| Return the gamepad choices supported by ViGEmBus. | |
| void | platf::x360_notify (client_t::pointer client, target_t::pointer target, std::uint8_t largeMotor, std::uint8_t smallMotor, std::uint8_t, void *userdata) |
| Handle Xbox 360 virtual gamepad notification events. | |
Variables | |
| constexpr DS4_REPORT_EX | platf::ds4_report_init_ex |
| DS4 report init ex. | |
| constexpr DS4_TOUCH | platf::ds4_touch_unused |
| DS4 touch unused. | |
| constexpr float | platf::EARTH_G = 9.80665f |
| Meters per second squared represented by one gravity unit. | |
Definitions for input handling on Windows.
| #define APPLY_CALIBRATION | ( | val, | |
| bias, | |||
| scale ) |
Macro for APPLY CALIBRATION.
| #define DPS_TO_DS4_GYRO | ( | x | ) |
Macro for DPS TO DS4 GYRO.
| #define MPS2_TO_DS4_ACCEL | ( | x | ) |
Macro for MPS2 TO DS4 ACCEL.
| int platf::alloc_gamepad | ( | input_t & | input, |
| const gamepad_id_t & | id, | ||
| const gamepad_arrival_t & | metadata, | ||
| feedback_queue_t | feedback_queue ) |
Create a new virtual gamepad.
| input | The global input context. |
| id | The gamepad ID. |
| metadata | Controller metadata from client (empty if none provided). |
| feedback_queue | The queue for posting messages back to the client. |
| std::unique_ptr< client_input_t > platf::allocate_client_input_context | ( | input_t & | input | ) |
Allocate a context to store per-client input data.
Allocates a context to store per-client input data.
| input | The global input context. |
| void platf::ds4_notify | ( | client_t::pointer | client, |
| target_t::pointer | target, | ||
| std::uint8_t | largeMotor, | ||
| std::uint8_t | smallMotor, | ||
| DS4_LIGHTBAR_COLOR | led_color, | ||
| void * | userdata ) |
Handle DualShock 4 virtual gamepad notification events.
| client | ViGEm client. |
| target | ViGEm target. |
| largeMotor | Large motor strength. |
| smallMotor | Small motor strength. |
| led_color | Requested lightbar color. |
| userdata | User data pointer. |
| void platf::ds4_update_ts_and_send | ( | vigem_t * | vigem, |
| int | nr ) |
Sends DS4 input with updated timestamps and repeats to keep timestamp updated.
Some applications require updated timestamps values to register DS4 input.
| vigem | The global ViGEm context object. |
| nr | The global gamepad index. |
| bool platf::ensure_vigem | ( | input_raw_t * | raw | ) |
Create the ViGEm fallback context if it is not already available.
| raw | Platform input context. |
| void platf::free_gamepad | ( | input_t & | input, |
| int | nr ) |
Release gamepad resources.
| input | Platform input backend that receives the event. |
| nr | Controller index assigned by the client. |
| void platf::freeInput | ( | input_raw_t * | input | ) |
Release a platform input backend created by input().
| input | Platform input backend to release. |
| void platf::gamepad_battery | ( | input_t & | input, |
| const gamepad_battery_t & | battery ) |
Send a gamepad battery event to the OS.
Sends a gamepad battery event to the OS.
| input | The global input context. |
| battery | The battery event. |
| void platf::gamepad_motion | ( | input_t & | input, |
| const gamepad_motion_t & | motion ) |
Send a gamepad motion event to the OS.
Sends a gamepad motion event to the OS.
| input | The global input context. |
| motion | The motion event. |
| void platf::gamepad_touch | ( | input_t & | input, |
| const gamepad_touch_t & | touch ) |
Send a gamepad touch event to the OS.
Sends a gamepad touch event to the OS.
| input | The global input context. |
| touch | The touch event. |
| void platf::gamepad_update | ( | input_t & | input, |
| int | nr, | ||
| const gamepad_state_t & | gamepad_state ) |
Submit updated Sunshine gamepad state to the virtual device.
| input | The input context. |
| nr | The gamepad index to update. |
| gamepad_state | The gamepad button/axis state sent from the client. |
| platform_caps::caps_t platf::get_capabilities | ( | ) |
Get the supported platform capabilities to advertise to the client.
Returns the supported platform capabilities to advertise to the client.
| std::optional< util::point_t > platf::get_mouse_loc | ( | input_t & | input | ) |
Get the current mouse position for platform input tests.
| input | The input_t instance to use. |
Examples
| input_t platf::input | ( | ) |
Create the platform input backend for a stream.
| int platf::rebind_gamepad | ( | input_t & | input, |
| const gamepad_id_t & | id, | ||
| feedback_queue_t | feedback_queue ) |
Rebind an existing virtual gamepad to a resumed client session.
| input | Platform input backend that owns the virtual gamepad. |
| id | Global and client-relative identifiers for the resumed controller. |
| feedback_queue | Queue used to return gamepad feedback to the resumed client. |
| bool platf::should_allocate_vigembus_gamepad | ( | const bool | virtualhid_selected | ) |
Check and explain whether a gamepad allocation may use ViGEmBus.
| virtualhid_selected | Whether Virtual HID Driver was selected for the allocation. |
| bool platf::should_use_virtualhid_gamepads | ( | const input_raw_t & | raw | ) |
Check whether the libvirtualhid runtime should receive gamepad allocations.
Backends that do not require the installed Windows driver, such as the fake test backend, do not require a machine license.
| raw | Global Windows input context. |
| std::vector< supported_gamepad_t > & platf::supported_gamepads | ( | input_t * | input | ) |
Gets the supported gamepads for this platform backend.
This may be called prior to platf::input()!
| input | Pointer to the platform's input_t or nullptr. |
| std::vector< supported_gamepad_t > platf::vigembus_supported_gamepads | ( | const bool | available | ) |
Return the gamepad choices supported by ViGEmBus.
| available | Whether Sunshine can connect to ViGEmBus. |
| void platf::x360_notify | ( | client_t::pointer | client, |
| target_t::pointer | target, | ||
| std::uint8_t | largeMotor, | ||
| std::uint8_t | smallMotor, | ||
| std::uint8_t | , | ||
| void * | userdata ) |
Handle Xbox 360 virtual gamepad notification events.
| client | ViGEm client. |
| target | ViGEm target. |
| largeMotor | Large motor strength. |
| smallMotor | Small motor strength. |
| userdata | User data pointer. |
|
constexpr |
DS4 report init ex.
|
constexpr |
DS4 touch unused.