From bc5bb4459e74ca03aba6f779a98f2788a1c722fe Mon Sep 17 00:00:00 2001 From: Emmanuel Hansen Date: Fri, 8 Jul 2022 12:53:48 +0000 Subject: [PATCH] Fix deadlock in mouse input on Avalonia (#3444) * fix deadlock in mouse input * apply @AcK77 changes --- Ryujinx.Ava/Input/AvaloniaMouseDriver.cs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Ryujinx.Ava/Input/AvaloniaMouseDriver.cs b/Ryujinx.Ava/Input/AvaloniaMouseDriver.cs index d00ea667..51fa0130 100644 --- a/Ryujinx.Ava/Input/AvaloniaMouseDriver.cs +++ b/Ryujinx.Ava/Input/AvaloniaMouseDriver.cs @@ -1,3 +1,4 @@ +using Avalonia; using Avalonia.Controls; using Avalonia.Input; using Avalonia.Threading; @@ -13,6 +14,7 @@ namespace Ryujinx.Ava.Input { private Control _widget; private bool _isDisposed; + private Size _size; public bool[] PressedButtons { get; } @@ -29,6 +31,14 @@ namespace Ryujinx.Ava.Input _widget.PointerWheelChanged += Parent_ScrollEvent; PressedButtons = new bool[(int)MouseButton.Count]; + + _size = new Size((int)parent.Bounds.Width, (int)parent.Bounds.Height); + parent.GetObservable(Control.BoundsProperty).Subscribe(Resized); + } + + private void Resized(Rect rect) + { + _size = new Size((int)rect.Width, (int)rect.Height); } private void Parent_ScrollEvent(object o, PointerWheelEventArgs args) @@ -78,14 +88,7 @@ namespace Ryujinx.Ava.Input public Size GetClientSize() { - Size size = new(); - - Dispatcher.UIThread.InvokeAsync(() => - { - size = new Size((int)_widget.Bounds.Width, (int)_widget.Bounds.Height); - }).Wait(); - - return size; + return _size; } public string DriverName => "Avalonia";