1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Merge branch 'feature/linux-input-fix' into feature/avalonia-preview7

This commit is contained in:
Diogo Trindade 2023-05-06 15:40:04 +01:00
commit 3c6d770ec2
7 changed files with 61 additions and 49 deletions

View File

@ -22,8 +22,6 @@ public class App : Application
Program.CreateLogger(_container); Program.CreateLogger(_container);
RxApp.MainThreadScheduler = AvaloniaScheduler.Instance; RxApp.MainThreadScheduler = AvaloniaScheduler.Instance;
AvaloniaXamlLoader.Load(this); AvaloniaXamlLoader.Load(this);
RegisterProviders();
} }
public override void OnFrameworkInitializationCompleted() public override void OnFrameworkInitializationCompleted()
@ -31,9 +29,13 @@ public class App : Application
if (Design.IsDesignMode) if (Design.IsDesignMode)
return; return;
if (ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop)
return;
ArtemisBootstrapper.Initialize(); ArtemisBootstrapper.Initialize();
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
_applicationStateManager = new ApplicationStateManager(_container!, desktop.Args); _applicationStateManager = new ApplicationStateManager(_container!, desktop.Args);
RegisterProviders();
} }
private void RegisterProviders() private void RegisterProviders()

View File

@ -2,6 +2,7 @@
public enum LinuxDeviceType public enum LinuxDeviceType
{ {
Unknown,
Keyboard, Keyboard,
Mouse, Mouse,
Gamepad Gamepad

View File

@ -19,7 +19,7 @@ public class LinuxInputDevice
switch (dataType) switch (dataType)
{ {
case 'I': case 'I':
InputId = new LinuxInputId(data); InputId = data;
break; break;
case 'N': case 'N':
Name = data.Replace("\"", "").Replace("Name=", ""); Name = data.Replace("\"", "").Replace("Name=", "");
@ -27,14 +27,16 @@ public class LinuxInputDevice
case 'H': case 'H':
Handlers = data.Replace("Handlers=", "").Split(" "); Handlers = data.Replace("Handlers=", "").Split(" ");
if (Handlers?.Any(h => h.Contains("mouse")) == true) if (Handlers.Any(h => h.Contains("mouse")))
DeviceType = LinuxDeviceType.Mouse; DeviceType = LinuxDeviceType.Mouse;
else if (Handlers?.Any(h => h.Contains("kbd")) == true) else if (Handlers.Any(h => h.Contains("kbd")))
DeviceType = LinuxDeviceType.Keyboard; DeviceType = LinuxDeviceType.Keyboard;
else if (Handlers?.Any(h => h.Contains("js")) == true) else if (Handlers.Any(h => h.Contains("js")))
DeviceType = LinuxDeviceType.Gamepad; 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}"; EventPath = $"/dev/input/{evt}";
break; break;
@ -45,7 +47,7 @@ public class LinuxInputDevice
throw new ArtemisLinuxInputProviderException("Linux device definition did not contain necessary data"); 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 Name { get; }
public string[] Handlers { get; } public string[] Handlers { get; }
public string EventPath { get; } public string EventPath { get; }
@ -60,29 +62,4 @@ public class LinuxInputDevice
} }
#endregion #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}";
}
}
} }

View File

@ -11,9 +11,37 @@ public static class LinuxInputDeviceFinder
public static IEnumerable<LinuxInputDevice> Find() public static IEnumerable<LinuxInputDevice> Find()
{ {
return File.ReadAllLines(DEVICES_FILE) var lineGroups = File.ReadAllLines(DEVICES_FILE)
.PartitionBy(s => s?.Length == 0) //split on empty lines .PartitionBy(s => s?.Length == 0); //split on empty lines
.Select(lineGroup => new LinuxInputDevice(lineGroup));
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 //https://stackoverflow.com/questions/56623354

View File

@ -75,7 +75,7 @@ public class LinuxInputProvider : InputProvider
//_logger.Verbose($"Keyboard Key: {(LinuxKeyboardKeyCodes)args.Code} | Down: {isDown}"); //_logger.Verbose($"Keyboard Key: {(LinuxKeyboardKeyCodes)args.Code} | Down: {isDown}");
LinuxInputDevice.LinuxInputId identifier = keyboard.InputId; string identifier = keyboard.InputId;
OnIdentifierReceived(identifier, InputDeviceType.Keyboard); OnIdentifierReceived(identifier, InputDeviceType.Keyboard);
ArtemisDevice? device = null; ArtemisDevice? device = null;
@ -93,7 +93,7 @@ public class LinuxInputProvider : InputProvider
private void HandleMouseData(LinuxInputDevice mouse, LinuxInputEventArgs args) private void HandleMouseData(LinuxInputDevice mouse, LinuxInputEventArgs args)
{ {
LinuxInputDevice.LinuxInputId identifier = mouse.InputId; string identifier = mouse.InputId;
OnIdentifierReceived(identifier, InputDeviceType.Mouse); OnIdentifierReceived(identifier, InputDeviceType.Mouse);
ArtemisDevice? device = null; ArtemisDevice? device = null;

View File

@ -52,7 +52,7 @@ public static class InputUtilities
LinuxKeyboardKeyCodes.KEY_APOSTROPHE => KeyboardKey.OemQuotes, LinuxKeyboardKeyCodes.KEY_APOSTROPHE => KeyboardKey.OemQuotes,
LinuxKeyboardKeyCodes.KEY_GRAVE => KeyboardKey.OemTilde, LinuxKeyboardKeyCodes.KEY_GRAVE => KeyboardKey.OemTilde,
LinuxKeyboardKeyCodes.KEY_LEFTSHIFT => KeyboardKey.LeftShift, LinuxKeyboardKeyCodes.KEY_LEFTSHIFT => KeyboardKey.LeftShift,
LinuxKeyboardKeyCodes.KEY_BACKSLASH => KeyboardKey.OemBackslash, LinuxKeyboardKeyCodes.KEY_BACKSLASH => KeyboardKey.OemPipe,
LinuxKeyboardKeyCodes.KEY_Z => KeyboardKey.Z, LinuxKeyboardKeyCodes.KEY_Z => KeyboardKey.Z,
LinuxKeyboardKeyCodes.KEY_X => KeyboardKey.X, LinuxKeyboardKeyCodes.KEY_X => KeyboardKey.X,
LinuxKeyboardKeyCodes.KEY_C => KeyboardKey.C, LinuxKeyboardKeyCodes.KEY_C => KeyboardKey.C,
@ -94,7 +94,7 @@ public static class InputUtilities
LinuxKeyboardKeyCodes.KEY_KP0 => KeyboardKey.NumPad0, LinuxKeyboardKeyCodes.KEY_KP0 => KeyboardKey.NumPad0,
LinuxKeyboardKeyCodes.KEY_KPDOT => KeyboardKey.NumPadDecimal, LinuxKeyboardKeyCodes.KEY_KPDOT => KeyboardKey.NumPadDecimal,
// LinuxKeyboardKeyCodes.KEY_ZENKAKUHANKAKU => expr, // LinuxKeyboardKeyCodes.KEY_ZENKAKUHANKAKU => expr,
// LinuxKeyboardKeyCodes.KEY_102ND => expr, LinuxKeyboardKeyCodes.KEY_102ND => KeyboardKey.OemBackslash,
LinuxKeyboardKeyCodes.KEY_F11 => KeyboardKey.F11, LinuxKeyboardKeyCodes.KEY_F11 => KeyboardKey.F11,
LinuxKeyboardKeyCodes.KEY_F12 => KeyboardKey.F12, LinuxKeyboardKeyCodes.KEY_F12 => KeyboardKey.F12,
//LinuxKeyboardKeyCodes.KEY_RO => expr, //LinuxKeyboardKeyCodes.KEY_RO => expr,

View File

@ -7,6 +7,7 @@ using Artemis.Core.Services;
using Artemis.UI.Shared; using Artemis.UI.Shared;
using Artemis.UI.Shared.Services; using Artemis.UI.Shared.Services;
using Artemis.UI.Shared.Services.Builders; using Artemis.UI.Shared.Services.Builders;
using Avalonia.Threading;
using FluentAvalonia.UI.Controls; using FluentAvalonia.UI.Controls;
using ReactiveUI; using ReactiveUI;
using RGB.NET.Core; using RGB.NET.Core;
@ -56,11 +57,14 @@ public class DeviceDetectInputViewModel : ContentDialogViewModelBase
public bool MadeChanges { get; set; } public bool MadeChanges { get; set; }
private void InputServiceOnDeviceIdentified() private void InputServiceOnDeviceIdentified()
{
Dispatcher.UIThread.Post(() =>
{ {
ContentDialog?.Hide(ContentDialogResult.Primary); ContentDialog?.Hide(ContentDialogResult.Primary);
_notificationService.CreateNotification() _notificationService.CreateNotification()
.WithMessage($"{Device.RgbDevice.DeviceInfo.DeviceName} identified 😁") .WithMessage($"{Device.RgbDevice.DeviceInfo.DeviceName} identified 😁")
.WithSeverity(NotificationSeverity.Success) .WithSeverity(NotificationSeverity.Success)
.Show(); .Show();
});
} }
} }