From 09bdc64ab2ae8f2d602d2c12d01cf296da03545b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Pazdiora?= Date: Tue, 5 Jan 2021 02:31:04 +0100 Subject: fix .rc files --- driver/driver.rc | 2 +- uninstaller/uninstaller.rc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/driver/driver.rc b/driver/driver.rc index e351ac3..53cad53 100644 --- a/driver/driver.rc +++ b/driver/driver.rc @@ -1,4 +1,4 @@ -// +// // Include the necessary resources // #include diff --git a/uninstaller/uninstaller.rc b/uninstaller/uninstaller.rc index a9e8304..23b773d 100644 --- a/uninstaller/uninstaller.rc +++ b/uninstaller/uninstaller.rc @@ -1,4 +1,4 @@ -// Microsoft Visual C++ generated resource script. +// Microsoft Visual C++ generated resource script. // #include "resource.h" -- cgit v1.2.3 From 3f12802a19f93fec99b5186b0d39c3fa2f783c6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Pazdiora?= Date: Tue, 5 Jan 2021 03:46:57 +0100 Subject: add devicelist app --- devicelist/App.config | 6 +++ devicelist/Program.cs | 27 +++++++++++++ devicelist/Properties/AssemblyInfo.cs | 36 +++++++++++++++++ devicelist/devicelist.csproj | 73 +++++++++++++++++++++++++++++++++++ rawaccel.sln | 6 +++ 5 files changed, 148 insertions(+) create mode 100644 devicelist/App.config create mode 100644 devicelist/Program.cs create mode 100644 devicelist/Properties/AssemblyInfo.cs create mode 100644 devicelist/devicelist.csproj diff --git a/devicelist/App.config b/devicelist/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/devicelist/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/devicelist/Program.cs b/devicelist/Program.cs new file mode 100644 index 0000000..6ac08f6 --- /dev/null +++ b/devicelist/Program.cs @@ -0,0 +1,27 @@ +using System; +using System.Text; +using System.Management; +using System.Windows.Forms; + +namespace devicelist +{ + class Program + { + static void Main(string[] args) + { + ManagementObjectSearcher searcher = new ManagementObjectSearcher(new SelectQuery("Win32_PnPEntity")); + + foreach (ManagementObject obj in searcher.Get()) + { + if (obj["PNPClass"].ToString() == "Mouse" && obj["HardwareID"] != null) { + String[] hwidArray = (String[])(obj["HardwareID"]); + String hwid = hwidArray[0].ToString().Replace(@"\", @"\\"); + String caption = "(" + obj["Name"].ToString() + ") Device Hardware ID:"; + if (MessageBox.Show(hwid, caption, MessageBoxButtons.OKCancel) == DialogResult.Cancel) { + break; + } + } + } + } + } +} diff --git a/devicelist/Properties/AssemblyInfo.cs b/devicelist/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..36f0015 --- /dev/null +++ b/devicelist/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Raw Accel devicelist")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Raw Accel")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("3666b731-7406-41b1-bcfc-c65073fd09a1")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion(RawAccelVersion.value)] +[assembly: AssemblyFileVersion(RawAccelVersion.value)] diff --git a/devicelist/devicelist.csproj b/devicelist/devicelist.csproj new file mode 100644 index 0000000..378c518 --- /dev/null +++ b/devicelist/devicelist.csproj @@ -0,0 +1,73 @@ + + + + + Debug + AnyCPU + {3666B731-7406-41B1-BCFC-C65073FD09A1} + WinExe + devicelist + devicelist + v4.7.2 + 512 + true + true + + + true + $(SolutionDir)$(Platform)\$(Configuration)\ + DEBUG;TRACE + full + x64 + 7.3 + prompt + MinimumRecommendedRules.ruleset + true + + + $(SolutionDir)$(Platform)\$(Configuration)\ + TRACE + true + pdbonly + x64 + 7.3 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + + + + + + + + + + + + + + + {28a3656f-a1de-405c-b547-191c32ec555f} + wrapper + + + + + IF ($(ConfigurationName)) == (Debug) GOTO END +copy /Y "$(TargetPath)" "$(SolutionDir)signed\$(TargetFileName)" +:END + + \ No newline at end of file diff --git a/rawaccel.sln b/rawaccel.sln index 9b3978c..fc3d256 100644 --- a/rawaccel.sln +++ b/rawaccel.sln @@ -27,6 +27,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "converter", "converter\conv {28A3656F-A1DE-405C-B547-191C32EC555F} = {28A3656F-A1DE-405C-B547-191C32EC555F} EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "devicelist", "devicelist\devicelist.csproj", "{3666B731-7406-41B1-BCFC-C65073FD09A1}" +EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution common\common.vcxitems*{24b4226f-1461-408f-a1a4-1371c97153ea}*SharedItemsImports = 9 @@ -73,6 +75,10 @@ Global {4C421992-9A27-4860-A40C-ADD76FBACE55}.Debug|x64.Build.0 = Debug|x64 {4C421992-9A27-4860-A40C-ADD76FBACE55}.Release|x64.ActiveCfg = Release|x64 {4C421992-9A27-4860-A40C-ADD76FBACE55}.Release|x64.Build.0 = Release|x64 + {3666B731-7406-41B1-BCFC-C65073FD09A1}.Debug|x64.ActiveCfg = Debug|x64 + {3666B731-7406-41B1-BCFC-C65073FD09A1}.Debug|x64.Build.0 = Debug|x64 + {3666B731-7406-41B1-BCFC-C65073FD09A1}.Release|x64.ActiveCfg = Release|x64 + {3666B731-7406-41B1-BCFC-C65073FD09A1}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE -- cgit v1.2.3 From 6f1098372b2016db9744ad13dffbb55b77102671 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Pazdiora?= Date: Tue, 5 Jan 2021 03:50:45 +0100 Subject: add "Device Hardware ID" setting, to affect only specific device --- common/rawaccel-settings.h | 1 + driver/driver.cpp | 47 ++++++++++++++++++++++++++++++---------------- driver/driver.h | 1 + grapher/Models/AccelGUI.cs | 3 ++- wrapper/wrapper.cpp | 6 +++++- 5 files changed, 40 insertions(+), 18 deletions(-) diff --git a/common/rawaccel-settings.h b/common/rawaccel-settings.h index 649c936..c9bd247 100644 --- a/common/rawaccel-settings.h +++ b/common/rawaccel-settings.h @@ -23,6 +23,7 @@ namespace rawaccel { vec2d sens = { 1, 1 }; vec2d dir_multipliers = {}; milliseconds time_min = DEFAULT_TIME_MIN; + wchar_t device_hw_id[512] = {0}; }; } diff --git a/driver/driver.cpp b/driver/driver.cpp index a99a70b..2c234ba 100644 --- a/driver/driver.cpp +++ b/driver/driver.cpp @@ -54,6 +54,11 @@ Arguments: WDFDEVICE hDevice = WdfWdmDeviceGetWdfDeviceHandle(DeviceObject); PDEVICE_EXTENSION devExt = FilterGetData(hDevice); + bool devMatch = true; + if (wcsncmp(L"", global.args.device_hw_id, sizeof(global.args.device_hw_id)) != 0) { + devMatch = wcsncmp(devExt->hwid, global.args.device_hw_id, sizeof(global.args.device_hw_id)) == 0; + } + if (!(InputDataStart->Flags & MOUSE_MOVE_ABSOLUTE)) { auto num_packets = InputDataEnd - InputDataStart; @@ -63,28 +68,29 @@ Arguments: vec2d carry = devExt->carry; - auto it = InputDataStart; - do { + for (auto it = InputDataStart; it != InputDataEnd; ++it) { vec2d input = { static_cast(it->LastX), static_cast(it->LastY) }; - global.modifier.apply_rotation(input); + if (devMatch) { + global.modifier.apply_rotation(input); - if (enable_accel) { - auto time_supplier = [=] { - counter_t now = KeQueryPerformanceCounter(NULL).QuadPart; - counter_t ticks = now - devExt->counter; - devExt->counter = now; - milliseconds time = ticks * global.tick_interval; - return clampsd(time, global.args.time_min, 100); - }; + if (enable_accel) { + auto time_supplier = [=] { + counter_t now = KeQueryPerformanceCounter(NULL).QuadPart; + counter_t ticks = now - devExt->counter; + devExt->counter = now; + milliseconds time = ticks * global.tick_interval; + return clampsd(time, global.args.time_min, 100); + }; - global.modifier.apply_acceleration(input, time_supplier); - } + global.modifier.apply_acceleration(input, time_supplier); + } - global.modifier.apply_sensitivity(input); + global.modifier.apply_sensitivity(input); + } double carried_result_x = input.x + carry.x; double carried_result_y = input.y + carry.y; @@ -98,7 +104,7 @@ Arguments: it->LastX = out_x; it->LastY = out_y; - } while (++it != InputDataEnd); + } devExt->carry = carry; } @@ -581,7 +587,16 @@ Routine Description: DebugPrint(("WdfRequestRetrieveInputBuffer failed %x\n", status)); break; } - + + ULONG resultLen; + status = WdfDeviceQueryProperty(hDevice, DevicePropertyHardwareID, + sizeof(devExt->hwid), devExt->hwid, &resultLen); + + if (!NT_SUCCESS(status)) { + DebugPrint(("WdfDeviceQueryProperty failed: 0x%x\n", status)); + break; + } + devExt->counter = 0; devExt->carry = {}; devExt->UpperConnectData = *connectData; diff --git a/driver/driver.h b/driver/driver.h index 8554f8c..de677ce 100644 --- a/driver/driver.h +++ b/driver/driver.h @@ -20,6 +20,7 @@ using counter_t = long long; typedef struct _DEVICE_EXTENSION { counter_t counter; vec2d carry; + WCHAR hwid[512]; CONNECT_DATA UpperConnectData; } DEVICE_EXTENSION, *PDEVICE_EXTENSION; diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index c6a2dcc..5c25813 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -141,7 +141,8 @@ namespace grapher modes = ApplyOptions.GetModes(), args = newArgs, minimumTime = driverSettings.minimumTime, - directionalMultipliers = driverSettings.directionalMultipliers + directionalMultipliers = driverSettings.directionalMultipliers, + deviceHardwareID = driverSettings.deviceHardwareID }; ButtonDelay(WriteButton); diff --git a/wrapper/wrapper.cpp b/wrapper/wrapper.cpp index fcbf2e8..7ac3a8d 100644 --- a/wrapper/wrapper.cpp +++ b/wrapper/wrapper.cpp @@ -51,7 +51,7 @@ public value struct Vec2 }; [JsonObject(ItemRequired = Required::Always)] -[StructLayout(LayoutKind::Sequential)] +[StructLayout(LayoutKind::Sequential, CharSet = CharSet::Unicode)] public ref struct DriverSettings { literal String^ Key = "Driver settings"; @@ -78,6 +78,10 @@ public ref struct DriverSettings [JsonProperty(Required = Required::Default)] double minimumTime; + [JsonProperty("Device Hardware ID", Required = Required::Default)] + [MarshalAs(UnmanagedType::ByValTStr, SizeConst = 512)] + String^ deviceHardwareID; + bool ShouldSerializeminimumTime() { return minimumTime > 0 && minimumTime != DEFAULT_TIME_MIN; -- cgit v1.2.3 From e11971e733d4b35cb6cdfe907b7a1f191ff4a97a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Pazdiora?= Date: Tue, 5 Jan 2021 19:11:48 +0100 Subject: simplify checking for configuration without specific device --- driver/driver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver/driver.cpp b/driver/driver.cpp index 2c234ba..38d127b 100644 --- a/driver/driver.cpp +++ b/driver/driver.cpp @@ -55,7 +55,7 @@ Arguments: PDEVICE_EXTENSION devExt = FilterGetData(hDevice); bool devMatch = true; - if (wcsncmp(L"", global.args.device_hw_id, sizeof(global.args.device_hw_id)) != 0) { + if (global.args.device_hw_id[0] != 0) { devMatch = wcsncmp(devExt->hwid, global.args.device_hw_id, sizeof(global.args.device_hw_id)) == 0; } -- cgit v1.2.3 From b9c79a8d13aaae30950da318526e2f4707062c4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Pazdiora?= Date: Tue, 5 Jan 2021 19:18:40 +0100 Subject: revert for loop -> do while (according to a1xd's conclusion) --- driver/driver.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/driver/driver.cpp b/driver/driver.cpp index 38d127b..1cdfadf 100644 --- a/driver/driver.cpp +++ b/driver/driver.cpp @@ -68,7 +68,8 @@ Arguments: vec2d carry = devExt->carry; - for (auto it = InputDataStart; it != InputDataEnd; ++it) { + auto it = InputDataStart; + do { vec2d input = { static_cast(it->LastX), static_cast(it->LastY) @@ -104,7 +105,7 @@ Arguments: it->LastX = out_x; it->LastY = out_y; - } + } while (++it != InputDataEnd); devExt->carry = carry; } -- cgit v1.2.3 From b4749bfb8480ed5c9e6151c0c899027cdc20c22b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Pazdiora?= Date: Tue, 5 Jan 2021 19:34:31 +0100 Subject: bugfix --- driver/driver.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/driver/driver.cpp b/driver/driver.cpp index 1cdfadf..8b72562 100644 --- a/driver/driver.cpp +++ b/driver/driver.cpp @@ -56,7 +56,8 @@ Arguments: bool devMatch = true; if (global.args.device_hw_id[0] != 0) { - devMatch = wcsncmp(devExt->hwid, global.args.device_hw_id, sizeof(global.args.device_hw_id)) == 0; + size_t max_cnt = sizeof(global.args.device_hw_id) / sizeof(global.args.device_hw_id[0]); + devMatch = wcsncmp(devExt->hwid, global.args.device_hw_id, max_cnt) == 0; } if (!(InputDataStart->Flags & MOUSE_MOVE_ABSOLUTE)) { -- cgit v1.2.3 From 632a66281e3700d7ca45847a44dcb765e91f02e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Pazdiora?= Date: Tue, 5 Jan 2021 19:52:07 +0100 Subject: Update driver/driver.h Co-authored-by: a1xd <68629610+a1xd@users.noreply.github.com> --- driver/driver.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver/driver.h b/driver/driver.h index de677ce..ac42f4b 100644 --- a/driver/driver.h +++ b/driver/driver.h @@ -20,8 +20,8 @@ using counter_t = long long; typedef struct _DEVICE_EXTENSION { counter_t counter; vec2d carry; - WCHAR hwid[512]; CONNECT_DATA UpperConnectData; + WCHAR hwid[512]; } DEVICE_EXTENSION, *PDEVICE_EXTENSION; WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(DEVICE_EXTENSION, FilterGetData) -- cgit v1.2.3 From 6969310edd56edb555dd98acbc1478caa5728593 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Tue, 5 Jan 2021 18:05:48 -0500 Subject: size device id/hwids based on docs this also changes the connect ioctl to not abort when hwid query fails --- common/rawaccel-settings.h | 4 +++- driver/driver.cpp | 47 ++++++++++++++++++++++++++++++---------------- driver/driver.h | 4 ++-- wrapper/wrapper.cpp | 2 +- 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/common/rawaccel-settings.h b/common/rawaccel-settings.h index c9bd247..f94e960 100644 --- a/common/rawaccel-settings.h +++ b/common/rawaccel-settings.h @@ -3,6 +3,8 @@ #include "vec2.h" #include "accel-base.hpp" +#define MAX_HWID_LEN 200 + namespace rawaccel { using milliseconds = double; @@ -23,7 +25,7 @@ namespace rawaccel { vec2d sens = { 1, 1 }; vec2d dir_multipliers = {}; milliseconds time_min = DEFAULT_TIME_MIN; - wchar_t device_hw_id[512] = {0}; + wchar_t device_hw_id[MAX_HWID_LEN] = {0}; }; } diff --git a/driver/driver.cpp b/driver/driver.cpp index 8b72562..ad837e7 100644 --- a/driver/driver.cpp +++ b/driver/driver.cpp @@ -56,8 +56,7 @@ Arguments: bool devMatch = true; if (global.args.device_hw_id[0] != 0) { - size_t max_cnt = sizeof(global.args.device_hw_id) / sizeof(global.args.device_hw_id[0]); - devMatch = wcsncmp(devExt->hwid, global.args.device_hw_id, max_cnt) == 0; + devMatch = wcsncmp(devExt->hwid, global.args.device_hw_id, MAX_HWID_LEN) == 0; } if (!(InputDataStart->Flags & MOUSE_MOVE_ABSOLUTE)) { @@ -569,7 +568,7 @@ Routine Description: // // Connect a mouse class device driver to the port driver. // - case IOCTL_INTERNAL_MOUSE_CONNECT: + case IOCTL_INTERNAL_MOUSE_CONNECT: { // // Only allow one connection. // @@ -577,26 +576,42 @@ Routine Description: status = STATUS_SHARING_VIOLATION; break; } - + // // Copy the connection parameters to the device extension. // - status = WdfRequestRetrieveInputBuffer(Request, - sizeof(CONNECT_DATA), - reinterpret_cast(&connectData), - &length); - if(!NT_SUCCESS(status)){ + status = WdfRequestRetrieveInputBuffer(Request, + sizeof(CONNECT_DATA), + reinterpret_cast(&connectData), + &length); + if (!NT_SUCCESS(status)) { DebugPrint(("WdfRequestRetrieveInputBuffer failed %x\n", status)); break; } - ULONG resultLen; - status = WdfDeviceQueryProperty(hDevice, DevicePropertyHardwareID, - sizeof(devExt->hwid), devExt->hwid, &resultLen); + // taken from REGSTR_VAL_MAX_HCID_LEN defined in um/RegStr.h + const size_t POOL_SIZE = sizeof(wchar_t) * 1024; - if (!NT_SUCCESS(status)) { - DebugPrint(("WdfDeviceQueryProperty failed: 0x%x\n", status)); - break; + auto pool = ExAllocatePoolWithTag(NonPagedPool, POOL_SIZE, 'AR'); + + if (!pool) { + DebugPrint(("RA - failed to allocate pool for hwid list\n")); + } + else { + RtlZeroMemory(pool, POOL_SIZE); + + ULONG resultLen; + NTSTATUS tmp = WdfDeviceQueryProperty(hDevice, DevicePropertyHardwareID, + POOL_SIZE, pool, &resultLen); + + if (!NT_SUCCESS(tmp)) { + DebugPrint(("WdfDeviceQueryProperty failed: 0x%x\n", tmp)); + } + else { + wcsncpy(devExt->hwid, reinterpret_cast(pool), MAX_HWID_LEN); + } + + ExFreePoolWithTag(pool, 'AR'); } devExt->counter = 0; @@ -612,7 +627,7 @@ Routine Description: connectData->ClassService = RawaccelCallback; break; - + } // // Disconnect a mouse class device driver from the port driver. // diff --git a/driver/driver.h b/driver/driver.h index ac42f4b..5b610fe 100644 --- a/driver/driver.h +++ b/driver/driver.h @@ -4,7 +4,7 @@ #include #include -#include "vec2.h" +#include "rawaccel-settings.h" #if DBG #define DebugPrint(_x_) DbgPrint _x_ @@ -21,7 +21,7 @@ typedef struct _DEVICE_EXTENSION { counter_t counter; vec2d carry; CONNECT_DATA UpperConnectData; - WCHAR hwid[512]; + WCHAR hwid[MAX_HWID_LEN]; } DEVICE_EXTENSION, *PDEVICE_EXTENSION; WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(DEVICE_EXTENSION, FilterGetData) diff --git a/wrapper/wrapper.cpp b/wrapper/wrapper.cpp index 7ac3a8d..7e3f736 100644 --- a/wrapper/wrapper.cpp +++ b/wrapper/wrapper.cpp @@ -79,7 +79,7 @@ public ref struct DriverSettings double minimumTime; [JsonProperty("Device Hardware ID", Required = Required::Default)] - [MarshalAs(UnmanagedType::ByValTStr, SizeConst = 512)] + [MarshalAs(UnmanagedType::ByValTStr, SizeConst = MAX_HWID_LEN)] String^ deviceHardwareID; bool ShouldSerializeminimumTime() -- cgit v1.2.3 From a249ac942811b995e25ed4af02cb748c5c5a284d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Pazdiora?= Date: Wed, 6 Jan 2021 14:26:48 +0100 Subject: better information for user when installing/removing driver --- installer/installer.cpp | 4 ++++ uninstaller/uninstaller.cpp | 23 ++++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/installer/installer.cpp b/installer/installer.cpp index 916209f..279fefc 100644 --- a/installer/installer.cpp +++ b/installer/installer.cpp @@ -53,6 +53,10 @@ int main() { fs::path target = get_target_path(); + if (fs::exists(target)) { + std::cout << "Driver already installed. Removing previous installation.\n"; + } + add_service(target); fs::path tmp = make_temp_path(target); diff --git a/uninstaller/uninstaller.cpp b/uninstaller/uninstaller.cpp index 8d9e890..bd9c564 100644 --- a/uninstaller/uninstaller.cpp +++ b/uninstaller/uninstaller.cpp @@ -4,13 +4,23 @@ int main() { try { - modify_upper_filters([](std::vector& filters) { - std::erase(filters, DRIVER_NAME); + bool reboot_required = false; + modify_upper_filters([&reboot_required](std::vector& filters) { + // check if driver is present in upper filters + bool driver_present = std::find(filters.begin(), filters.end(), DRIVER_NAME) != filters.end(); + if (driver_present) { + std::erase(filters, DRIVER_NAME); + reboot_required = true; + } }); fs::path target = get_target_path(); fs::path tmp = make_temp_path(target); + if (fs::exists(target) || fs::exists(tmp)) { + reboot_required = true; + } + // schedule tmp to be deleted if rename target -> tmp is successful if (MoveFileExW(target.c_str(), tmp.c_str(), MOVEFILE_REPLACE_EXISTING)) { MoveFileExW(tmp.c_str(), NULL, MOVEFILE_DELAY_UNTIL_REBOOT); @@ -18,7 +28,14 @@ int main() { else { // tmp is in use and delete is already scheduled if (fs::exists(target)) fs::remove(target); } - std::cout << "Removal complete, change will take effect after restart.\n"; + + if (reboot_required) { + std::cout << "Removal complete, change will take effect after restart.\n"; + } + else { + std::cout << "No installed driver found.\n"; + } + } catch (const std::system_error& e) { std::cerr << "Error: " << e.what() << ' ' << e.code() << '\n'; -- cgit v1.2.3 From dc38efedbefe8753643a57e8ae3edb989632f2de Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Wed, 6 Jan 2021 12:36:14 -0500 Subject: get hwid when adding device --- driver/driver.cpp | 48 ++++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/driver/driver.cpp b/driver/driver.cpp index ad837e7..e3ffb4d 100644 --- a/driver/driver.cpp +++ b/driver/driver.cpp @@ -472,7 +472,7 @@ Return Value: WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&deviceAttributes, DEVICE_EXTENSION); - + // // Create a framework device object. This call will in turn create // a WDM deviceobject, attach to the lower stack and set the @@ -484,6 +484,27 @@ Return Value: return status; } + // + // get device hwid + // + WDFMEMORY memory = NULL; + + NTSTATUS hwid_query = WdfDeviceAllocAndQueryProperty( + hDevice, + DevicePropertyHardwareID, + PagedPool, + WDF_NO_OBJECT_ATTRIBUTES, + &memory); + + if (!NT_SUCCESS(hwid_query)) { + DebugPrint(("WdfDeviceAllocAndQueryProperty failed: 0x%x\n", hwid_query)); + } + else { + auto dev_ext = FilterGetData(hDevice); + void* buffer = WdfMemoryGetBuffer(memory, NULL); + wcsncpy(dev_ext->hwid, reinterpret_cast(buffer), MAX_HWID_LEN); + WdfObjectDelete(memory); + } // // Configure the default queue to be Parallel. Do not use sequential queue @@ -589,31 +610,6 @@ Routine Description: break; } - // taken from REGSTR_VAL_MAX_HCID_LEN defined in um/RegStr.h - const size_t POOL_SIZE = sizeof(wchar_t) * 1024; - - auto pool = ExAllocatePoolWithTag(NonPagedPool, POOL_SIZE, 'AR'); - - if (!pool) { - DebugPrint(("RA - failed to allocate pool for hwid list\n")); - } - else { - RtlZeroMemory(pool, POOL_SIZE); - - ULONG resultLen; - NTSTATUS tmp = WdfDeviceQueryProperty(hDevice, DevicePropertyHardwareID, - POOL_SIZE, pool, &resultLen); - - if (!NT_SUCCESS(tmp)) { - DebugPrint(("WdfDeviceQueryProperty failed: 0x%x\n", tmp)); - } - else { - wcsncpy(devExt->hwid, reinterpret_cast(pool), MAX_HWID_LEN); - } - - ExFreePoolWithTag(pool, 'AR'); - } - devExt->counter = 0; devExt->carry = {}; devExt->UpperConnectData = *connectData; -- cgit v1.2.3 From be22e78f96fd34245bdad03b68cfd4e60ded1ba6 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 7 Jan 2021 12:52:51 -0500 Subject: refactor main callback check for empty input as suggested by @aroidzap --- driver/driver.cpp | 51 +++++++++++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/driver/driver.cpp b/driver/driver.cpp index e3ffb4d..4f108bd 100644 --- a/driver/driver.cpp +++ b/driver/driver.cpp @@ -54,20 +54,18 @@ Arguments: WDFDEVICE hDevice = WdfWdmDeviceGetWdfDeviceHandle(DeviceObject); PDEVICE_EXTENSION devExt = FilterGetData(hDevice); - bool devMatch = true; - if (global.args.device_hw_id[0] != 0) { - devMatch = wcsncmp(devExt->hwid, global.args.device_hw_id, MAX_HWID_LEN) == 0; - } + auto num_packets = InputDataEnd - InputDataStart; + + bool any = num_packets > 0; + bool rel_move = !(InputDataStart->Flags & MOUSE_MOVE_ABSOLUTE); + bool dev_match = global.args.device_hw_id[0] == 0 || + wcsncmp(devExt->hwid, global.args.device_hw_id, MAX_HWID_LEN) == 0; - if (!(InputDataStart->Flags & MOUSE_MOVE_ABSOLUTE)) { - auto num_packets = InputDataEnd - InputDataStart; - + if (any && rel_move && dev_match) { // if IO is backed up to the point where we get more than 1 packet here // then applying accel is pointless as we can't get an accurate timing bool enable_accel = num_packets == 1; - vec2d carry = devExt->carry; - auto it = InputDataStart; do { vec2d input = { @@ -75,39 +73,36 @@ Arguments: static_cast(it->LastY) }; - if (devMatch) { - global.modifier.apply_rotation(input); + global.modifier.apply_rotation(input); - if (enable_accel) { - auto time_supplier = [=] { - counter_t now = KeQueryPerformanceCounter(NULL).QuadPart; - counter_t ticks = now - devExt->counter; - devExt->counter = now; - milliseconds time = ticks * global.tick_interval; - return clampsd(time, global.args.time_min, 100); - }; + if (enable_accel) { + auto time_supplier = [=] { + counter_t now = KeQueryPerformanceCounter(NULL).QuadPart; + counter_t ticks = now - devExt->counter; + devExt->counter = now; + milliseconds time = ticks * global.tick_interval; + return clampsd(time, global.args.time_min, 100); + }; - global.modifier.apply_acceleration(input, time_supplier); - } - - global.modifier.apply_sensitivity(input); + global.modifier.apply_acceleration(input, time_supplier); } - double carried_result_x = input.x + carry.x; - double carried_result_y = input.y + carry.y; + global.modifier.apply_sensitivity(input); + + double carried_result_x = input.x + devExt->carry.x; + double carried_result_y = input.y + devExt->carry.y; LONG out_x = static_cast(carried_result_x); LONG out_y = static_cast(carried_result_y); - carry.x = carried_result_x - out_x; - carry.y = carried_result_y - out_y; + devExt->carry.x = carried_result_x - out_x; + devExt->carry.y = carried_result_y - out_y; it->LastX = out_x; it->LastY = out_y; } while (++it != InputDataEnd); - devExt->carry = carry; } (*(PSERVICE_CALLBACK_ROUTINE)devExt->UpperConnectData.ClassService)( -- cgit v1.2.3 From 100794dde83e9ca211cbcbe446992f8a5b914e16 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 7 Jan 2021 13:27:41 -0500 Subject: update signed/driver --- signed/driver/rawaccel.sys | Bin 61096 -> 61640 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/signed/driver/rawaccel.sys b/signed/driver/rawaccel.sys index 3762899..0fef07f 100644 Binary files a/signed/driver/rawaccel.sys and b/signed/driver/rawaccel.sys differ -- cgit v1.2.3 From 7c4fd76da65b5545d30fbe123274d348f86e24b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Pazdiora?= Date: Thu, 7 Jan 2021 20:37:23 +0100 Subject: update devicelist app --- devicelist/Program.cs | 20 +++++++++++++++----- devicelist/devicelist.csproj | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/devicelist/Program.cs b/devicelist/Program.cs index 6ac08f6..9323fd4 100644 --- a/devicelist/Program.cs +++ b/devicelist/Program.cs @@ -9,19 +9,29 @@ namespace devicelist { static void Main(string[] args) { + Console.WriteLine("To use Raw Accel driver for a specific device, " + + "replace '\"Device Hardware ID\": null' in 'settings.json' by following:"); + Console.WriteLine(""); + ManagementObjectSearcher searcher = new ManagementObjectSearcher(new SelectQuery("Win32_PnPEntity")); foreach (ManagementObject obj in searcher.Get()) { - if (obj["PNPClass"].ToString() == "Mouse" && obj["HardwareID"] != null) { + bool is_mouse = obj["PNPClass"] != null && obj["PNPClass"].ToString() == "Mouse"; // == "HIDClass" ??? + + if (is_mouse && obj["HardwareID"] != null) { String[] hwidArray = (String[])(obj["HardwareID"]); - String hwid = hwidArray[0].ToString().Replace(@"\", @"\\"); - String caption = "(" + obj["Name"].ToString() + ") Device Hardware ID:"; - if (MessageBox.Show(hwid, caption, MessageBoxButtons.OKCancel) == DialogResult.Cancel) { - break; + if (hwidArray.Length > 0) { + String hwid = hwidArray[0].ToString().Replace(@"\", @"\\"); + String name = obj["Name"].ToString(); + Console.WriteLine(name + ":"); + Console.WriteLine("\"Device Hardware ID\": \"" + hwid + "\""); + Console.WriteLine(""); } } } + + Console.ReadKey(); } } } diff --git a/devicelist/devicelist.csproj b/devicelist/devicelist.csproj index 378c518..154d0d0 100644 --- a/devicelist/devicelist.csproj +++ b/devicelist/devicelist.csproj @@ -5,7 +5,7 @@ Debug AnyCPU {3666B731-7406-41B1-BCFC-C65073FD09A1} - WinExe + Exe devicelist devicelist v4.7.2 -- cgit v1.2.3 From 215a21f9b62aa50d9ca4037ca0a22f5b0920f373 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Pazdiora?= Date: Thu, 7 Jan 2021 23:21:33 +0100 Subject: rough GUI integration of "Device Hardware ID" --- devicelist/App.config | 6 --- devicelist/Program.cs | 37 -------------- devicelist/Properties/AssemblyInfo.cs | 36 -------------- devicelist/devicelist.csproj | 73 ---------------------------- grapher/Form1.Designer.cs | 31 +++++++----- grapher/Form1.cs | 1 + grapher/Models/AccelGUIFactory.cs | 2 + grapher/Models/Devices/DeviceList.cs | 33 +++++++++++++ grapher/Models/Serialized/SettingsManager.cs | 66 +++++++++++++++++++++++++ grapher/grapher.csproj | 2 + rawaccel.sln | 6 --- 11 files changed, 124 insertions(+), 169 deletions(-) delete mode 100644 devicelist/App.config delete mode 100644 devicelist/Program.cs delete mode 100644 devicelist/Properties/AssemblyInfo.cs delete mode 100644 devicelist/devicelist.csproj create mode 100644 grapher/Models/Devices/DeviceList.cs diff --git a/devicelist/App.config b/devicelist/App.config deleted file mode 100644 index 56efbc7..0000000 --- a/devicelist/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/devicelist/Program.cs b/devicelist/Program.cs deleted file mode 100644 index 9323fd4..0000000 --- a/devicelist/Program.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using System.Text; -using System.Management; -using System.Windows.Forms; - -namespace devicelist -{ - class Program - { - static void Main(string[] args) - { - Console.WriteLine("To use Raw Accel driver for a specific device, " - + "replace '\"Device Hardware ID\": null' in 'settings.json' by following:"); - Console.WriteLine(""); - - ManagementObjectSearcher searcher = new ManagementObjectSearcher(new SelectQuery("Win32_PnPEntity")); - - foreach (ManagementObject obj in searcher.Get()) - { - bool is_mouse = obj["PNPClass"] != null && obj["PNPClass"].ToString() == "Mouse"; // == "HIDClass" ??? - - if (is_mouse && obj["HardwareID"] != null) { - String[] hwidArray = (String[])(obj["HardwareID"]); - if (hwidArray.Length > 0) { - String hwid = hwidArray[0].ToString().Replace(@"\", @"\\"); - String name = obj["Name"].ToString(); - Console.WriteLine(name + ":"); - Console.WriteLine("\"Device Hardware ID\": \"" + hwid + "\""); - Console.WriteLine(""); - } - } - } - - Console.ReadKey(); - } - } -} diff --git a/devicelist/Properties/AssemblyInfo.cs b/devicelist/Properties/AssemblyInfo.cs deleted file mode 100644 index 36f0015..0000000 --- a/devicelist/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Raw Accel devicelist")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Raw Accel")] -[assembly: AssemblyCopyright("")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("3666b731-7406-41b1-bcfc-c65073fd09a1")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion(RawAccelVersion.value)] -[assembly: AssemblyFileVersion(RawAccelVersion.value)] diff --git a/devicelist/devicelist.csproj b/devicelist/devicelist.csproj deleted file mode 100644 index 154d0d0..0000000 --- a/devicelist/devicelist.csproj +++ /dev/null @@ -1,73 +0,0 @@ - - - - - Debug - AnyCPU - {3666B731-7406-41B1-BCFC-C65073FD09A1} - Exe - devicelist - devicelist - v4.7.2 - 512 - true - true - - - true - $(SolutionDir)$(Platform)\$(Configuration)\ - DEBUG;TRACE - full - x64 - 7.3 - prompt - MinimumRecommendedRules.ruleset - true - - - $(SolutionDir)$(Platform)\$(Configuration)\ - TRACE - true - pdbonly - x64 - 7.3 - prompt - MinimumRecommendedRules.ruleset - true - - - - - - - - - - - - - - - - - - - - - - - - - - - {28a3656f-a1de-405c-b547-191c32ec555f} - wrapper - - - - - IF ($(ConfigurationName)) == (Debug) GOTO END -copy /Y "$(TargetPath)" "$(SolutionDir)signed\$(TargetFileName)" -:END - - \ No newline at end of file diff --git a/grapher/Form1.Designer.cs b/grapher/Form1.Designer.cs index 6fd9478..c388d79 100644 --- a/grapher/Form1.Designer.cs +++ b/grapher/Form1.Designer.cs @@ -161,6 +161,8 @@ namespace grapher this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.wholeVectorToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.byVectorComponentToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.AutoWriteMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.UseSpecificDeviceMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.chartsPanel = new System.Windows.Forms.Panel(); this.GainChartY = new System.Windows.Forms.DataVisualization.Charting.Chart(); this.VelocityChartY = new System.Windows.Forms.DataVisualization.Charting.Chart(); @@ -168,7 +170,6 @@ namespace grapher this.GainChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); this.VelocityChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); this.AccelerationChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); - this.AutoWriteMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.optionsPanel.SuspendLayout(); this.menuStrip1.SuspendLayout(); this.chartsPanel.SuspendLayout(); @@ -956,7 +957,8 @@ namespace grapher this.capStyleToolStripMenuItem, this.offsetStyleToolStripMenuItem, this.toolStripMenuItem1, - this.AutoWriteMenuItem}); + this.AutoWriteMenuItem, + this.UseSpecificDeviceMenuItem}); this.advancedToolStripMenuItem.Name = "advancedToolStripMenuItem"; this.advancedToolStripMenuItem.Size = new System.Drawing.Size(72, 20); this.advancedToolStripMenuItem.Text = "Advanced"; @@ -1029,6 +1031,21 @@ namespace grapher this.byVectorComponentToolStripMenuItem.Size = new System.Drawing.Size(154, 22); this.byVectorComponentToolStripMenuItem.Text = "By Component"; // + // AutoWriteMenuItem + // + this.AutoWriteMenuItem.Checked = true; + this.AutoWriteMenuItem.CheckOnClick = true; + this.AutoWriteMenuItem.CheckState = System.Windows.Forms.CheckState.Checked; + this.AutoWriteMenuItem.Name = "AutoWriteMenuItem"; + this.AutoWriteMenuItem.Size = new System.Drawing.Size(210, 22); + this.AutoWriteMenuItem.Text = "Apply Settings On Startup"; + // + // UseSpecificDeviceMenuItem + // + this.UseSpecificDeviceMenuItem.Name = "UseSpecificDeviceMenuItem"; + this.UseSpecificDeviceMenuItem.Size = new System.Drawing.Size(210, 22); + this.UseSpecificDeviceMenuItem.Text = "Use Specific Device"; + // // chartsPanel // this.chartsPanel.AutoScroll = true; @@ -1281,15 +1298,6 @@ namespace grapher title6.Text = "Sensitivity"; this.AccelerationChart.Titles.Add(title6); // - // AutoWriteMenuItem - // - this.AutoWriteMenuItem.Checked = true; - this.AutoWriteMenuItem.CheckOnClick = true; - this.AutoWriteMenuItem.CheckState = System.Windows.Forms.CheckState.Checked; - this.AutoWriteMenuItem.Name = "AutoWriteMenuItem"; - this.AutoWriteMenuItem.Size = new System.Drawing.Size(210, 22); - this.AutoWriteMenuItem.Text = "Apply Settings On Startup"; - // // RawAcceleration // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -1418,6 +1426,7 @@ namespace grapher private System.Windows.Forms.DataVisualization.Charting.Chart VelocityChart; private System.Windows.Forms.DataVisualization.Charting.Chart AccelerationChart; private System.Windows.Forms.ToolStripMenuItem AutoWriteMenuItem; + private System.Windows.Forms.ToolStripMenuItem UseSpecificDeviceMenuItem; } } diff --git a/grapher/Form1.cs b/grapher/Form1.cs index 0c12b86..e149163 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -71,6 +71,7 @@ namespace grapher gainOffsetToolStripMenuItem, legacyOffsetToolStripMenuItem, AutoWriteMenuItem, + UseSpecificDeviceMenuItem, ScaleMenuItem, DPITextBox, PollRateTextBox, diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs index 901a1b5..0e3646d 100644 --- a/grapher/Models/AccelGUIFactory.cs +++ b/grapher/Models/AccelGUIFactory.cs @@ -34,6 +34,7 @@ namespace grapher.Models ToolStripMenuItem gainOffsetToolStripMenuItem, ToolStripMenuItem legacyOffsetToolStripMenuItem, ToolStripMenuItem autoWriteMenuItem, + ToolStripMenuItem useSpecificDeviceMenuItem, ToolStripMenuItem scaleMenuItem, ToolStripTextBox dpiTextBox, ToolStripTextBox pollRateTextBox, @@ -329,6 +330,7 @@ namespace grapher.Models accelCalculator.DPI, accelCalculator.PollRate, autoWriteMenuItem, + useSpecificDeviceMenuItem, showLastMouseMoveMenuItem, showVelocityGainToolStripMenuItem); diff --git a/grapher/Models/Devices/DeviceList.cs b/grapher/Models/Devices/DeviceList.cs new file mode 100644 index 0000000..9f2b81d --- /dev/null +++ b/grapher/Models/Devices/DeviceList.cs @@ -0,0 +1,33 @@ +using System; +using System.Management; +using System.Collections.Generic; + +namespace grapher.Models.Devices +{ + class DeviceList + { + public static List> GetDeviceHardwareIDs(string PNPClass = "Mouse") + { + var results = new List>(); + + ManagementObjectSearcher searcher = new ManagementObjectSearcher(new SelectQuery("Win32_PnPEntity")); + + foreach (ManagementObject obj in searcher.Get()) + { + if (obj["PNPClass"] != null && obj["PNPClass"].ToString() == PNPClass && obj["HardwareID"] != null) + { + String[] hwidArray = (String[])(obj["HardwareID"]); + if (hwidArray.Length > 0) + { + String hwid = hwidArray[0].ToString(); + String name = obj["Name"].ToString(); + results.Add(Tuple.Create(name, hwid)); + } + } + } + + return results; + } + + } +} diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index 41ebcb5..3adbc8b 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -3,6 +3,7 @@ using System; using System.Windows.Forms; using System.Threading; using System.Text; +using System.Drawing; namespace grapher.Models.Serialized { @@ -15,6 +16,7 @@ namespace grapher.Models.Serialized Field dpiField, Field pollRateField, ToolStripMenuItem autoWrite, + ToolStripMenuItem useSpecificDevice, ToolStripMenuItem showLastMouseMove, ToolStripMenuItem showVelocityAndGain) { @@ -22,6 +24,7 @@ namespace grapher.Models.Serialized DpiField = dpiField; PollRateField = pollRateField; AutoWriteMenuItem = autoWrite; + UseSpecificDeviceMenuItem = useSpecificDevice; ShowLastMouseMoveMenuItem = showLastMouseMove; ShowVelocityAndGainMoveMenuItem = showVelocityAndGain; } @@ -40,6 +43,8 @@ namespace grapher.Models.Serialized private ToolStripMenuItem AutoWriteMenuItem { get; set; } + private ToolStripMenuItem UseSpecificDeviceMenuItem { get; set; } + private ToolStripMenuItem ShowLastMouseMoveMenuItem { get; set; } private ToolStripMenuItem ShowVelocityAndGainMoveMenuItem { get; set; } @@ -61,6 +66,66 @@ namespace grapher.Models.Serialized return errors; } + private void SpecificDeviceClickHnadler(Object o, EventArgs a, string hwid) + { + var item = (ToolStripMenuItem)o; + foreach (ToolStripMenuItem i in UseSpecificDeviceMenuItem.DropDownItems) + { + i.Checked = false; + } + item.Checked = true; + if (hwid == null || hwid == "") + { + UseSpecificDeviceMenuItem.Checked = false; + } else + { + UseSpecificDeviceMenuItem.Checked = true; + } + RawAccelSettings.AccelerationSettings.deviceHardwareID = hwid; + + TryUpdateActiveSettings(RawAccelSettings.AccelerationSettings); + + } + private void UpdateUseSpecificDeviceMenu() + { + var hwid = RawAccelSettings.AccelerationSettings.deviceHardwareID; + if (hwid == null) { hwid = ""; } + + UseSpecificDeviceMenuItem.Checked = hwid.Length > 0; + UseSpecificDeviceMenuItem.DropDownItems.Clear(); + + var any_device = new ToolStripMenuItem(); + any_device.Text = ""; + any_device.Checked = hwid.Length == 0; + any_device.Click += new EventHandler(delegate(Object o, EventArgs a) { SpecificDeviceClickHnadler(o, a, ""); }); + UseSpecificDeviceMenuItem.DropDownItems.Add(any_device); + + var hwid_not_found = true; + + foreach (Tuple device in Models.Devices.DeviceList.GetDeviceHardwareIDs()) + { + if (hwid == device.Item2) + { + hwid_not_found = false; + } + var dev = new ToolStripMenuItem(); + dev.Text = device.Item1; + dev.Checked = device.Item2 == RawAccelSettings.AccelerationSettings.deviceHardwareID; + dev.Click += new EventHandler(delegate (Object o, EventArgs a) { SpecificDeviceClickHnadler(o, a, device.Item2); }); + UseSpecificDeviceMenuItem.DropDownItems.Add(dev); + } + + if (hwid.Length > 0 && hwid_not_found) + { + var current_hwid = new ToolStripMenuItem(); + current_hwid.Text = "Disconnected (" + hwid + ")"; + current_hwid.ForeColor = Color.DarkGray; + current_hwid.Checked = true; + current_hwid.Click += new EventHandler(delegate (Object o, EventArgs a) { SpecificDeviceClickHnadler(o, a, hwid); }); + UseSpecificDeviceMenuItem.DropDownItems.Add(current_hwid); + } + } + public void UpdateFieldsFromGUISettings() { DpiField.SetToEntered(RawAccelSettings.GUISettings.DPI); @@ -110,6 +175,7 @@ namespace grapher.Models.Serialized { RawAccelSettings = RawAccelSettings.Load(() => MakeGUISettingsFromFields()); UpdateFieldsFromGUISettings(); + UpdateUseSpecificDeviceMenu(); if (RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup) { TryUpdateAccel(RawAccelSettings.AccelerationSettings); diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj index f6bdcb9..8adfa75 100644 --- a/grapher/grapher.csproj +++ b/grapher/grapher.csproj @@ -59,6 +59,7 @@ + @@ -92,6 +93,7 @@ + diff --git a/rawaccel.sln b/rawaccel.sln index fc3d256..9b3978c 100644 --- a/rawaccel.sln +++ b/rawaccel.sln @@ -27,8 +27,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "converter", "converter\conv {28A3656F-A1DE-405C-B547-191C32EC555F} = {28A3656F-A1DE-405C-B547-191C32EC555F} EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "devicelist", "devicelist\devicelist.csproj", "{3666B731-7406-41B1-BCFC-C65073FD09A1}" -EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution common\common.vcxitems*{24b4226f-1461-408f-a1a4-1371c97153ea}*SharedItemsImports = 9 @@ -75,10 +73,6 @@ Global {4C421992-9A27-4860-A40C-ADD76FBACE55}.Debug|x64.Build.0 = Debug|x64 {4C421992-9A27-4860-A40C-ADD76FBACE55}.Release|x64.ActiveCfg = Release|x64 {4C421992-9A27-4860-A40C-ADD76FBACE55}.Release|x64.Build.0 = Release|x64 - {3666B731-7406-41B1-BCFC-C65073FD09A1}.Debug|x64.ActiveCfg = Debug|x64 - {3666B731-7406-41B1-BCFC-C65073FD09A1}.Debug|x64.Build.0 = Debug|x64 - {3666B731-7406-41B1-BCFC-C65073FD09A1}.Release|x64.ActiveCfg = Release|x64 - {3666B731-7406-41B1-BCFC-C65073FD09A1}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE -- cgit v1.2.3 From 8273ecf0c22876f0f4e9dfa9eb29b9d491614faa Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 7 Jan 2021 23:11:24 -0800 Subject: Refactor --- grapher/Models/AccelGUI.cs | 9 ++- grapher/Models/AccelGUIFactory.cs | 11 +++- grapher/Models/Devices/DeviceIDItem.cs | 73 ++++++++++++++++++++++ grapher/Models/Devices/DeviceIDManager.cs | 90 ++++++++++++++++++++++++++++ grapher/Models/Devices/DeviceList.cs | 33 ---------- grapher/Models/Serialized/SettingsManager.cs | 73 +++------------------- 6 files changed, 185 insertions(+), 104 deletions(-) create mode 100644 grapher/Models/Devices/DeviceIDItem.cs create mode 100644 grapher/Models/Devices/DeviceIDManager.cs delete mode 100644 grapher/Models/Devices/DeviceList.cs diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index 5c25813..9f97eed 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -1,4 +1,5 @@ using grapher.Models.Calculations; +using grapher.Models.Devices; using grapher.Models.Mouse; using grapher.Models.Options; using grapher.Models.Serialized; @@ -23,7 +24,8 @@ namespace grapher Button writeButton, ButtonBase toggleButton, MouseWatcher mouseWatcher, - ToolStripMenuItem scaleMenuItem) + ToolStripMenuItem scaleMenuItem, + DeviceIDManager deviceIDManager) { AccelForm = accelForm; AccelCalculator = accelCalculator; @@ -36,6 +38,7 @@ namespace grapher DefaultButtonFont = WriteButton.Font; SmallButtonFont = new Font(WriteButton.Font.Name, WriteButton.Font.Size * Constants.SmallButtonSizeFactor); MouseWatcher = mouseWatcher; + DeviceIDManager = deviceIDManager; ScaleMenuItem.Click += new System.EventHandler(OnScaleMenuItemClick); WriteButton.Click += new System.EventHandler(OnWriteButtonClick); @@ -95,6 +98,8 @@ namespace grapher public ToolStripMenuItem ScaleMenuItem { get; } + public DeviceIDManager DeviceIDManager { get; } + private Timer ChartRefresh { get; } private Font SmallButtonFont { get; } @@ -142,7 +147,7 @@ namespace grapher args = newArgs, minimumTime = driverSettings.minimumTime, directionalMultipliers = driverSettings.directionalMultipliers, - deviceHardwareID = driverSettings.deviceHardwareID + deviceHardwareID = DeviceIDManager.HWID, }; ButtonDelay(WriteButton); diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs index 0e3646d..0669bf5 100644 --- a/grapher/Models/AccelGUIFactory.cs +++ b/grapher/Models/AccelGUIFactory.cs @@ -1,4 +1,5 @@ using grapher.Models.Calculations; +using grapher.Models.Devices; using grapher.Models.Mouse; using grapher.Models.Options; using grapher.Models.Serialized; @@ -325,17 +326,20 @@ namespace grapher.Models lockXYLabel, accelCharts); + var deviceIdManager = new DeviceIDManager(useSpecificDeviceMenuItem); + var settings = new SettingsManager( activeAccel, accelCalculator.DPI, accelCalculator.PollRate, autoWriteMenuItem, - useSpecificDeviceMenuItem, showLastMouseMoveMenuItem, - showVelocityGainToolStripMenuItem); + showVelocityGainToolStripMenuItem, + deviceIdManager); var mouseWatcher = new MouseWatcher(form, mouseLabel, accelCharts, settings); + return new AccelGUI( form, accelCalculator, @@ -345,7 +349,8 @@ namespace grapher.Models writeButton, toggleButton, mouseWatcher, - scaleMenuItem); + scaleMenuItem, + deviceIdManager); } #endregion Methods diff --git a/grapher/Models/Devices/DeviceIDItem.cs b/grapher/Models/Devices/DeviceIDItem.cs new file mode 100644 index 0000000..2bdff81 --- /dev/null +++ b/grapher/Models/Devices/DeviceIDItem.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher.Models.Devices +{ + public class DeviceIDItem + { + public DeviceIDItem(string name, string hwid, DeviceIDManager manager) + { + Name = name; + HWID = hwid; + Manager = manager; + DeviceIDMenuItem = new ToolStripMenuItem(); + DeviceIDMenuItem.Checked = false; + DeviceIDMenuItem.Text = MenuItemText(); + DeviceIDMenuItem.Click += OnClicked; + manager.DeviceIDsMenuItem.DropDownItems.Add(DeviceIDMenuItem); + } + + private ToolStripMenuItem DeviceIDMenuItem { get; } + + public string Name { get; } + + public string HWID { get; } + + private DeviceIDManager Manager { get; } + + public void SetActivated() + { + DeviceIDMenuItem.Checked = true; + } + + public void SetDeactivated() + { + DeviceIDMenuItem.Checked = false; + } + + private string MenuItemText() => string.IsNullOrWhiteSpace(HWID) ? $"{Name}" : $"{Name}: {HWID}"; + + private string DisconnectedText() => $"Disconnected: {HWID}"; + + public void SetDisconnected() + { + DeviceIDMenuItem.ForeColor = Color.DarkGray; + DeviceIDMenuItem.Text = DisconnectedText(); + } + + public void OnClicked(object sender, EventArgs e) + { + Manager.SetActive(this); + } + + public override bool Equals(object obj) + { + return obj is DeviceIDItem item && + Name == item.Name && + HWID == item.HWID; + } + + public override int GetHashCode() + { + int hashCode = -1692744877; + hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(Name); + hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(HWID); + return hashCode; + } + } +} diff --git a/grapher/Models/Devices/DeviceIDManager.cs b/grapher/Models/Devices/DeviceIDManager.cs new file mode 100644 index 0000000..00e7f9d --- /dev/null +++ b/grapher/Models/Devices/DeviceIDManager.cs @@ -0,0 +1,90 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Management; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher.Models.Devices +{ + public class DeviceIDManager + { + public DeviceIDManager(ToolStripMenuItem deviceIDs) + { + DeviceIDsMenuItem = deviceIDs; + } + + public ToolStripMenuItem DeviceIDsMenuItem { get; } + + public string HWID { get => SelectedDeviceID.HWID; } + + public DeviceIDItem SelectedDeviceID { get; private set; } + + public Dictionary DeviceIDs { get; private set; } + + public static IEnumerable<(string, string)> GetDeviceHardwareIDs(string PNPClass = "Mouse") + { + ManagementObjectSearcher searcher = new ManagementObjectSearcher(new SelectQuery("Win32_PnPEntity")); + + foreach (ManagementObject obj in searcher.Get()) + { + if (obj["PNPClass"] != null && obj["PNPClass"].ToString().Equals(PNPClass) && obj["HardwareID"] != null) + { + string[] hwidArray = (string[])(obj["HardwareID"]); + if (hwidArray.Length > 0) + { + string hwid = hwidArray[0].ToString(); + string name = obj["Name"].ToString(); + yield return (name, hwid); + } + } + } + } + + public void SetActive(DeviceIDItem deviceIDItem) + { + if (SelectedDeviceID != null) + { + SelectedDeviceID.SetDeactivated(); + } + + SelectedDeviceID = deviceIDItem; + SelectedDeviceID.SetActivated(); + } + + public void OnStartup(string hwid) + { + var nonEmptyHwid = !string.IsNullOrWhiteSpace(hwid); + + DeviceIDsMenuItem.Checked = nonEmptyHwid; + DeviceIDsMenuItem.DropDownItems.Clear(); + var anyDevice = new DeviceIDItem("Any", string.Empty, this); + if (!nonEmptyHwid) + { + SetActive(anyDevice); + } + + bool found = false; + + foreach (var device in GetDeviceHardwareIDs()) + { + var deviceItem = new DeviceIDItem(device.Item1, device.Item2, this); + if (deviceItem.HWID.Equals(hwid)) + { + found = true; + deviceItem.SetActivated(); + SelectedDeviceID = deviceItem; + } + } + + if (nonEmptyHwid && !found) + { + var deviceItem = new DeviceIDItem(string.Empty, hwid, this); + deviceItem.SetDisconnected(); + } + } + + } +} diff --git a/grapher/Models/Devices/DeviceList.cs b/grapher/Models/Devices/DeviceList.cs deleted file mode 100644 index 9f2b81d..0000000 --- a/grapher/Models/Devices/DeviceList.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Management; -using System.Collections.Generic; - -namespace grapher.Models.Devices -{ - class DeviceList - { - public static List> GetDeviceHardwareIDs(string PNPClass = "Mouse") - { - var results = new List>(); - - ManagementObjectSearcher searcher = new ManagementObjectSearcher(new SelectQuery("Win32_PnPEntity")); - - foreach (ManagementObject obj in searcher.Get()) - { - if (obj["PNPClass"] != null && obj["PNPClass"].ToString() == PNPClass && obj["HardwareID"] != null) - { - String[] hwidArray = (String[])(obj["HardwareID"]); - if (hwidArray.Length > 0) - { - String hwid = hwidArray[0].ToString(); - String name = obj["Name"].ToString(); - results.Add(Tuple.Create(name, hwid)); - } - } - } - - return results; - } - - } -} diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index 3adbc8b..4dbf7bf 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -4,6 +4,7 @@ using System.Windows.Forms; using System.Threading; using System.Text; using System.Drawing; +using grapher.Models.Devices; namespace grapher.Models.Serialized { @@ -16,17 +17,17 @@ namespace grapher.Models.Serialized Field dpiField, Field pollRateField, ToolStripMenuItem autoWrite, - ToolStripMenuItem useSpecificDevice, ToolStripMenuItem showLastMouseMove, - ToolStripMenuItem showVelocityAndGain) + ToolStripMenuItem showVelocityAndGain, + DeviceIDManager deviceIDManager) { ActiveAccel = activeAccel; DpiField = dpiField; PollRateField = pollRateField; AutoWriteMenuItem = autoWrite; - UseSpecificDeviceMenuItem = useSpecificDevice; ShowLastMouseMoveMenuItem = showLastMouseMove; ShowVelocityAndGainMoveMenuItem = showVelocityAndGain; + DeviceIDManager = deviceIDManager; } #endregion Constructors @@ -43,12 +44,12 @@ namespace grapher.Models.Serialized private ToolStripMenuItem AutoWriteMenuItem { get; set; } - private ToolStripMenuItem UseSpecificDeviceMenuItem { get; set; } - private ToolStripMenuItem ShowLastMouseMoveMenuItem { get; set; } private ToolStripMenuItem ShowVelocityAndGainMoveMenuItem { get; set; } + private DeviceIDManager DeviceIDManager { get; } + #endregion Properties #region Methods @@ -66,66 +67,6 @@ namespace grapher.Models.Serialized return errors; } - private void SpecificDeviceClickHnadler(Object o, EventArgs a, string hwid) - { - var item = (ToolStripMenuItem)o; - foreach (ToolStripMenuItem i in UseSpecificDeviceMenuItem.DropDownItems) - { - i.Checked = false; - } - item.Checked = true; - if (hwid == null || hwid == "") - { - UseSpecificDeviceMenuItem.Checked = false; - } else - { - UseSpecificDeviceMenuItem.Checked = true; - } - RawAccelSettings.AccelerationSettings.deviceHardwareID = hwid; - - TryUpdateActiveSettings(RawAccelSettings.AccelerationSettings); - - } - private void UpdateUseSpecificDeviceMenu() - { - var hwid = RawAccelSettings.AccelerationSettings.deviceHardwareID; - if (hwid == null) { hwid = ""; } - - UseSpecificDeviceMenuItem.Checked = hwid.Length > 0; - UseSpecificDeviceMenuItem.DropDownItems.Clear(); - - var any_device = new ToolStripMenuItem(); - any_device.Text = ""; - any_device.Checked = hwid.Length == 0; - any_device.Click += new EventHandler(delegate(Object o, EventArgs a) { SpecificDeviceClickHnadler(o, a, ""); }); - UseSpecificDeviceMenuItem.DropDownItems.Add(any_device); - - var hwid_not_found = true; - - foreach (Tuple device in Models.Devices.DeviceList.GetDeviceHardwareIDs()) - { - if (hwid == device.Item2) - { - hwid_not_found = false; - } - var dev = new ToolStripMenuItem(); - dev.Text = device.Item1; - dev.Checked = device.Item2 == RawAccelSettings.AccelerationSettings.deviceHardwareID; - dev.Click += new EventHandler(delegate (Object o, EventArgs a) { SpecificDeviceClickHnadler(o, a, device.Item2); }); - UseSpecificDeviceMenuItem.DropDownItems.Add(dev); - } - - if (hwid.Length > 0 && hwid_not_found) - { - var current_hwid = new ToolStripMenuItem(); - current_hwid.Text = "Disconnected (" + hwid + ")"; - current_hwid.ForeColor = Color.DarkGray; - current_hwid.Checked = true; - current_hwid.Click += new EventHandler(delegate (Object o, EventArgs a) { SpecificDeviceClickHnadler(o, a, hwid); }); - UseSpecificDeviceMenuItem.DropDownItems.Add(current_hwid); - } - } - public void UpdateFieldsFromGUISettings() { DpiField.SetToEntered(RawAccelSettings.GUISettings.DPI); @@ -133,6 +74,7 @@ namespace grapher.Models.Serialized ShowLastMouseMoveMenuItem.Checked = RawAccelSettings.GUISettings.ShowLastMouseMove; ShowVelocityAndGainMoveMenuItem.Checked = RawAccelSettings.GUISettings.ShowVelocityAndGain; AutoWriteMenuItem.Checked = RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup; + DeviceIDManager.OnStartup(RawAccelSettings.AccelerationSettings.deviceHardwareID); } public SettingsErrors TryUpdateAccel(DriverSettings settings) @@ -175,7 +117,6 @@ namespace grapher.Models.Serialized { RawAccelSettings = RawAccelSettings.Load(() => MakeGUISettingsFromFields()); UpdateFieldsFromGUISettings(); - UpdateUseSpecificDeviceMenu(); if (RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup) { TryUpdateAccel(RawAccelSettings.AccelerationSettings); -- cgit v1.2.3 From 0adaf6bb52a871265805046566059f7994dd3ee6 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 7 Jan 2021 23:11:36 -0800 Subject: Include csproj as well --- grapher/grapher.csproj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj index 8adfa75..2788cca 100644 --- a/grapher/grapher.csproj +++ b/grapher/grapher.csproj @@ -93,7 +93,8 @@ - + + -- cgit v1.2.3 From 0fc716f6529c97aa77a53762785603158dc680ac Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 7 Jan 2021 23:16:45 -0800 Subject: Small behavior improvements --- grapher/Models/Devices/DeviceIDManager.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/grapher/Models/Devices/DeviceIDManager.cs b/grapher/Models/Devices/DeviceIDManager.cs index 00e7f9d..d0a90a2 100644 --- a/grapher/Models/Devices/DeviceIDManager.cs +++ b/grapher/Models/Devices/DeviceIDManager.cs @@ -14,6 +14,7 @@ namespace grapher.Models.Devices public DeviceIDManager(ToolStripMenuItem deviceIDs) { DeviceIDsMenuItem = deviceIDs; + DeviceIDsMenuItem.Checked = false; } public ToolStripMenuItem DeviceIDsMenuItem { get; } @@ -58,7 +59,6 @@ namespace grapher.Models.Devices { var nonEmptyHwid = !string.IsNullOrWhiteSpace(hwid); - DeviceIDsMenuItem.Checked = nonEmptyHwid; DeviceIDsMenuItem.DropDownItems.Clear(); var anyDevice = new DeviceIDItem("Any", string.Empty, this); if (!nonEmptyHwid) @@ -83,6 +83,7 @@ namespace grapher.Models.Devices { var deviceItem = new DeviceIDItem(string.Empty, hwid, this); deviceItem.SetDisconnected(); + anyDevice.SetActivated(); } } -- cgit v1.2.3 From 24fc23d2ac33d9203a2e978aecc363ad449bf766 Mon Sep 17 00:00:00 2001 From: Michael S Date: Fri, 8 Jan 2021 12:02:07 -0500 Subject: Add hyperlink to FAQ pages in Further Help section --- doc/Guide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/Guide.md b/doc/Guide.md index 4ac296d..75b7d54 100644 --- a/doc/Guide.md +++ b/doc/Guide.md @@ -100,4 +100,4 @@ This curve looks like an "S" with the top half bigger than the bottom. Mathemati ![MotivityExample](images/motivity_example.png) ## Further Help -Further help and frequently asked questions can be found in the FAQ. +Further help and frequently asked questions can be found in the ![FAQ](https://github.com/a1xd/rawaccel/blob/master/doc/FAQ.md). -- cgit v1.2.3 From 0e60e22b73dd0693b349cbb63cf9a390c01fd5dd Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Tue, 12 Jan 2021 17:01:18 -0500 Subject: filter raw input based on id use device id (from device instance) over first hardware id use buffered method for all ioctls update gui/DeviceIDManager to match driver behavior respond to device change events desync MouseData and PointData accessors --- common/common.vcxitems | 1 + common/rawaccel-io-def.h | 4 +- common/rawaccel-settings.h | 4 +- common/utility-rawinput.hpp | 74 +++++++++++++++++++++++++++ driver/driver.cpp | 46 ++++++++++------- driver/driver.h | 2 +- grapher/Form1.Designer.cs | 3 -- grapher/Form1.cs | 21 ++------ grapher/Models/AccelGUI.cs | 12 ++++- grapher/Models/Devices/DeviceIDItem.cs | 14 ++--- grapher/Models/Devices/DeviceIDManager.cs | 45 ++++++++-------- grapher/Models/Mouse/MouseData.cs | 17 ++---- grapher/Models/Mouse/MouseWatcher.cs | 33 +++++++++--- grapher/Models/Mouse/PointData.cs | 13 +---- grapher/Models/Serialized/RawAccelSettings.cs | 3 +- grapher/Models/Serialized/SettingsManager.cs | 5 +- wrapper/wrapper.cpp | 27 ++++++++-- wrapper/wrapper.vcxproj | 4 +- 18 files changed, 213 insertions(+), 115 deletions(-) create mode 100644 common/utility-rawinput.hpp diff --git a/common/common.vcxitems b/common/common.vcxitems index 2b03405..ba9bd98 100644 --- a/common/common.vcxitems +++ b/common/common.vcxitems @@ -29,6 +29,7 @@ + diff --git a/common/rawaccel-io-def.h b/common/rawaccel-io-def.h index d8d4088..e169390 100644 --- a/common/rawaccel-io-def.h +++ b/common/rawaccel-io-def.h @@ -8,6 +8,6 @@ #define RA_DEV_TYPE 0x8888u -#define RA_READ CTL_CODE(RA_DEV_TYPE, 0x888, METHOD_OUT_DIRECT, FILE_ANY_ACCESS) +#define RA_READ CTL_CODE(RA_DEV_TYPE, 0x888, METHOD_BUFFERED, FILE_ANY_ACCESS) #define RA_WRITE CTL_CODE(RA_DEV_TYPE, 0x889, METHOD_BUFFERED, FILE_ANY_ACCESS) -#define RA_GET_VERSION CTL_CODE(RA_DEV_TYPE, 0x88a, METHOD_OUT_DIRECT, FILE_ANY_ACCESS) +#define RA_GET_VERSION CTL_CODE(RA_DEV_TYPE, 0x88a, METHOD_BUFFERED, FILE_ANY_ACCESS) diff --git a/common/rawaccel-settings.h b/common/rawaccel-settings.h index f94e960..eb7c49a 100644 --- a/common/rawaccel-settings.h +++ b/common/rawaccel-settings.h @@ -3,7 +3,7 @@ #include "vec2.h" #include "accel-base.hpp" -#define MAX_HWID_LEN 200 +#define MAX_DEV_ID_LEN 200 namespace rawaccel { @@ -25,7 +25,7 @@ namespace rawaccel { vec2d sens = { 1, 1 }; vec2d dir_multipliers = {}; milliseconds time_min = DEFAULT_TIME_MIN; - wchar_t device_hw_id[MAX_HWID_LEN] = {0}; + wchar_t device_id[MAX_DEV_ID_LEN] = {0}; }; } diff --git a/common/utility-rawinput.hpp b/common/utility-rawinput.hpp new file mode 100644 index 0000000..3c44068 --- /dev/null +++ b/common/utility-rawinput.hpp @@ -0,0 +1,74 @@ +#pragma once + +#pragma comment(lib, "cfgmgr32.lib") + +#include +#include +#include +#include + +#include +#include +#include // needed for devpkey.h to parse properly +#include + +// returns device handles corresponding to a "device id" +// https://docs.microsoft.com/en-us/windows-hardware/drivers/install/device-ids +std::vector rawinput_handles_from_dev_id(const std::wstring& dev_id, DWORD input_type = RIM_TYPEMOUSE) { + const UINT RI_ERROR = -1; + + UINT num_devs = 0; + + if (GetRawInputDeviceList(NULL, &num_devs, sizeof(RAWINPUTDEVICELIST)) == RI_ERROR) { + 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) { + throw std::system_error(GetLastError(), std::system_category(), "GetRawInputDeviceList failed"); + } + + std::vector handles; + + for (auto&& dev : devs) { + if (dev.dwType != input_type) continue; + + WCHAR name[256] = {}; + UINT name_size = sizeof(name); + + if (GetRawInputDeviceInfoW(dev.hDevice, RIDI_DEVICENAME, name, &name_size) == RI_ERROR) { + throw std::system_error(GetLastError(), std::system_category(), "GetRawInputDeviceInfoW failed"); + } + + ULONG id_size = 0; + DEVPROPTYPE type; + CONFIGRET cm_res; + + cm_res = CM_Get_Device_Interface_PropertyW(name, &DEVPKEY_Device_InstanceId, + &type, NULL, &id_size, 0); + + if (cm_res != CR_BUFFER_SMALL && cm_res != CR_SUCCESS) { + throw std::runtime_error("CM_Get_Device_Interface_PropertyW failed (" + + std::to_string(cm_res) + ')'); + } + + std::wstring id((static_cast(id_size) + 1) / 2, '\0'); + + cm_res = CM_Get_Device_Interface_PropertyW(name, &DEVPKEY_Device_InstanceId, + &type, reinterpret_cast(&id[0]), &id_size, 0); + + if (cm_res != CR_SUCCESS) { + throw std::runtime_error("CM_Get_Device_Interface_PropertyW failed (" + + std::to_string(cm_res) + ')'); + } + + // remove instance id + id.resize(id.find_last_of('\\')); + + if (id == dev_id) handles.push_back(dev.hDevice); + } + + return handles; +} + diff --git a/driver/driver.cpp b/driver/driver.cpp index 4f108bd..a92f773 100644 --- a/driver/driver.cpp +++ b/driver/driver.cpp @@ -58,8 +58,8 @@ Arguments: bool any = num_packets > 0; bool rel_move = !(InputDataStart->Flags & MOUSE_MOVE_ABSOLUTE); - bool dev_match = global.args.device_hw_id[0] == 0 || - wcsncmp(devExt->hwid, global.args.device_hw_id, MAX_HWID_LEN) == 0; + bool dev_match = global.args.device_id[0] == 0 || + wcsncmp(devExt->dev_id, global.args.device_id, MAX_DEV_ID_LEN) == 0; if (any && rel_move && dev_match) { // if IO is backed up to the point where we get more than 1 packet here @@ -146,6 +146,8 @@ Return Value: NTSTATUS status; void* buffer; + size_t bytes_out = 0; + UNREFERENCED_PARAMETER(Queue); UNREFERENCED_PARAMETER(OutputBufferLength); UNREFERENCED_PARAMETER(InputBufferLength); @@ -166,6 +168,7 @@ Return Value: } else { *reinterpret_cast(buffer) = global.args; + bytes_out = sizeof(ra::settings); } break; case RA_WRITE: @@ -205,6 +208,7 @@ Return Value: } else { *reinterpret_cast(buffer) = { RA_VER_MAJOR, RA_VER_MINOR, RA_VER_PATCH }; + bytes_out = sizeof(ra::version_t); } break; default: @@ -212,7 +216,7 @@ Return Value: break; } - WdfRequestComplete(Request, status); + WdfRequestCompleteWithInformation(Request, status, bytes_out); } #pragma warning(pop) // enable 28118 again @@ -480,25 +484,31 @@ Return Value: } // - // get device hwid + // get device id from bus driver // - WDFMEMORY memory = NULL; + DEVICE_OBJECT* pdo = WdfDeviceWdmGetPhysicalDevice(hDevice); - NTSTATUS hwid_query = WdfDeviceAllocAndQueryProperty( - hDevice, - DevicePropertyHardwareID, - PagedPool, - WDF_NO_OBJECT_ATTRIBUTES, - &memory); + KEVENT ke; + KeInitializeEvent(&ke, NotificationEvent, FALSE); + IO_STATUS_BLOCK iosb = {}; + PIRP Irp = IoBuildSynchronousFsdRequest(IRP_MJ_PNP, + pdo, NULL, 0, NULL, &ke, &iosb); + Irp->IoStatus.Status = STATUS_NOT_SUPPORTED; + PIO_STACK_LOCATION stack = IoGetNextIrpStackLocation(Irp); + stack->MinorFunction = IRP_MN_QUERY_ID; + stack->Parameters.QueryId.IdType = BusQueryDeviceID; + + NTSTATUS nts = IoCallDriver(pdo, Irp); - if (!NT_SUCCESS(hwid_query)) { - DebugPrint(("WdfDeviceAllocAndQueryProperty failed: 0x%x\n", hwid_query)); + if (nts == STATUS_PENDING) { + KeWaitForSingleObject(&ke, Executive, KernelMode, FALSE, NULL); } - else { - auto dev_ext = FilterGetData(hDevice); - void* buffer = WdfMemoryGetBuffer(memory, NULL); - wcsncpy(dev_ext->hwid, reinterpret_cast(buffer), MAX_HWID_LEN); - WdfObjectDelete(memory); + + if (NT_SUCCESS(nts)) { + auto* id_ptr = reinterpret_cast(iosb.Information); + wcsncpy(FilterGetData(hDevice)->dev_id, id_ptr, MAX_DEV_ID_LEN); + DebugPrint(("Device ID = %ws\n", id_ptr)); + ExFreePool(id_ptr); } // diff --git a/driver/driver.h b/driver/driver.h index 5b610fe..a0381fb 100644 --- a/driver/driver.h +++ b/driver/driver.h @@ -21,7 +21,7 @@ typedef struct _DEVICE_EXTENSION { counter_t counter; vec2d carry; CONNECT_DATA UpperConnectData; - WCHAR hwid[MAX_HWID_LEN]; + WCHAR dev_id[MAX_DEV_ID_LEN]; } DEVICE_EXTENSION, *PDEVICE_EXTENSION; WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(DEVICE_EXTENSION, FilterGetData) diff --git a/grapher/Form1.Designer.cs b/grapher/Form1.Designer.cs index c388d79..b375de1 100644 --- a/grapher/Form1.Designer.cs +++ b/grapher/Form1.Designer.cs @@ -261,7 +261,6 @@ namespace grapher this.optionsPanel.Name = "optionsPanel"; this.optionsPanel.Size = new System.Drawing.Size(483, 956); this.optionsPanel.TabIndex = 34; - this.optionsPanel.Paint += new System.Windows.Forms.PaintEventHandler(this.optionsPanel_Paint); // // toggleButton // @@ -1308,8 +1307,6 @@ namespace grapher this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Name = "RawAcceleration"; this.Text = "Raw Accel"; - this.Load += new System.EventHandler(this.Form1_Load); - this.Paint += new System.Windows.Forms.PaintEventHandler(this.RawAcceleration_Paint); this.optionsPanel.ResumeLayout(false); this.optionsPanel.PerformLayout(); this.menuStrip1.ResumeLayout(false); diff --git a/grapher/Form1.cs b/grapher/Form1.cs index e149163..afa7a50 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -155,19 +155,18 @@ namespace grapher protected override void WndProc(ref Message m) { - if (m.Msg == 0x00ff) + if (m.Msg == 0x00ff) // WM_INPUT { AccelGUI.MouseWatcher.ReadMouseMove(m); } + else if (m.Msg == 0x00fe) // WM_INPUT_DEVICE_CHANGE + { + AccelGUI.UpdateInputManagers(); + } base.WndProc(ref m); } - private void Form1_Load(object sender, EventArgs e) - { - - } - public void ResetAutoScroll() { chartsPanel.AutoScrollPosition = Constants.Origin; @@ -187,16 +186,6 @@ namespace grapher }; } - private void RawAcceleration_Paint(object sender, PaintEventArgs e) - { - //AccelGUI.AccelCharts.DrawLastMovement(); - } - #endregion Method - - private void optionsPanel_Paint(object sender, PaintEventArgs e) - { - - } } } diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index 9f97eed..81b3e13 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -100,6 +100,8 @@ namespace grapher public DeviceIDManager DeviceIDManager { get; } + public Action UpdateInputManagers { get; private set; } + private Timer ChartRefresh { get; } private Font SmallButtonFont { get; } @@ -147,7 +149,7 @@ namespace grapher args = newArgs, minimumTime = driverSettings.minimumTime, directionalMultipliers = driverSettings.directionalMultipliers, - deviceHardwareID = DeviceIDManager.HWID, + deviceID = DeviceIDManager.ID, }; ButtonDelay(WriteButton); @@ -168,6 +170,14 @@ namespace grapher { UpdateShownActiveValues(args); UpdateGraph(args); + + UpdateInputManagers = () => + { + MouseWatcher.UpdateHandles(args.deviceID); + DeviceIDManager.Update(args.deviceID); + }; + + UpdateInputManagers(); } public void UpdateGraph(DriverSettings args) diff --git a/grapher/Models/Devices/DeviceIDItem.cs b/grapher/Models/Devices/DeviceIDItem.cs index 2bdff81..63c2761 100644 --- a/grapher/Models/Devices/DeviceIDItem.cs +++ b/grapher/Models/Devices/DeviceIDItem.cs @@ -10,10 +10,10 @@ namespace grapher.Models.Devices { public class DeviceIDItem { - public DeviceIDItem(string name, string hwid, DeviceIDManager manager) + public DeviceIDItem(string name, string id, DeviceIDManager manager) { Name = name; - HWID = hwid; + ID = id; Manager = manager; DeviceIDMenuItem = new ToolStripMenuItem(); DeviceIDMenuItem.Checked = false; @@ -26,7 +26,7 @@ namespace grapher.Models.Devices public string Name { get; } - public string HWID { get; } + public string ID { get; } private DeviceIDManager Manager { get; } @@ -40,9 +40,9 @@ namespace grapher.Models.Devices DeviceIDMenuItem.Checked = false; } - private string MenuItemText() => string.IsNullOrWhiteSpace(HWID) ? $"{Name}" : $"{Name}: {HWID}"; + private string MenuItemText() => string.IsNullOrEmpty(ID) ? $"{Name}" : $"{Name}: {ID}"; - private string DisconnectedText() => $"Disconnected: {HWID}"; + private string DisconnectedText() => $"Disconnected: {ID}"; public void SetDisconnected() { @@ -59,14 +59,14 @@ namespace grapher.Models.Devices { return obj is DeviceIDItem item && Name == item.Name && - HWID == item.HWID; + ID == item.ID; } public override int GetHashCode() { int hashCode = -1692744877; hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(Name); - hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(HWID); + hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(ID); return hashCode; } } diff --git a/grapher/Models/Devices/DeviceIDManager.cs b/grapher/Models/Devices/DeviceIDManager.cs index d0a90a2..c50cda8 100644 --- a/grapher/Models/Devices/DeviceIDManager.cs +++ b/grapher/Models/Devices/DeviceIDManager.cs @@ -19,27 +19,26 @@ namespace grapher.Models.Devices public ToolStripMenuItem DeviceIDsMenuItem { get; } - public string HWID { get => SelectedDeviceID.HWID; } + public string ID { get => SelectedDeviceID.ID; } public DeviceIDItem SelectedDeviceID { get; private set; } public Dictionary DeviceIDs { get; private set; } - public static IEnumerable<(string, string)> GetDeviceHardwareIDs(string PNPClass = "Mouse") + public static IEnumerable<(string, string)> GetDeviceIDs(string PNPClass = "Mouse") { ManagementObjectSearcher searcher = new ManagementObjectSearcher(new SelectQuery("Win32_PnPEntity")); foreach (ManagementObject obj in searcher.Get()) { - if (obj["PNPClass"] != null && obj["PNPClass"].ToString().Equals(PNPClass) && obj["HardwareID"] != null) + if (obj["PNPClass"] != null && obj["PNPClass"].ToString().Equals(PNPClass) && obj["DeviceID"] != null) { - string[] hwidArray = (string[])(obj["HardwareID"]); - if (hwidArray.Length > 0) - { - string hwid = hwidArray[0].ToString(); - string name = obj["Name"].ToString(); - yield return (name, hwid); - } + string name = obj["Name"].ToString(); + + string devInstanceID = obj["DeviceID"].ToString(); + string devID = devInstanceID.Remove(devInstanceID.LastIndexOf('\\')); + + yield return (name, devID); } } } @@ -55,35 +54,31 @@ namespace grapher.Models.Devices SelectedDeviceID.SetActivated(); } - public void OnStartup(string hwid) + public void Update(string devID) { - var nonEmptyHwid = !string.IsNullOrWhiteSpace(hwid); - DeviceIDsMenuItem.DropDownItems.Clear(); + + bool found = string.IsNullOrEmpty(devID); + var anyDevice = new DeviceIDItem("Any", string.Empty, this); - if (!nonEmptyHwid) - { - SetActive(anyDevice); - } - bool found = false; + if (found) SetActive(anyDevice); - foreach (var device in GetDeviceHardwareIDs()) + foreach (var device in GetDeviceIDs().Distinct()) { var deviceItem = new DeviceIDItem(device.Item1, device.Item2, this); - if (deviceItem.HWID.Equals(hwid)) + if (!found && deviceItem.ID.Equals(devID)) { + SetActive(deviceItem); found = true; - deviceItem.SetActivated(); - SelectedDeviceID = deviceItem; } } - if (nonEmptyHwid && !found) + if (!found) { - var deviceItem = new DeviceIDItem(string.Empty, hwid, this); + var deviceItem = new DeviceIDItem(string.Empty, devID, this); deviceItem.SetDisconnected(); - anyDevice.SetActivated(); + SetActive(deviceItem); } } diff --git a/grapher/Models/Mouse/MouseData.cs b/grapher/Models/Mouse/MouseData.cs index e59a969..5944fe4 100644 --- a/grapher/Models/Mouse/MouseData.cs +++ b/grapher/Models/Mouse/MouseData.cs @@ -8,7 +8,6 @@ namespace grapher.Models.Mouse public MouseData() { - Lock = new Object(); X = 0; Y = 0; } @@ -17,18 +16,13 @@ namespace grapher.Models.Mouse #region Properties - public Object Lock { get; } - private int X { get; set; } private int Y { get; set; } public void Set(int x, int y) { - lock (Lock) - { - X = x; - Y = y; - } + X = x; + Y = y; } #endregion Properties @@ -37,11 +31,8 @@ namespace grapher.Models.Mouse public void Get(out int x, out int y) { - lock (Lock) - { - x = X; - y = Y; - } + x = X; + y = Y; } #endregion Methods diff --git a/grapher/Models/Mouse/MouseWatcher.cs b/grapher/Models/Mouse/MouseWatcher.cs index cbfc119..151a2a2 100644 --- a/grapher/Models/Mouse/MouseWatcher.cs +++ b/grapher/Models/Mouse/MouseWatcher.cs @@ -1,5 +1,6 @@ using grapher.Models.Serialized; using System; +using System.Collections.Generic; using System.Runtime.InteropServices; using System.Windows.Forms; @@ -397,7 +398,11 @@ namespace grapher.Models.Mouse /// If set, the application-defined keyboard device hotkeys are not handled. However, the system hotkeys; for example, ALT+TAB and CTRL+ALT+DEL, are still handled. By default, all keyboard hotkeys are handled. NoHotKeys can be specified even if NoLegacy is not specified and WindowHandle is NULL. NoHotKeys = 0x00000200, /// If set, application keys are handled. NoLegacy must be specified. Keyboard only. - AppKeys = 0x00000400 + AppKeys = 0x00000400, + /// If set, this enables the caller to receive input in the background only if the foreground application does not process it. In other words, if the foreground application is not registered for raw input, then the background application that is registered will receive the input. + ExInputSink = 0x00001000, + /// If set, this enables the caller to receive WM_INPUT_DEVICE_CHANGE notifications for device arrival and device removal. + DevNotify = 0x00002000 } /// Value type for raw input devices. @@ -685,12 +690,13 @@ namespace grapher.Models.Mouse AccelCharts = accelCharts; SettingsManager = setMngr; MouseData = new MouseData(); + DeviceHandles = new List(); RAWINPUTDEVICE device = new RAWINPUTDEVICE(); device.WindowHandle = ContainingForm.Handle; device.UsagePage = HIDUsagePage.Generic; device.Usage = HIDUsage.Mouse; - device.Flags = RawInputDeviceFlags.InputSink; + device.Flags = RawInputDeviceFlags.InputSink | RawInputDeviceFlags.DevNotify; RAWINPUTDEVICE[] devices = new RAWINPUTDEVICE[1]; devices[0] = device; @@ -711,6 +717,10 @@ namespace grapher.Models.Mouse private MouseData MouseData { get; } + private List DeviceHandles { get; } + + private bool AnyDevice { get; set; } + private double PollTime { get => 1000 / SettingsManager.PollRateField.Data; @@ -720,6 +730,16 @@ namespace grapher.Models.Mouse #region Methods + public void UpdateHandles(string devID) + { + DeviceHandles.Clear(); + AnyDevice = string.IsNullOrEmpty(devID); + if (!AnyDevice) + { + RawInputInterop.AddHandlesFromID(devID, DeviceHandles); + } + } + public void UpdateLastMove() { MouseData.Get(out var x, out var y); @@ -728,15 +748,14 @@ namespace grapher.Models.Mouse public void ReadMouseMove(Message message) { - RawInput rawInput = new RawInput(); - int outSize = 0; + RawInput rawInput; int size = Marshal.SizeOf(typeof(RawInput)); - - outSize = GetRawInputData((IntPtr)message.LParam, RawInputCommand.Input, out rawInput, ref size, Marshal.SizeOf(typeof(RAWINPUTHEADER))); + _ = GetRawInputData(message.LParam, RawInputCommand.Input, out rawInput, ref size, Marshal.SizeOf(typeof(RAWINPUTHEADER))); bool relative = !rawInput.Data.Mouse.Flags.HasFlag(RawMouseFlags.MoveAbsolute); + bool deviceMatch = AnyDevice || DeviceHandles.Contains(rawInput.Header.Device); - if (relative && (rawInput.Data.Mouse.LastX != 0 || rawInput.Data.Mouse.LastY != 0)) + if (relative && deviceMatch && (rawInput.Data.Mouse.LastX != 0 || rawInput.Data.Mouse.LastY != 0)) { double x = rawInput.Data.Mouse.LastX; double y = rawInput.Data.Mouse.LastY; diff --git a/grapher/Models/Mouse/PointData.cs b/grapher/Models/Mouse/PointData.cs index e3f44ea..87bfc62 100644 --- a/grapher/Models/Mouse/PointData.cs +++ b/grapher/Models/Mouse/PointData.cs @@ -8,7 +8,6 @@ namespace grapher.Models.Mouse public PointData() { - Lock = new Object(); X = new double[] { 0.01 }; Y = new double[] { 0.01 }; } @@ -17,18 +16,13 @@ namespace grapher.Models.Mouse #region Properties - public Object Lock { get; } - private double[] X { get; set; } private double[] Y { get; set; } public void Set(double x, double y) { - lock(Lock) - { - X[0] = x; - Y[0] = y; - } + X[0] = x; + Y[0] = y; } #endregion Properties @@ -37,11 +31,8 @@ namespace grapher.Models.Mouse public void Get(out double[] x, out double[] y) { - lock(Lock) - { x = X; y = Y; - } } #endregion Methods diff --git a/grapher/Models/Serialized/RawAccelSettings.cs b/grapher/Models/Serialized/RawAccelSettings.cs index dcaf864..f4fb1e2 100644 --- a/grapher/Models/Serialized/RawAccelSettings.cs +++ b/grapher/Models/Serialized/RawAccelSettings.cs @@ -125,7 +125,8 @@ namespace grapher.Models.Serialized bool wholeOrNoY = accelSettings.combineMagnitudes || accelSettings.modes.y == AccelMode.noaccel; - return accelSettings.sensitivity.x == 1 && + return string.IsNullOrEmpty(accelSettings.deviceID) && + accelSettings.sensitivity.x == 1 && accelSettings.sensitivity.y == 1 && accelSettings.directionalMultipliers.x <= 0 && accelSettings.directionalMultipliers.y <= 0 && diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index 4dbf7bf..40652dd 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -42,14 +42,14 @@ namespace grapher.Models.Serialized public Field PollRateField { get; private set; } + public DeviceIDManager DeviceIDManager { get; } + private ToolStripMenuItem AutoWriteMenuItem { get; set; } private ToolStripMenuItem ShowLastMouseMoveMenuItem { get; set; } private ToolStripMenuItem ShowVelocityAndGainMoveMenuItem { get; set; } - private DeviceIDManager DeviceIDManager { get; } - #endregion Properties #region Methods @@ -74,7 +74,6 @@ namespace grapher.Models.Serialized ShowLastMouseMoveMenuItem.Checked = RawAccelSettings.GUISettings.ShowLastMouseMove; ShowVelocityAndGainMoveMenuItem.Checked = RawAccelSettings.GUISettings.ShowVelocityAndGain; AutoWriteMenuItem.Checked = RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup; - DeviceIDManager.OnStartup(RawAccelSettings.AccelerationSettings.deviceHardwareID); } public SettingsErrors TryUpdateAccel(DriverSettings settings) diff --git a/wrapper/wrapper.cpp b/wrapper/wrapper.cpp index 7e3f736..2c0d5e3 100644 --- a/wrapper/wrapper.cpp +++ b/wrapper/wrapper.cpp @@ -1,13 +1,16 @@ #pragma once #include +#include #include #include +#include #include "wrapper_io.hpp" using namespace System; +using namespace System::Collections::Generic; using namespace System::Runtime::InteropServices; using namespace System::Reflection; @@ -78,9 +81,9 @@ public ref struct DriverSettings [JsonProperty(Required = Required::Default)] double minimumTime; - [JsonProperty("Device Hardware ID", Required = Required::Default)] - [MarshalAs(UnmanagedType::ByValTStr, SizeConst = MAX_HWID_LEN)] - String^ deviceHardwareID; + [JsonProperty("Device ID", Required = Required::Default)] + [MarshalAs(UnmanagedType::ByValTStr, SizeConst = MAX_DEV_ID_LEN)] + String^ deviceID = ""; bool ShouldSerializeminimumTime() { @@ -221,6 +224,24 @@ public: } }; +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 System::Exception(gcnew String(e.what())); + } + } +}; + public ref struct DriverInterop { literal double WriteDelayMs = WRITE_DELAY; diff --git a/wrapper/wrapper.vcxproj b/wrapper/wrapper.vcxproj index 4f8ed1c..721a981 100644 --- a/wrapper/wrapper.vcxproj +++ b/wrapper/wrapper.vcxproj @@ -59,7 +59,7 @@ stdcpp17 - + User32.lib; $(SolutionDir)/common; @@ -72,7 +72,7 @@ stdcpp17 - + User32.lib; copy /Y "$(TargetPath)" "$(SolutionDir)signed\$(TargetFileName)" & -- cgit v1.2.3 From 652384872807bb90dfa1501ddad01905ba9039f6 Mon Sep 17 00:00:00 2001 From: tatsujinichi Date: Thu, 14 Jan 2021 19:01:17 +0900 Subject: Fixed typo in example --- doc/Guide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/Guide.md b/doc/Guide.md index 4ac296d..e5e56df 100644 --- a/doc/Guide.md +++ b/doc/Guide.md @@ -35,7 +35,7 @@ The above is much more clear with an example. Let's say I have and I move my mouse to create an input of (30,40) at a poll rate of 1000 hz. -Then our input speed is sqrt(30^2 + 40^2) = 50 counts/ms. Our accelerated sensitivity is calculated to be (1 + 0.1 \* 50) * 0.5 = 1.5 \* 0.5 = 0.75. So our output velocity is 0.75 \* 50 = 37.5. If I run the previous calculations with input speed 49.9 I get output velocity 37.40005, so our gain is about (37.5-37.40005)/(50-49.9) = 0.9995. Here is a picture of the charts in Raw Accel showing the same thing: +Then our input speed is sqrt(30^2 + 40^2) = 50 counts/ms. Our accelerated sensitivity is calculated to be (1 + 0.01 \* 50) * 0.5 = 1.5 \* 0.5 = 0.75. So our output velocity is 0.75 \* 50 = 37.5. If I run the previous calculations with input speed 49.9 I get output velocity 37.40005, so our gain is about (37.5-37.40005)/(50-49.9) = 0.9995. Here is a picture of the charts in Raw Accel showing the same thing: ![SensVelocityGainExample](images/accel_readme_example.png) -- cgit v1.2.3 From bdb0820ac0c3d7da3b16ad5ae646c269de2e9411 Mon Sep 17 00:00:00 2001 From: tatsujinichi Date: Thu, 14 Jan 2021 19:01:39 +0900 Subject: Added Visual Studio Code gitignores --- .gitignore | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.gitignore b/.gitignore index 71d9e60..2a7c213 100644 --- a/.gitignore +++ b/.gitignore @@ -138,6 +138,17 @@ _TeamCity* .axoCover/* !.axoCover/settings.json +# Visual Studio code +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + # Visual Studio code coverage results *.coverage *.coveragexml -- cgit v1.2.3 From 36dbbad87d54a9a8c43ba05ff0707e8fdbd75afd Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 14 Jan 2021 12:39:58 -0500 Subject: update faq hyperlink syntax --- doc/Guide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/Guide.md b/doc/Guide.md index 75b7d54..ca2fc52 100644 --- a/doc/Guide.md +++ b/doc/Guide.md @@ -100,4 +100,4 @@ This curve looks like an "S" with the top half bigger than the bottom. Mathemati ![MotivityExample](images/motivity_example.png) ## Further Help -Further help and frequently asked questions can be found in the ![FAQ](https://github.com/a1xd/rawaccel/blob/master/doc/FAQ.md). +Further help and frequently asked questions can be found in the [FAQ](https://github.com/a1xd/rawaccel/blob/master/doc/FAQ.md). -- cgit v1.2.3 From c1cd6664a4479ff2210d2461dac5ad84c514bb75 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 14 Jan 2021 12:44:57 -0500 Subject: show custom dialog on bad input (#63) * show custom dialog on bad input fixes #62 * Update MessageDialog constructor args --- grapher/MessageDialog.Designer.cs | 98 +++++++++++++++++++++++++++++++++++++++ grapher/MessageDialog.cs | 24 ++++++++++ grapher/Models/AccelGUI.cs | 2 +- grapher/grapher.csproj | 7 +++ 4 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 grapher/MessageDialog.Designer.cs create mode 100644 grapher/MessageDialog.cs diff --git a/grapher/MessageDialog.Designer.cs b/grapher/MessageDialog.Designer.cs new file mode 100644 index 0000000..f7fa8d6 --- /dev/null +++ b/grapher/MessageDialog.Designer.cs @@ -0,0 +1,98 @@ + +namespace grapher +{ + partial class MessageDialog + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.tableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); + this.okButton = new System.Windows.Forms.Button(); + this.messageLabel = new System.Windows.Forms.Label(); + this.tableLayoutPanel.SuspendLayout(); + this.SuspendLayout(); + // + // tableLayoutPanel + // + this.tableLayoutPanel.AutoSize = true; + this.tableLayoutPanel.ColumnCount = 1; + this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel.Controls.Add(this.okButton, 0, 1); + this.tableLayoutPanel.Controls.Add(this.messageLabel, 0, 0); + this.tableLayoutPanel.ForeColor = System.Drawing.SystemColors.ControlText; + this.tableLayoutPanel.Location = new System.Drawing.Point(0, 0); + this.tableLayoutPanel.Name = "tableLayoutPanel"; + this.tableLayoutPanel.Padding = new System.Windows.Forms.Padding(5); + this.tableLayoutPanel.RowCount = 2; + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 35F)); + this.tableLayoutPanel.Size = new System.Drawing.Size(224, 61); + this.tableLayoutPanel.TabIndex = 2; + // + // okButton + // + this.okButton.Anchor = System.Windows.Forms.AnchorStyles.Bottom; + this.okButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.okButton.Location = new System.Drawing.Point(74, 30); + this.okButton.Name = "okButton"; + this.okButton.Size = new System.Drawing.Size(75, 23); + this.okButton.TabIndex = 4; + this.okButton.Text = "&OK"; + this.okButton.UseVisualStyleBackColor = true; + // + // messageLabel + // + this.messageLabel.AutoSize = true; + this.messageLabel.Location = new System.Drawing.Point(8, 5); + this.messageLabel.Name = "messageLabel"; + this.messageLabel.Size = new System.Drawing.Size(35, 13); + this.messageLabel.TabIndex = 3; + this.messageLabel.Text = "label1"; + // + // MessageDialog + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.AutoSize = true; + this.CancelButton = this.okButton; + this.ClientSize = new System.Drawing.Size(224, 61); + this.Controls.Add(this.tableLayoutPanel); + this.Name = "MessageDialog"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.tableLayoutPanel.ResumeLayout(false); + this.tableLayoutPanel.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel; + private System.Windows.Forms.Button okButton; + private System.Windows.Forms.Label messageLabel; + } +} \ No newline at end of file diff --git a/grapher/MessageDialog.cs b/grapher/MessageDialog.cs new file mode 100644 index 0000000..0e153f8 --- /dev/null +++ b/grapher/MessageDialog.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher +{ + public partial class MessageDialog : Form + { + public MessageDialog(string message, string title = "") + { + InitializeComponent(); + Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath); + Text = title; + messageLabel.Text = message; + } + + } +} diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index 81b3e13..bb634ff 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -162,7 +162,7 @@ namespace grapher } else { - throw new Exception($"Bad arguments:\n\n{errors}"); + new MessageDialog(errors.ToString(), "bad input").ShowDialog(); } } diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj index 2788cca..35d7e0c 100644 --- a/grapher/grapher.csproj +++ b/grapher/grapher.csproj @@ -81,6 +81,12 @@ + + Form + + + MessageDialog.cs + @@ -133,6 +139,7 @@ AboutBox.cs + Designer Form1.cs -- cgit v1.2.3