mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-12 13:28:33 +00:00
Merge pull request #863 from Artemis-RGB/feature/linux-fixes
Handle unplugging devices properly on Linux
This commit is contained in:
commit
ff74376ca2
@ -1,20 +1,24 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Serilog;
|
||||
|
||||
namespace Artemis.UI.Linux.Providers.Input;
|
||||
|
||||
internal class LinuxInputDeviceReader
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly byte[] _buffer;
|
||||
private readonly CancellationTokenSource _cts;
|
||||
private readonly FileStream _stream;
|
||||
private readonly Task _task;
|
||||
|
||||
public LinuxInputDeviceReader(LinuxInputDevice inputDevice)
|
||||
public LinuxInputDeviceReader(LinuxInputDevice inputDevice, ILogger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
InputDevice = inputDevice;
|
||||
|
||||
_buffer = new byte[Marshal.SizeOf<LinuxInputEventArgs>()];
|
||||
@ -50,9 +54,10 @@ internal class LinuxInputDeviceReader
|
||||
|
||||
InputEvent?.Invoke(this, MemoryMarshal.Read<LinuxInputEventArgs>(_buffer));
|
||||
}
|
||||
catch
|
||||
catch(Exception e)
|
||||
{
|
||||
// ignored
|
||||
_logger.Error("Error reading device input from {fileName}. Did you unplug a device? Stopping reader. {e}", InputDevice.EventPath, e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,7 +21,7 @@ public class LinuxInputProvider : InputProvider
|
||||
|
||||
foreach (LinuxInputDevice deviceDefinition in LinuxInputDeviceFinder.Find())
|
||||
{
|
||||
LinuxInputDeviceReader? reader = new(deviceDefinition);
|
||||
LinuxInputDeviceReader? reader = new(deviceDefinition, logger);
|
||||
reader.InputEvent += OnInputEvent;
|
||||
_readers.Add(reader);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user