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