Skip to content

Commit

Permalink
Fix for gamepad buttons jittering
Browse files Browse the repository at this point in the history
  • Loading branch information
XITRIX committed Apr 30, 2024
1 parent 9d56afa commit 510f7ca
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
11 changes: 9 additions & 2 deletions app/src/streaming/InputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,21 @@ void MoonlightInputManager::handleControllers(bool specialKey) {

short mappedControllersCount = controllersToMap();

if (lastControllerCount != controllersCount) {
lastControllerCount = controllersCount;

for (int i = 0; i < controllersCount; i++) {
Logger::debug("StreamingView: send features message for controller #{}", i);
LiSendControllerArrivalEvent(i, mappedControllersCount, LI_CTYPE_UNKNOWN, 0, LI_CCAP_RUMBLE | LI_CCAP_ACCEL | LI_CCAP_GYRO);
}
}

for (int i = 0; i < controllersCount; i++) {
GamepadState gamepadState = getControllerState(i, specialKey);

if (!gamepadState.is_equal(lastGamepadStates[i])) {
lastGamepadStates[i] = gamepadState;

LiSendControllerArrivalEvent(i, mappedControllersCount, LI_CTYPE_UNKNOWN, 0, LI_CCAP_RUMBLE | LI_CCAP_ACCEL | LI_CCAP_GYRO);

if (LiSendMultiControllerEvent(
i, mappedControllersCount, gamepadState.buttonFlags,
gamepadState.leftTrigger, gamepadState.rightTrigger,
Expand Down
2 changes: 2 additions & 0 deletions app/src/streaming/MoonlightSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,15 @@ void MoonlightSession::connection_stage_failed(int stage, int error_code) {

void MoonlightSession::connection_started() {
brls::Logger::info("MoonlightSession: Connection started");
m_active_session->m_is_active = true;
}

void MoonlightSession::connection_terminated(int error_code) {
brls::Logger::info("MoonlightSession: Connection terminated...");

if (m_active_session) {
m_active_session->m_is_active = false;
m_active_session->m_is_terminated = true;
}
}

Expand Down
4 changes: 3 additions & 1 deletion app/src/streaming/MoonlightSession.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class MoonlightSession {
void draw(NVGcontext* vg, int width, int height);

bool is_active() const { return m_is_active; }
bool is_terminated() const { return m_is_terminated; }

bool connection_status_is_poor() const {
return m_connection_status_is_poor;
Expand Down Expand Up @@ -69,7 +70,8 @@ class MoonlightSession {
IVideoRenderer* m_video_renderer = nullptr;
IAudioRenderer* m_audio_renderer = nullptr;

bool m_is_active = true;
bool m_is_active = false;
bool m_is_terminated = false;
bool m_connection_status_is_poor = false;

SessionStats m_session_stats = {};
Expand Down
4 changes: 2 additions & 2 deletions app/src/streaming_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,14 @@ void StreamingView::onFocusLost() {

void StreamingView::draw(NVGcontext* vg, float x, float y, float width,
float height, Style style, FrameContext* ctx) {
if (!session->is_active()) {
if (session->is_terminated()) {
terminate(false);
return;
}

session->draw(vg, width, height);

if (!tempInputLock)
if (!tempInputLock && session->is_active())
handleInput();
handleOverlayCombo();
handleMouseInputCombo();
Expand Down

0 comments on commit 510f7ca

Please sign in to comment.