From 443dd92464c1f3526e43359855511a82347a8ef6 Mon Sep 17 00:00:00 2001 From: ProfOzpin Date: Thu, 7 Mar 2024 14:24:10 +0400 Subject: [PATCH] Modified UI and ConfigurationState to add a changeable idle timeout for the cursor called CursorHideIdleTime. (What the hardcoded variable was called beforehand) --- src/Ryujinx.Gtk3/UI/Windows/SettingsWindow.cs | 4 ++++ .../Configuration/ConfigurationFileFormat.cs | 7 ++++++- .../Configuration/ConfigurationState.cs | 20 ++++++++++++++++++- src/Ryujinx/AppHost.cs | 3 +-- src/Ryujinx/Assets/Locales/en_US.json | 2 ++ .../UI/ViewModels/SettingsViewModel.cs | 3 +++ .../UI/Views/Settings/SettingsUIView.axaml | 15 ++++++++++++++ 7 files changed, 50 insertions(+), 4 deletions(-) diff --git a/src/Ryujinx.Gtk3/UI/Windows/SettingsWindow.cs b/src/Ryujinx.Gtk3/UI/Windows/SettingsWindow.cs index dc467c0f2..bef16049e 100644 --- a/src/Ryujinx.Gtk3/UI/Windows/SettingsWindow.cs +++ b/src/Ryujinx.Gtk3/UI/Windows/SettingsWindow.cs @@ -56,6 +56,7 @@ namespace Ryujinx.UI.Windows [GUI] RadioButton _hideCursorNever; [GUI] RadioButton _hideCursorOnIdle; [GUI] RadioButton _hideCursorAlways; + [GUI] Entry _cursorHideIdleTime; [GUI] CheckButton _vSyncToggle; [GUI] CheckButton _shaderCacheToggle; [GUI] CheckButton _textureRecompressionToggle; @@ -232,6 +233,7 @@ namespace Ryujinx.UI.Windows switch (ConfigurationState.Instance.HideCursor.Value) { + case HideCursorMode.Never: _hideCursorNever.Click(); break; @@ -241,6 +243,7 @@ namespace Ryujinx.UI.Windows case HideCursorMode.Always: _hideCursorAlways.Click(); break; + } if (ConfigurationState.Instance.Graphics.EnableVsync) @@ -640,6 +643,7 @@ namespace Ryujinx.UI.Windows ConfigurationState.Instance.System.IgnoreMissingServices.Value = _ignoreToggle.Active; ConfigurationState.Instance.Hid.EnableKeyboard.Value = _directKeyboardAccess.Active; ConfigurationState.Instance.Hid.EnableMouse.Value = _directMouseAccess.Active; + ConfigurationState.Instance.CursorHideIdleTime.Value = int.Parse(_cursorHideIdleTime.Text); ConfigurationState.Instance.UI.EnableCustomTheme.Value = _custThemeToggle.Active; ConfigurationState.Instance.System.Language.Value = Enum.Parse(_systemLanguageSelect.ActiveId); ConfigurationState.Instance.System.Region.Value = Enum.Parse(_systemRegionSelect.ActiveId); diff --git a/src/Ryujinx.UI.Common/Configuration/ConfigurationFileFormat.cs b/src/Ryujinx.UI.Common/Configuration/ConfigurationFileFormat.cs index 0f6c21ef2..1ee1b7661 100644 --- a/src/Ryujinx.UI.Common/Configuration/ConfigurationFileFormat.cs +++ b/src/Ryujinx.UI.Common/Configuration/ConfigurationFileFormat.cs @@ -15,7 +15,7 @@ namespace Ryujinx.UI.Common.Configuration /// /// The current version of the file format /// - public const int CurrentVersion = 49; + public const int CurrentVersion = 50; /// /// Version of the configuration file format @@ -167,6 +167,11 @@ namespace Ryujinx.UI.Common.Configuration /// public HideCursorMode HideCursor { get; set; } + /// + /// Amount of seconds needed by the mouse to be spent idle for cursor to hide. + /// + public int CursorHideIdleTime { get; set; } + /// /// Enables or disables Vertical Sync /// diff --git a/src/Ryujinx.UI.Common/Configuration/ConfigurationState.cs b/src/Ryujinx.UI.Common/Configuration/ConfigurationState.cs index b7f36087c..182f038a9 100644 --- a/src/Ryujinx.UI.Common/Configuration/ConfigurationState.cs +++ b/src/Ryujinx.UI.Common/Configuration/ConfigurationState.cs @@ -631,6 +631,11 @@ namespace Ryujinx.UI.Common.Configuration /// public ReactiveObject HideCursor { get; private set; } + /// + /// Amount of seconds needed by the mouse to be spent idle to hide the cursor. + /// + public ReactiveObject CursorHideIdleTime {get; private set; } + private ConfigurationState() { UI = new UISection(); @@ -643,6 +648,7 @@ namespace Ryujinx.UI.Common.Configuration CheckUpdatesOnStart = new ReactiveObject(); ShowConfirmExit = new ReactiveObject(); HideCursor = new ReactiveObject(); + CursorHideIdleTime = new ReactiveObject(); } public ConfigurationFileFormat ToFileFormat() @@ -679,6 +685,7 @@ namespace Ryujinx.UI.Common.Configuration CheckUpdatesOnStart = CheckUpdatesOnStart, ShowConfirmExit = ShowConfirmExit, HideCursor = HideCursor, + CursorHideIdleTime = CursorHideIdleTime, EnableVsync = Graphics.EnableVsync, EnableShaderCache = Graphics.EnableShaderCache, EnableTextureRecompression = Graphics.EnableTextureRecompression, @@ -843,6 +850,7 @@ namespace Ryujinx.UI.Common.Configuration UI.WindowStartup.WindowMaximized.Value = false; Hid.EnableKeyboard.Value = false; Hid.EnableMouse.Value = false; + CursorHideIdleTime.Value = 5; Hid.Hotkeys.Value = new KeyboardHotkeys { ToggleVsync = Key.F1, @@ -1442,6 +1450,15 @@ namespace Ryujinx.UI.Common.Configuration configurationFileUpdated = true; } + if(configurationFileFormat.Version < 50) + { + Ryujinx.Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 50."); + + configurationFileFormat.CursorHideIdleTime = 5; + + configurationFileUpdated = true; + } + Logger.EnableFileLog.Value = configurationFileFormat.EnableFileLog; Graphics.ResScale.Value = configurationFileFormat.ResScale; Graphics.ResScaleCustom.Value = configurationFileFormat.ResScaleCustom; @@ -1473,6 +1490,7 @@ namespace Ryujinx.UI.Common.Configuration CheckUpdatesOnStart.Value = configurationFileFormat.CheckUpdatesOnStart; ShowConfirmExit.Value = configurationFileFormat.ShowConfirmExit; HideCursor.Value = configurationFileFormat.HideCursor; + CursorHideIdleTime.Value = configurationFileFormat.CursorHideIdleTime; Graphics.EnableVsync.Value = configurationFileFormat.EnableVsync; Graphics.EnableShaderCache.Value = configurationFileFormat.EnableShaderCache; Graphics.EnableTextureRecompression.Value = configurationFileFormat.EnableTextureRecompression; @@ -1527,7 +1545,7 @@ namespace Ryujinx.UI.Common.Configuration Hid.EnableMouse.Value = configurationFileFormat.EnableMouse; Hid.Hotkeys.Value = configurationFileFormat.Hotkeys; Hid.InputConfig.Value = configurationFileFormat.InputConfig; - + if (Hid.InputConfig.Value == null) { Hid.InputConfig.Value = new List(); diff --git a/src/Ryujinx/AppHost.cs b/src/Ryujinx/AppHost.cs index 04cec9579..0ee74b700 100644 --- a/src/Ryujinx/AppHost.cs +++ b/src/Ryujinx/AppHost.cs @@ -65,7 +65,6 @@ namespace Ryujinx.Ava { internal class AppHost { - private const int CursorHideIdleTime = 5; // Hide Cursor seconds. private const float MaxResolutionScale = 4.0f; // Max resolution hotkeys can scale to before wrapping. private const int TargetFps = 60; private const float VolumeDelta = 0.05f; @@ -1029,7 +1028,7 @@ namespace Ryujinx.Ava ShowCursor(); break; case HideCursorMode.OnIdle: - if (Stopwatch.GetTimestamp() - _lastCursorMoveTime >= CursorHideIdleTime * Stopwatch.Frequency) + if (Stopwatch.GetTimestamp() - _lastCursorMoveTime >= ConfigurationState.Instance.CursorHideIdleTime.Value * Stopwatch.Frequency) { HideCursor(); } diff --git a/src/Ryujinx/Assets/Locales/en_US.json b/src/Ryujinx/Assets/Locales/en_US.json index 2febf90ec..ce38fe26b 100644 --- a/src/Ryujinx/Assets/Locales/en_US.json +++ b/src/Ryujinx/Assets/Locales/en_US.json @@ -96,6 +96,8 @@ "SettingsTabGeneralHideCursorNever": "Never", "SettingsTabGeneralHideCursorOnIdle": "On Idle", "SettingsTabGeneralHideCursorAlways": "Always", + "SettingsTabGeneralCursorHideIdleTime": "Seconds:", + "SettingsTabGeneralCursorHideIdleTimeTooltip": "Amount of seconds needed by the mouse to be spent idle to hide the cursor.", "SettingsTabGeneralGameDirectories": "Game Directories", "SettingsTabGeneralAdd": "Add", "SettingsTabGeneralRemove": "Remove", diff --git a/src/Ryujinx/UI/ViewModels/SettingsViewModel.cs b/src/Ryujinx/UI/ViewModels/SettingsViewModel.cs index bcaa08600..2ec5ab815 100644 --- a/src/Ryujinx/UI/ViewModels/SettingsViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/SettingsViewModel.cs @@ -133,6 +133,7 @@ namespace Ryujinx.Ava.UI.ViewModels public bool CheckUpdatesOnStart { get; set; } public bool ShowConfirmExit { get; set; } public int HideCursor { get; set; } + public int CursorHideIdleTime { get; set; } public bool EnableDockedMode { get; set; } public bool EnableKeyboard { get; set; } public bool EnableMouse { get; set; } @@ -406,6 +407,7 @@ namespace Ryujinx.Ava.UI.ViewModels CheckUpdatesOnStart = config.CheckUpdatesOnStart; ShowConfirmExit = config.ShowConfirmExit; HideCursor = (int)config.HideCursor.Value; + CursorHideIdleTime = config.CursorHideIdleTime.Value; GameDirectories.Clear(); GameDirectories.AddRange(config.UI.GameDirs.Value); @@ -490,6 +492,7 @@ namespace Ryujinx.Ava.UI.ViewModels config.CheckUpdatesOnStart.Value = CheckUpdatesOnStart; config.ShowConfirmExit.Value = ShowConfirmExit; config.HideCursor.Value = (HideCursorMode)HideCursor; + config.CursorHideIdleTime.Value = CursorHideIdleTime; if (_directoryChanged) { diff --git a/src/Ryujinx/UI/Views/Settings/SettingsUIView.axaml b/src/Ryujinx/UI/Views/Settings/SettingsUIView.axaml index 6504637e6..4c9d34450 100644 --- a/src/Ryujinx/UI/Views/Settings/SettingsUIView.axaml +++ b/src/Ryujinx/UI/Views/Settings/SettingsUIView.axaml @@ -4,6 +4,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:ui="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia" xmlns:locale="clr-namespace:Ryujinx.Ava.Common.Locale" xmlns:viewModels="clr-namespace:Ryujinx.Ava.UI.ViewModels" mc:Ignorable="d" @@ -53,6 +54,20 @@ + +