Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to set idle time before cursor is hidden #6720

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
16 changes: 14 additions & 2 deletions src/Ryujinx.Gtk3/UI/RendererWidgetBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ public abstract class RendererWidgetBase : DrawingArea
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;
Expand Down Expand Up @@ -116,9 +116,12 @@ public RendererWidgetBase(InputManager inputManager, GraphicsDebugLevel glLogLev
_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;
Expand Down Expand Up @@ -170,9 +173,18 @@ private void HideCursorStateChanged(object sender, ReactiveEventArgs<HideCursorM
});
}

private void HideCursorIdleTimeStateChanged(object sender, ReactiveEventArgs<int> 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;
Expand Down Expand Up @@ -335,7 +347,7 @@ private void HandleScreenState(KeyboardStateSnapshot keyboard)
{
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;
Expand Down
38 changes: 9 additions & 29 deletions src/Ryujinx.Gtk3/UI/Windows/SettingsWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public class SettingsWindow : Window
[GUI] CheckButton _discordToggle;
[GUI] CheckButton _checkUpdatesToggle;
[GUI] CheckButton _showConfirmExitToggle;
[GUI] RadioButton _hideCursorNever;
[GUI] RadioButton _hideCursorOnIdle;
[GUI] RadioButton _hideCursorAlways;
[GUI] ComboBoxText _hideCursorSelect;
[GUI] Box _hideCursorIdleTimeBox;
[GUI] Entry _hideCursorIdleTimeSpin;
[GUI] CheckButton _vSyncToggle;
[GUI] CheckButton _shaderCacheToggle;
[GUI] CheckButton _textureRecompressionToggle;
Expand Down Expand Up @@ -147,6 +147,7 @@ private SettingsWindow(MainWindow parent, Builder builder, VirtualFileSystem vir
_configureControllerH.Pressed += (sender, args) => ConfigureController_Pressed(sender, PlayerIndex.Handheld);
_systemTimeZoneEntry.FocusOutEvent += TimeZoneEntry_FocusOut;

_hideCursorSelect.Changed += (sender, args) => _hideCursorIdleTimeBox.Visible = _hideCursorSelect.ActiveId == HideCursorMode.OnIdle.ToString();
_resScaleCombo.Changed += (sender, args) => _resScaleText.Visible = _resScaleCombo.ActiveId == "-1";
_scalingFilter.Changed += (sender, args) => _scalingFilterSlider.Visible = _scalingFilter.ActiveId == "2";
_galThreading.Changed += (sender, args) =>
Expand Down Expand Up @@ -230,19 +231,6 @@ private SettingsWindow(MainWindow parent, Builder builder, VirtualFileSystem vir
_showConfirmExitToggle.Click();
}

switch (ConfigurationState.Instance.HideCursor.Value)
{
case HideCursorMode.Never:
_hideCursorNever.Click();
break;
case HideCursorMode.OnIdle:
_hideCursorOnIdle.Click();
break;
case HideCursorMode.Always:
_hideCursorAlways.Click();
break;
}

if (ConfigurationState.Instance.Graphics.EnableVsync)
{
_vSyncToggle.Click();
Expand Down Expand Up @@ -349,6 +337,7 @@ private SettingsWindow(MainWindow parent, Builder builder, VirtualFileSystem vir

_systemTimeZoneCompletion.MatchFunc = TimeZoneMatchFunc;

_hideCursorSelect.SetActiveId(ConfigurationState.Instance.HideCursor.Value.ToString());
_systemLanguageSelect.SetActiveId(ConfigurationState.Instance.System.Language.Value.ToString());
_systemRegionSelect.SetActiveId(ConfigurationState.Instance.System.Region.Value.ToString());
_galThreading.SetActiveId(ConfigurationState.Instance.Graphics.BackendThreading.Value.ToString());
Expand All @@ -366,6 +355,8 @@ private SettingsWindow(MainWindow parent, Builder builder, VirtualFileSystem vir
_multiLanSelect.SetActiveId(ConfigurationState.Instance.Multiplayer.LanInterfaceId.Value);
_multiModeSelect.SetActiveId(ConfigurationState.Instance.Multiplayer.Mode.Value.ToString());

_hideCursorIdleTimeBox.Visible = _hideCursorSelect.ActiveId == HideCursorMode.OnIdle.ToString();
_hideCursorIdleTimeSpin.Buffer.Text = ConfigurationState.Instance.HideCursorIdleTime.Value.ToString();
_custThemePath.Buffer.Text = ConfigurationState.Instance.UI.CustomThemePath;
_resScaleText.Buffer.Text = ConfigurationState.Instance.Graphics.ResScaleCustom.Value.ToString();
_scalingFilterLevel.Value = ConfigurationState.Instance.Graphics.ScalingFilterLevel.Value;
Expand Down Expand Up @@ -573,18 +564,6 @@ private void SaveSettings()
_directoryChanged = false;
}

HideCursorMode hideCursor = HideCursorMode.Never;

if (_hideCursorOnIdle.Active)
{
hideCursor = HideCursorMode.OnIdle;
}

if (_hideCursorAlways.Active)
{
hideCursor = HideCursorMode.Always;
}

if (!float.TryParse(_resScaleText.Buffer.Text, out float resScaleCustom) || resScaleCustom <= 0.0f)
{
resScaleCustom = 1.0f;
Expand Down Expand Up @@ -627,7 +606,8 @@ private void SaveSettings()
ConfigurationState.Instance.EnableDiscordIntegration.Value = _discordToggle.Active;
ConfigurationState.Instance.CheckUpdatesOnStart.Value = _checkUpdatesToggle.Active;
ConfigurationState.Instance.ShowConfirmExit.Value = _showConfirmExitToggle.Active;
ConfigurationState.Instance.HideCursor.Value = hideCursor;
ConfigurationState.Instance.HideCursor.Value = Enum.Parse<HideCursorMode>(_hideCursorSelect.ActiveId);
ConfigurationState.Instance.HideCursorIdleTime.Value = int.Parse(_hideCursorIdleTimeSpin.Buffer.Text);
ConfigurationState.Instance.Graphics.EnableVsync.Value = _vSyncToggle.Active;
ConfigurationState.Instance.Graphics.EnableShaderCache.Value = _shaderCacheToggle.Active;
ConfigurationState.Instance.Graphics.EnableTextureRecompression.Value = _textureRecompressionToggle.Active;
Expand Down