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.
This commit is contained in:
Premo 2024-04-25 21:21:25 -04:00 committed by GitHub
parent f90cb93def
commit f514b51079
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -70,10 +70,10 @@ namespace Ryujinx.UI
private readonly CancellationTokenSource _gpuCancellationTokenSource; private readonly CancellationTokenSource _gpuCancellationTokenSource;
// Hide Cursor // Hide Cursor
const int CursorHideIdleTime = 5; // seconds
private static readonly Cursor _invisibleCursor = new(Display.Default, CursorType.BlankCursor); private static readonly Cursor _invisibleCursor = new(Display.Default, CursorType.BlankCursor);
private long _lastCursorMoveTime; private long _lastCursorMoveTime;
private HideCursorMode _hideCursorMode; private HideCursorMode _hideCursorMode;
private int _hideCursorIdleTime;
private readonly InputManager _inputManager; private readonly InputManager _inputManager;
private readonly IKeyboard _keyboardInterface; private readonly IKeyboard _keyboardInterface;
private readonly GraphicsDebugLevel _glLogLevel; private readonly GraphicsDebugLevel _glLogLevel;
@ -116,9 +116,12 @@ namespace Ryujinx.UI
_gpuCancellationTokenSource = new CancellationTokenSource(); _gpuCancellationTokenSource = new CancellationTokenSource();
_hideCursorMode = ConfigurationState.Instance.HideCursor; _hideCursorMode = ConfigurationState.Instance.HideCursor;
_hideCursorIdleTime = ConfigurationState.Instance.HideCursorIdleTime;
_lastCursorMoveTime = Stopwatch.GetTimestamp(); _lastCursorMoveTime = Stopwatch.GetTimestamp();
ConfigurationState.Instance.HideCursor.Event += HideCursorStateChanged; ConfigurationState.Instance.HideCursor.Event += HideCursorStateChanged;
ConfigurationState.Instance.HideCursorIdleTime.Event += HideCursorIdleTimeStateChanged;
ConfigurationState.Instance.Graphics.AntiAliasing.Event += UpdateAnriAliasing; ConfigurationState.Instance.Graphics.AntiAliasing.Event += UpdateAnriAliasing;
ConfigurationState.Instance.Graphics.ScalingFilter.Event += UpdateScalingFilter; ConfigurationState.Instance.Graphics.ScalingFilter.Event += UpdateScalingFilter;
ConfigurationState.Instance.Graphics.ScalingFilterLevel.Event += UpdateScalingFilterLevel; ConfigurationState.Instance.Graphics.ScalingFilterLevel.Event += UpdateScalingFilterLevel;
@ -170,9 +173,18 @@ namespace Ryujinx.UI
}); });
} }
private void HideCursorIdleTimeStateChanged(object sender, ReactiveEventArgs<int> state)
{
Application.Invoke(delegate
{
_hideCursorIdleTime = state.NewValue;
});
}
private void Renderer_Destroyed(object sender, EventArgs e) private void Renderer_Destroyed(object sender, EventArgs e)
{ {
ConfigurationState.Instance.HideCursor.Event -= HideCursorStateChanged; ConfigurationState.Instance.HideCursor.Event -= HideCursorStateChanged;
ConfigurationState.Instance.HideCursorIdleTime.Event -= HideCursorIdleTimeStateChanged;
ConfigurationState.Instance.Graphics.AntiAliasing.Event -= UpdateAnriAliasing; ConfigurationState.Instance.Graphics.AntiAliasing.Event -= UpdateAnriAliasing;
ConfigurationState.Instance.Graphics.ScalingFilter.Event -= UpdateScalingFilter; ConfigurationState.Instance.Graphics.ScalingFilter.Event -= UpdateScalingFilter;
ConfigurationState.Instance.Graphics.ScalingFilterLevel.Event -= UpdateScalingFilterLevel; ConfigurationState.Instance.Graphics.ScalingFilterLevel.Event -= UpdateScalingFilterLevel;
@ -335,7 +347,7 @@ namespace Ryujinx.UI
{ {
case HideCursorMode.OnIdle: case HideCursorMode.OnIdle:
long cursorMoveDelta = Stopwatch.GetTimestamp() - _lastCursorMoveTime; long cursorMoveDelta = Stopwatch.GetTimestamp() - _lastCursorMoveTime;
Window.Cursor = (cursorMoveDelta >= CursorHideIdleTime * Stopwatch.Frequency) ? _invisibleCursor : null; Window.Cursor = (cursorMoveDelta >= _hideCursorIdleTime * Stopwatch.Frequency) ? _invisibleCursor : null;
break; break;
case HideCursorMode.Always: case HideCursorMode.Always:
Window.Cursor = _invisibleCursor; Window.Cursor = _invisibleCursor;