Sunshine v2025.118.151840
Self-hosted game stream host for Moonlight.
inputtino_common.h
Go to the documentation of this file.
1
5#pragma once
6
7#include <boost/locale.hpp>
8#include <inputtino/input.hpp>
9#include <libevdev/libevdev.h>
10
11#include "src/config.h"
12#include "src/logging.h"
13#include "src/platform/common.h"
14#include "src/utility.h"
15
16using namespace std::literals;
17
18namespace platf {
19
20 using joypads_t = std::variant<inputtino::XboxOneJoypad, inputtino::SwitchJoypad, inputtino::PS5Joypad>;
21
22 struct joypad_state {
23 std::unique_ptr<joypads_t> joypad;
24 gamepad_feedback_msg_t last_rumble;
25 gamepad_feedback_msg_t last_rgb_led;
26 };
27
28 struct input_raw_t {
30 mouse(inputtino::Mouse::create({
31 .name = "Mouse passthrough",
32 .vendor_id = 0xBEEF,
33 .product_id = 0xDEAD,
34 .version = 0x111,
35 })),
36 keyboard(inputtino::Keyboard::create({
37 .name = "Keyboard passthrough",
38 .vendor_id = 0xBEEF,
39 .product_id = 0xDEAD,
40 .version = 0x111,
41 })),
42 gamepads(MAX_GAMEPADS) {
43 if (!mouse) {
44 BOOST_LOG(warning) << "Unable to create virtual mouse: " << mouse.getErrorMessage();
45 }
46 if (!keyboard) {
47 BOOST_LOG(warning) << "Unable to create virtual keyboard: " << keyboard.getErrorMessage();
48 }
49 }
50
51 ~input_raw_t() = default;
52
53 // All devices are wrapped in Result because it might be that we aren't able to create them (ex: udev permission denied)
54 inputtino::Result<inputtino::Mouse> mouse;
55 inputtino::Result<inputtino::Keyboard> keyboard;
56
61 std::vector<std::shared_ptr<joypad_state>> gamepads;
62 };
63
66 touch(inputtino::TouchScreen::create({
67 .name = "Touch passthrough",
68 .vendor_id = 0xBEEF,
69 .product_id = 0xDEAD,
70 .version = 0x111,
71 })),
72 pen(inputtino::PenTablet::create({
73 .name = "Pen passthrough",
74 .vendor_id = 0xBEEF,
75 .product_id = 0xDEAD,
76 .version = 0x111,
77 })) {
78 global = (input_raw_t *) input.get();
79 if (!touch) {
80 BOOST_LOG(warning) << "Unable to create virtual touch screen: " << touch.getErrorMessage();
81 }
82 if (!pen) {
83 BOOST_LOG(warning) << "Unable to create virtual pen tablet: " << pen.getErrorMessage();
84 }
85 }
86
87 input_raw_t *global;
88
89 // Device state and handles for pen and touch input must be stored in the per-client
90 // input context, because each connected client may be sending their own independent
91 // pen/touch events. To maintain separation, we expose separate pen and touch devices
92 // for each client.
93 inputtino::Result<inputtino::TouchScreen> touch;
94 inputtino::Result<inputtino::PenTablet> pen;
95 };
96
97 inline float
98 deg2rad(float degree) {
99 return degree * (M_PI / 180.f);
100 }
101} // namespace platf
Definition common.h:336
Definition utility.h:496
Declarations for common platform specific utilities.
Declarations for the configuration of Sunshine.
Declarations for logging related functions.
Definition inputtino_common.h:64
Definition common.h:105
Definition inputtino_common.h:28
std::vector< std::shared_ptr< joypad_state > > gamepads
Definition inputtino_common.h:61
Definition inputtino_common.h:22
Declarations for utility functions.