diff options
| author | 2021-01-10 22:09:56 -0700 | |
|---|---|---|
| committer | 2021-01-10 22:09:56 -0700 | |
| commit | 7a3c884e39fccfbb498b855080bffabc9ce2e7f1 (patch) | |
| tree | 5056f9406dec188439cb0deb87603498243a9412 /src/input_common/main.cpp | |
| parent | More forgetting... duh (diff) | |
| parent | Merge pull request #5229 from Morph1984/fullscreen-opt (diff) | |
| download | yuzu-7a3c884e39fccfbb498b855080bffabc9ce2e7f1.tar.gz yuzu-7a3c884e39fccfbb498b855080bffabc9ce2e7f1.tar.xz yuzu-7a3c884e39fccfbb498b855080bffabc9ce2e7f1.zip | |
Merge remote-tracking branch 'upstream/master' into int-flags
Diffstat (limited to 'src/input_common/main.cpp')
| -rw-r--r-- | src/input_common/main.cpp | 98 |
1 files changed, 78 insertions, 20 deletions
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index 8da829132..7c4e7dd3b 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp | |||
| @@ -10,7 +10,9 @@ | |||
| 10 | #include "input_common/gcadapter/gc_poller.h" | 10 | #include "input_common/gcadapter/gc_poller.h" |
| 11 | #include "input_common/keyboard.h" | 11 | #include "input_common/keyboard.h" |
| 12 | #include "input_common/main.h" | 12 | #include "input_common/main.h" |
| 13 | #include "input_common/motion_emu.h" | 13 | #include "input_common/motion_from_button.h" |
| 14 | #include "input_common/mouse/mouse_input.h" | ||
| 15 | #include "input_common/mouse/mouse_poller.h" | ||
| 14 | #include "input_common/touch_from_button.h" | 16 | #include "input_common/touch_from_button.h" |
| 15 | #include "input_common/udp/client.h" | 17 | #include "input_common/udp/client.h" |
| 16 | #include "input_common/udp/udp.h" | 18 | #include "input_common/udp/udp.h" |
| @@ -27,13 +29,15 @@ struct InputSubsystem::Impl { | |||
| 27 | Input::RegisterFactory<Input::ButtonDevice>("gcpad", gcbuttons); | 29 | Input::RegisterFactory<Input::ButtonDevice>("gcpad", gcbuttons); |
| 28 | gcanalog = std::make_shared<GCAnalogFactory>(gcadapter); | 30 | gcanalog = std::make_shared<GCAnalogFactory>(gcadapter); |
| 29 | Input::RegisterFactory<Input::AnalogDevice>("gcpad", gcanalog); | 31 | Input::RegisterFactory<Input::AnalogDevice>("gcpad", gcanalog); |
| 32 | gcvibration = std::make_shared<GCVibrationFactory>(gcadapter); | ||
| 33 | Input::RegisterFactory<Input::VibrationDevice>("gcpad", gcvibration); | ||
| 30 | 34 | ||
| 31 | keyboard = std::make_shared<Keyboard>(); | 35 | keyboard = std::make_shared<Keyboard>(); |
| 32 | Input::RegisterFactory<Input::ButtonDevice>("keyboard", keyboard); | 36 | Input::RegisterFactory<Input::ButtonDevice>("keyboard", keyboard); |
| 33 | Input::RegisterFactory<Input::AnalogDevice>("analog_from_button", | 37 | Input::RegisterFactory<Input::AnalogDevice>("analog_from_button", |
| 34 | std::make_shared<AnalogFromButton>()); | 38 | std::make_shared<AnalogFromButton>()); |
| 35 | motion_emu = std::make_shared<MotionEmu>(); | 39 | Input::RegisterFactory<Input::MotionDevice>("keyboard", |
| 36 | Input::RegisterFactory<Input::MotionDevice>("motion_emu", motion_emu); | 40 | std::make_shared<MotionFromButton>()); |
| 37 | Input::RegisterFactory<Input::TouchDevice>("touch_from_button", | 41 | Input::RegisterFactory<Input::TouchDevice>("touch_from_button", |
| 38 | std::make_shared<TouchFromButtonFactory>()); | 42 | std::make_shared<TouchFromButtonFactory>()); |
| 39 | 43 | ||
| @@ -46,35 +50,56 @@ struct InputSubsystem::Impl { | |||
| 46 | Input::RegisterFactory<Input::MotionDevice>("cemuhookudp", udpmotion); | 50 | Input::RegisterFactory<Input::MotionDevice>("cemuhookudp", udpmotion); |
| 47 | udptouch = std::make_shared<UDPTouchFactory>(udp); | 51 | udptouch = std::make_shared<UDPTouchFactory>(udp); |
| 48 | Input::RegisterFactory<Input::TouchDevice>("cemuhookudp", udptouch); | 52 | Input::RegisterFactory<Input::TouchDevice>("cemuhookudp", udptouch); |
| 53 | |||
| 54 | mouse = std::make_shared<MouseInput::Mouse>(); | ||
| 55 | mousebuttons = std::make_shared<MouseButtonFactory>(mouse); | ||
| 56 | Input::RegisterFactory<Input::ButtonDevice>("mouse", mousebuttons); | ||
| 57 | mouseanalog = std::make_shared<MouseAnalogFactory>(mouse); | ||
| 58 | Input::RegisterFactory<Input::AnalogDevice>("mouse", mouseanalog); | ||
| 59 | mousemotion = std::make_shared<MouseMotionFactory>(mouse); | ||
| 60 | Input::RegisterFactory<Input::MotionDevice>("mouse", mousemotion); | ||
| 61 | mousetouch = std::make_shared<MouseTouchFactory>(mouse); | ||
| 62 | Input::RegisterFactory<Input::TouchDevice>("mouse", mousetouch); | ||
| 49 | } | 63 | } |
| 50 | 64 | ||
| 51 | void Shutdown() { | 65 | void Shutdown() { |
| 52 | Input::UnregisterFactory<Input::ButtonDevice>("keyboard"); | 66 | Input::UnregisterFactory<Input::ButtonDevice>("keyboard"); |
| 67 | Input::UnregisterFactory<Input::MotionDevice>("keyboard"); | ||
| 53 | keyboard.reset(); | 68 | keyboard.reset(); |
| 54 | Input::UnregisterFactory<Input::AnalogDevice>("analog_from_button"); | 69 | Input::UnregisterFactory<Input::AnalogDevice>("analog_from_button"); |
| 55 | Input::UnregisterFactory<Input::MotionDevice>("motion_emu"); | ||
| 56 | motion_emu.reset(); | ||
| 57 | Input::UnregisterFactory<Input::TouchDevice>("touch_from_button"); | 70 | Input::UnregisterFactory<Input::TouchDevice>("touch_from_button"); |
| 58 | #ifdef HAVE_SDL2 | 71 | #ifdef HAVE_SDL2 |
| 59 | sdl.reset(); | 72 | sdl.reset(); |
| 60 | #endif | 73 | #endif |
| 61 | Input::UnregisterFactory<Input::ButtonDevice>("gcpad"); | 74 | Input::UnregisterFactory<Input::ButtonDevice>("gcpad"); |
| 62 | Input::UnregisterFactory<Input::AnalogDevice>("gcpad"); | 75 | Input::UnregisterFactory<Input::AnalogDevice>("gcpad"); |
| 76 | Input::UnregisterFactory<Input::VibrationDevice>("gcpad"); | ||
| 63 | 77 | ||
| 64 | gcbuttons.reset(); | 78 | gcbuttons.reset(); |
| 65 | gcanalog.reset(); | 79 | gcanalog.reset(); |
| 80 | gcvibration.reset(); | ||
| 66 | 81 | ||
| 67 | Input::UnregisterFactory<Input::MotionDevice>("cemuhookudp"); | 82 | Input::UnregisterFactory<Input::MotionDevice>("cemuhookudp"); |
| 68 | Input::UnregisterFactory<Input::TouchDevice>("cemuhookudp"); | 83 | Input::UnregisterFactory<Input::TouchDevice>("cemuhookudp"); |
| 69 | 84 | ||
| 70 | udpmotion.reset(); | 85 | udpmotion.reset(); |
| 71 | udptouch.reset(); | 86 | udptouch.reset(); |
| 87 | |||
| 88 | Input::UnregisterFactory<Input::ButtonDevice>("mouse"); | ||
| 89 | Input::UnregisterFactory<Input::AnalogDevice>("mouse"); | ||
| 90 | Input::UnregisterFactory<Input::MotionDevice>("mouse"); | ||
| 91 | Input::UnregisterFactory<Input::TouchDevice>("mouse"); | ||
| 92 | |||
| 93 | mousebuttons.reset(); | ||
| 94 | mouseanalog.reset(); | ||
| 95 | mousemotion.reset(); | ||
| 96 | mousetouch.reset(); | ||
| 72 | } | 97 | } |
| 73 | 98 | ||
| 74 | [[nodiscard]] std::vector<Common::ParamPackage> GetInputDevices() const { | 99 | [[nodiscard]] std::vector<Common::ParamPackage> GetInputDevices() const { |
| 75 | std::vector<Common::ParamPackage> devices = { | 100 | std::vector<Common::ParamPackage> devices = { |
| 76 | Common::ParamPackage{{"display", "Any"}, {"class", "any"}}, | 101 | Common::ParamPackage{{"display", "Any"}, {"class", "any"}}, |
| 77 | Common::ParamPackage{{"display", "Keyboard/Mouse"}, {"class", "key"}}, | 102 | Common::ParamPackage{{"display", "Keyboard/Mouse"}, {"class", "keyboard"}}, |
| 78 | }; | 103 | }; |
| 79 | #ifdef HAVE_SDL2 | 104 | #ifdef HAVE_SDL2 |
| 80 | auto sdl_devices = sdl->GetInputDevices(); | 105 | auto sdl_devices = sdl->GetInputDevices(); |
| @@ -92,10 +117,6 @@ struct InputSubsystem::Impl { | |||
| 92 | if (!params.Has("class") || params.Get("class", "") == "any") { | 117 | if (!params.Has("class") || params.Get("class", "") == "any") { |
| 93 | return {}; | 118 | return {}; |
| 94 | } | 119 | } |
| 95 | if (params.Get("class", "") == "key") { | ||
| 96 | // TODO consider returning the SDL key codes for the default keybindings | ||
| 97 | return {}; | ||
| 98 | } | ||
| 99 | if (params.Get("class", "") == "gcpad") { | 120 | if (params.Get("class", "") == "gcpad") { |
| 100 | return gcadapter->GetAnalogMappingForDevice(params); | 121 | return gcadapter->GetAnalogMappingForDevice(params); |
| 101 | } | 122 | } |
| @@ -112,10 +133,6 @@ struct InputSubsystem::Impl { | |||
| 112 | if (!params.Has("class") || params.Get("class", "") == "any") { | 133 | if (!params.Has("class") || params.Get("class", "") == "any") { |
| 113 | return {}; | 134 | return {}; |
| 114 | } | 135 | } |
| 115 | if (params.Get("class", "") == "key") { | ||
| 116 | // TODO consider returning the SDL key codes for the default keybindings | ||
| 117 | return {}; | ||
| 118 | } | ||
| 119 | if (params.Get("class", "") == "gcpad") { | 136 | if (params.Get("class", "") == "gcpad") { |
| 120 | return gcadapter->GetButtonMappingForDevice(params); | 137 | return gcadapter->GetButtonMappingForDevice(params); |
| 121 | } | 138 | } |
| @@ -140,16 +157,21 @@ struct InputSubsystem::Impl { | |||
| 140 | } | 157 | } |
| 141 | 158 | ||
| 142 | std::shared_ptr<Keyboard> keyboard; | 159 | std::shared_ptr<Keyboard> keyboard; |
| 143 | std::shared_ptr<MotionEmu> motion_emu; | ||
| 144 | #ifdef HAVE_SDL2 | 160 | #ifdef HAVE_SDL2 |
| 145 | std::unique_ptr<SDL::State> sdl; | 161 | std::unique_ptr<SDL::State> sdl; |
| 146 | #endif | 162 | #endif |
| 147 | std::shared_ptr<GCButtonFactory> gcbuttons; | 163 | std::shared_ptr<GCButtonFactory> gcbuttons; |
| 148 | std::shared_ptr<GCAnalogFactory> gcanalog; | 164 | std::shared_ptr<GCAnalogFactory> gcanalog; |
| 165 | std::shared_ptr<GCVibrationFactory> gcvibration; | ||
| 149 | std::shared_ptr<UDPMotionFactory> udpmotion; | 166 | std::shared_ptr<UDPMotionFactory> udpmotion; |
| 150 | std::shared_ptr<UDPTouchFactory> udptouch; | 167 | std::shared_ptr<UDPTouchFactory> udptouch; |
| 168 | std::shared_ptr<MouseButtonFactory> mousebuttons; | ||
| 169 | std::shared_ptr<MouseAnalogFactory> mouseanalog; | ||
| 170 | std::shared_ptr<MouseMotionFactory> mousemotion; | ||
| 171 | std::shared_ptr<MouseTouchFactory> mousetouch; | ||
| 151 | std::shared_ptr<CemuhookUDP::Client> udp; | 172 | std::shared_ptr<CemuhookUDP::Client> udp; |
| 152 | std::shared_ptr<GCAdapter::Adapter> gcadapter; | 173 | std::shared_ptr<GCAdapter::Adapter> gcadapter; |
| 174 | std::shared_ptr<MouseInput::Mouse> mouse; | ||
| 153 | }; | 175 | }; |
| 154 | 176 | ||
| 155 | InputSubsystem::InputSubsystem() : impl{std::make_unique<Impl>()} {} | 177 | InputSubsystem::InputSubsystem() : impl{std::make_unique<Impl>()} {} |
| @@ -172,12 +194,12 @@ const Keyboard* InputSubsystem::GetKeyboard() const { | |||
| 172 | return impl->keyboard.get(); | 194 | return impl->keyboard.get(); |
| 173 | } | 195 | } |
| 174 | 196 | ||
| 175 | MotionEmu* InputSubsystem::GetMotionEmu() { | 197 | MouseInput::Mouse* InputSubsystem::GetMouse() { |
| 176 | return impl->motion_emu.get(); | 198 | return impl->mouse.get(); |
| 177 | } | 199 | } |
| 178 | 200 | ||
| 179 | const MotionEmu* InputSubsystem::GetMotionEmu() const { | 201 | const MouseInput::Mouse* InputSubsystem::GetMouse() const { |
| 180 | return impl->motion_emu.get(); | 202 | return impl->mouse.get(); |
| 181 | } | 203 | } |
| 182 | 204 | ||
| 183 | std::vector<Common::ParamPackage> InputSubsystem::GetInputDevices() const { | 205 | std::vector<Common::ParamPackage> InputSubsystem::GetInputDevices() const { |
| @@ -192,6 +214,10 @@ ButtonMapping InputSubsystem::GetButtonMappingForDevice(const Common::ParamPacka | |||
| 192 | return impl->GetButtonMappingForDevice(device); | 214 | return impl->GetButtonMappingForDevice(device); |
| 193 | } | 215 | } |
| 194 | 216 | ||
| 217 | MotionMapping InputSubsystem::GetMotionMappingForDevice(const Common::ParamPackage& device) const { | ||
| 218 | return impl->GetMotionMappingForDevice(device); | ||
| 219 | } | ||
| 220 | |||
| 195 | GCAnalogFactory* InputSubsystem::GetGCAnalogs() { | 221 | GCAnalogFactory* InputSubsystem::GetGCAnalogs() { |
| 196 | return impl->gcanalog.get(); | 222 | return impl->gcanalog.get(); |
| 197 | } | 223 | } |
| @@ -224,11 +250,43 @@ const UDPTouchFactory* InputSubsystem::GetUDPTouch() const { | |||
| 224 | return impl->udptouch.get(); | 250 | return impl->udptouch.get(); |
| 225 | } | 251 | } |
| 226 | 252 | ||
| 253 | MouseButtonFactory* InputSubsystem::GetMouseButtons() { | ||
| 254 | return impl->mousebuttons.get(); | ||
| 255 | } | ||
| 256 | |||
| 257 | const MouseButtonFactory* InputSubsystem::GetMouseButtons() const { | ||
| 258 | return impl->mousebuttons.get(); | ||
| 259 | } | ||
| 260 | |||
| 261 | MouseAnalogFactory* InputSubsystem::GetMouseAnalogs() { | ||
| 262 | return impl->mouseanalog.get(); | ||
| 263 | } | ||
| 264 | |||
| 265 | const MouseAnalogFactory* InputSubsystem::GetMouseAnalogs() const { | ||
| 266 | return impl->mouseanalog.get(); | ||
| 267 | } | ||
| 268 | |||
| 269 | MouseMotionFactory* InputSubsystem::GetMouseMotions() { | ||
| 270 | return impl->mousemotion.get(); | ||
| 271 | } | ||
| 272 | |||
| 273 | const MouseMotionFactory* InputSubsystem::GetMouseMotions() const { | ||
| 274 | return impl->mousemotion.get(); | ||
| 275 | } | ||
| 276 | |||
| 277 | MouseTouchFactory* InputSubsystem::GetMouseTouch() { | ||
| 278 | return impl->mousetouch.get(); | ||
| 279 | } | ||
| 280 | |||
| 281 | const MouseTouchFactory* InputSubsystem::GetMouseTouch() const { | ||
| 282 | return impl->mousetouch.get(); | ||
| 283 | } | ||
| 284 | |||
| 227 | void InputSubsystem::ReloadInputDevices() { | 285 | void InputSubsystem::ReloadInputDevices() { |
| 228 | if (!impl->udp) { | 286 | if (!impl->udp) { |
| 229 | return; | 287 | return; |
| 230 | } | 288 | } |
| 231 | impl->udp->ReloadUDPClient(); | 289 | impl->udp->ReloadSockets(); |
| 232 | } | 290 | } |
| 233 | 291 | ||
| 234 | std::vector<std::unique_ptr<Polling::DevicePoller>> InputSubsystem::GetPollers( | 292 | std::vector<std::unique_ptr<Polling::DevicePoller>> InputSubsystem::GetPollers( |