From 7c1f14845bc948e9ea25908e96099203d9433a69 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Tue, 6 Apr 2021 01:21:42 -0400 Subject: update wrapper + writer to handle lut grapher is building but applying options still broken for the most part --- wrapper/input.cpp | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 wrapper/input.cpp (limited to 'wrapper/input.cpp') diff --git a/wrapper/input.cpp b/wrapper/input.cpp new file mode 100644 index 0000000..d50f774 --- /dev/null +++ b/wrapper/input.cpp @@ -0,0 +1,74 @@ +#include "interop-exception.h" + +#include +#include +#include + +using namespace System; +using namespace System::Collections::Generic; + +struct device_info { + std::wstring name; + std::wstring id; +}; + +std::vector get_unique_device_info() { + std::vector 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^ rawInputHandles) + { + try + { + std::vector nativeHandles = rawinput_handles_from_dev_id( + msclr::interop::marshal_as(deviceID)); + + for (auto nh : nativeHandles) rawInputHandles->Add(IntPtr(nh)); + } + catch (const std::exception& e) + { + throw gcnew RawInputInteropException(e); + } + } + + static List>^ GetDeviceIDs() + { + try + { + auto managed = gcnew List>(); + + for (auto&& [name, id] : get_unique_device_info()) + { + managed->Add( + ValueTuple( + msclr::interop::marshal_as(name), + msclr::interop::marshal_as(id))); + } + + return managed; + } + catch (const std::exception& e) + { + throw gcnew RawInputInteropException(e); + } + } + +}; + -- cgit v1.2.3 From 9f1ebe0feaaaf1eef1ffa5706d270b7600edfc63 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Tue, 6 Jul 2021 16:10:52 -0400 Subject: fix typo and wrapper/input code from lut2 merge --- wrapper/input.cpp | 65 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 30 deletions(-) (limited to 'wrapper/input.cpp') diff --git a/wrapper/input.cpp b/wrapper/input.cpp index d50f774..3ce257a 100644 --- a/wrapper/input.cpp +++ b/wrapper/input.cpp @@ -1,43 +1,52 @@ +#include "input.h" #include "interop-exception.h" -#include -#include #include +#include using namespace System; using namespace System::Collections::Generic; -struct device_info { - std::wstring name; - std::wstring id; -}; +std::vector rawinput_handles_from_id(const std::wstring& device_id) +{ + std::vector handles; + + rawinput_foreach([&](const auto& dev) { + if (dev.id == device_id) handles.push_back(dev.handle); + }); -std::vector get_unique_device_info() { - std::vector info; + return handles; +} + +std::vector rawinput_id_list() +{ + std::vector ids; - 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) - }); + rawinput_foreach([&](const auto& dev) { + ids.push_back(dev.id); }); - 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; + std::sort(ids.begin(), ids.end()); + ids.erase(std::unique(ids.begin(), ids.end()), ids.end()); + return ids; } +public ref struct RawInputInteropException : InteropException { + RawInputInteropException(System::String^ what) : + InteropException(what) {} + RawInputInteropException(const char* what) : + InteropException(what) {} + RawInputInteropException(const std::exception& e) : + InteropException(e) {} +}; + public ref struct RawInputInterop { static void AddHandlesFromID(String^ deviceID, List^ rawInputHandles) { try { - std::vector nativeHandles = rawinput_handles_from_dev_id( + std::vector nativeHandles = rawinput_handles_from_id( msclr::interop::marshal_as(deviceID)); for (auto nh : nativeHandles) rawInputHandles->Add(IntPtr(nh)); @@ -48,21 +57,18 @@ public ref struct RawInputInterop } } - static List>^ GetDeviceIDs() + static List^ GetDeviceIDs() { try { - auto managed = gcnew List>(); + auto ids = gcnew List(); - for (auto&& [name, id] : get_unique_device_info()) + for (auto&& name : rawinput_id_list()) { - managed->Add( - ValueTuple( - msclr::interop::marshal_as(name), - msclr::interop::marshal_as(id))); + ids->Add(msclr::interop::marshal_as(name)); } - return managed; + return ids; } catch (const std::exception& e) { @@ -71,4 +77,3 @@ public ref struct RawInputInterop } }; - -- cgit v1.2.3