evdev: Add hotplugging support

This adds hotplugging support to the evdev input backend. We use
libudev to monitor changes to input devices in a separate thread.
Removed devices are removed from the devices list, and new devices
are added to the list.

The effect is that controllers are usable immediately after plugging
them without having to manually refresh devices (if they were
configured to be used, of course).
This commit is contained in:
Léo Lam 2016-07-14 17:50:35 +02:00
parent 3926db624d
commit 135641404a
3 changed files with 152 additions and 17 deletions
Source/Core/InputCommon/ControllerInterface

View file

@ -106,17 +106,6 @@ void ControllerInterface::Shutdown()
if (!m_is_init)
return;
std::lock_guard<std::mutex> lk(m_devices_mutex);
for (const auto& d : m_devices)
{
// Set outputs to ZERO before destroying device
for (ciface::Core::Device::Output* o : d->Outputs())
o->SetState(0);
}
m_devices.clear();
#ifdef CIFACE_USE_XINPUT
ciface::XInput::DeInit();
#endif
@ -136,6 +125,20 @@ void ControllerInterface::Shutdown()
#ifdef CIFACE_USE_ANDROID
// nothing needed
#endif
#ifdef CIFACE_USE_EVDEV
ciface::evdev::Shutdown();
#endif
std::lock_guard<std::mutex> lk(m_devices_mutex);
for (const auto& d : m_devices)
{
// Set outputs to ZERO before destroying device
for (ciface::Core::Device::Output* o : d->Outputs())
o->SetState(0);
}
m_devices.clear();
m_is_init = false;
}