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
---
common/common.vcxitems | 1 -
common/utility-rawinput.hpp | 103 ---------------------------
grapher/Models/Serialized/SettingsManager.cs | 2 +-
wrapper/input.cpp | 65 +++++++++--------
wrapper/input.h | 78 ++++++++++++++++++++
wrapper/interop-exception.h | 9 ---
wrapper/wrapper.vcxproj | 1 +
wrapper/wrapper.vcxproj.filters | 3 +
8 files changed, 118 insertions(+), 144 deletions(-)
delete mode 100644 common/utility-rawinput.hpp
create mode 100644 wrapper/input.h
diff --git a/common/common.vcxitems b/common/common.vcxitems
index 2cf2df2..296fbfd 100644
--- a/common/common.vcxitems
+++ b/common/common.vcxitems
@@ -31,7 +31,6 @@
-
diff --git a/common/utility-rawinput.hpp b/common/utility-rawinput.hpp
deleted file mode 100644
index f04b2c1..0000000
--- a/common/utility-rawinput.hpp
+++ /dev/null
@@ -1,103 +0,0 @@
-#pragma once
-
-#pragma comment(lib, "cfgmgr32.lib")
-
-#include
-#include
-#include
-#include
-
-#include
-#include
-#include // needed for devpkey.h to parse properly
-#include
-
-template
-void rawinput_foreach_dev_with_id(Func fn, bool with_instance_id = false,
- DWORD input_type = RIM_TYPEMOUSE)
-{
- const UINT RI_ERROR = -1;
-
- // get number of devices
- UINT num_devs = 0;
- if (GetRawInputDeviceList(NULL, &num_devs, sizeof(RAWINPUTDEVICELIST)) != 0) {
- throw std::system_error(GetLastError(), std::system_category(), "GetRawInputDeviceList failed");
- }
-
- auto devs = std::vector(num_devs);
-
- if (GetRawInputDeviceList(&devs[0], &num_devs, sizeof(RAWINPUTDEVICELIST)) == RI_ERROR) {
- return;
- }
-
- std::wstring name;
- std::wstring id;
- DEVPROPTYPE type;
- CONFIGRET cm_res;
-
- for (auto&& dev : devs) {
- if (dev.dwType != input_type) continue;
-
- // get interface name length
- UINT name_len = 0;
- if (GetRawInputDeviceInfoW(dev.hDevice, RIDI_DEVICENAME, NULL, &name_len) == RI_ERROR) {
- continue;
- }
-
- name.resize(name_len);
-
- if (GetRawInputDeviceInfoW(dev.hDevice, RIDI_DEVICENAME, &name[0], &name_len) == RI_ERROR) {
- continue;
- }
-
- // get sizeof dev instance id
- ULONG id_size = 0;
- cm_res = CM_Get_Device_Interface_PropertyW(&name[0], &DEVPKEY_Device_InstanceId,
- &type, NULL, &id_size, 0);
-
- if (cm_res != CR_BUFFER_SMALL && cm_res != CR_SUCCESS) continue;
-
- id.resize((id_size + 1) / 2);
-
- cm_res = CM_Get_Device_Interface_PropertyW(&name[0], &DEVPKEY_Device_InstanceId,
- &type, reinterpret_cast(&id[0]), &id_size, 0);
-
- if (cm_res != CR_SUCCESS) continue;
-
- if (!with_instance_id) {
- auto instance_delim_pos = id.find_last_of('\\');
- if (instance_delim_pos != std::string::npos) id.resize(instance_delim_pos);
- }
-
- fn(dev, id);
- }
-}
-
-inline
-std::vector rawinput_handles_from_dev_id(const std::wstring& device_id,
- bool with_instance_id = false,
- DWORD input_type = RIM_TYPEMOUSE)
-{
- std::vector handles;
-
- rawinput_foreach_dev_with_id([&](const auto& dev, const std::wstring& id) {
- if (id == device_id) handles.push_back(dev.hDevice);
- }, with_instance_id, input_type);
-
- return handles;
-}
-
-inline
-std::vector rawinput_dev_id_list(bool with_instance_id = false,
- DWORD input_type = RIM_TYPEMOUSE)
-{
- std::vector ids;
-
- rawinput_foreach_dev_with_id([&](const auto& dev, const std::wstring& id) {
- ids.push_back(id);
- }, with_instance_id, input_type);
-
- std::sort(ids.begin(), ids.end());
- ids.erase(std::unique(ids.begin(), ids.end()), ids.end());
- return ids;
-}
diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs
index 6bcfab8..346bc9b 100644
--- a/grapher/Models/Serialized/SettingsManager.cs
+++ b/grapher/Models/Serialized/SettingsManager.cs
@@ -90,7 +90,7 @@ namespace grapher.Models.Serialized
PollRateField.SetToEntered(GuiSettings.PollRate);
ShowLastMouseMoveMenuItem.Checked = GuiSettings.ShowLastMouseMove;
ShowVelocityAndGainMoveMenuItem.Checked = GuiSettings.ShowVelocityAndGain;
- StreamingModeMenuItem.Checked = GUISettings.StreamingMode;
+ StreamingModeMenuItem.Checked = GuiSettings.StreamingMode;
AutoWriteMenuItem.Checked = GuiSettings.AutoWriteToDriverOnStartup;
}
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
}
};
-
diff --git a/wrapper/input.h b/wrapper/input.h
new file mode 100644
index 0000000..c83dca8
--- /dev/null
+++ b/wrapper/input.h
@@ -0,0 +1,78 @@
+#pragma once
+
+#pragma comment(lib, "cfgmgr32.lib")
+
+#include
+#include
+#include
+
+#include
+#include
+#include // needed for devpkey.h to parse properly
+#include
+
+struct rawinput_device {
+ HANDLE handle;
+ std::wstring id;
+};
+
+template
+void rawinput_foreach(Func fn, DWORD device_type = RIM_TYPEMOUSE)
+{
+ const UINT RI_ERROR = -1;
+
+ // get number of devices
+ UINT num_devs = 0;
+ if (GetRawInputDeviceList(NULL, &num_devs, sizeof(RAWINPUTDEVICELIST)) != 0) {
+ throw std::system_error(GetLastError(), std::system_category(), "GetRawInputDeviceList failed");
+ }
+
+ auto dev_list = std::vector(num_devs);
+
+ if (GetRawInputDeviceList(&dev_list[0], &num_devs, sizeof(RAWINPUTDEVICELIST)) == RI_ERROR) {
+ return;
+ }
+
+ std::wstring name;
+ rawinput_device dev;
+ DEVPROPTYPE prop_type;
+ CONFIGRET cm_res;
+
+ for (auto [handle, dev_type] : dev_list) {
+ if (dev_type != device_type) continue;
+
+ // get interface name length
+ UINT name_len = 0;
+ if (GetRawInputDeviceInfoW(handle, RIDI_DEVICENAME, NULL, &name_len) == RI_ERROR) {
+ continue;
+ }
+
+ name.resize(name_len);
+
+ if (GetRawInputDeviceInfoW(handle, RIDI_DEVICENAME, &name[0], &name_len) == RI_ERROR) {
+ continue;
+ }
+
+ // get sizeof device instance id
+ ULONG id_size = 0;
+ cm_res = CM_Get_Device_Interface_PropertyW(&name[0], &DEVPKEY_Device_InstanceId,
+ &prop_type, NULL, &id_size, 0);
+
+ if (cm_res != CR_BUFFER_SMALL && cm_res != CR_SUCCESS) continue;
+
+ dev.id.resize((id_size + 1) / 2);
+
+ cm_res = CM_Get_Device_Interface_PropertyW(&name[0], &DEVPKEY_Device_InstanceId,
+ &prop_type, reinterpret_cast(&dev.id[0]), &id_size, 0);
+
+ if (cm_res != CR_SUCCESS) continue;
+
+ // pop instance id
+ auto instance_delim_pos = dev.id.find_last_of('\\');
+ if (instance_delim_pos != std::string::npos) dev.id.resize(instance_delim_pos);
+
+ dev.handle = handle;
+
+ fn(dev);
+ }
+}
diff --git a/wrapper/interop-exception.h b/wrapper/interop-exception.h
index 8ebae5c..0e88b2c 100644
--- a/wrapper/interop-exception.h
+++ b/wrapper/interop-exception.h
@@ -10,12 +10,3 @@ public ref struct InteropException : System::Exception {
InteropException(const std::exception& e) :
InteropException(e.what()) {}
};
-
-public ref struct RawInputInteropException : InteropException {
- RawInputInteropException(System::String^ what) :
- InteropException(what) {}
- RawInputInteropException(const char* what) :
- InteropException(what) {}
- RawInputInteropException(const std::exception& e) :
- InteropException(e) {}
-};
diff --git a/wrapper/wrapper.vcxproj b/wrapper/wrapper.vcxproj
index cd121a2..5d58614 100644
--- a/wrapper/wrapper.vcxproj
+++ b/wrapper/wrapper.vcxproj
@@ -85,6 +85,7 @@ copy /Y "$(TargetDir)Newtonsoft.Json.dll" "$(SolutionDir)signed\Newtonsoft.Json.
+
diff --git a/wrapper/wrapper.vcxproj.filters b/wrapper/wrapper.vcxproj.filters
index 9caeae1..1d0196d 100644
--- a/wrapper/wrapper.vcxproj.filters
+++ b/wrapper/wrapper.vcxproj.filters
@@ -21,6 +21,9 @@
Header Files
+
+ Header Files
+
--
cgit v1.2.3