Replace FilteredDevices dictionary with call to DeviceHandler.IsFiltered()

device-handlers
Clive Galway 2 years ago
parent 835fc71764
commit b08098f38b

@ -20,5 +20,15 @@ namespace AutoHotInterception.DeviceHandlers
public abstract void ProcessStroke(ManagedWrapper.Stroke stroke);
int IDeviceHandler.IsFiltered()
{
return Convert.ToInt32(IsFiltered);
}
public void SetFilterState(bool state)
{
IsFiltered = state;
}
}
}

@ -4,6 +4,23 @@ namespace AutoHotInterception.DeviceHandlers
{
interface IDeviceHandler
{
/// <summary>
/// Will be called by Interception to decide whether or not to filter (consume input) from this device
/// A "predicate" function is passed to Interception's SetFilter method, and it expects a 0 (Not Filtered) or 1 (Filtered) result
/// </summary>
/// <returns>0 for not filtered, 1 for filtered</returns>
int IsFiltered();
/// <summary>
/// Lets this device know if it is currently being filtered or not, and governs what IsFiltered() returns
/// </summary>
/// <param name="state">true for filtered, false for not filtered</param>
void SetFilterState(bool state);
/// <summary>
/// Process an incoming stroke
/// </summary>
/// <param name="stroke">The stroke to process</param>
void ProcessStroke(ManagedWrapper.Stroke stroke);
}
}

@ -11,7 +11,7 @@ namespace AutoHotInterception.DeviceHandlers
public KeyboardHandler(IntPtr deviceContext, int deviceId) : base (deviceContext, deviceId)
{
IsFiltered = true;
}
public override void ProcessStroke(ManagedWrapper.Stroke stroke)

@ -16,7 +16,7 @@ namespace AutoHotInterception
// If a device ID exists as a key in this Dictionary then that device is filtered.
// Used by IsMonitoredDevice, which is handed to Interception as a "Predicate".
private static readonly ConcurrentDictionary<int, bool> FilteredDevices = new ConcurrentDictionary<int, bool>();
//private static readonly ConcurrentDictionary<int, bool> FilteredDevices = new ConcurrentDictionary<int, bool>();
private static readonly ConcurrentDictionary<int, IDeviceHandler> DeviceHandlers = new ConcurrentDictionary<int, IDeviceHandler>();
@ -562,11 +562,12 @@ namespace AutoHotInterception
/// ... requiring a reboot.
/// When working with AHI, it's generally best to keep this matching as little as possible....
/// </summary>
/// <param name="device"></param>
/// <param name="device">The Interception ID of the device</param>
/// <returns></returns>
private static int IsMonitoredDevice(int device)
{
return Convert.ToInt32(FilteredDevices.ContainsKey(device));
//return Convert.ToInt32(FilteredDevices.ContainsKey(device));
return DeviceHandlers[device].IsFiltered();
}
private void SetFilterState(bool state)
@ -577,10 +578,11 @@ namespace AutoHotInterception
private void SetDeviceFilterState(int device, bool state)
{
if (state && !FilteredDevices.ContainsKey(device))
FilteredDevices[device] = true;
else if (!state && FilteredDevices.ContainsKey(device))
FilteredDevices.TryRemove(device, out _);
//if (state && !FilteredDevices.ContainsKey(device))
// FilteredDevices[device] = true;
//else if (!state && FilteredDevices.ContainsKey(device))
// FilteredDevices.TryRemove(device, out _);
DeviceHandlers[device].SetFilterState(state);
}
private bool DeviceHasBindings(int id)

Loading…
Cancel
Save