Fix bluetooth reconnection events

This commit is contained in:
PixlOne
2019-09-21 13:29:12 -04:00
parent ac414bf33e
commit 0002d9f536
2 changed files with 42 additions and 3 deletions
+26 -1
View File
@@ -193,9 +193,15 @@ void Device::set_dpi(int dpi)
void Device::start()
{
configure();
listener->addEventHandler( std::make_unique<ButtonHandler>(hidpp_dev, this) );
try { listener->addEventHandler(std::make_unique<ButtonHandler>(this)); }
catch(HIDPP20::UnsupportedFeature &e) { }
if(index != HIDPP::DefaultDevice && index != HIDPP::CordedDevice)
listener->addEventHandler( std::make_unique<ReceiverHandler>(this) );
else
{
try { listener->addEventHandler( std::make_unique<WirelessStatusHandler>(this) ); }
catch(HIDPP20::UnsupportedFeature &e) { }
}
listener->start();
}
@@ -274,6 +280,25 @@ void ReceiverHandler::handleEvent(const HIDPP::Report &event)
}
}
void WirelessStatusHandler::handleEvent(const HIDPP::Report &event)
{
switch(event.function())
{
case HIDPP20::IWirelessDeviceStatus::StatusBroadcast:
{
auto status = HIDPP20::IWirelessDeviceStatus::statusBroadcastEvent(event);
if(status.ReconfNeeded)
dev->configure();
break;
}
default:
{
log_printf(DEBUG, "Undocumented event %02x from WirelessDeviceStatus", event.function());
break;
}
}
}
void EventListener::removeEventHandlers ()
{
for (const auto &p: iterators)