ManetteGamepadProvider.h [plain text]
#pragma once
#if ENABLE(GAMEPAD) && OS(LINUX)
#include "GamepadProvider.h"
#include <libmanette.h>
#include <wtf/HashMap.h>
#include <wtf/RunLoop.h>
namespace WebCore {
class ManetteGamepad;
class GamepadProviderClient;
class ManetteGamepadProvider final : public GamepadProvider {
WTF_MAKE_NONCOPYABLE(ManetteGamepadProvider);
friend class NeverDestroyed<ManetteGamepadProvider>;
public:
static ManetteGamepadProvider& singleton();
virtual ~ManetteGamepadProvider();
void startMonitoringGamepads(GamepadProviderClient&) final;
void stopMonitoringGamepads(GamepadProviderClient&) final;
const Vector<PlatformGamepad*>& platformGamepads() final { return m_gamepadVector; }
void deviceConnected(ManetteDevice*);
void deviceDisconnected(ManetteDevice*);
enum class ShouldMakeGamepadsVisible : bool { No, Yes };
void gamepadHadInput(ManetteGamepad&, ShouldMakeGamepadsVisible);
private:
ManetteGamepadProvider();
std::unique_ptr<ManetteGamepad> removeGamepadForDevice(ManetteDevice*);
unsigned indexForNewlyConnectedDevice();
void initialGamepadsConnectedTimerFired();
void inputNotificationTimerFired();
Vector<PlatformGamepad*> m_gamepadVector;
HashMap<ManetteDevice*, std::unique_ptr<ManetteGamepad>> m_gamepadMap;
bool m_initialGamepadsConnected { false };
GRefPtr<ManetteMonitor> m_monitor;
RunLoop::Timer<ManetteGamepadProvider> m_initialGamepadsConnectedTimer;
RunLoop::Timer<ManetteGamepadProvider> m_inputNotificationTimer;
};
}
#endif // ENABLE(GAMEPAD) && OS(LINUX)