Skip to content

Commit 510f7ca

Browse files
committed
Fix for gamepad buttons jittering
1 parent 9d56afa commit 510f7ca

File tree

5 files changed

+17
-6
lines changed

5 files changed

+17
-6
lines changed

app/src/streaming/InputManager.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,21 @@ void MoonlightInputManager::handleControllers(bool specialKey) {
253253

254254
short mappedControllersCount = controllersToMap();
255255

256+
if (lastControllerCount != controllersCount) {
257+
lastControllerCount = controllersCount;
258+
259+
for (int i = 0; i < controllersCount; i++) {
260+
Logger::debug("StreamingView: send features message for controller #{}", i);
261+
LiSendControllerArrivalEvent(i, mappedControllersCount, LI_CTYPE_UNKNOWN, 0, LI_CCAP_RUMBLE | LI_CCAP_ACCEL | LI_CCAP_GYRO);
262+
}
263+
}
264+
256265
for (int i = 0; i < controllersCount; i++) {
257266
GamepadState gamepadState = getControllerState(i, specialKey);
258267

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

262-
LiSendControllerArrivalEvent(i, mappedControllersCount, LI_CTYPE_UNKNOWN, 0, LI_CCAP_RUMBLE | LI_CCAP_ACCEL | LI_CCAP_GYRO);
263-
264271
if (LiSendMultiControllerEvent(
265272
i, mappedControllersCount, gamepadState.buttonFlags,
266273
gamepadState.leftTrigger, gamepadState.rightTrigger,

app/src/streaming/MoonlightSession.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,15 @@ void MoonlightSession::connection_stage_failed(int stage, int error_code) {
7272

7373
void MoonlightSession::connection_started() {
7474
brls::Logger::info("MoonlightSession: Connection started");
75+
m_active_session->m_is_active = true;
7576
}
7677

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

8081
if (m_active_session) {
8182
m_active_session->m_is_active = false;
83+
m_active_session->m_is_terminated = true;
8284
}
8385
}
8486

app/src/streaming/MoonlightSession.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class MoonlightSession {
2323
void draw(NVGcontext* vg, int width, int height);
2424

2525
bool is_active() const { return m_is_active; }
26+
bool is_terminated() const { return m_is_terminated; }
2627

2728
bool connection_status_is_poor() const {
2829
return m_connection_status_is_poor;
@@ -69,7 +70,8 @@ class MoonlightSession {
6970
IVideoRenderer* m_video_renderer = nullptr;
7071
IAudioRenderer* m_audio_renderer = nullptr;
7172

72-
bool m_is_active = true;
73+
bool m_is_active = false;
74+
bool m_is_terminated = false;
7375
bool m_connection_status_is_poor = false;
7476

7577
SessionStats m_session_stats = {};

app/src/streaming_view.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,14 @@ void StreamingView::onFocusLost() {
209209

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

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

219-
if (!tempInputLock)
219+
if (!tempInputLock && session->is_active())
220220
handleInput();
221221
handleOverlayCombo();
222222
handleMouseInputCombo();

0 commit comments

Comments
 (0)