Sunshine0.0.5917
Sunshine 0.0.5917
Self-hosted game stream host for Moonlight.
Loading...
Searching...
No Matches
Go to the documentation of this file.
1
5#pragma once
6
7// standard includes
8#include <cstddef>
9#include <cstdint>
10#include <functional>
11#include <memory>
12#include <span>
13#include <string_view>
14#include <vector>
15
16// local includes
17#include "platform/common.h"
18#include "thread_safe.h"
19
20namespace input {
21 struct input_t;
22
28 void print(void *input);
34 void reset(std::shared_ptr<input_t> &input);
35
42 void terminate_gamepads();
43
49 void terminate_gamepads(std::string_view session_id);
50
54 void passthrough(std::shared_ptr<input_t> &input, std::vector<std::uint8_t> &&input_data);
55
61 [[nodiscard]] std::unique_ptr<platf::deinit_t> init();
62
68 bool probe_gamepads();
69
77
85 std::shared_ptr<input_t> alloc(safe::mail_t mail, std::string session_id);
86
87#ifdef SUNSHINE_TESTS
88 namespace testing {
94 void set_platform_input(platf::input_t input);
95
104 int alloc_gamepad(std::shared_ptr<input_t> &input, std::uint8_t client_index, const platf::gamepad_arrival_t &metadata);
105
113 int gamepad_id(const std::shared_ptr<input_t> &input, std::uint8_t client_index);
114
119 void set_input_packet_hook(std::function<void(std::uint32_t)> hook);
120
126 void set_input_task_sink(std::function<void(std::shared_ptr<input_t>)> sink);
127
133 void process_queued_messages(std::shared_ptr<input_t> input);
134
138 struct keyboard_event_t {
139 std::uint16_t key_code;
140 bool release;
141 std::uint8_t flags;
142 bool extended = false;
143 };
144
154 void set_keyboard_sink(std::function<void(const keyboard_event_t &)> sink);
155
165 void send_keyboard_packet(std::shared_ptr<input_t> &input, std::uint16_t key_code, std::uint8_t modifiers, std::uint8_t flags, bool release);
166
174 void send_relative_mouse_packet(std::shared_ptr<input_t> &input, std::int16_t delta_x, std::int16_t delta_y);
175
179 void reset_keyboard_state();
180
184 void release_held_keys();
185
192 bool is_valid_input_packet(std::span<const std::uint8_t> packet);
193
200 std::size_t queued_input_packet_count(const std::shared_ptr<input_t> &input);
201 } // namespace testing
202#endif
203
210
211 // Offset x and y coordinates of the client
214
217
220
224 explicit operator bool() const {
225 return width != 0 && height != 0 && env_width != 0 && env_height != 0;
226 }
227 };
228
236 std::pair<float, float> scale_client_contact_area(const std::pair<float, float> &val, uint16_t rotation, const std::pair<float, float> &scalar);
237} // namespace input
Declarations for common platform specific utilities.
util::safe_ptr< input_raw_t, &freeInput > input_t
Owning pointer for a platform input backend.
Definition common.h:893
bool probe_gamepads()
Probe connected gamepads and update input capability state.
Definition input.cpp:2401
void passthrough(std::shared_ptr< input_t > &input, PNV_REL_MOUSE_MOVE_PACKET packet)
Forward a client input packet directly to the platform backend.
Definition input.cpp:771
void reset(std::shared_ptr< input_t > &input)
Reset the object to its initial empty state.
Definition input.cpp:2327
std::unique_ptr< platf::deinit_t > init()
Initialize the platform input backend.
Definition input.cpp:2392
void terminate_gamepads()
Destroy every retained virtual gamepad session.
Definition input.cpp:2335
void refresh_virtual_input()
Recreate shared libvirtualhid keyboard and mouse devices after a license-state change.
Definition input.cpp:2408
void print(PNV_REL_MOUSE_MOVE_PACKET packet)
Write a debug log representation of the input packet.
Definition input.cpp:472
std::shared_ptr< input_t > alloc(safe::mail_t mail, std::string session_id)
Allocate and initialize platform input state for a stream.
Definition input.cpp:2425
int alloc_gamepad(std::shared_ptr< input_t > &input, int client_index, const platf::gamepad_arrival_t &arrival)
Allocate a virtual gamepad for a client-relative controller slot.
Definition input.cpp:1329
boost::shared_ptr< boost::log::sinks::asynchronous_sink< boost::log::sinks::text_ostream_backend > > sink
Sink.
Definition logging.cpp:40
Handles process-wide communication.
Definition globals.h:34
Input emulation settings loaded from configuration.
Definition input.cpp:281
Touchscreen coordinate bounds used to scale absolute input.
Definition input.h:207
int env_width
Width of the full capture environment in physical pixels.
Definition input.h:208
float client_offsetY
Vertical client viewport offset used when scaling touch input.
Definition input.h:213
int env_logical_width
Width of the full capture environment after display scaling.
Definition input.h:218
float client_offsetX
Horizontal client viewport offset used when scaling touch input.
Definition input.h:212
float scalar_tpcoords
Scale factor from client coordinates to touch-port coordinates.
Definition input.h:216
int env_logical_height
Height of the full capture environment after display scaling.
Definition input.h:219
float scalar_inv
Inverse scale factor from client coordinates to display coordinates.
Definition input.h:215
int env_height
Height of the full capture environment in physical pixels.
Definition input.h:209
Capabilities reported when a controller is connected.
Definition common.h:445
Touchscreen coordinate bounds used to scale absolute input.
Definition common.h:387
int height
Frame or display height in pixels.
Definition common.h:391
int width
Frame or display width in pixels.
Definition common.h:390
Declarations for thread-safe data structures.
std::shared_ptr< mail_raw_t > mail_t
Shared mailbox handle used by event and queue wrappers.
Definition thread_safe.h:753