From dd574146fb5f05c1c0a469a4ad4a20c46bb37d74 Mon Sep 17 00:00:00 2001 From: TSRBerry <20988865+TSRBerry@users.noreply.github.com> Date: Tue, 2 May 2023 03:29:47 +0200 Subject: [PATCH] Add hide-cursor command line argument & always hide cursor option (#4613) * Add hide-cursor command line argument * gtk: Adjust SettingsWindow for hide cursor options * ava: Adjust SettingsWindow for hide cursor options * ava: Add override check for HideCursor arg * Remove copy&paste sins * ava: Leave a little more room between the options * gtk: Fix hide cursor issues * ava: Only hide cursor if it's within the embedded window --- src/Ryujinx.Ava/AppHost.cs | 44 ++++++----- src/Ryujinx.Ava/Assets/Locales/en_US.json | 5 +- src/Ryujinx.Ava/Program.cs | 14 +++- .../UI/ViewModels/SettingsViewModel.cs | 6 +- .../UI/Views/Settings/SettingsUIView.axaml | 31 ++++++-- .../Configuration/HideCursorMode.cs | 9 +++ src/Ryujinx.Headless.SDL2/HideCursor.cs | 9 --- .../OpenGL/OpenGLWindow.cs | 4 +- src/Ryujinx.Headless.SDL2/Options.cs | 4 +- src/Ryujinx.Headless.SDL2/Program.cs | 4 +- src/Ryujinx.Headless.SDL2/SDL2MouseDriver.cs | 13 ++-- .../Vulkan/VulkanWindow.cs | 4 +- src/Ryujinx.Headless.SDL2/WindowBase.cs | 4 +- .../Configuration/ConfigurationFileFormat.cs | 6 +- .../Configuration/ConfigurationState.cs | 12 +-- .../Helper/CommandLineState.cs | 11 +++ src/Ryujinx/Program.cs | 16 +++- src/Ryujinx/Ui/RendererWidgetBase.cs | 59 +++++++++----- src/Ryujinx/Ui/Windows/SettingsWindow.cs | 32 ++++++-- src/Ryujinx/Ui/Windows/SettingsWindow.glade | 78 +++++++++++++++++-- 20 files changed, 266 insertions(+), 99 deletions(-) create mode 100644 src/Ryujinx.Common/Configuration/HideCursorMode.cs delete mode 100644 src/Ryujinx.Headless.SDL2/HideCursor.cs diff --git a/src/Ryujinx.Ava/AppHost.cs b/src/Ryujinx.Ava/AppHost.cs index 957a1c9d3..e11a954d8 100644 --- a/src/Ryujinx.Ava/AppHost.cs +++ b/src/Ryujinx.Ava/AppHost.cs @@ -157,7 +157,7 @@ namespace Ryujinx.Ava _isFirmwareTitle = true; } - ConfigurationState.Instance.HideCursorOnIdle.Event += HideCursorState_Changed; + ConfigurationState.Instance.HideCursor.Event += HideCursorState_Changed; _topLevel.PointerMoved += TopLevel_PointerMoved; @@ -468,9 +468,9 @@ namespace Ryujinx.Ava (_rendererHost.EmbeddedWindow as EmbeddedWindowOpenGL)?.MakeCurrent(null); } - private void HideCursorState_Changed(object sender, ReactiveEventArgs state) + private void HideCursorState_Changed(object sender, ReactiveEventArgs state) { - if (state.NewValue) + if (state.NewValue == HideCursorMode.OnIdle) { _lastCursorMoveTime = Stopwatch.GetTimestamp(); } @@ -965,30 +965,38 @@ namespace Ryujinx.Ava if (_viewModel.IsActive) { - if (ConfigurationState.Instance.Hid.EnableMouse) + if (_isCursorInRenderer) { - if (_isCursorInRenderer) + if (ConfigurationState.Instance.Hid.EnableMouse) { HideCursor(); } else { - ShowCursor(); + switch (ConfigurationState.Instance.HideCursor.Value) + { + case HideCursorMode.Never: + ShowCursor(); + break; + case HideCursorMode.OnIdle: + if (Stopwatch.GetTimestamp() - _lastCursorMoveTime >= CursorHideIdleTime * Stopwatch.Frequency) + { + HideCursor(); + } + else + { + ShowCursor(); + } + break; + case HideCursorMode.Always: + HideCursor(); + break; + } } } else { - if (ConfigurationState.Instance.HideCursorOnIdle) - { - if (Stopwatch.GetTimestamp() - _lastCursorMoveTime >= CursorHideIdleTime * Stopwatch.Frequency) - { - HideCursor(); - } - else - { - ShowCursor(); - } - } + ShowCursor(); } Dispatcher.UIThread.Post(() => @@ -1133,4 +1141,4 @@ namespace Ryujinx.Ava return state; } } -} +} \ No newline at end of file diff --git a/src/Ryujinx.Ava/Assets/Locales/en_US.json b/src/Ryujinx.Ava/Assets/Locales/en_US.json index 3a4bfc65e..617cad34f 100644 --- a/src/Ryujinx.Ava/Assets/Locales/en_US.json +++ b/src/Ryujinx.Ava/Assets/Locales/en_US.json @@ -80,7 +80,10 @@ "SettingsTabGeneralEnableDiscordRichPresence": "Enable Discord Rich Presence", "SettingsTabGeneralCheckUpdatesOnLaunch": "Check for Updates on Launch", "SettingsTabGeneralShowConfirmExitDialog": "Show \"Confirm Exit\" Dialog", - "SettingsTabGeneralHideCursorOnIdle": "Hide Cursor on Idle", + "SettingsTabGeneralHideCursor": "Hide Cursor:", + "SettingsTabGeneralHideCursorNever": "Never", + "SettingsTabGeneralHideCursorOnIdle": "On Idle", + "SettingsTabGeneralHideCursorAlways": "Always", "SettingsTabGeneralGameDirectories": "Game Directories", "SettingsTabGeneralAdd": "Add", "SettingsTabGeneralRemove": "Remove", diff --git a/src/Ryujinx.Ava/Program.cs b/src/Ryujinx.Ava/Program.cs index 7f35c62a4..0629e6062 100644 --- a/src/Ryujinx.Ava/Program.cs +++ b/src/Ryujinx.Ava/Program.cs @@ -183,6 +183,18 @@ namespace Ryujinx.Ava { ConfigurationState.Instance.System.EnableDockedMode.Value = CommandLineState.OverrideDockedMode.Value; } + + // Check if HideCursor was overridden. + if (CommandLineState.OverrideHideCursor is not null) + { + ConfigurationState.Instance.HideCursor.Value = CommandLineState.OverrideHideCursor!.ToLower() switch + { + "never" => HideCursorMode.Never, + "onidle" => HideCursorMode.OnIdle, + "always" => HideCursorMode.Always, + _ => ConfigurationState.Instance.HideCursor.Value + }; + } } private static void PrintSystemInfo() @@ -226,4 +238,4 @@ namespace Ryujinx.Ava Logger.Shutdown(); } } -} +} \ No newline at end of file diff --git a/src/Ryujinx.Ava/UI/ViewModels/SettingsViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/SettingsViewModel.cs index 232c9d436..08612117a 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/SettingsViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/SettingsViewModel.cs @@ -132,7 +132,7 @@ namespace Ryujinx.Ava.UI.ViewModels public bool EnableDiscordIntegration { get; set; } public bool CheckUpdatesOnStart { get; set; } public bool ShowConfirmExit { get; set; } - public bool HideCursorOnIdle { get; set; } + public int HideCursor { get; set; } public bool EnableDockedMode { get; set; } public bool EnableKeyboard { get; set; } public bool EnableMouse { get; set; } @@ -375,7 +375,7 @@ namespace Ryujinx.Ava.UI.ViewModels EnableDiscordIntegration = config.EnableDiscordIntegration; CheckUpdatesOnStart = config.CheckUpdatesOnStart; ShowConfirmExit = config.ShowConfirmExit; - HideCursorOnIdle = config.HideCursorOnIdle; + HideCursor = (int)config.HideCursor.Value; GameDirectories.Clear(); GameDirectories.AddRange(config.Ui.GameDirs.Value); @@ -458,7 +458,7 @@ namespace Ryujinx.Ava.UI.ViewModels config.EnableDiscordIntegration.Value = EnableDiscordIntegration; config.CheckUpdatesOnStart.Value = CheckUpdatesOnStart; config.ShowConfirmExit.Value = ShowConfirmExit; - config.HideCursorOnIdle.Value = HideCursorOnIdle; + config.HideCursor.Value = (HideCursorMode)HideCursor; if (_directoryChanged) { diff --git a/src/Ryujinx.Ava/UI/Views/Settings/SettingsUIView.axaml b/src/Ryujinx.Ava/UI/Views/Settings/SettingsUIView.axaml index 61b6c4335..acc5e2b70 100644 --- a/src/Ryujinx.Ava/UI/Views/Settings/SettingsUIView.axaml +++ b/src/Ryujinx.Ava/UI/Views/Settings/SettingsUIView.axaml @@ -1,4 +1,4 @@ - - - - - + + + + + + + + + + + + + + @@ -105,7 +120,7 @@ - @@ -122,7 +137,7 @@ Grid.Column="1" Margin="0,10,0,0" Text="{Binding CustomThemePath}" /> -