Files
moonlight-qt/app/gui/sdlgamepadkeynavigation.h
T
Cameron Gutman 457aa3ab26 Only use SDL_JoystickUpdate() when required to avoid reentrancy
It doesn't properly handle hotplugging on all joystick backends,
so we want to use it only as long as we need to avoid crashing
during video subsystem shutdown.

Fixes #2104
2026-11-23 01:56:13 -06:00

49 lines
968 B
C++

#pragma once
#include <QTimer>
#include <QEvent>
#include "SDL_compat.h"
#include "settings/streamingpreferences.h"
class SdlGamepadKeyNavigation : public QObject
{
Q_OBJECT
public:
SdlGamepadKeyNavigation(StreamingPreferences* prefs);
~SdlGamepadKeyNavigation();
Q_INVOKABLE void enable();
Q_INVOKABLE void disable();
Q_INVOKABLE void notifyWindowFocus(bool hasFocus);
Q_INVOKABLE void setUiNavMode(bool settingsMode);
Q_INVOKABLE int getConnectedGamepads();
private:
void sendKey(QEvent::Type type, Qt::Key key, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
void updateTimerState();
void pumpGamepadEvents();
private slots:
void onPollingTimerFired();
private:
StreamingPreferences* m_Prefs;
QTimer* m_PollingTimer;
QList<SDL_GameController*> m_Gamepads;
bool m_Enabled;
bool m_UiNavMode;
bool m_FirstPoll;
bool m_HasFocus;
Uint32 m_LastAxisNavigationEventTime;
};