From f514b510791606dae419070cfc8814208a12379d Mon Sep 17 00:00:00 2001 From: Premo <38495887+Dansla116@users.noreply.github.com> Date: Thu, 25 Apr 2024 21:21:25 -0400 Subject: [PATCH] Added option to set idle time before cursor is hidden (Ryujinx#4390) In SettingsWindow.cs and SettingsWindow.glade: Replaced Always/On Idle/Never radio buttons with a dropdown (combo box). When selecting "On Idle", a "Seconds" label and numeric text box (spinner) appear. The spinner is limited 1-10. In ConfigurationFileFormat.cs and ConfigurationState.cs, and SettingsViewModel.cs: Load the saved value, or default 5 seconds if no value exists. Save the custom set value to the config file. In SettingsViewModel.cs: Catch when the idle time setting is changed while a game is running, and change the value live. --- src/Ryujinx.Gtk3/UI/RendererWidgetBase.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Ryujinx.Gtk3/UI/RendererWidgetBase.cs b/src/Ryujinx.Gtk3/UI/RendererWidgetBase.cs index 0e636792d..70f474a94 100644 --- a/src/Ryujinx.Gtk3/UI/RendererWidgetBase.cs +++ b/src/Ryujinx.Gtk3/UI/RendererWidgetBase.cs @@ -70,10 +70,10 @@ namespace Ryujinx.UI private readonly CancellationTokenSource _gpuCancellationTokenSource; // Hide Cursor - const int CursorHideIdleTime = 5; // seconds private static readonly Cursor _invisibleCursor = new(Display.Default, CursorType.BlankCursor); private long _lastCursorMoveTime; private HideCursorMode _hideCursorMode; + private int _hideCursorIdleTime; private readonly InputManager _inputManager; private readonly IKeyboard _keyboardInterface; private readonly GraphicsDebugLevel _glLogLevel; @@ -116,9 +116,12 @@ namespace Ryujinx.UI _gpuCancellationTokenSource = new CancellationTokenSource(); _hideCursorMode = ConfigurationState.Instance.HideCursor; + _hideCursorIdleTime = ConfigurationState.Instance.HideCursorIdleTime; + _lastCursorMoveTime = Stopwatch.GetTimestamp(); ConfigurationState.Instance.HideCursor.Event += HideCursorStateChanged; + ConfigurationState.Instance.HideCursorIdleTime.Event += HideCursorIdleTimeStateChanged; ConfigurationState.Instance.Graphics.AntiAliasing.Event += UpdateAnriAliasing; ConfigurationState.Instance.Graphics.ScalingFilter.Event += UpdateScalingFilter; ConfigurationState.Instance.Graphics.ScalingFilterLevel.Event += UpdateScalingFilterLevel; @@ -170,9 +173,18 @@ namespace Ryujinx.UI }); } + private void HideCursorIdleTimeStateChanged(object sender, ReactiveEventArgs state) + { + Application.Invoke(delegate + { + _hideCursorIdleTime = state.NewValue; + }); + } + private void Renderer_Destroyed(object sender, EventArgs e) { ConfigurationState.Instance.HideCursor.Event -= HideCursorStateChanged; + ConfigurationState.Instance.HideCursorIdleTime.Event -= HideCursorIdleTimeStateChanged; ConfigurationState.Instance.Graphics.AntiAliasing.Event -= UpdateAnriAliasing; ConfigurationState.Instance.Graphics.ScalingFilter.Event -= UpdateScalingFilter; ConfigurationState.Instance.Graphics.ScalingFilterLevel.Event -= UpdateScalingFilterLevel; @@ -335,7 +347,7 @@ namespace Ryujinx.UI { case HideCursorMode.OnIdle: long cursorMoveDelta = Stopwatch.GetTimestamp() - _lastCursorMoveTime; - Window.Cursor = (cursorMoveDelta >= CursorHideIdleTime * Stopwatch.Frequency) ? _invisibleCursor : null; + Window.Cursor = (cursorMoveDelta >= _hideCursorIdleTime * Stopwatch.Frequency) ? _invisibleCursor : null; break; case HideCursorMode.Always: Window.Cursor = _invisibleCursor;