diff options
| author | a1xd <[email protected]> | 2021-01-30 01:23:34 -0500 |
|---|---|---|
| committer | a1xd <[email protected]> | 2021-01-30 01:23:34 -0500 |
| commit | f64c40346dab580220101b0aacb4a6ff5484d86a (patch) | |
| tree | e6103ccb3a0a4adde6cab99a6293a63dbc90738e /wrapper/wrapper.cpp | |
| parent | bump version (diff) | |
| download | rawaccel-f64c40346dab580220101b0aacb4a6ff5484d86a.tar.xz rawaccel-f64c40346dab580220101b0aacb4a6ff5484d86a.zip | |
fix device id not working with g305
this uses w32 apis for enumerating dev info instead of ManagementObjectSearcher, which upper-cases dev ids, differing from kernel/cfgmgr32
this also breaks showing dev name alongside id, as the name seems inaccessible from cfgmgr32 given an interface supplied by rawinput
not a big deal considering the names are too generic to be useful anyway
Diffstat (limited to 'wrapper/wrapper.cpp')
| -rw-r--r-- | wrapper/wrapper.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/wrapper/wrapper.cpp b/wrapper/wrapper.cpp index f5672a1..71a8cf6 100644 --- a/wrapper/wrapper.cpp +++ b/wrapper/wrapper.cpp @@ -1,5 +1,6 @@ #pragma once +#include <algorithm> #include <type_traits> #include <msclr\marshal_cppstd.h> @@ -276,6 +277,30 @@ public: } }; +struct device_info { + std::wstring name; + std::wstring id; +}; + +std::vector<device_info> get_unique_device_info() { + std::vector<device_info> info; + + rawinput_foreach_with_interface([&](const auto& dev, const WCHAR* name) { + info.push_back({ + L"", // get_property_wstr(name, &DEVPKEY_Device_FriendlyName), /* doesn't work */ + dev_id_from_interface(name) + }); + }); + + std::sort(info.begin(), info.end(), + [](auto&& l, auto&& r) { return l.id < r.id; }); + auto last = std::unique(info.begin(), info.end(), + [](auto&& l, auto&& r) { return l.id == r.id; }); + info.erase(last, info.end()); + + return info; +} + public ref struct RawInputInterop { static void AddHandlesFromID(String^ deviceID, List<IntPtr>^ rawInputHandles) @@ -292,6 +317,29 @@ public ref struct RawInputInterop throw gcnew System::Exception(gcnew String(e.what())); } } + + static List<ValueTuple<String^, String^>>^ GetDeviceIDs() + { + try + { + auto managed = gcnew List<ValueTuple<String^, String^>>(); + + for (auto&& [name, id] : get_unique_device_info()) + { + managed->Add( + ValueTuple<String^, String^>( + msclr::interop::marshal_as<String^>(name), + msclr::interop::marshal_as<String^>(id))); + } + + return managed; + } + catch (const std::exception& e) + { + throw gcnew System::Exception(gcnew String(e.what())); + } + } + }; public ref struct DriverInterop |