Skip to content

Commit

Permalink
Add hide-cursor command line argument & always hide cursor option (#4…
Browse files Browse the repository at this point in the history
…613)

* 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
  • Loading branch information
TSRBerry authored May 2, 2023
1 parent 2c94ac4 commit dd57414
Show file tree
Hide file tree
Showing 20 changed files with 266 additions and 99 deletions.
44 changes: 26 additions & 18 deletions src/Ryujinx.Ava/AppHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public AppHost(
_isFirmwareTitle = true;
}

ConfigurationState.Instance.HideCursorOnIdle.Event += HideCursorState_Changed;
ConfigurationState.Instance.HideCursor.Event += HideCursorState_Changed;

_topLevel.PointerMoved += TopLevel_PointerMoved;

Expand Down Expand Up @@ -468,9 +468,9 @@ public void DisposeGpu()
(_rendererHost.EmbeddedWindow as EmbeddedWindowOpenGL)?.MakeCurrent(null);
}

private void HideCursorState_Changed(object sender, ReactiveEventArgs<bool> state)
private void HideCursorState_Changed(object sender, ReactiveEventArgs<HideCursorMode> state)
{
if (state.NewValue)
if (state.NewValue == HideCursorMode.OnIdle)
{
_lastCursorMoveTime = Stopwatch.GetTimestamp();
}
Expand Down Expand Up @@ -965,30 +965,38 @@ private bool UpdateFrame()

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(() =>
Expand Down Expand Up @@ -1133,4 +1141,4 @@ private KeyboardHotkeyState GetHotkeyState()
return state;
}
}
}
}
5 changes: 4 additions & 1 deletion src/Ryujinx.Ava/Assets/Locales/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 13 additions & 1 deletion src/Ryujinx.Ava/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,18 @@ public static void ReloadConfig()
{
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()
Expand Down Expand Up @@ -226,4 +238,4 @@ public static void Exit()
Logger.Shutdown();
}
}
}
}
6 changes: 3 additions & 3 deletions src/Ryujinx.Ava/UI/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public bool DirectoryChanged
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; }
Expand Down Expand Up @@ -375,7 +375,7 @@ public void LoadCurrentConfiguration()
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);
Expand Down Expand Up @@ -458,7 +458,7 @@ public void SaveSettings()
config.EnableDiscordIntegration.Value = EnableDiscordIntegration;
config.CheckUpdatesOnStart.Value = CheckUpdatesOnStart;
config.ShowConfirmExit.Value = ShowConfirmExit;
config.HideCursorOnIdle.Value = HideCursorOnIdle;
config.HideCursor.Value = (HideCursorMode)HideCursor;

if (_directoryChanged)
{
Expand Down
31 changes: 23 additions & 8 deletions src/Ryujinx.Ava/UI/Views/Settings/SettingsUIView.axaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<UserControl
<UserControl
x:Class="Ryujinx.Ava.UI.Views.Settings.SettingsUIView"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Expand All @@ -12,7 +12,7 @@
<Design.DataContext>
<viewModels:SettingsViewModel />
</Design.DataContext>
<ScrollViewer
<ScrollViewer
Name="UiPage"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Expand All @@ -37,9 +37,24 @@
<CheckBox IsChecked="{Binding ShowConfirmExit}">
<TextBlock Text="{locale:Locale SettingsTabGeneralShowConfirmExitDialog}" />
</CheckBox>
<CheckBox IsChecked="{Binding HideCursorOnIdle}">
<TextBlock Text="{locale:Locale SettingsTabGeneralHideCursorOnIdle}" />
</CheckBox>
<StackPanel Margin="0, 15, 0, 10" Orientation="Horizontal">
<TextBlock VerticalAlignment="Center"
Text="{locale:Locale SettingsTabGeneralHideCursor}"
Width="150" />
<ComboBox SelectedIndex="{Binding HideCursor}"
HorizontalContentAlignment="Left"
MinWidth="100">
<ComboBoxItem>
<TextBlock Text="{locale:Locale SettingsTabGeneralHideCursorNever}" />
</ComboBoxItem>
<ComboBoxItem>
<TextBlock Text="{locale:Locale SettingsTabGeneralHideCursorOnIdle}" />
</ComboBoxItem>
<ComboBoxItem>
<TextBlock Text="{locale:Locale SettingsTabGeneralHideCursorAlways}" />
</ComboBoxItem>
</ComboBox>
</StackPanel>
</StackPanel>
<Separator Height="1" />
<TextBlock Classes="h1" Text="{locale:Locale SettingsTabGeneralGameDirectories}" />
Expand Down Expand Up @@ -105,7 +120,7 @@
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<CheckBox
<CheckBox
IsChecked="{Binding EnableCustomTheme}"
ToolTip.Tip="{locale:Locale CustomThemeCheckTooltip}">
<TextBlock Text="{locale:Locale SettingsTabGeneralThemeEnableCustomTheme}" />
Expand All @@ -122,7 +137,7 @@
Grid.Column="1"
Margin="0,10,0,0"
Text="{Binding CustomThemePath}" />
<Button
<Button
Grid.Row="1"
Grid.Column="2"
Margin="10,10,0,0"
Expand Down Expand Up @@ -153,4 +168,4 @@
</StackPanel>
</Border>
</ScrollViewer>
</UserControl>
</UserControl>
9 changes: 9 additions & 0 deletions src/Ryujinx.Common/Configuration/HideCursorMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Ryujinx.Common.Configuration
{
public enum HideCursorMode
{
Never,
OnIdle,
Always
}
}
9 changes: 0 additions & 9 deletions src/Ryujinx.Headless.SDL2/HideCursor.cs

This file was deleted.

4 changes: 2 additions & 2 deletions src/Ryujinx.Headless.SDL2/OpenGL/OpenGLWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ public OpenGLWindow(
GraphicsDebugLevel glLogLevel,
AspectRatio aspectRatio,
bool enableMouse,
HideCursor hideCursor)
: base(inputManager, glLogLevel, aspectRatio, enableMouse, hideCursor)
HideCursorMode hideCursorMode)
: base(inputManager, glLogLevel, aspectRatio, enableMouse, hideCursorMode)
{
_glLogLevel = glLogLevel;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Ryujinx.Headless.SDL2/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public class Options
[Option("enable-mouse", Required = false, Default = false, HelpText = "Enable or disable mouse support.")]
public bool EnableMouse { get; set; }

[Option("hide-cursor", Required = false, Default = HideCursor.OnIdle, HelpText = "Change when the cursor gets hidden.")]
public HideCursor HideCursor { get; set; }
[Option("hide-cursor", Required = false, Default = HideCursorMode.OnIdle, HelpText = "Change when the cursor gets hidden.")]
public HideCursorMode HideCursorMode { get; set; }

[Option("list-input-profiles", Required = false, HelpText = "List inputs profiles.")]
public bool ListInputProfiles { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions src/Ryujinx.Headless.SDL2/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,8 @@ private static void ProgressHandler<T>(T state, int current, int total) where T
private static WindowBase CreateWindow(Options options)
{
return options.GraphicsBackend == GraphicsBackend.Vulkan
? new VulkanWindow(_inputManager, options.LoggingGraphicsDebugLevel, options.AspectRatio, options.EnableMouse, options.HideCursor)
: new OpenGLWindow(_inputManager, options.LoggingGraphicsDebugLevel, options.AspectRatio, options.EnableMouse, options.HideCursor);
? new VulkanWindow(_inputManager, options.LoggingGraphicsDebugLevel, options.AspectRatio, options.EnableMouse, options.HideCursorMode)
: new OpenGLWindow(_inputManager, options.LoggingGraphicsDebugLevel, options.AspectRatio, options.EnableMouse, options.HideCursorMode);
}

private static IRenderer CreateRenderer(Options options, WindowBase window)
Expand Down
13 changes: 7 additions & 6 deletions src/Ryujinx.Headless.SDL2/SDL2MouseDriver.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Ryujinx.Input;
using Ryujinx.Common.Configuration;
using Ryujinx.Input;
using System;
using System.Diagnostics;
using System.Drawing;
Expand All @@ -13,7 +14,7 @@ class SDL2MouseDriver : IGamepadDriver
private const int CursorHideIdleTime = 5; // seconds

private bool _isDisposed;
private HideCursor _hideCursor;
private HideCursorMode _hideCursorMode;
private bool _isHidden;
private long _lastCursorMoveTime;

Expand All @@ -23,12 +24,12 @@ class SDL2MouseDriver : IGamepadDriver
public Vector2 Scroll { get; private set; }
public Size _clientSize;

public SDL2MouseDriver(HideCursor hideCursor)
public SDL2MouseDriver(HideCursorMode hideCursorMode)
{
PressedButtons = new bool[(int)MouseButton.Count];
_hideCursor = hideCursor;
_hideCursorMode = hideCursorMode;

if (_hideCursor == HideCursor.Always)
if (_hideCursorMode == HideCursorMode.Always)
{
SDL_ShowCursor(SDL_DISABLE);
_isHidden = true;
Expand Down Expand Up @@ -59,7 +60,7 @@ public void UpdatePosition()

private void CheckIdle()
{
if (_hideCursor != HideCursor.OnIdle)
if (_hideCursorMode != HideCursorMode.OnIdle)
{
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Ryujinx.Headless.SDL2/Vulkan/VulkanWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public VulkanWindow(
GraphicsDebugLevel glLogLevel,
AspectRatio aspectRatio,
bool enableMouse,
HideCursor hideCursor)
: base(inputManager, glLogLevel, aspectRatio, enableMouse, hideCursor)
HideCursorMode hideCursorMode)
: base(inputManager, glLogLevel, aspectRatio, enableMouse, hideCursorMode)
{
_glLogLevel = glLogLevel;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Ryujinx.Headless.SDL2/WindowBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ public WindowBase(
GraphicsDebugLevel glLogLevel,
AspectRatio aspectRatio,
bool enableMouse,
HideCursor hideCursor)
HideCursorMode hideCursorMode)
{
MouseDriver = new SDL2MouseDriver(hideCursor);
MouseDriver = new SDL2MouseDriver(hideCursorMode);
_inputManager = inputManager;
_inputManager.SetMouseDriver(MouseDriver);
NpadManager = _inputManager.CreateNpadManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ public class ConfigurationFileFormat
public bool ShowConfirmExit { get; set; }

/// <summary>
/// Hide Cursor on Idle
/// Whether to hide cursor on idle, always or never
/// </summary>
public bool HideCursorOnIdle { get; set; }
public HideCursorMode HideCursor { get; set; }

/// <summary>
/// Enables or disables Vertical Sync
Expand Down Expand Up @@ -395,4 +395,4 @@ public void SaveConfig(string path)
JsonHelper.SerializeToFile(path, this, ConfigurationFileFormatSettings.SerializerContext.ConfigurationFileFormat);
}
}
}
}
Loading

0 comments on commit dd57414

Please sign in to comment.