summaryrefslogtreecommitdiff
path: root/grapher/Models
diff options
context:
space:
mode:
authora1xd <[email protected]>2021-01-12 17:01:18 -0500
committera1xd <[email protected]>2021-01-12 17:01:18 -0500
commit0e60e22b73dd0693b349cbb63cf9a390c01fd5dd (patch)
tree493bfaeb2b59b7db452c52e9ec9713e8b8296510 /grapher/Models
parentSmall behavior improvements (diff)
downloadrawaccel-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')
-rw-r--r--grapher/Models/AccelGUI.cs12
-rw-r--r--grapher/Models/Devices/DeviceIDItem.cs14
-rw-r--r--grapher/Models/Devices/DeviceIDManager.cs45
-rw-r--r--grapher/Models/Mouse/MouseData.cs17
-rw-r--r--grapher/Models/Mouse/MouseWatcher.cs33
-rw-r--r--grapher/Models/Mouse/PointData.cs13
-rw-r--r--grapher/Models/Serialized/RawAccelSettings.cs3
-rw-r--r--grapher/Models/Serialized/SettingsManager.cs5
8 files changed, 74 insertions, 68 deletions
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<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);
}
}
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
/// <summary>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.</summary>
NoHotKeys = 0x00000200,
/// <summary>If set, application keys are handled. NoLegacy must be specified. Keyboard only.</summary>
- AppKeys = 0x00000400
+ AppKeys = 0x00000400,
+ /// <summary>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.</summary>
+ ExInputSink = 0x00001000,
+ /// <summary>If set, this enables the caller to receive WM_INPUT_DEVICE_CHANGE notifications for device arrival and device removal.</summary>
+ DevNotify = 0x00002000
}
/// <summary>Value type for raw input devices.</summary>
@@ -685,12 +690,13 @@ namespace grapher.Models.Mouse
AccelCharts = accelCharts;
SettingsManager = setMngr;
MouseData = new MouseData();
+ DeviceHandles = new List<IntPtr>();
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<IntPtr> 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)