diff options
Diffstat (limited to 'src/input_common/sdl/sdl_impl.h')
| -rw-r--r-- | src/input_common/sdl/sdl_impl.h | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/input_common/sdl/sdl_impl.h b/src/input_common/sdl/sdl_impl.h new file mode 100644 index 000000000..fec82fbe6 --- /dev/null +++ b/src/input_common/sdl/sdl_impl.h | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | // Copyright 2018 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <atomic> | ||
| 8 | #include <memory> | ||
| 9 | #include <thread> | ||
| 10 | #include "common/threadsafe_queue.h" | ||
| 11 | #include "input_common/sdl/sdl.h" | ||
| 12 | |||
| 13 | union SDL_Event; | ||
| 14 | using SDL_Joystick = struct _SDL_Joystick; | ||
| 15 | using SDL_JoystickID = s32; | ||
| 16 | |||
| 17 | namespace InputCommon::SDL { | ||
| 18 | |||
| 19 | class SDLJoystick; | ||
| 20 | class SDLButtonFactory; | ||
| 21 | class SDLAnalogFactory; | ||
| 22 | |||
| 23 | class SDLState : public State { | ||
| 24 | public: | ||
| 25 | /// Initializes and registers SDL device factories | ||
| 26 | SDLState(); | ||
| 27 | |||
| 28 | /// Unresisters SDL device factories and shut them down. | ||
| 29 | ~SDLState() override; | ||
| 30 | |||
| 31 | /// Handle SDL_Events for joysticks from SDL_PollEvent | ||
| 32 | void HandleGameControllerEvent(const SDL_Event& event); | ||
| 33 | |||
| 34 | std::shared_ptr<SDLJoystick> GetSDLJoystickBySDLID(SDL_JoystickID sdl_id); | ||
| 35 | std::shared_ptr<SDLJoystick> GetSDLJoystickByGUID(const std::string& guid, int port); | ||
| 36 | |||
| 37 | /// Get all DevicePoller that use the SDL backend for a specific device type | ||
| 38 | std::vector<std::unique_ptr<InputCommon::Polling::DevicePoller>> GetPollers( | ||
| 39 | InputCommon::Polling::DeviceType type) override; | ||
| 40 | |||
| 41 | /// Used by the Pollers during config | ||
| 42 | std::atomic<bool> polling = false; | ||
| 43 | Common::SPSCQueue<SDL_Event> event_queue; | ||
| 44 | |||
| 45 | private: | ||
| 46 | void InitJoystick(int joystick_index); | ||
| 47 | void CloseJoystick(SDL_Joystick* sdl_joystick); | ||
| 48 | |||
| 49 | /// Needs to be called before SDL_QuitSubSystem. | ||
| 50 | void CloseJoysticks(); | ||
| 51 | |||
| 52 | /// Map of GUID of a list of corresponding virtual Joysticks | ||
| 53 | std::unordered_map<std::string, std::vector<std::shared_ptr<SDLJoystick>>> joystick_map; | ||
| 54 | std::mutex joystick_map_mutex; | ||
| 55 | |||
| 56 | std::shared_ptr<SDLButtonFactory> button_factory; | ||
| 57 | std::shared_ptr<SDLAnalogFactory> analog_factory; | ||
| 58 | |||
| 59 | bool start_thread = false; | ||
| 60 | std::atomic<bool> initialized = false; | ||
| 61 | |||
| 62 | std::thread poll_thread; | ||
| 63 | }; | ||
| 64 | } // namespace InputCommon::SDL | ||