// SPDX-License-Identifier: MIT // // ES-DE Frontend // InputManager.h // // Low-level input handling. // Initiates and maps the keyboard and controllers. // Reads and writes the es_input.xml configuration file. // #ifndef ES_CORE_INPUT_MANAGER_H #define ES_CORE_INPUT_MANAGER_H #include "CECInput.h" #if defined(__ANDROID__) #include "InputOverlay.h" #endif #include #include #include #include #include class InputConfig; class Window; class InputManager { public: static InputManager& getInstance(); void init(); void deinit(); void writeDeviceConfig(InputConfig* config); void doOnFinish(); static std::string getConfigPath(); static std::string getTemporaryConfigPath(); int getNumConfiguredDevices(); int getAxisCountByDevice(int deviceId); int getButtonCountByDevice(int deviceId); std::string getDeviceGUIDString(int deviceId); InputConfig* getInputConfigByDevice(int deviceId); bool parseEvent(const SDL_Event& event); int getNumJoysticks() { return static_cast(mJoysticks.size()); } private: InputManager() noexcept; virtual ~InputManager(); bool initialized() const { return mKeyboardInputConfig != nullptr; } bool loadInputConfig(InputConfig* config); void loadDefaultKBConfig(); void loadDefaultControllerConfig(SDL_JoystickID deviceIndex); void loadTouchConfig(); void addControllerByDeviceIndex(Window* window, int deviceIndex); void removeControllerByJoystickID(Window* window, SDL_JoystickID joyID); Window* mWindow; CECInput mCECInput; #if defined(__ANDROID__) InputOverlay& mInputOverlay; #endif static const int DEADZONE_TRIGGERS = 18000; static const int DEADZONE_THUMBSTICKS = 23000; bool mConfigFileExists; std::map mJoysticks; std::map mControllers; std::map> mInputConfigs; std::unique_ptr mKeyboardInputConfig; std::unique_ptr mTouchInputConfig; std::unique_ptr mCECInputConfig; std::map, int> mPrevAxisValues; std::map, int> mPrevButtonValues; }; #endif // ES_CORE_INPUT_MANAGER_H