summaryrefslogtreecommitdiff
path: root/src/input_common/main.cpp
diff options
context:
space:
mode:
authorGravatar Morph2020-07-22 10:39:53 -0400
committerGravatar Morph2020-08-26 02:32:32 -0400
commitf0fac0c7fb6f7dd9fe81747b3369767c8c9e7d01 (patch)
tree4438688a9b9b4bc015985f2df1a731de57fe50db /src/input_common/main.cpp
parentMerge pull request #4582 from lioncash/xbyak (diff)
downloadyuzu-f0fac0c7fb6f7dd9fe81747b3369767c8c9e7d01.tar.gz
yuzu-f0fac0c7fb6f7dd9fe81747b3369767c8c9e7d01.tar.xz
yuzu-f0fac0c7fb6f7dd9fe81747b3369767c8c9e7d01.zip
Project Mjölnir: Part 1
Co-authored-by: James Rowe <jroweboy@gmail.com> Co-authored-by: Its-Rei <kupfel@gmail.com>
Diffstat (limited to 'src/input_common/main.cpp')
-rw-r--r--src/input_common/main.cpp50
1 files changed, 49 insertions, 1 deletions
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp
index b9d5d0ec3..b8725e9af 100644
--- a/src/input_common/main.cpp
+++ b/src/input_common/main.cpp
@@ -44,7 +44,6 @@ void Init() {
44#ifdef HAVE_SDL2 44#ifdef HAVE_SDL2
45 sdl = SDL::Init(); 45 sdl = SDL::Init();
46#endif 46#endif
47
48 udp = CemuhookUDP::Init(); 47 udp = CemuhookUDP::Init();
49} 48}
50 49
@@ -103,6 +102,55 @@ std::string GenerateAnalogParamFromKeys(int key_up, int key_down, int key_left,
103 return circle_pad_param.Serialize(); 102 return circle_pad_param.Serialize();
104} 103}
105 104
105std::vector<Common::ParamPackage> GetInputDevices() {
106 std::vector<Common::ParamPackage> devices = {
107 Common::ParamPackage{{"display", "Any"}, {"class", "any"}},
108 Common::ParamPackage{{"display", "Keyboard"}, {"class", "key"}},
109 };
110#ifdef HAVE_SDL2
111 auto sdl_devices = sdl->GetInputDevices();
112 devices.insert(devices.end(), sdl_devices.begin(), sdl_devices.end());
113#endif
114 auto udp_devices = udp->GetInputDevices();
115 devices.insert(devices.end(), udp_devices.begin(), udp_devices.end());
116 return devices;
117}
118
119std::unordered_map<Settings::NativeButton::Values, Common::ParamPackage> GetButtonMappingForDevice(
120 const Common::ParamPackage& params) {
121 std::unordered_map<Settings::NativeButton::Values, Common::ParamPackage> mappings{};
122 if (!params.Has("class") || params.Get("class", "") == "any") {
123 return mappings;
124 }
125 if (params.Get("class", "") == "key") {
126 // TODO consider returning the SDL key codes for the default keybindings
127 }
128#ifdef HAVE_SDL2
129 if (params.Get("class", "") == "sdl") {
130 return sdl->GetButtonMappingForDevice(params);
131 }
132#endif
133 return mappings;
134}
135
136std::unordered_map<Settings::NativeAnalog::Values, Common::ParamPackage> GetAnalogMappingForDevice(
137 const Common::ParamPackage& params) {
138 std::unordered_map<Settings::NativeAnalog::Values, Common::ParamPackage> mappings{};
139 if (!params.Has("class") || params.Get("class", "") == "any") {
140 return mappings;
141 }
142 if (params.Get("class", "") == "key") {
143 // TODO consider returning the SDL key codes for the default keybindings
144 return mappings;
145 }
146#ifdef HAVE_SDL2
147 if (params.Get("class", "") == "sdl") {
148 return sdl->GetAnalogMappingForDevice(params);
149 }
150#endif
151 return mappings;
152}
153
106namespace Polling { 154namespace Polling {
107 155
108std::vector<std::unique_ptr<DevicePoller>> GetPollers(DeviceType type) { 156std::vector<std::unique_ptr<DevicePoller>> GetPollers(DeviceType type) {