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
23 inline std::string inputtino_name_for_seat(std::string_view base_name) {
24 auto seat_id = inputtino_seat::get_target_seat();
25 if (seat_id.empty() || seat_id == "seat0") {
26 return std::string(base_name);
27 }
28
29 std::string name;
30 name.reserve(base_name.size() + seat_id.size() + 3);
31 name.append(base_name);
32 name.append(" (");
33 name.append(seat_id);
34 name.push_back(')');
35 return name;
36 }
37
38 using joypads_t = std::variant<inputtino::XboxOneJoypad, inputtino::SwitchJoypad, inputtino::PS5Joypad>;
39
40 struct joypad_state {
41 std::unique_ptr<joypads_t> joypad;
42 gamepad_feedback_msg_t last_rumble;
43 gamepad_feedback_msg_t last_rgb_led;
44 };
45
46 struct input_raw_t {
48 mouse(inputtino::Mouse::create({
49 .name = inputtino_name_for_seat("Mouse passthrough"sv),
50 .vendor_id = 0xBEEF,
51 .product_id = 0xDEAD,
52 .version = 0x111,
53 })),
54 keyboard(inputtino::Keyboard::create({
55 .name = inputtino_name_for_seat("Keyboard passthrough"sv),
56 .vendor_id = 0xBEEF,
57 .product_id = 0xDEAD,
58 .version = 0x111,
59 })),
60 gamepads(MAX_GAMEPADS) {
61 if (!mouse) {
62 BOOST_LOG(warning) << "Unable to create virtual mouse: " << mouse.getErrorMessage();
63 }
64 if (!keyboard) {
65 BOOST_LOG(warning) << "Unable to create virtual keyboard: " << keyboard.getErrorMessage();
66 }
67 }
68
69 ~input_raw_t() = default;
70
71 // All devices are wrapped in Result because it might be that we aren't able to create them (ex: udev permission denied)
72 inputtino::Result<inputtino::Mouse> mouse;
73 inputtino::Result<inputtino::Keyboard> keyboard;
74
79 std::vector<std::shared_ptr<joypad_state>> gamepads;
80 };
81
82 struct client_input_raw_t: public client_input_t {
84 touch(inputtino::TouchScreen::create({
85 .name = inputtino_name_for_seat("Touch passthrough"sv),
86 .vendor_id = 0xBEEF,
87 .product_id = 0xDEAD,
88 .version = 0x111,
89 })),
90 pen(inputtino::PenTablet::create({
91 .name = inputtino_name_for_seat("Pen passthrough"sv),
92 .vendor_id = 0xBEEF,
93 .product_id = 0xDEAD,
94 .version = 0x111,
95 })) {
96 global = (input_raw_t *) input.get();
97 if (!touch) {
98 BOOST_LOG(warning) << "Unable to create virtual touch screen: " << touch.getErrorMessage();
99 }
100 if (!pen) {
101 BOOST_LOG(warning) << "Unable to create virtual pen tablet: " << pen.getErrorMessage();
102 }
103 }
104
105 input_raw_t *global;
106
107 // Device state and handles for pen and touch input must be stored in the per-client
108 // input context, because each connected client may be sending their own independent
109 // pen/touch events. To maintain separation, we expose separate pen and touch devices
110 // for each client.
111 inputtino::Result<inputtino::TouchScreen> touch;
112 inputtino::Result<inputtino::PenTablet> pen;
113 };
114
115 inline float deg2rad(float degree) {
116 return degree * (M_PI / 180.f);
117 }
118} // namespace platf
Definition common.h:365
Definition utility.h:530
Declarations for common platform specific utilities.
Declarations for the configuration of Sunshine.
Helpers for multi-seat naming (udev-only).
Declarations for logging related functions.
Definition input.cpp:656
Definition common.h:112
Definition input.cpp:434
std::vector< std::shared_ptr< joypad_state > > gamepads
Definition inputtino_common.h:79
Definition inputtino_common.h:40
Declarations for utility functions.