From 3df6b7c0f578ee1ca412d229a8fba140ffbea1fc 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 (ryubing/ryujinx!116) See merge request ryubing/ryujinx!116 --- src/Ryujinx/Input/AvaloniaMouseDriver.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Ryujinx/Input/AvaloniaMouseDriver.cs b/src/Ryujinx/Input/AvaloniaMouseDriver.cs index be1441101..4b4b86ede 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.Collections.Generic; @@ -16,6 +17,8 @@ namespace Ryujinx.Ava.Input private bool _isDisposed; private Size _size; private readonly TopLevel _window; + private DispatcherTimer _scrollStopTimer; + private const int _dispatchTimerMS = 100; public bool[] PressedButtons { get; } public Vector2 CurrentPosition { get; private set; } @@ -39,6 +42,11 @@ namespace Ryujinx.Ava.Input _window.PointerReleased += Parent_PointerReleasedEvent; _window.PointerWheelChanged += Parent_PointerWheelChanged; + _scrollStopTimer = new DispatcherTimer + { + Interval = TimeSpan.FromMilliseconds(_dispatchTimerMS) + }; + PressedButtons = new bool[(int)MouseButton.Count]; _size = new Size((int)parent.Bounds.Width, (int)parent.Bounds.Height); @@ -62,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)