From 247b77f1acd5b06bc85a15a47be4f5697d055e87 Mon Sep 17 00:00:00 2001 From: Giuseppe Lippolis Date: Mon, 25 Mar 2024 09:29:21 +0100 Subject: [PATCH] fix: Address review --- .../Input/LibInput/LibInputBackend.cs | 13 +++++-------- .../Input/LibInput/LibInputBackendOptions.cs | 9 ++------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/Linux/Avalonia.LinuxFramebuffer/Input/LibInput/LibInputBackend.cs b/src/Linux/Avalonia.LinuxFramebuffer/Input/LibInput/LibInputBackend.cs index 018bc0bdf46..91e33526d0c 100644 --- a/src/Linux/Avalonia.LinuxFramebuffer/Input/LibInput/LibInputBackend.cs +++ b/src/Linux/Avalonia.LinuxFramebuffer/Input/LibInput/LibInputBackend.cs @@ -11,7 +11,7 @@ public partial class LibInputBackend : IInputBackend { private IScreenInfoProvider? _screen; private IInputRoot? _inputRoot; - private const string LibInput = nameof(Avalonia.LinuxFramebuffer) + "/" + nameof(Avalonia.LinuxFramebuffer.Input) + "/" + nameof(LibInput); + private const string LibInput = nameof(LinuxFramebuffer) + "/" + nameof(Input) + "/" + nameof(LibInput); private Action? _onInput; private readonly LibInputBackendOptions? _options; @@ -25,13 +25,11 @@ public LibInputBackend(LibInputBackendOptions options) _options = options; } - private unsafe void InputThread(object? state) + private unsafe void InputThread(IntPtr ctx, LibInputBackendOptions options) { - var options = (LibInputBackendOptions)state!; - var ctx = options.LibInputContext; var fd = libinput_get_fd(ctx); - foreach (var f in options.Events) + foreach (var f in options.Events!) libinput_path_add_device(ctx, f); while (true) { @@ -67,16 +65,15 @@ public void Initialize(IScreenInfoProvider screen, Action onI var ctx = libinput_path_create_context(); var options = new LibInputBackendOptions() { - LibInputContext = ctx, Events = _options?.Events is null ? Directory.GetFiles("/dev/input", "event*") : _options.Events, }; - new Thread(InputThread) + new Thread(() => InputThread(ctx, options)) { Name = "Input Manager Worker", IsBackground = true - }.Start(options); + }.Start(); } public void SetInputRoot(IInputRoot root) diff --git a/src/Linux/Avalonia.LinuxFramebuffer/Input/LibInput/LibInputBackendOptions.cs b/src/Linux/Avalonia.LinuxFramebuffer/Input/LibInput/LibInputBackendOptions.cs index bc04e02ccc0..6df91ad5bb6 100644 --- a/src/Linux/Avalonia.LinuxFramebuffer/Input/LibInput/LibInputBackendOptions.cs +++ b/src/Linux/Avalonia.LinuxFramebuffer/Input/LibInput/LibInputBackendOptions.cs @@ -1,4 +1,4 @@ -using System; +#nullable enable using System.Collections.Generic; namespace Avalonia.LinuxFramebuffer.Input.LibInput; @@ -8,13 +8,8 @@ namespace Avalonia.LinuxFramebuffer.Input.LibInput; /// public sealed record class LibInputBackendOptions { - /// - /// Used internally to pass libinput context to . - /// - internal IntPtr LibInputContext { get; init; } - /// /// List Events of events handler to monitoring eg: /dev/eventX. /// - public IReadOnlyList Events { get; init; } = null; + public IReadOnlyList? Events { get; init; } = null; }