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>
|
|
|
|
|
2020-07-12 22:06:36 +00:00
|
|
|
#define SDL_CODE_HIDE_CURSOR 1
|
|
|
|
#define SDL_CODE_SHOW_CURSOR 2
|
2021-02-07 18:38:57 +00:00
|
|
|
#define SDL_CODE_UNCAPTURE_MOUSE 3
|
2020-07-12 22:06:36 +00:00
|
|
|
|
2018-06-28 08:44:43 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2021-02-27 03:43:47 +00:00
|
|
|
#ifdef Q_OS_DARWIN
|
|
|
|
#include <CoreGraphics/CGError.h>
|
|
|
|
extern "C" {
|
|
|
|
typedef int CGSConnection;
|
|
|
|
typedef enum {
|
|
|
|
CGSGlobalHotKeyEnable = 0,
|
|
|
|
CGSGlobalHotKeyDisable = 1,
|
|
|
|
} CGSGlobalHotKeyOperatingMode;
|
|
|
|
|
|
|
|
extern CGSConnection _CGSDefaultConnection(void);
|
|
|
|
|
|
|
|
extern CGError CGSGetGlobalHotKeyOperatingMode(CGSConnection connection,
|
|
|
|
CGSGlobalHotKeyOperatingMode* mode);
|
|
|
|
|
|
|
|
extern CGError CGSSetGlobalHotKeyOperatingMode(CGSConnection connection,
|
|
|
|
CGSGlobalHotKeyOperatingMode mode);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-06-28 08:44:43 +00:00
|
|
|
#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);
|
|
|
|
|
2021-02-07 23:18:35 +00:00
|
|
|
void sendText(QString& string);
|
2021-02-07 19:46:38 +00:00
|
|
|
|
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
|
|
|
|
2021-02-27 03:43:47 +00:00
|
|
|
void notifyFocusGained();
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
void updateMousePositionReport(int mouseX, int mouseY);
|
|
|
|
|
2020-09-05 21:50:38 +00:00
|
|
|
void flushMousePositionUpdate();
|
|
|
|
|
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,
|
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);
|
|
|
|
|
2020-05-01 03:55:15 +00:00
|
|
|
void handleAbsoluteFingerEvent(SDL_TouchFingerEvent* event);
|
|
|
|
|
|
|
|
void handleRelativeFingerEvent(SDL_TouchFingerEvent* event);
|
|
|
|
|
2021-01-24 19:02:42 +00:00
|
|
|
void performPendingSpecialKeyCombo();
|
|
|
|
|
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);
|
|
|
|
|
2021-02-07 23:18:35 +00:00
|
|
|
static
|
|
|
|
int clipboardThreadProc(void *ptr);
|
|
|
|
|
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;
|
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;
|
2020-07-12 22:06:36 +00:00
|
|
|
bool m_MouseWasInVideoRegion;
|
|
|
|
bool m_PendingMouseButtonsAllUpOnVideoRegionLeave;
|
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-01-12 05:43:32 +00:00
|
|
|
bool m_CaptureSystemKeysEnabled;
|
2021-01-30 17:08:01 +00:00
|
|
|
int m_MouseCursorCapturedVisibilityState;
|
2018-06-28 08:44:43 +00:00
|
|
|
|
2021-02-27 03:43:47 +00:00
|
|
|
#ifdef Q_OS_DARWIN
|
|
|
|
CGSGlobalHotKeyOperatingMode m_OldHotKeyMode;
|
|
|
|
#endif
|
|
|
|
|
2021-01-24 19:02:42 +00:00
|
|
|
struct {
|
|
|
|
KeyCombo keyCombo;
|
|
|
|
SDL_Keycode keyCode;
|
|
|
|
SDL_Scancode scanCode;
|
|
|
|
bool enabled;
|
|
|
|
} m_SpecialKeyCombos[KeyComboMax];
|
|
|
|
KeyCombo m_PendingKeyCombo;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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
|
|
|
|
2021-02-07 23:18:35 +00:00
|
|
|
SDL_Thread* m_ClipboardThread;
|
|
|
|
SDL_atomic_t m_ShutdownClipboardThread;
|
|
|
|
QString m_ClipboardData;
|
|
|
|
SDL_cond* m_ClipboardHasData;
|
|
|
|
SDL_mutex* m_ClipboardLock;
|
|
|
|
|
2018-06-28 08:44:43 +00:00
|
|
|
static const int k_ButtonMap[];
|
|
|
|
};
|