Sunshine master
Self-hosted game stream host for Moonlight.
inputtino_common.h
Go to the documentation of this file.
1
5#pragma once
6
7// lib includes
8#include <boost/locale.hpp>
9#include <inputtino/input.hpp>
10#include <libevdev/libevdev.h>
11
12// local includes
13#include "src/config.h"
14#include "src/logging.h"
15#include "src/platform/common.h"
17#include "src/utility.h"
18
19using namespace std::literals;
20
21namespace platf {
22
29 inline std::string inputtino_name_for_seat(std::string_view base_name) {
30 auto seat_id = inputtino_seat::get_target_seat();
31 if (seat_id.empty() || seat_id == "seat0") {
32 return std::string(base_name);
33 }
34
35 std::string name;
36 name.reserve(base_name.size() + seat_id.size() + 3);
37 name.append(base_name);
38 name.append(" (");
39 name.append(seat_id);
40 name.push_back(')');
41 return name;
42 }
43
47 using joypads_t = std::variant<inputtino::XboxOneJoypad, inputtino::SwitchJoypad, inputtino::PS5Joypad>;
48
57
61 struct input_raw_t {
63 mouse(inputtino::Mouse::create({
64 .name = inputtino_name_for_seat("Mouse passthrough"sv),
65 .vendor_id = 0xBEEF,
66 .product_id = 0xDEAD,
67 .version = 0x111,
68 })),
69 keyboard(inputtino::Keyboard::create({
70 .name = inputtino_name_for_seat("Keyboard passthrough"sv),
71 .vendor_id = 0xBEEF,
72 .product_id = 0xDEAD,
73 .version = 0x111,
74 })),
75 gamepads(MAX_GAMEPADS) {
76 if (!mouse) {
77 BOOST_LOG(warning) << "Unable to create virtual mouse: " << mouse.getErrorMessage();
78 }
79 if (!keyboard) {
80 BOOST_LOG(warning) << "Unable to create virtual keyboard: " << keyboard.getErrorMessage();
81 }
82 }
83
84 ~input_raw_t() = default;
85
86 // All devices are wrapped in Result because it might be that we aren't able to create them (ex: udev permission denied)
87 inputtino::Result<inputtino::Mouse> mouse;
88 inputtino::Result<inputtino::Keyboard> keyboard;
89
94 std::vector<std::shared_ptr<joypad_state>> gamepads;
95 };
96
100 struct client_input_raw_t: public client_input_t {
107 touch(inputtino::TouchScreen::create({
108 .name = inputtino_name_for_seat("Touch passthrough"sv),
109 .vendor_id = 0xBEEF,
110 .product_id = 0xDEAD,
111 .version = 0x111,
112 })),
113 pen(inputtino::PenTablet::create({
114 .name = inputtino_name_for_seat("Pen passthrough"sv),
115 .vendor_id = 0xBEEF,
116 .product_id = 0xDEAD,
117 .version = 0x111,
118 })) {
119 global = (input_raw_t *) input.get();
120 if (!touch) {
121 BOOST_LOG(warning) << "Unable to create virtual touch screen: " << touch.getErrorMessage();
122 }
123 if (!pen) {
124 BOOST_LOG(warning) << "Unable to create virtual pen tablet: " << pen.getErrorMessage();
125 }
126 }
127
129
130 // Device state and handles for pen and touch input must be stored in the per-client
131 // input context, because each connected client may be sending their own independent
132 // pen/touch events. To maintain separation, we expose separate pen and touch devices
133 // for each client.
134 inputtino::Result<inputtino::TouchScreen> touch;
135 inputtino::Result<inputtino::PenTablet> pen;
136 };
137
144 inline float deg2rad(float degree) {
145 return degree * (M_PI / 180.f);
146 }
147} // namespace platf
RAII helper that runs shutdown cleanup when destroyed.
Definition common.h:491
Unique pointer wrapper with customizable pointer and deleter types.
Definition utility.h:820
Declarations for common platform specific utilities.
Declarations for the configuration of Sunshine.
float deg2rad(float degree)
Convert degrees to radians for controller motion data.
Definition inputtino_common.h:144
std::variant< inputtino::XboxOneJoypad, inputtino::SwitchJoypad, inputtino::PS5Joypad > joypads_t
Variant of inputtino virtual gamepad implementations Sunshine can create.
Definition inputtino_common.h:47
std::string inputtino_name_for_seat(std::string_view base_name)
Append the target seat name to an inputtino device name when needed.
Definition inputtino_common.h:29
Helpers for multi-seat naming (udev-only).
bl::sources::severity_logger< int > warning
Strange events.
Definition logging.cpp:43
Declarations for logging related functions.
Per-client inputtino devices for touch and pen input.
Definition input.cpp:731
input_raw_t * global
Shared inputtino device set owned by the global input context.
Definition inputtino_common.h:128
client_input_raw_t(input_t &input)
Create per-client inputtino devices for touch and pen input.
Definition inputtino_common.h:106
inputtino::Result< inputtino::TouchScreen > touch
Per-client virtual touchscreen device.
Definition inputtino_common.h:134
inputtino::Result< inputtino::PenTablet > pen
Per-client virtual pen tablet device.
Definition inputtino_common.h:135
Feedback command sent from Sunshine to a virtual gamepad.
Definition common.h:124
Global inputtino device handles shared by clients.
Definition input.cpp:506
inputtino::Result< inputtino::Keyboard > keyboard
inputtino virtual keyboard device.
Definition inputtino_common.h:88
std::vector< std::shared_ptr< joypad_state > > gamepads
Definition inputtino_common.h:94
inputtino::Result< inputtino::Mouse > mouse
Shared inputtino virtual mouse device.
Definition inputtino_common.h:87
inputtino joypad collection and its ownership state.
Definition inputtino_common.h:52
std::unique_ptr< joypads_t > joypad
Active virtual gamepad object for one connected client slot.
Definition inputtino_common.h:53
gamepad_feedback_msg_t last_rgb_led
Last RGB led.
Definition inputtino_common.h:55
gamepad_feedback_msg_t last_rumble
Last rumble.
Definition inputtino_common.h:54
Declarations for utility functions.