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 | |
| 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')
| -rw-r--r-- | grapher/Models/Devices/DeviceIDItem.cs | 14 | ||||
| -rw-r--r-- | grapher/Models/Devices/DeviceIDManager.cs | 45 |
2 files changed, 27 insertions, 32 deletions
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<string>.Default.GetHashCode(Name); - hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(HWID); + hashCode = hashCode * -1521134295 + EqualityComparer<string>.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<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); } } |