mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2026-06-17 22:23:31 +00:00
Discard stale gamepad events when enabling gamepad navigation
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
SdlGamepadKeyNavigation::SdlGamepadKeyNavigation()
|
SdlGamepadKeyNavigation::SdlGamepadKeyNavigation()
|
||||||
: m_Enabled(false),
|
: m_Enabled(false),
|
||||||
m_UiNavMode(false),
|
m_UiNavMode(false),
|
||||||
|
m_FirstPoll(false),
|
||||||
m_LastAxisNavigationEventTime(0)
|
m_LastAxisNavigationEventTime(0)
|
||||||
{
|
{
|
||||||
m_PollingTimer = new QTimer(this);
|
m_PollingTimer = new QTimer(this);
|
||||||
@@ -62,6 +63,9 @@ void SdlGamepadKeyNavigation::enable()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Flush events on the first poll
|
||||||
|
m_FirstPoll = true;
|
||||||
|
|
||||||
// Poll every 50 ms for a new joystick event
|
// Poll every 50 ms for a new joystick event
|
||||||
m_PollingTimer->start(50);
|
m_PollingTimer->start(50);
|
||||||
|
|
||||||
@@ -91,6 +95,16 @@ void SdlGamepadKeyNavigation::onPollingTimerFired()
|
|||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
StreamingPreferences prefs;
|
StreamingPreferences prefs;
|
||||||
|
|
||||||
|
// Discard any pending button events on the first poll to avoid picking up
|
||||||
|
// stale input data from the stream session (like the quit combo).
|
||||||
|
if (m_FirstPoll) {
|
||||||
|
SDL_PumpEvents();
|
||||||
|
SDL_FlushEvent(SDL_CONTROLLERBUTTONDOWN);
|
||||||
|
SDL_FlushEvent(SDL_CONTROLLERBUTTONUP);
|
||||||
|
|
||||||
|
m_FirstPoll = false;
|
||||||
|
}
|
||||||
|
|
||||||
while (SDL_PollEvent(&event)) {
|
while (SDL_PollEvent(&event)) {
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case SDL_QUIT:
|
case SDL_QUIT:
|
||||||
|
|||||||
@@ -34,5 +34,6 @@ private:
|
|||||||
QList<SDL_GameController*> m_Gamepads;
|
QList<SDL_GameController*> m_Gamepads;
|
||||||
bool m_Enabled;
|
bool m_Enabled;
|
||||||
bool m_UiNavMode;
|
bool m_UiNavMode;
|
||||||
|
bool m_FirstPoll;
|
||||||
Uint32 m_LastAxisNavigationEventTime;
|
Uint32 m_LastAxisNavigationEventTime;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user