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;
|
|
|
|
|
2023-06-18 21:08:32 +00:00
|
|
|
uint8_t gyroReportPeriodMs;
|
2023-07-03 00:22:00 +00:00
|
|
|
float lastGyroEventData[SDL_arraysize(SDL_ControllerSensorEvent::data)];
|
2023-06-18 21:08:32 +00:00
|
|
|
uint32_t lastGyroEventTime;
|
|
|
|
|
|
|
|
uint8_t accelReportPeriodMs;
|
2023-07-03 00:22:00 +00:00
|
|
|
float lastAccelEventData[SDL_arraysize(SDL_ControllerSensorEvent::data)];
|
2023-06-18 21:08:32 +00:00
|
|
|
uint32_t lastAccelEventTime;
|
|
|
|
|
2023-06-18 19:32:18 +00:00
|
|
|
int buttons;
|
2018-06-28 08:44:43 +00:00
|
|
|
short lsX, lsY;
|
|
|
|
short rsX, rsY;
|
|
|
|
unsigned char lt, rt;
|
|
|
|
};
|
|
|
|
|
2023-06-18 21:39:24 +00:00
|
|
|
// activeGamepadMask is a short, so we're bounded by the number of mask bits
|
|
|
|
#define MAX_GAMEPADS 16
|
|
|
|
|
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:
|
2023-03-18 19:29:45 +00:00
|
|
|
explicit SdlInputHandler(StreamingPreferences& prefs, 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);
|
|
|
|
|
2023-06-18 21:08:32 +00:00
|
|
|
#if SDL_VERSION_ATLEAST(2, 0, 14)
|
|
|
|
void handleControllerSensorEvent(SDL_ControllerSensorEvent* event);
|
|
|
|
|
|
|
|
void handleControllerTouchpadEvent(SDL_ControllerTouchpadEvent* event);
|
|
|
|
#endif
|
|
|
|
|
2023-07-02 21:44:41 +00:00
|
|
|
#if SDL_VERSION_ATLEAST(2, 24, 0)
|
|
|
|
void handleJoystickBatteryEvent(SDL_JoyBatteryEvent* event);
|
|
|
|
#endif
|
|
|
|
|
2018-09-30 02:14:52 +00:00
|
|
|
void handleJoystickArrivalEvent(SDL_JoyDeviceEvent* event);
|
|
|
|
|
2021-02-07 23:18:35 +00:00
|
|
|
void sendText(QString& string);
|
2021-02-07 19:46:38 +00:00
|
|
|
|
2023-06-18 21:04:49 +00:00
|
|
|
void rumble(uint16_t controllerNumber, uint16_t lowFreqMotor, uint16_t highFreqMotor);
|
|
|
|
|
|
|
|
void rumbleTriggers(uint16_t controllerNumber, uint16_t leftTrigger, uint16_t rightTrigger);
|
2019-02-12 05:39:55 +00:00
|
|
|
|
2023-06-18 21:08:32 +00:00
|
|
|
void setMotionEventState(uint16_t controllerNumber, uint8_t motionType, uint16_t reportRateHz);
|
|
|
|
|
2023-07-02 21:44:41 +00:00
|
|
|
void setControllerLED(uint16_t controllerNumber, uint8_t r, uint8_t g, uint8_t b);
|
|
|
|
|
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();
|
|
|
|
|
2021-01-12 05:43:32 +00:00
|
|
|
bool isSystemKeyCaptureActive();
|
|
|
|
|
2019-07-03 05:17:18 +00:00
|
|
|
void setCaptureActive(bool active);
|
|
|
|
|
2020-07-12 22:03:08 +00:00
|
|
|
bool isMouseInVideoRegion(int mouseX, int mouseY, int windowWidth = -1, int windowHeight = -1);
|
|
|
|
|
2021-02-27 22:47:38 +00:00
|
|
|
void updateKeyboardGrabState();
|
|
|
|
|
2022-03-29 23:26:09 +00:00
|
|
|
void updatePointerRegionLock();
|
|
|
|
|
2018-09-30 02:14:52 +00:00
|
|
|
static
|
|
|
|
QString getUnmappedGamepads();
|
|
|
|
|
2018-06-28 08:44:43 +00:00
|
|
|
private:
|
2021-01-24 19:02:42 +00:00
|
|
|
enum KeyCombo {
|
|
|
|
KeyComboQuit,
|
|
|
|
KeyComboUngrabInput,
|
|
|
|
KeyComboToggleFullScreen,
|
|
|
|
KeyComboToggleStatsOverlay,
|
|
|
|
KeyComboToggleMouseMode,
|
|
|
|
KeyComboToggleCursorHide,
|
|
|
|
KeyComboToggleMinimize,
|
2021-02-07 19:46:38 +00:00
|
|
|
KeyComboPasteText,
|
2022-03-29 23:26:09 +00:00
|
|
|
KeyComboTogglePointerRegionLock,
|
2021-01-24 19:02:42 +00:00
|
|
|
KeyComboMax
|
|
|
|
};
|
|
|
|
|
2018-06-28 08:44:43 +00:00
|
|
|
GamepadState*
|
|
|
|
findStateForGamepad(SDL_JoystickID id);
|
|
|
|
|
|
|
|
void sendGamepadState(GamepadState* state);
|
|
|
|
|
2023-07-02 21:44:41 +00:00
|
|
|
void sendGamepadBatteryState(GamepadState* state, SDL_JoystickPowerLevel level);
|
|
|
|
|
2020-05-01 03:55:15 +00:00
|
|
|
void handleAbsoluteFingerEvent(SDL_TouchFingerEvent* event);
|
|
|
|
|
2023-06-18 21:02:21 +00:00
|
|
|
void emulateAbsoluteFingerEvent(SDL_TouchFingerEvent* event);
|
|
|
|
|
2023-07-23 05:17:58 +00:00
|
|
|
void disableTouchFeedback();
|
|
|
|
|
2020-05-01 03:55:15 +00:00
|
|
|
void handleRelativeFingerEvent(SDL_TouchFingerEvent* event);
|
|
|
|
|
2021-02-28 21:06:46 +00:00
|
|
|
void performSpecialKeyCombo(KeyCombo combo);
|
2021-01-24 19:02:42 +00:00
|
|
|
|
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
|
|
|
|
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;
|
2020-08-23 14:05:00 +00:00
|
|
|
bool m_SwapMouseButtons;
|
2020-12-26 04:21:20 +00:00
|
|
|
bool m_ReverseScrollDirection;
|
|
|
|
bool m_SwapFaceButtons;
|
2023-02-15 02:39:56 +00:00
|
|
|
|
2020-07-12 22:06:36 +00:00
|
|
|
bool m_MouseWasInVideoRegion;
|
|
|
|
bool m_PendingMouseButtonsAllUpOnVideoRegionLeave;
|
2022-03-29 23:26:09 +00:00
|
|
|
bool m_PointerRegionLockActive;
|
2022-05-20 00:14:55 +00:00
|
|
|
bool m_PointerRegionLockToggledByUser;
|
2020-05-31 20:34:50 +00:00
|
|
|
|
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;
|
2020-08-22 19:02:26 +00:00
|
|
|
QString m_OldIgnoreDevices;
|
|
|
|
QString m_OldIgnoreDevicesExcept;
|
2021-02-27 22:47:38 +00:00
|
|
|
StreamingPreferences::CaptureSysKeysMode m_CaptureSystemKeysMode;
|
2021-01-30 17:08:01 +00:00
|
|
|
int m_MouseCursorCapturedVisibilityState;
|
2018-06-28 08:44:43 +00:00
|
|
|
|
2021-01-24 19:02:42 +00:00
|
|
|
struct {
|
|
|
|
KeyCombo keyCombo;
|
|
|
|
SDL_Keycode keyCode;
|
|
|
|
SDL_Scancode scanCode;
|
|
|
|
bool enabled;
|
|
|
|
} m_SpecialKeyCombos[KeyComboMax];
|
|
|
|
|
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;
|
2023-07-23 05:17:58 +00:00
|
|
|
bool m_DisabledTouchFeedback;
|
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[];
|
|
|
|
};
|