-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathinput.h
More file actions
145 lines (125 loc) · 5.01 KB
/
Copy pathinput.h
File metadata and controls
145 lines (125 loc) · 5.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
* @file src/input.h
* @brief Declarations for gamepad, keyboard, and mouse input handling.
*/
#pragma once
// standard includes
#include <functional>
#include <string_view>
// local includes
#include "platform/common.h"
#include "thread_safe.h"
namespace input {
struct input_t;
/**
* @brief Write a debug log representation of the input packet.
*
* @param input Raw input packet to format for logging.
*/
void print(void *input);
/**
* @brief Reset stream input state after a client disconnect or shutdown.
*
* @param input Shared stream input state to reset.
*/
void reset(std::shared_ptr<input_t> &input);
/**
* @brief Destroy every retained virtual gamepad session.
*
* Retained gamepads survive a paused transport connection so they can be reused on resume. Call this when the
* streamed application or all streaming sessions are explicitly terminated.
*/
void terminate_gamepads();
/**
* @brief Destroy virtual gamepads retained for one paired client.
*
* @param session_id Stable paired-client identity used by alloc().
*/
void terminate_gamepads(std::string_view session_id);
/**
* @brief Queue a raw input message for platform passthrough.
*/
void passthrough(std::shared_ptr<input_t> &input, std::vector<std::uint8_t> &&input_data);
/**
* @brief Initialize global input resources and platform backends.
*
* @return Cleanup handle for initialized input resources, or null if none are required.
*/
[[nodiscard]] std::unique_ptr<platf::deinit_t> init();
/**
* @brief Probe whether the platform can create virtual gamepads.
*
* @return True when at least one configured gamepad backend is available.
*/
bool probe_gamepads();
/**
* @brief Recreate shared libvirtualhid keyboard and mouse devices after a license-state change.
*
* The work is serialized with streamed input so both backends can switch
* safely between the Windows HID and SendInput paths.
*/
void refresh_virtual_input();
/**
* @brief Allocate and initialize platform input state for a stream.
*
* @param mail Mailbox used to exchange messages with worker threads.
* @param session_id Stable paired-client identity shared by launch and resume connections.
* @return Shared input state bound to the stream mailbox.
*/
std::shared_ptr<input_t> alloc(safe::mail_t mail, std::string session_id);
#ifdef SUNSHINE_TESTS
namespace testing {
/**
* @brief Replace the global platform input backend for a unit test.
*
* @param input Test-owned platform input backend.
*/
void set_platform_input(platf::input_t input);
/**
* @brief Allocate a gamepad directly in retained input state for a unit test.
*
* @param input Retained input state.
* @param client_index Client-relative controller index.
* @param metadata Client-reported controller metadata.
* @return Assigned global gamepad slot, or -1 on failure.
*/
int alloc_gamepad(std::shared_ptr<input_t> &input, std::uint8_t client_index, const platf::gamepad_arrival_t &metadata);
/**
* @brief Return the global gamepad slot stored for a test controller.
*
* @param input Retained input state.
* @param client_index Client-relative controller index.
* @return Assigned global gamepad slot, or -1 when unallocated.
*/
int gamepad_id(const std::shared_ptr<input_t> &input, std::uint8_t client_index);
} // namespace testing
#endif
/**
* @brief Touchscreen coordinate bounds used to scale absolute input.
*/
struct touch_port_t: public platf::touch_port_t {
int env_width; ///< Width of the full capture environment in physical pixels.
int env_height; ///< Height of the full capture environment in physical pixels.
// Offset x and y coordinates of the client
float client_offsetX; ///< Horizontal client viewport offset used when scaling touch input.
float client_offsetY; ///< Vertical client viewport offset used when scaling touch input.
float scalar_inv; ///< Inverse scale factor from client coordinates to display coordinates.
float scalar_tpcoords; ///< Scale factor from client coordinates to touch-port coordinates.
int env_logical_width; ///< Width of the full capture environment after display scaling.
int env_logical_height; ///< Height of the full capture environment after display scaling.
/**
* @brief Check whether the touch-port bounds are initialized.
*/
explicit operator bool() const {
return width != 0 && height != 0 && env_width != 0 && env_height != 0;
}
};
/**
* @brief Scale the ellipse axes according to the provided size.
* @param val The major and minor axis pair.
* @param rotation The rotation value from the touch/pen event.
* @param scalar The scalar cartesian coordinate pair.
* @return The major and minor axis pair.
*/
std::pair<float, float> scale_client_contact_area(const std::pair<float, float> &val, uint16_t rotation, const std::pair<float, float> &scalar);
} // namespace input