mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-27 08:15:33 +01:00
ControllerInterface: don't call InvokeDevicesChangedCallbacks more than once when refreshing
This commit is contained in:
parent
fd7cbd633e
commit
8e6677be90
@ -47,6 +47,7 @@ void ControllerInterface::Initialize(void* const hwnd)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
m_hwnd = hwnd;
|
m_hwnd = hwnd;
|
||||||
|
m_is_populating_devices = true;
|
||||||
|
|
||||||
#ifdef CIFACE_USE_DINPUT
|
#ifdef CIFACE_USE_DINPUT
|
||||||
// nothing needed
|
// nothing needed
|
||||||
@ -88,6 +89,8 @@ void ControllerInterface::RefreshDevices()
|
|||||||
m_devices.clear();
|
m_devices.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_is_populating_devices = true;
|
||||||
|
|
||||||
#ifdef CIFACE_USE_DINPUT
|
#ifdef CIFACE_USE_DINPUT
|
||||||
ciface::DInput::PopulateDevices(reinterpret_cast<HWND>(m_hwnd));
|
ciface::DInput::PopulateDevices(reinterpret_cast<HWND>(m_hwnd));
|
||||||
#endif
|
#endif
|
||||||
@ -113,6 +116,9 @@ void ControllerInterface::RefreshDevices()
|
|||||||
#ifdef CIFACE_USE_PIPES
|
#ifdef CIFACE_USE_PIPES
|
||||||
ciface::Pipes::PopulateDevices();
|
ciface::Pipes::PopulateDevices();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
m_is_populating_devices = false;
|
||||||
|
InvokeDevicesChangedCallbacks();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -188,6 +194,8 @@ void ControllerInterface::AddDevice(std::shared_ptr<ciface::Core::Device> device
|
|||||||
NOTICE_LOG(SERIALINTERFACE, "Added device: %s", device->GetQualifiedName().c_str());
|
NOTICE_LOG(SERIALINTERFACE, "Added device: %s", device->GetQualifiedName().c_str());
|
||||||
m_devices.emplace_back(std::move(device));
|
m_devices.emplace_back(std::move(device));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!m_is_populating_devices)
|
||||||
InvokeDevicesChangedCallbacks();
|
InvokeDevicesChangedCallbacks();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,6 +213,8 @@ void ControllerInterface::RemoveDevice(std::function<bool(const ciface::Core::De
|
|||||||
});
|
});
|
||||||
m_devices.erase(it, m_devices.end());
|
m_devices.erase(it, m_devices.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!m_is_populating_devices)
|
||||||
InvokeDevicesChangedCallbacks();
|
InvokeDevicesChangedCallbacks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
@ -57,6 +58,7 @@ private:
|
|||||||
std::vector<std::function<void()>> m_devices_changed_callbacks;
|
std::vector<std::function<void()>> m_devices_changed_callbacks;
|
||||||
mutable std::mutex m_callbacks_mutex;
|
mutable std::mutex m_callbacks_mutex;
|
||||||
bool m_is_init;
|
bool m_is_init;
|
||||||
|
std::atomic<bool> m_is_populating_devices{false};
|
||||||
void* m_hwnd;
|
void* m_hwnd;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user