From 46b2da24352cab7e42730ac820f1e1d8587c94d4 Mon Sep 17 00:00:00 2001 From: MaxLastBreath Date: Tue, 19 Aug 2025 18:46:20 -0500 Subject: [PATCH] Fix Avalonia Native MouseWheel-Support * Rename timer interval constant * Also cut the delay after which scrolling is considered ended in half Co-authored-by: GreemDev --- src/Ryujinx/Input/AvaloniaMouseDriver.cs | 25 ++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/Ryujinx/Input/AvaloniaMouseDriver.cs b/src/Ryujinx/Input/AvaloniaMouseDriver.cs index e71bbf64a..564307bbd 100644 --- a/src/Ryujinx/Input/AvaloniaMouseDriver.cs +++ b/src/Ryujinx/Input/AvaloniaMouseDriver.cs @@ -1,6 +1,7 @@ using Avalonia; using Avalonia.Controls; using Avalonia.Input; +using Avalonia.Threading; using Ryujinx.Input; using System; using System.Numerics; @@ -11,10 +12,13 @@ namespace Ryujinx.Ava.Input { internal class AvaloniaMouseDriver : IGamepadDriver { + private const int ScrollTimerIntervalMilliseconds = 50; + private Control _widget; private bool _isDisposed; private Size _size; private readonly TopLevel _window; + private DispatcherTimer _scrollStopTimer; public bool[] PressedButtons { get; } public Vector2 CurrentPosition { get; private set; } @@ -38,6 +42,11 @@ namespace Ryujinx.Ava.Input _window.PointerReleased += Parent_PointerReleasedEvent; _window.PointerWheelChanged += Parent_PointerWheelChanged; + _scrollStopTimer = new DispatcherTimer + { + Interval = TimeSpan.FromMilliseconds(ScrollTimerIntervalMilliseconds) + }; + PressedButtons = new bool[(int)MouseButton.Count]; _size = new Size((int)parent.Bounds.Width, (int)parent.Bounds.Height); @@ -61,10 +70,26 @@ namespace Ryujinx.Ava.Input { _size = new Size((int)rect.Width, (int)rect.Height); } + + private void HandleScrollStopped() + { + Scroll = new Vector2(0, 0); + } private void Parent_PointerWheelChanged(object o, PointerWheelEventArgs args) { Scroll = new Vector2((float)args.Delta.X, (float)args.Delta.Y); + + _scrollStopTimer.Stop(); + + _scrollStopTimer.Tick += (_, _) => + { + _scrollStopTimer.Stop(); + + HandleScrollStopped(); + + }; + _scrollStopTimer.Start(); } private void Parent_PointerReleasedEvent(object o, PointerReleasedEventArgs args)