From 5b659e1cfbc4b8fbbd2f2bf41dc716929976c77d Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Sat, 28 Aug 2021 01:19:18 -0400 Subject: add per-device configuration adds input and [in, out] cap for classic mode adds input cap for power mode change wrapper/input, now gets useful device names change (now dev specific) dpi to adjust sensitivity change y sensitivity to y/x ratio remove spaced LUTs grapher and convert do not build --- wrapper/input.cpp | 119 +++++++++++++++++++++++++++++------------------------- 1 file changed, 65 insertions(+), 54 deletions(-) (limited to 'wrapper/input.cpp') diff --git a/wrapper/input.cpp b/wrapper/input.cpp index 3ce257a..e34af4a 100644 --- a/wrapper/input.cpp +++ b/wrapper/input.cpp @@ -1,79 +1,90 @@ #include "input.h" -#include "interop-exception.h" - -#include -#include using namespace System; using namespace System::Collections::Generic; +using namespace System::Runtime::InteropServices; -std::vector rawinput_handles_from_id(const std::wstring& device_id) -{ - std::vector handles; +[StructLayout(LayoutKind::Sequential, CharSet = CharSet::Unicode)] +public ref struct RawInputDevice { + System::IntPtr handle; - rawinput_foreach([&](const auto& dev) { - if (dev.id == device_id) handles.push_back(dev.handle); - }); + [MarshalAs(UnmanagedType::ByValTStr, SizeConst = MAX_NAME_LEN)] + System::String^ name; - return handles; -} + [MarshalAs(UnmanagedType::ByValTStr, SizeConst = MAX_DEV_ID_LEN)] + System::String^ id; +}; -std::vector rawinput_id_list() +static int CompareByID(RawInputDevice^ x, RawInputDevice^ y) { - std::vector ids; - - rawinput_foreach([&](const auto& dev) { - ids.push_back(dev.id); - }); - - std::sort(ids.begin(), ids.end()); - ids.erase(std::unique(ids.begin(), ids.end()), ids.end()); - return ids; + return String::Compare(x->id, y->id); } -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 MultiHandleDevice { + System::String^ name; + System::String^ id; + List^ handles; -public ref struct RawInputInterop -{ - static void AddHandlesFromID(String^ deviceID, List^ rawInputHandles) + // Each element in the list returned has a distinct id + // https://docs.microsoft.com/en-us/windows-hardware/drivers/install/device-ids + static List^ GetList() { - try - { - std::vector nativeHandles = rawinput_handles_from_id( - msclr::interop::marshal_as(deviceID)); + return ListMaker::MakeList(); + } - for (auto nh : nativeHandles) rawInputHandles->Add(IntPtr(nh)); - } - catch (const std::exception& e) + ref class ListMaker { + List^ devices = gcnew List(); + + delegate void NativeDevHandler(rawinput_device&); + + void Add(rawinput_device& dev) { - throw gcnew RawInputInteropException(e); + devices->Add(Marshal::PtrToStructure(IntPtr(&dev))); } - } - static List^ GetDeviceIDs() - { - try + ListMaker() {} + public: + static List^ MakeList() { - auto ids = gcnew List(); + auto maker = gcnew ListMaker(); + NativeDevHandler^ del = gcnew NativeDevHandler(maker, &Add); + GCHandle gch = GCHandle::Alloc(del); + auto fp = static_cast( + Marshal::GetFunctionPointerForDelegate(del).ToPointer()); + rawinput_foreach(fp); + gch.Free(); - for (auto&& name : rawinput_id_list()) - { - ids->Add(msclr::interop::marshal_as(name)); + auto ret = gcnew List(); + auto count = maker->devices->Count; + auto first = 0; + auto last = 0; + + if (count > 0) { + maker->devices->Sort(gcnew Comparison(&CompareByID)); + while (++last != count) { + if (!String::Equals(maker->devices[first]->id, maker->devices[last]->id)) { + auto range = maker->devices->GetRange(first, last - first); + ret->Add(gcnew MultiHandleDevice(range)); + first = last; + } + } + auto range = maker->devices->GetRange(first, last - first); + ret->Add(gcnew MultiHandleDevice(range)); } - return ids; + return ret; } - catch (const std::exception& e) - { - throw gcnew RawInputInteropException(e); + }; + +private: + MultiHandleDevice(IEnumerable^ seq) + { + auto it = seq->GetEnumerator(); + if (it->MoveNext()) { + name = it->Current->name; + id = it->Current->id; + handles = gcnew List(); + do handles->Add(it->Current->handle); while (it->MoveNext()); } } - }; -- cgit v1.2.3 From a8d48325d5e6fe0466502b865c82317b6f7410a2 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Mon, 6 Sep 2021 23:24:51 -0400 Subject: get grapher building --- wrapper/input.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'wrapper/input.cpp') diff --git a/wrapper/input.cpp b/wrapper/input.cpp index e34af4a..334a0ec 100644 --- a/wrapper/input.cpp +++ b/wrapper/input.cpp @@ -25,11 +25,12 @@ public ref struct MultiHandleDevice { System::String^ id; List^ handles; - // Each element in the list returned has a distinct id + // Returned list represents the current connected raw input devices, + // where each device has a distinct device id // https://docs.microsoft.com/en-us/windows-hardware/drivers/install/device-ids - static List^ GetList() + static IList^ GetList() { - return ListMaker::MakeList(); + return ListMaker::MakeList()->AsReadOnly(); } ref class ListMaker { -- cgit v1.2.3