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-12-08 00:17:01 +00:00
|
|
|
short index;
|
|
|
|
|
|
|
|
#if !SDL_VERSION_ATLEAST(2, 0, 9)
|
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;
|
2019-12-08 00:17:01 +00:00
|
|
|
#endif
|
2018-06-28 08:44:43 +00:00
|
|
|
|
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();
|
|
|
|
|
2020-04-29 03:24:23 +00:00
|
|
|
void setWindow(SDL_Window* window);
|
|
|
|
|
2018-06-28 08:44:43 +00:00
|
|
|
void handleKeyEvent(SDL_KeyboardEvent* event);
|
|
|
|
|
|
|
|
void handleMouseButtonEvent(SDL_MouseButtonEvent* event);
|
|
|
|
|
2020-04-29 03:24:23 +00:00
|
|
|
void handleMouseMotionEvent(SDL_MouseMotionEvent* event);
|
2018-06-28 08:44:43 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2020-04-29 03:24:23 +00:00
|
|
|
void handleTouchFingerEvent(SDL_TouchFingerEvent* event);
|
2018-09-30 05:43:28 +00:00
|
|
|
|
2018-06-28 08:44:43 +00:00
|
|
|
int getAttachedGamepadMask();
|
|
|
|
|
2018-10-04 01:27:12 +00:00
|
|
|
void raiseAllKeys();
|
|
|
|
|
2020-05-08 02:26:02 +00:00
|
|
|
void notifyMouseLeave();
|
|
|
|
|
2020-04-29 03:24:23 +00:00
|
|
|
void notifyFocusLost();
|
2020-04-25 22:37:33 +00:00
|
|
|
|
2019-07-03 05:17:18 +00:00
|
|
|
bool isCaptureActive();
|
|
|
|
|
|
|
|
void setCaptureActive(bool active);
|
|
|
|
|
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);
|
|
|
|
|
2020-05-01 03:55:15 +00:00
|
|
|
void handleAbsoluteFingerEvent(SDL_TouchFingerEvent* event);
|
|
|
|
|
|
|
|
void handleRelativeFingerEvent(SDL_TouchFingerEvent* event);
|
|
|
|
|
2018-09-30 05:43:28 +00:00
|
|
|
static
|
2020-04-24 04:33:45 +00:00
|
|
|
Uint32 longPressTimerCallback(Uint32 interval, void* param);
|
2018-09-30 05:43:28 +00:00
|
|
|
|
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);
|
|
|
|
|
2020-05-01 03:55:15 +00:00
|
|
|
static
|
|
|
|
Uint32 releaseLeftButtonTimerCallback(Uint32 interval, void* param);
|
|
|
|
|
|
|
|
static
|
|
|
|
Uint32 releaseRightButtonTimerCallback(Uint32 interval, void* param);
|
|
|
|
|
|
|
|
static
|
|
|
|
Uint32 dragTimerCallback(Uint32 interval, void* param);
|
|
|
|
|
2020-04-29 03:24:23 +00:00
|
|
|
SDL_Window* m_Window;
|
2018-06-28 08:44:43 +00:00
|
|
|
bool m_MultiController;
|
2019-06-30 01:24:59 +00:00
|
|
|
bool m_GamepadMouse;
|
2018-11-16 04:52:07 +00:00
|
|
|
SDL_TimerID m_MouseMoveTimer;
|
|
|
|
SDL_atomic_t m_MouseDeltaX;
|
|
|
|
SDL_atomic_t m_MouseDeltaY;
|
2020-05-31 20:34:50 +00:00
|
|
|
|
|
|
|
SDL_SpinLock m_MousePositionLock;
|
|
|
|
struct {
|
|
|
|
int x, y;
|
|
|
|
int windowWidth, windowHeight;
|
|
|
|
} m_MousePositionReport;
|
|
|
|
SDL_atomic_t m_MousePositionUpdated;
|
|
|
|
|
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;
|
2019-07-03 05:17:18 +00:00
|
|
|
bool m_FakeCaptureActive;
|
2018-06-28 08:44:43 +00:00
|
|
|
|
2020-04-24 04:33:45 +00:00
|
|
|
SDL_TouchFingerEvent m_LastTouchDownEvent;
|
|
|
|
SDL_TouchFingerEvent m_LastTouchUpEvent;
|
|
|
|
SDL_TimerID m_LongPressTimer;
|
2018-09-30 08:03:26 +00:00
|
|
|
int m_StreamWidth;
|
|
|
|
int m_StreamHeight;
|
2020-04-11 23:12:18 +00:00
|
|
|
bool m_AbsoluteMouseMode;
|
2020-05-01 03:55:15 +00:00
|
|
|
bool m_AbsoluteTouchMode;
|
2020-05-08 02:26:02 +00:00
|
|
|
Uint32 m_PendingMouseLeaveButtonUp;
|
2020-05-01 03:55:15 +00:00
|
|
|
|
|
|
|
SDL_TouchFingerEvent m_TouchDownEvent[MAX_FINGERS];
|
|
|
|
SDL_TimerID m_LeftButtonReleaseTimer;
|
|
|
|
SDL_TimerID m_RightButtonReleaseTimer;
|
|
|
|
SDL_TimerID m_DragTimer;
|
|
|
|
char m_DragButton;
|
|
|
|
int m_NumFingersDown;
|
2018-09-30 05:43:28 +00:00
|
|
|
|
2018-06-28 08:44:43 +00:00
|
|
|
static const int k_ButtonMap[];
|
|
|
|
};
|