#pragma once #include "settings/streamingpreferences.h" #include "backend/computermanager.h" #include struct GamepadState { SDL_GameController* controller; SDL_JoystickID jsId; short index; #if !SDL_VERSION_ATLEAST(2, 0, 9) SDL_Haptic* haptic; int hapticMethod; int hapticEffectId; #endif SDL_TimerID mouseEmulationTimer; uint32_t lastStartDownTime; short buttons; short lsX, lsY; short rsX, rsY; unsigned char lt, rt; }; #define MAX_GAMEPADS 4 #define MAX_FINGERS 2 #define GAMEPAD_HAPTIC_METHOD_NONE 0 #define GAMEPAD_HAPTIC_METHOD_LEFTRIGHT 1 #define GAMEPAD_HAPTIC_METHOD_SIMPLERUMBLE 2 #define GAMEPAD_HAPTIC_SIMPLE_HIFREQ_MOTOR_WEIGHT 0.33 #define GAMEPAD_HAPTIC_SIMPLE_LOWFREQ_MOTOR_WEIGHT 0.8 class SdlInputHandler { public: explicit SdlInputHandler(StreamingPreferences& prefs, NvComputer* computer, int streamWidth, int streamHeight); ~SdlInputHandler(); void handleKeyEvent(SDL_KeyboardEvent* event); void handleMouseButtonEvent(SDL_MouseButtonEvent* event); void handleMouseMotionEvent(SDL_Window* window, SDL_MouseMotionEvent* event); void handleMouseWheelEvent(SDL_MouseWheelEvent* event); void handleControllerAxisEvent(SDL_ControllerAxisEvent* event); void handleControllerButtonEvent(SDL_ControllerButtonEvent* event); void handleControllerDeviceEvent(SDL_ControllerDeviceEvent* event); void handleJoystickArrivalEvent(SDL_JoyDeviceEvent* event); void rumble(unsigned short controllerNumber, unsigned short lowFreqMotor, unsigned short highFreqMotor); void handleTouchFingerEvent(SDL_Window* window, SDL_TouchFingerEvent* event); int getAttachedGamepadMask(); void raiseAllKeys(); bool isCaptureActive(); void setCaptureActive(bool active); static QString getUnmappedGamepads(); private: GamepadState* findStateForGamepad(SDL_JoystickID id); void sendGamepadState(GamepadState* state); static Uint32 longPressTimerCallback(Uint32 interval, void* param); static Uint32 mouseMoveTimerCallback(Uint32 interval, void* param); static Uint32 mouseEmulationTimerCallback(Uint32 interval, void* param); bool m_MultiController; bool m_GamepadMouse; SDL_TimerID m_MouseMoveTimer; SDL_atomic_t m_MouseDeltaX; SDL_atomic_t m_MouseDeltaY; int m_GamepadMask; GamepadState m_GamepadState[MAX_GAMEPADS]; QSet m_KeysDown; bool m_FakeCaptureActive; SDL_TouchFingerEvent m_LastTouchDownEvent; SDL_TouchFingerEvent m_LastTouchUpEvent; SDL_TimerID m_LongPressTimer; int m_StreamWidth; int m_StreamHeight; bool m_AbsoluteMouseMode; static const int k_ButtonMap[]; };