mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-12 21:38:38 +00:00
wip: try to fix input id on linux
i need this code on my linux machine to test
This commit is contained in:
parent
18d69bbf42
commit
497b6e0742
@ -2,6 +2,7 @@
|
||||
|
||||
public enum LinuxDeviceType
|
||||
{
|
||||
Unknown,
|
||||
Keyboard,
|
||||
Mouse,
|
||||
Gamepad
|
||||
|
||||
@ -19,7 +19,7 @@ public class LinuxInputDevice
|
||||
switch (dataType)
|
||||
{
|
||||
case 'I':
|
||||
InputId = new LinuxInputId(data);
|
||||
InputId = data;
|
||||
break;
|
||||
case 'N':
|
||||
Name = data.Replace("\"", "").Replace("Name=", "");
|
||||
@ -27,14 +27,16 @@ public class LinuxInputDevice
|
||||
case 'H':
|
||||
Handlers = data.Replace("Handlers=", "").Split(" ");
|
||||
|
||||
if (Handlers?.Any(h => h.Contains("mouse")) == true)
|
||||
if (Handlers.Any(h => h.Contains("mouse")))
|
||||
DeviceType = LinuxDeviceType.Mouse;
|
||||
else if (Handlers?.Any(h => h.Contains("kbd")) == true)
|
||||
else if (Handlers.Any(h => h.Contains("kbd")))
|
||||
DeviceType = LinuxDeviceType.Keyboard;
|
||||
else if (Handlers?.Any(h => h.Contains("js")) == true)
|
||||
else if (Handlers.Any(h => h.Contains("js")))
|
||||
DeviceType = LinuxDeviceType.Gamepad;
|
||||
else
|
||||
DeviceType = LinuxDeviceType.Unknown;
|
||||
|
||||
string evt = Handlers!.First(h => h.Contains("event"));
|
||||
string evt = Handlers.First(h => h.Contains("event"));
|
||||
|
||||
EventPath = $"/dev/input/{evt}";
|
||||
break;
|
||||
@ -45,7 +47,7 @@ public class LinuxInputDevice
|
||||
throw new ArtemisLinuxInputProviderException("Linux device definition did not contain necessary data");
|
||||
}
|
||||
|
||||
public LinuxInputId InputId { get; }
|
||||
public string InputId { get; }
|
||||
public string Name { get; }
|
||||
public string[] Handlers { get; }
|
||||
public string EventPath { get; }
|
||||
@ -60,29 +62,4 @@ public class LinuxInputDevice
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public class LinuxInputId
|
||||
{
|
||||
public LinuxInputId(string line)
|
||||
{
|
||||
Dictionary<string, string> components = line.Split(" ")
|
||||
.Select(c => c.Split('='))
|
||||
.ToDictionary(c => c[0], c => c[1]);
|
||||
|
||||
Bus = components["Bus"];
|
||||
Vendor = components["Vendor"];
|
||||
Product = components["Product"];
|
||||
Version = components["Version"];
|
||||
}
|
||||
|
||||
public string Bus { get; }
|
||||
public string Vendor { get; }
|
||||
public string Product { get; }
|
||||
public string Version { get; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Bus={Bus} Vendor={Vendor} Product={Product} Version={Version}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -11,9 +11,37 @@ public static class LinuxInputDeviceFinder
|
||||
|
||||
public static IEnumerable<LinuxInputDevice> Find()
|
||||
{
|
||||
return File.ReadAllLines(DEVICES_FILE)
|
||||
.PartitionBy(s => s?.Length == 0) //split on empty lines
|
||||
.Select(lineGroup => new LinuxInputDevice(lineGroup));
|
||||
var lineGroups = File.ReadAllLines(DEVICES_FILE)
|
||||
.PartitionBy(s => s?.Length == 0); //split on empty lines
|
||||
|
||||
foreach (var lineGroup in lineGroups)
|
||||
{
|
||||
LinuxInputDevice device;
|
||||
|
||||
try
|
||||
{
|
||||
device = new LinuxInputDevice(lineGroup);
|
||||
}
|
||||
catch
|
||||
{
|
||||
continue;
|
||||
//some devices don't have all the required data, we can ignore those
|
||||
}
|
||||
|
||||
if (ShouldReadDevice(device))
|
||||
{
|
||||
yield return device;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool ShouldReadDevice(LinuxInputDevice device)
|
||||
{
|
||||
if (device.DeviceType == LinuxDeviceType.Unknown)
|
||||
return false;
|
||||
//possibly add more checks here
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//https://stackoverflow.com/questions/56623354
|
||||
@ -34,7 +62,7 @@ public static class LinuxInputDeviceFinder
|
||||
return groupNumber;
|
||||
};
|
||||
return a
|
||||
.Select(x => new {Value = x, GroupNumber = getGroupNumber(predicate(x))})
|
||||
.Select(x => new { Value = x, GroupNumber = getGroupNumber(predicate(x)) })
|
||||
.Where(x => x.GroupNumber != null)
|
||||
.GroupBy(x => x.GroupNumber)
|
||||
.Select(g => g.Select(x => x.Value));
|
||||
|
||||
@ -75,7 +75,7 @@ public class LinuxInputProvider : InputProvider
|
||||
|
||||
//_logger.Verbose($"Keyboard Key: {(LinuxKeyboardKeyCodes)args.Code} | Down: {isDown}");
|
||||
|
||||
LinuxInputDevice.LinuxInputId identifier = keyboard.InputId;
|
||||
string identifier = keyboard.InputId;
|
||||
OnIdentifierReceived(identifier, InputDeviceType.Keyboard);
|
||||
ArtemisDevice? device = null;
|
||||
|
||||
@ -93,7 +93,7 @@ public class LinuxInputProvider : InputProvider
|
||||
|
||||
private void HandleMouseData(LinuxInputDevice mouse, LinuxInputEventArgs args)
|
||||
{
|
||||
LinuxInputDevice.LinuxInputId identifier = mouse.InputId;
|
||||
string identifier = mouse.InputId;
|
||||
OnIdentifierReceived(identifier, InputDeviceType.Mouse);
|
||||
ArtemisDevice? device = null;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user