mirror of
https://github.com/whoswhip/Spectrum.git
synced 2026-12-06 01:28:42 +00:00
all of these changes were done MONTHS ago, but i'll try to list them out: - simplified input library switching & implementation - implemented makcu binary, which is their new communication, have NOT tested - renamed existing makcu implementation to makcuLegacy since they've changed their communication format - overall simplification of code - formatted code via csharpier - minimal optimizations
61 lines
1.8 KiB
C#
61 lines
1.8 KiB
C#
|
|
|
|
namespace Spectrum.Input.InputLibraries
|
|
{
|
|
internal sealed class InputLibraryManager
|
|
{
|
|
private IInputLibrary? _current;
|
|
private InputLibraryType _currentType = InputLibraryType.MouseEvent;
|
|
private readonly object _lock = new();
|
|
|
|
public InputLibraryType CurrentType => _currentType;
|
|
public IInputLibrary? Current => _current;
|
|
|
|
public bool Switch(InputLibraryType type)
|
|
{
|
|
lock (_lock)
|
|
{
|
|
if (_currentType == type)
|
|
return true;
|
|
|
|
_current?.Dispose();
|
|
_current = null;
|
|
_currentType = InputLibraryType.MouseEvent;
|
|
|
|
_current = type switch
|
|
{
|
|
InputLibraryType.HID => HID.HIDMain.Instance,
|
|
InputLibraryType.Arduino => Arduino.ArduinoMain.Instance,
|
|
InputLibraryType.MouseEvent => MouseEvent.MouseMain.Instance,
|
|
InputLibraryType.MakcuBinary => MakcuBinary.MakcuBinaryMain.Instance,
|
|
InputLibraryType.MakcuLegacy => MakcuLegacy.MakcuLegacyMain.Instance,
|
|
_ => MouseEvent.MouseMain.Instance,
|
|
};
|
|
|
|
if (_current == null)
|
|
return true;
|
|
|
|
if (_current.RequiresInitialization && !_current.Initialize())
|
|
{
|
|
_current.Dispose();
|
|
_current = null;
|
|
return false;
|
|
}
|
|
|
|
_currentType = type;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
lock (_lock)
|
|
{
|
|
_current?.Dispose();
|
|
_current = null;
|
|
_currentType = InputLibraryType.MouseEvent;
|
|
}
|
|
}
|
|
}
|
|
}
|