From 4c7a2faf85a2d74508cc8a95df42ebe52b47383b Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 9 Nov 2024 01:53:01 +0000 Subject: [PATCH] input: cleanup device naming logic ref #8301 --- src/devices/IHID.hpp | 2 +- src/devices/IKeyboard.hpp | 1 - src/devices/IPointer.hpp | 1 - src/devices/ITouch.hpp | 1 - src/devices/Tablet.hpp | 5 ----- src/managers/input/InputManager.cpp | 27 ++++----------------------- src/managers/input/Tablets.cpp | 6 ++++++ 7 files changed, 11 insertions(+), 32 deletions(-) diff --git a/src/devices/IHID.hpp b/src/devices/IHID.hpp index cac25112..4a0ff8fd 100644 --- a/src/devices/IHID.hpp +++ b/src/devices/IHID.hpp @@ -36,5 +36,5 @@ class IHID { CSignal destroy; } events; - std::string deviceName; + std::string deviceName, hlName; }; \ No newline at end of file diff --git a/src/devices/IKeyboard.hpp b/src/devices/IKeyboard.hpp index 76d2c31b..dce2127a 100644 --- a/src/devices/IKeyboard.hpp +++ b/src/devices/IKeyboard.hpp @@ -94,7 +94,6 @@ class IKeyboard : public IHID { std::array modIndexes = {XKB_MOD_INVALID}; uint32_t leds = 0; - std::string hlName = ""; std::string xkbFilePath = ""; std::string xkbKeymapString = ""; int xkbKeymapFD = -1; diff --git a/src/devices/IPointer.hpp b/src/devices/IPointer.hpp index f38ef55a..503a690e 100644 --- a/src/devices/IPointer.hpp +++ b/src/devices/IPointer.hpp @@ -104,7 +104,6 @@ class IPointer : public IHID { CSignal holdEnd; } pointerEvents; - std::string hlName; bool connected = false; // means connected to the cursor std::string boundOutput = ""; diff --git a/src/devices/ITouch.hpp b/src/devices/ITouch.hpp index bf969b2f..766c0510 100644 --- a/src/devices/ITouch.hpp +++ b/src/devices/ITouch.hpp @@ -44,7 +44,6 @@ class ITouch : public IHID { CSignal frame; } touchEvents; - std::string hlName = ""; std::string boundOutput = ""; WP self; diff --git a/src/devices/Tablet.hpp b/src/devices/Tablet.hpp index 01901721..4894ac8e 100644 --- a/src/devices/Tablet.hpp +++ b/src/devices/Tablet.hpp @@ -92,7 +92,6 @@ class CTablet : public IHID { WP self; bool relativeInput = false; - std::string hlName = ""; std::string boundOutput = ""; CBox activeArea; CBox boundBox; // output-local @@ -154,8 +153,6 @@ class CTabletPad : public IHID { WP self; WP parent; - std::string hlName; - private: CTabletPad(SP pad); @@ -210,8 +207,6 @@ class CTabletTool : public IHID { std::vector buttonsDown; Vector2D absolutePos; // last known absolute position. - std::string hlName; - private: CTabletTool(SP tool); diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index b12a6e03..2787cbf7 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -1655,31 +1655,12 @@ std::string CInputManager::getNameForNewDevice(std::string internalName) { auto proposedNewName = deviceNameToInternalString(internalName); int dupeno = 0; - while (std::find_if(m_vKeyboards.begin(), m_vKeyboards.end(), - [&](const auto& other) { return other->hlName == proposedNewName + (dupeno == 0 ? "" : ("-" + std::to_string(dupeno))); }) != m_vKeyboards.end()) + auto makeNewName = [&]() { return (proposedNewName.empty() ? "unknown-device" : proposedNewName) + (dupeno == 0 ? "" : ("-" + std::to_string(dupeno))); }; + + while (std::find_if(m_vHIDs.begin(), m_vHIDs.end(), [&](const auto& other) { return other->hlName == makeNewName(); }) != m_vHIDs.end()) dupeno++; - while (std::find_if(m_vPointers.begin(), m_vPointers.end(), - [&](const auto& other) { return other->hlName == proposedNewName + (dupeno == 0 ? "" : ("-" + std::to_string(dupeno))); }) != m_vPointers.end()) - dupeno++; - - while (std::find_if(m_vTouches.begin(), m_vTouches.end(), - [&](const auto& other) { return other->hlName == proposedNewName + (dupeno == 0 ? "" : ("-" + std::to_string(dupeno))); }) != m_vTouches.end()) - dupeno++; - - while (std::find_if(m_vTabletPads.begin(), m_vTabletPads.end(), - [&](const auto& other) { return other->hlName == proposedNewName + (dupeno == 0 ? "" : ("-" + std::to_string(dupeno))); }) != m_vTabletPads.end()) - dupeno++; - - while (std::find_if(m_vTablets.begin(), m_vTablets.end(), - [&](const auto& other) { return other->hlName == proposedNewName + (dupeno == 0 ? "" : ("-" + std::to_string(dupeno))); }) != m_vTablets.end()) - dupeno++; - - while (std::find_if(m_vTabletTools.begin(), m_vTabletTools.end(), - [&](const auto& other) { return other->hlName == proposedNewName + (dupeno == 0 ? "" : ("-" + std::to_string(dupeno))); }) != m_vTabletTools.end()) - dupeno++; - - return proposedNewName + (dupeno == 0 ? "" : ("-" + std::to_string(dupeno))); + return makeNewName(); } void CInputManager::releaseAllMouseButtons() { diff --git a/src/managers/input/Tablets.cpp b/src/managers/input/Tablets.cpp index 9f80726e..3884afec 100644 --- a/src/managers/input/Tablets.cpp +++ b/src/managers/input/Tablets.cpp @@ -228,6 +228,12 @@ SP CInputManager::ensureTabletToolPresent(SPhlName = deviceNameToInternalString(pTool->getName()); + } catch (std::exception& e) { + Debug::log(ERR, "Tablet had no name???"); // logic error + } + PTOOL->events.destroy.registerStaticListener( [this](void* owner, std::any d) { auto TOOL = ((CTabletTool*)owner)->self;