mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2026-02-16 10:40:59 +00:00
DualSense adaptive trigger support (#1561)
This commit is contained in:
@@ -40,6 +40,7 @@
|
||||
#define SDL_CODE_GAMECONTROLLER_RUMBLE_TRIGGERS 102
|
||||
#define SDL_CODE_GAMECONTROLLER_SET_MOTION_EVENT_STATE 103
|
||||
#define SDL_CODE_GAMECONTROLLER_SET_CONTROLLER_LED 104
|
||||
#define SDL_CODE_GAMECONTROLLER_SET_ADAPTIVE_TRIGGERS 105
|
||||
|
||||
#include <openssl/rand.h>
|
||||
|
||||
@@ -69,6 +70,7 @@ CONNECTION_LISTENER_CALLBACKS Session::k_ConnCallbacks = {
|
||||
Session::clRumbleTriggers,
|
||||
Session::clSetMotionEventState,
|
||||
Session::clSetControllerLED,
|
||||
Session::clSetAdaptiveTriggers
|
||||
};
|
||||
|
||||
Session* Session::s_ActiveSession;
|
||||
@@ -259,6 +261,30 @@ void Session::clSetControllerLED(uint16_t controllerNumber, uint8_t r, uint8_t g
|
||||
SDL_PushEvent(&setControllerLEDEvent);
|
||||
}
|
||||
|
||||
void Session::clSetAdaptiveTriggers(uint16_t controllerNumber, uint8_t eventFlags, uint8_t typeLeft, uint8_t typeRight, uint8_t *left, uint8_t *right){
|
||||
// We push an event for the main thread to handle in order to properly synchronize
|
||||
// with the removal of game controllers that could result in our game controller
|
||||
// going away during this callback.
|
||||
SDL_Event setControllerLEDEvent = {};
|
||||
setControllerLEDEvent.type = SDL_USEREVENT;
|
||||
setControllerLEDEvent.user.code = SDL_CODE_GAMECONTROLLER_SET_ADAPTIVE_TRIGGERS;
|
||||
setControllerLEDEvent.user.data1 = (void*)(uintptr_t)controllerNumber;
|
||||
|
||||
// Based on the following SDL code:
|
||||
// https://github.com/libsdl-org/SDL/blob/120c76c84bbce4c1bfed4e9eb74e10678bd83120/test/testgamecontroller.c#L286-L307
|
||||
DualSenseOutputReport *state = (DualSenseOutputReport *) SDL_malloc(sizeof(DualSenseOutputReport));
|
||||
SDL_zero(*state);
|
||||
state->validFlag0 = (eventFlags & DS_EFFECT_RIGHT_TRIGGER) | (eventFlags & DS_EFFECT_LEFT_TRIGGER);
|
||||
state->rightTriggerEffectType = typeRight;
|
||||
SDL_memcpy(state->rightTriggerEffect, right, sizeof(state->rightTriggerEffect));
|
||||
state->leftTriggerEffectType = typeLeft;
|
||||
SDL_memcpy(state->leftTriggerEffect, left, sizeof(state->leftTriggerEffect));
|
||||
|
||||
setControllerLEDEvent.user.data2 = (void *) state;
|
||||
SDL_PushEvent(&setControllerLEDEvent);
|
||||
}
|
||||
|
||||
|
||||
bool Session::chooseDecoder(StreamingPreferences::VideoDecoderSelection vds,
|
||||
SDL_Window* window, int videoFormat, int width, int height,
|
||||
int frameRate, bool enableVsync, bool enableFramePacing, bool testOnly, IVideoDecoder*& chosenDecoder)
|
||||
@@ -2041,6 +2067,10 @@ void Session::execInternal()
|
||||
(uint8_t)((uintptr_t)event.user.data2 >> 8),
|
||||
(uint8_t)((uintptr_t)event.user.data2));
|
||||
break;
|
||||
case SDL_CODE_GAMECONTROLLER_SET_ADAPTIVE_TRIGGERS:
|
||||
m_InputHandler->setAdaptiveTriggers((uint16_t)(uintptr_t)event.user.data1,
|
||||
(DualSenseOutputReport *)event.user.data2);
|
||||
break;
|
||||
default:
|
||||
SDL_assert(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user