From eaa4f8464b53be0b2b1bb7d0a06f70c7f3d43b0e Mon Sep 17 00:00:00 2001 From: joncruz Date: Mon, 24 Mar 2008 05:19:52 +0000 Subject: [PATCH] Fixed unlinking of devices --- src/device-manager.cpp | 50 ++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/src/device-manager.cpp b/src/device-manager.cpp index dcf86edb7..a9a8844ab 100644 --- a/src/device-manager.cpp +++ b/src/device-manager.cpp @@ -240,34 +240,46 @@ void DeviceManagerImpl::setLinkedTo(Glib::ustring const & id, Glib::ustring cons std::list::iterator it = std::find_if(devices.begin(), devices.end(), IdMatcher(id)); if ( it != devices.end() ) { InputDeviceImpl* dev = *it; - // Need to be sure the target of the link exists - it = std::find_if(devices.begin(), devices.end(), IdMatcher(link)); - if ( it != devices.end() ) { - InputDeviceImpl* targetDev = *it; - if ( (dev->getLink() != link) || (targetDev->getLink() != id) ) { - // only muck about if they aren't already linked - std::list changedItems; - // Is something else already using that link? + + InputDeviceImpl* targetDev = 0; + if ( !link.empty() ) { + // Need to be sure the target of the link exists + it = std::find_if(devices.begin(), devices.end(), IdMatcher(link)); + if ( it != devices.end() ) { + targetDev = *it; + } + } + + + if ( (link.empty() && !dev->getLink().empty()) + || (targetDev && (targetDev->getLink() != id)) ) { + // only muck about if they aren't already linked + std::list changedItems; + + if ( targetDev ) { + // Is something else already using that link? it = std::find_if(devices.begin(), devices.end(), LinkMatcher(link)); if ( it != devices.end() ) { (*it)->setLink(""); changedItems.push_back(*it); } - it = std::find_if(devices.begin(), devices.end(), LinkMatcher(id)); - if ( it != devices.end() ) { - (*it)->setLink(""); - changedItems.push_back(*it); - } - dev->setLink(link); + } + it = std::find_if(devices.begin(), devices.end(), LinkMatcher(id)); + if ( it != devices.end() ) { + (*it)->setLink(""); + changedItems.push_back(*it); + } + if ( targetDev ) { targetDev->setLink(id); changedItems.push_back(targetDev); - changedItems.push_back(dev); + } + dev->setLink(link); + changedItems.push_back(dev); - for ( std::list::const_iterator iter = changedItems.begin(); iter != changedItems.end(); ++iter ) { - (*iter)->reference(); - signalLinkChangedPriv.emit(Glib::RefPtr(*iter)); - } + for ( std::list::const_iterator iter = changedItems.begin(); iter != changedItems.end(); ++iter ) { + (*iter)->reference(); + signalLinkChangedPriv.emit(Glib::RefPtr(*iter)); } } } -- 2.30.2