2020-09-21 17:17:34 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-06-21 12:25:28 +00:00
|
|
|
//
|
2020-09-21 17:17:34 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-21 12:25:28 +00:00
|
|
|
// InputManager.h
|
|
|
|
//
|
|
|
|
// Low-level input handling.
|
|
|
|
// Initiates and maps the keyboard and controllers.
|
2021-06-16 17:20:53 +00:00
|
|
|
// Reads and writes the es_input.xml configuration file.
|
2020-06-21 12:25:28 +00:00
|
|
|
//
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#ifndef ES_CORE_INPUT_MANAGER_H
|
|
|
|
#define ES_CORE_INPUT_MANAGER_H
|
2012-07-20 01:08:29 +00:00
|
|
|
|
2022-01-04 20:21:26 +00:00
|
|
|
#include "CECInput.h"
|
|
|
|
|
2021-05-22 20:18:00 +00:00
|
|
|
#include <SDL2/SDL.h>
|
2020-06-26 16:03:55 +00:00
|
|
|
#include <SDL2/SDL_joystick.h>
|
|
|
|
|
2012-07-22 21:15:55 +00:00
|
|
|
#include <map>
|
2021-05-22 20:18:00 +00:00
|
|
|
#include <memory>
|
2020-11-28 21:27:00 +00:00
|
|
|
#include <string>
|
2012-07-20 01:08:29 +00:00
|
|
|
|
2013-04-08 14:41:25 +00:00
|
|
|
class InputConfig;
|
|
|
|
class Window;
|
2017-11-01 22:21:10 +00:00
|
|
|
union SDL_Event;
|
2012-07-20 01:08:29 +00:00
|
|
|
|
2013-04-08 14:41:25 +00:00
|
|
|
class InputManager
|
|
|
|
{
|
|
|
|
public:
|
2022-01-04 20:21:26 +00:00
|
|
|
static InputManager& getInstance();
|
2012-07-20 01:08:29 +00:00
|
|
|
|
2021-05-22 20:18:00 +00:00
|
|
|
void init();
|
|
|
|
void deinit();
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
void writeDeviceConfig(InputConfig* config);
|
|
|
|
void doOnFinish();
|
2021-05-22 20:18:00 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
static std::string getConfigPath();
|
|
|
|
static std::string getTemporaryConfigPath();
|
2013-04-08 16:52:40 +00:00
|
|
|
|
2021-05-22 20:18:00 +00:00
|
|
|
int getNumConfiguredDevices();
|
2020-06-21 12:25:28 +00:00
|
|
|
int getAxisCountByDevice(int deviceId);
|
|
|
|
int getButtonCountByDevice(int deviceId);
|
2012-07-20 01:08:29 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
std::string getDeviceGUIDString(int deviceId);
|
|
|
|
InputConfig* getInputConfigByDevice(int deviceId);
|
2012-07-22 21:15:55 +00:00
|
|
|
|
2022-01-19 17:01:54 +00:00
|
|
|
bool parseEvent(const SDL_Event& event);
|
2020-07-14 17:16:21 +00:00
|
|
|
|
2021-07-04 19:34:21 +00:00
|
|
|
int getNumJoysticks() { return static_cast<int>(mJoysticks.size()); }
|
2021-07-03 10:24:23 +00:00
|
|
|
|
2020-07-14 17:16:21 +00:00
|
|
|
private:
|
2022-01-04 20:21:26 +00:00
|
|
|
InputManager() noexcept;
|
|
|
|
virtual ~InputManager();
|
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
bool initialized() const { return mKeyboardInputConfig != nullptr; }
|
2020-07-14 17:16:21 +00:00
|
|
|
|
2021-05-22 20:18:00 +00:00
|
|
|
bool loadInputConfig(InputConfig* config);
|
|
|
|
void loadDefaultKBConfig();
|
|
|
|
void loadDefaultControllerConfig(SDL_JoystickID deviceIndex);
|
2020-07-14 17:16:21 +00:00
|
|
|
|
2021-10-07 16:33:13 +00:00
|
|
|
void addControllerByDeviceIndex(Window* window, int deviceIndex);
|
|
|
|
void removeControllerByJoystickID(Window* window, SDL_JoystickID joyID);
|
2020-07-14 17:16:21 +00:00
|
|
|
|
2022-01-19 17:01:54 +00:00
|
|
|
Window* mWindow;
|
2022-01-04 20:21:26 +00:00
|
|
|
CECInput mCECInput;
|
|
|
|
|
2021-07-01 15:39:08 +00:00
|
|
|
static const int DEADZONE_TRIGGERS = 18000;
|
|
|
|
static const int DEADZONE_THUMBSTICKS = 23000;
|
2021-05-22 20:18:00 +00:00
|
|
|
bool mConfigFileExists;
|
2020-07-14 17:16:21 +00:00
|
|
|
|
|
|
|
std::map<SDL_JoystickID, SDL_Joystick*> mJoysticks;
|
2021-05-22 20:18:00 +00:00
|
|
|
std::map<SDL_JoystickID, SDL_GameController*> mControllers;
|
|
|
|
std::map<SDL_JoystickID, std::unique_ptr<InputConfig>> mInputConfigs;
|
2020-07-14 17:16:21 +00:00
|
|
|
|
2021-05-22 20:18:00 +00:00
|
|
|
std::unique_ptr<InputConfig> mKeyboardInputConfig;
|
|
|
|
std::unique_ptr<InputConfig> mCECInputConfig;
|
2020-07-14 17:16:21 +00:00
|
|
|
|
2021-05-22 20:18:00 +00:00
|
|
|
std::map<std::pair<SDL_JoystickID, int>, int> mPrevAxisValues;
|
|
|
|
std::map<std::pair<SDL_JoystickID, int>, int> mPrevButtonValues;
|
2013-04-08 14:41:25 +00:00
|
|
|
};
|
2012-07-20 01:08:29 +00:00
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#endif // ES_CORE_INPUT_MANAGER_H
|