|
Sunshine master
Self-hosted game stream host for Moonlight.
|
Definitions for input handling on Windows. More...
#include <Windows.h>#include <cmath>#include <thread>#include <vector>#include <ViGEm/Client.h>#include "keylayout.h"#include "misc.h"#include "src/config.h"#include "src/globals.h"#include "src/logging.h"#include "src/platform/common.h"Classes | |
| struct | platf::client_input_raw_t |
| Per-client inputtino 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 inputtino 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 | |
| void | platf::abs_mouse (input_t &input, const touch_port_t &touch_port, float x, float y) |
| Move the pointer to an absolute client-provided touch coordinate. | |
| 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::button_mouse (input_t &input, int button, bool release) |
| Press or release a virtual mouse button. | |
| void | platf::cancel_all_active_touches (client_input_raw_t *raw) |
| Cancels all active touches. | |
| 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. | |
| void | platf::free_gamepad (input_t &input, int nr) |
| Release gamepad resources. | |
| void | platf::freeInput (void *) |
| 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. | |
| util::point_t | platf::get_mouse_loc (input_t &input) |
| Get the current mouse position on screen. | |
| void | platf::hscroll (input_t &input, int distance) |
| Apply a horizontal scroll event to the virtual mouse. | |
| bool | platf::inject_synthetic_pointer_input (input_raw_t *input, HSYNTHETICPOINTERDEVICE device, const POINTER_TYPE_INFO *pointerInfo, UINT32 count) |
| Calls InjectSyntheticPointerInput() and switches input desktops if required. | |
| input_t | platf::input () |
| Create the platform input backend for a stream. | |
| void | platf::keyboard_update (input_t &input, uint16_t modcode, bool release, uint8_t flags) |
| Press or release a virtual keyboard key. | |
| void | platf::move_mouse (input_t &input, int deltaX, int deltaY) |
| Move mouse using the backend coordinate system. | |
| void | platf::pen_update (client_input_t *input, const touch_port_t &touch_port, const pen_input_t &pen) |
| Send a pen event to the OS. | |
| void | platf::perform_touch_compaction (client_input_raw_t *raw) |
| Compacts the touch slots into a contiguous block and updates the active count. | |
| POINTER_TYPE_INFO * | platf::pointer_by_id (client_input_raw_t *raw, uint32_t pointerId, uint8_t eventType) |
| Gets a pointer slot by client-relative pointer ID, claiming a new one if necessary. | |
| void | platf::populate_common_pointer_info (POINTER_INFO &pointerInfo, const touch_port_t &touchPort, uint8_t eventType, float x, float y) |
Populate common POINTER_INFO members shared between pen and touch events. | |
| void | platf::repeat_pen (client_input_raw_t *raw) |
| Repeats the current pen state to avoid the interactions timing out. | |
| void | platf::repeat_touch (client_input_raw_t *raw) |
| Repeats the current touch state to avoid the interactions timing out. | |
| void | platf::scroll (input_t &input, int distance) |
| Apply a vertical scroll event to the virtual mouse. | |
| void | platf::send_input (INPUT &i) |
| Calls SendInput() and switches input desktops if required. | |
| std::vector< supported_gamepad_t > & | platf::supported_gamepads (input_t *input) |
| Gets the supported gamepads for this platform backend. | |
| void | platf::touch_update (client_input_t *input, const touch_port_t &touch_port, const touch_input_t &touch) |
| Send a touch event to the OS. | |
| void | platf::unicode (input_t &input, char *utf8, int size) |
| Submit UTF-8 text input to the keyboard backend. | |
| 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 | |
| thread_local HDESK | platf::_lastKnownInputDesktop = nullptr |
| Last known input desktop. | |
| 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. | |
| constexpr auto | platf::EDGE_TRIGGERED_POINTER_FLAGS = POINTER_FLAG_DOWN | POINTER_FLAG_UP | POINTER_FLAG_CANCELED | POINTER_FLAG_UPDATE |
| Protocol or platform constant for edge triggered pointer flags. | |
| constexpr auto | platf::ISPI_REPEAT_INTERVAL = 50ms |
| Protocol or platform constant for ispi repeat interval. | |
| constexpr touch_port_t | platf::target_touch_port |
| Target touch port. | |
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.
| void platf::abs_mouse | ( | input_t & | input, |
| const touch_port_t & | touch_port, | ||
| float | x, | ||
| float | y ) |
Move the pointer to an absolute client-provided touch coordinate.
| input | Platform input backend that receives the event. |
| touch_port | Touch coordinate bounds used for scaling. |
| x | Horizontal absolute coordinate from the client. |
| y | Vertical absolute coordinate from the client. |
| 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::button_mouse | ( | input_t & | input, |
| int | button, | ||
| bool | release ) |
Press or release a virtual mouse button.
| input | Platform input backend that receives the event. |
| button | Mouse button identifier to press or release. |
| release | Whether the key or button event is a release. |
| void platf::cancel_all_active_touches | ( | client_input_raw_t * | raw | ) |
Cancels all active touches.
| raw | The raw client-specific 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. |
| 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 | ( | void * | p | ) |
Release a platform input backend created by input().
| p | Pointer passed to the deleter or conversion helper. |
| 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.
| util::point_t platf::get_mouse_loc | ( | input_t & | input | ) |
Get the current mouse position on screen.
| input | The input_t instance to use. |
*Examples**
| void platf::hscroll | ( | input_t & | input, |
| int | distance ) |
Apply a horizontal scroll event to the virtual mouse.
| input | Platform input backend that receives the event. |
| distance | High-resolution scroll distance reported by the client. |
| bool platf::inject_synthetic_pointer_input | ( | input_raw_t * | input, |
| HSYNTHETICPOINTERDEVICE | device, | ||
| const POINTER_TYPE_INFO * | pointerInfo, | ||
| UINT32 | count ) |
Calls InjectSyntheticPointerInput() and switches input desktops if required.
Must only be called if InjectSyntheticPointerInput() is available.
| input | The global input context. |
| device | The synthetic pointer device handle. |
| pointerInfo | An array of POINTER_TYPE_INFO structs. |
| count | The number of elements in pointerInfo. |
| input_t platf::input | ( | ) |
Create the platform input backend for a stream.
| void platf::keyboard_update | ( | input_t & | input, |
| uint16_t | modcode, | ||
| bool | release, | ||
| uint8_t | flags ) |
Press or release a virtual keyboard key.
| input | Platform input backend that receives the event. |
| modcode | Modifier key code to update. |
| release | Whether the key or button event is a release. |
| flags | Bit flags that modify the requested operation. |
| void platf::move_mouse | ( | input_t & | input, |
| int | deltaX, | ||
| int | deltaY ) |
Move mouse using the backend coordinate system.
| input | Platform input backend that receives the event. |
| deltaX | Delta x. |
| deltaY | Delta y. |
| void platf::pen_update | ( | client_input_t * | input, |
| const touch_port_t & | touch_port, | ||
| const pen_input_t & | pen ) |
Send a pen event to the OS.
Sends a pen event to the OS.
| input | The client-specific input context. |
| touch_port | The current viewport for translating to screen coordinates. |
| pen | The pen event. |
| void platf::perform_touch_compaction | ( | client_input_raw_t * | raw | ) |
Compacts the touch slots into a contiguous block and updates the active count.
Since this swaps entries around, all slot pointers/references are invalid after compaction.
| raw | The client-specific input context. |
| POINTER_TYPE_INFO * platf::pointer_by_id | ( | client_input_raw_t * | raw, |
| uint32_t | pointerId, | ||
| uint8_t | eventType ) |
Gets a pointer slot by client-relative pointer ID, claiming a new one if necessary.
| raw | The raw client-specific input context. |
| pointerId | The client's pointer ID. |
| eventType | The LI_TOUCH_EVENT value from the client. |
| void platf::populate_common_pointer_info | ( | POINTER_INFO & | pointerInfo, |
| const touch_port_t & | touchPort, | ||
| uint8_t | eventType, | ||
| float | x, | ||
| float | y ) |
Populate common POINTER_INFO members shared between pen and touch events.
| pointerInfo | The pointer info to populate. |
| touchPort | The current viewport for translating to screen coordinates. |
| eventType | The type of touch/pen event. |
| x | The normalized 0.0-1.0 X coordinate. |
| y | The normalized 0.0-1.0 Y coordinate. |
| void platf::repeat_pen | ( | client_input_raw_t * | raw | ) |
Repeats the current pen state to avoid the interactions timing out.
| raw | The raw client-specific input context. |
| void platf::repeat_touch | ( | client_input_raw_t * | raw | ) |
Repeats the current touch state to avoid the interactions timing out.
| raw | The raw client-specific input context. |
| void platf::scroll | ( | input_t & | input, |
| int | distance ) |
Apply a vertical scroll event to the virtual mouse.
| input | Platform input backend that receives the event. |
| distance | High-resolution scroll distance reported by the client. |
| void platf::send_input | ( | INPUT & | i | ) |
Calls SendInput() and switches input desktops if required.
| i | The INPUT struct to send. |
| 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. |
| void platf::touch_update | ( | client_input_t * | input, |
| const touch_port_t & | touch_port, | ||
| const touch_input_t & | touch ) |
Send a touch event to the OS.
Sends a touch event to the OS.
| input | The client-specific input context. |
| touch_port | The current viewport for translating to screen coordinates. |
| touch | The touch event. |
| void platf::unicode | ( | input_t & | input, |
| char * | utf8, | ||
| int | size ) |
Submit UTF-8 text input to the keyboard backend.
| input | Platform input backend that receives the event. |
| utf8 | UTF-8 text submitted by the client. |
| size | Number of bytes or elements requested. |
| 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.
|
constexpr |
Target touch port.