mirror of
https://github.com/ddeverill/SteamlessController.git
synced 2026-10-22 06:32:20 -05:00
Auto-enable Steamless mode after startup reconnect
This commit is contained in:
1 parent
a660f671b4
commit
bc3e9932b1
4 files changed
+29
No files matched your search
@@ -20,9 +20,24 @@ void ControllerManager::OnDeviceChange() {
|
||||
TryOpen();
|
||||
else if (g_ctrl && !g_ctrl->IsOpen())
|
||||
Close(/*restoreLizard=*/false);
|
||||
|
||||
if (m_connected && m_wantsGameMode && !m_gameModeActive)
|
||||
EnableGameMode();
|
||||
}
|
||||
|
||||
void ControllerManager::Tick() {
|
||||
if (!m_connected) {
|
||||
TryOpen();
|
||||
} else if (g_ctrl && !g_ctrl->IsOpen()) {
|
||||
Close(/*restoreLizard=*/false);
|
||||
}
|
||||
|
||||
if (m_connected && m_wantsGameMode && !m_gameModeActive)
|
||||
EnableGameMode();
|
||||
}
|
||||
|
||||
void ControllerManager::EnableGameMode() {
|
||||
m_wantsGameMode = true;
|
||||
if (!m_connected || m_gameModeActive) return;
|
||||
if (!g_ctrl->DisableLizardMode()) return;
|
||||
|
||||
@@ -52,6 +67,7 @@ void ControllerManager::EnableGameMode() {
|
||||
}
|
||||
|
||||
void ControllerManager::DisableGameMode() {
|
||||
m_wantsGameMode = false;
|
||||
if (!m_gameModeActive) return;
|
||||
StopReadLoop();
|
||||
if (g_ctrl && g_ctrl->IsOpen())
|
||||
@@ -83,6 +99,8 @@ void ControllerManager::TryOpen() {
|
||||
if (g_ctrl->Open()) {
|
||||
m_connected = true;
|
||||
m_onStateChanged(m_connected, m_gameModeActive, false);
|
||||
if (m_wantsGameMode && !m_gameModeActive)
|
||||
EnableGameMode();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ public:
|
||||
|
||||
// Called when Windows reports a device arrival or removal (WM_DEVICECHANGE).
|
||||
void OnDeviceChange();
|
||||
void Tick();
|
||||
|
||||
// Toggle game mode on/off. No-op if controller is not connected.
|
||||
void EnableGameMode();
|
||||
@@ -46,6 +47,7 @@ private:
|
||||
StateChangedFn m_onStateChanged;
|
||||
bool m_connected = false;
|
||||
bool m_gameModeActive = false;
|
||||
bool m_wantsGameMode = true;
|
||||
bool m_trackpadMouseEnabled = false;
|
||||
bool m_backButtonsEnabled = false;
|
||||
bool m_useLeftTrackpad = false;
|
||||
|
||||
@@ -14,6 +14,8 @@ TrayApp::TrayApp() {
|
||||
}
|
||||
|
||||
TrayApp::~TrayApp() {
|
||||
if (m_hwnd)
|
||||
KillTimer(m_hwnd, TIMER_RECONNECT);
|
||||
RemoveTrayIcon();
|
||||
g_app = nullptr;
|
||||
}
|
||||
@@ -52,6 +54,7 @@ bool TrayApp::Init(HINSTANCE hInstance) {
|
||||
|
||||
LoadSettings();
|
||||
AddTrayIcon();
|
||||
SetTimer(m_hwnd, TIMER_RECONNECT, 2000, nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -121,6 +124,11 @@ LRESULT TrayApp::HandleMessage(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
|
||||
m_controller->OnDeviceChange();
|
||||
return TRUE;
|
||||
|
||||
case WM_TIMER:
|
||||
if (wp == TIMER_RECONNECT)
|
||||
m_controller->Tick();
|
||||
return 0;
|
||||
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
|
||||
@@ -39,6 +39,7 @@ private:
|
||||
static constexpr UINT IDM_BACKBUTTONS = 1004;
|
||||
static constexpr UINT IDM_LEFT_TRACKPAD = 1005;
|
||||
static constexpr UINT IDM_STARTUP = 1006;
|
||||
static constexpr UINT_PTR TIMER_RECONNECT = 1;
|
||||
static constexpr UINT WM_TRAY = WM_APP + 1;
|
||||
static constexpr UINT TRAY_UID = 1;
|
||||
};
|
||||
Reference in new issue
Block a user