2018-06-28 08:44:43 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-09-09 20:21:11 +00:00
|
|
|
#include "settings/streamingpreferences.h"
|
2018-09-15 01:35:28 +00:00
|
|
|
#include "backend/computermanager.h"
|
2018-09-09 20:21:11 +00:00
|
|
|
|
2018-06-28 08:44:43 +00:00
|
|
|
#include <SDL.h>
|
|
|
|
|
|
|
|
struct GamepadState {
|
|
|
|
SDL_GameController* controller;
|
|
|
|
SDL_JoystickID jsId;
|
2019-02-12 05:39:55 +00:00
|
|
|
SDL_Haptic* haptic;
|
2019-02-21 03:22:38 +00:00
|
|
|
int hapticMethod;
|
2019-02-12 05:39:55 +00:00
|
|
|
int hapticEffectId;
|
2018-06-28 08:44:43 +00:00
|
|
|
short index;
|
|
|
|
|
2019-05-19 19:17:23 +00:00
|
|
|
SDL_TimerID mouseEmulationTimer;
|
|
|
|
uint32_t lastStartDownTime;
|
|
|
|
|
2018-06-28 08:44:43 +00:00
|
|
|
short buttons;
|
|
|
|
short lsX, lsY;
|
|
|
|
short rsX, rsY;
|
|
|
|
unsigned char lt, rt;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MAX_GAMEPADS 4
|
2018-09-30 08:03:26 +00:00
|
|
|
#define MAX_FINGERS 2
|
2018-06-28 08:44:43 +00:00
|
|
|
|
2019-02-21 03:22:38 +00:00
|
|
|
#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
|
|
|
|
|
2018-06-28 08:44:43 +00:00
|
|
|
class SdlInputHandler
|
|
|
|
{
|
|
|
|
public:
|
2018-09-30 08:03:26 +00:00
|
|
|
explicit SdlInputHandler(StreamingPreferences& prefs, NvComputer* computer,
|
|
|
|
int streamWidth, int streamHeight);
|
2018-06-28 08:44:43 +00:00
|
|
|
|
2018-06-28 09:04:51 +00:00
|
|
|
~SdlInputHandler();
|
|
|
|
|
2018-06-28 08:44:43 +00:00
|
|
|
void handleKeyEvent(SDL_KeyboardEvent* event);
|
|
|
|
|
|
|
|
void handleMouseButtonEvent(SDL_MouseButtonEvent* event);
|
|
|
|
|
|
|
|
void handleMouseMotionEvent(SDL_MouseMotionEvent* event);
|
|
|
|
|
|
|
|
void handleMouseWheelEvent(SDL_MouseWheelEvent* event);
|
|
|
|
|
|
|
|
void handleControllerAxisEvent(SDL_ControllerAxisEvent* event);
|
|
|
|
|
|
|
|
void handleControllerButtonEvent(SDL_ControllerButtonEvent* event);
|
|
|
|
|
|
|
|
void handleControllerDeviceEvent(SDL_ControllerDeviceEvent* event);
|
|
|
|
|
2018-09-30 02:14:52 +00:00
|
|
|
void handleJoystickArrivalEvent(SDL_JoyDeviceEvent* event);
|
|
|
|
|
2019-02-12 05:39:55 +00:00
|
|
|
void rumble(unsigned short controllerNumber, unsigned short lowFreqMotor, unsigned short highFreqMotor);
|
|
|
|
|
2018-09-30 05:43:28 +00:00
|
|
|
void handleTouchFingerEvent(SDL_TouchFingerEvent* event);
|
|
|
|
|
2018-06-28 08:44:43 +00:00
|
|
|
int getAttachedGamepadMask();
|
|
|
|
|
2018-10-04 01:27:12 +00:00
|
|
|
void raiseAllKeys();
|
|
|
|
|
2018-09-30 02:14:52 +00:00
|
|
|
static
|
|
|
|
QString getUnmappedGamepads();
|
|
|
|
|
2018-06-28 08:44:43 +00:00
|
|
|
private:
|
|
|
|
GamepadState*
|
|
|
|
findStateForGamepad(SDL_JoystickID id);
|
|
|
|
|
|
|
|
void sendGamepadState(GamepadState* state);
|
|
|
|
|
2018-09-30 05:43:28 +00:00
|
|
|
static
|
|
|
|
Uint32 releaseLeftButtonTimerCallback(Uint32 interval, void* param);
|
|
|
|
|
|
|
|
static
|
|
|
|
Uint32 releaseRightButtonTimerCallback(Uint32 interval, void* param);
|
|
|
|
|
|
|
|
static
|
|
|
|
Uint32 dragTimerCallback(Uint32 interval, void* param);
|
|
|
|
|
2018-11-16 04:52:07 +00:00
|
|
|
static
|
|
|
|
Uint32 mouseMoveTimerCallback(Uint32 interval, void* param);
|
|
|
|
|
2019-05-19 19:17:23 +00:00
|
|
|
static
|
|
|
|
Uint32 mouseEmulationTimerCallback(Uint32 interval, void* param);
|
|
|
|
|
2018-06-28 08:44:43 +00:00
|
|
|
bool m_MultiController;
|
2018-11-16 04:52:07 +00:00
|
|
|
SDL_TimerID m_MouseMoveTimer;
|
|
|
|
SDL_atomic_t m_MouseDeltaX;
|
|
|
|
SDL_atomic_t m_MouseDeltaY;
|
2018-06-28 08:44:43 +00:00
|
|
|
int m_GamepadMask;
|
|
|
|
GamepadState m_GamepadState[MAX_GAMEPADS];
|
2018-10-04 01:27:12 +00:00
|
|
|
QSet<short> m_KeysDown;
|
2018-06-28 08:44:43 +00:00
|
|
|
|
2018-09-30 05:43:28 +00:00
|
|
|
SDL_TouchFingerEvent m_TouchDownEvent[MAX_FINGERS];
|
2018-09-30 08:03:26 +00:00
|
|
|
float m_CumulativeDelta[MAX_FINGERS];
|
2018-09-30 05:43:28 +00:00
|
|
|
SDL_TimerID m_LeftButtonReleaseTimer;
|
|
|
|
SDL_TimerID m_RightButtonReleaseTimer;
|
|
|
|
SDL_TimerID m_DragTimer;
|
|
|
|
char m_DragButton;
|
|
|
|
int m_NumFingersDown;
|
2018-09-30 08:03:26 +00:00
|
|
|
int m_StreamWidth;
|
|
|
|
int m_StreamHeight;
|
2018-09-30 05:43:28 +00:00
|
|
|
|
2018-06-28 08:44:43 +00:00
|
|
|
static const int k_ButtonMap[];
|
|
|
|
};
|