diff options
| author | a1xd <[email protected]> | 2021-01-12 17:01:18 -0500 |
|---|---|---|
| committer | a1xd <[email protected]> | 2021-01-12 17:01:18 -0500 |
| commit | 0e60e22b73dd0693b349cbb63cf9a390c01fd5dd (patch) | |
| tree | 493bfaeb2b59b7db452c52e9ec9713e8b8296510 /grapher/Models/Devices/DeviceIDManager.cs | |
| parent | Small behavior improvements (diff) | |
| download | rawaccel-0e60e22b73dd0693b349cbb63cf9a390c01fd5dd.tar.xz rawaccel-0e60e22b73dd0693b349cbb63cf9a390c01fd5dd.zip | |
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
Diffstat (limited to 'grapher/Models/Devices/DeviceIDManager.cs')
| -rw-r--r-- | grapher/Models/Devices/DeviceIDManager.cs | 45 |
1 files changed, 20 insertions, 25 deletions
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<string, DeviceIDItem> 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); } } |