Volume Hotkeys (#3500)

* Initial GTK implementation

* Less messy and Avalonia imp

* Move clamping to HLE and streamline imps

* Make viewmodel update consistent

* Fix rebase and add an english locale.

Co-authored-by: Mary-nyan <mary@mary.zone>
This commit is contained in:
MutantAura 2022-10-02 10:38:37 +01:00 committed by GitHub
parent 45ce540b9b
commit 358a781639
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 98 additions and 5 deletions

View file

@ -35,6 +35,7 @@ namespace Ryujinx.Ui
private const int SwitchPanelHeight = 720;
private const int TargetFps = 60;
private const float MaxResolutionScale = 4.0f; // Max resolution hotkeys can scale to before wrapping.
private const float VolumeDelta = 0.05f;
public ManualResetEvent WaitEvent { get; set; }
public NpadManager NpadManager { get; }
@ -57,6 +58,7 @@ namespace Ryujinx.Ui
private readonly long _ticksPerFrame;
private long _ticks = 0;
private float _newVolume;
private readonly Stopwatch _chrono;
@ -643,6 +645,20 @@ namespace Ryujinx.Ui
(MaxResolutionScale + GraphicsConfig.ResScale - 2) % MaxResolutionScale + 1;
}
if (currentHotkeyState.HasFlag(KeyboardHotkeyState.VolumeUp) &&
!_prevHotkeyState.HasFlag(KeyboardHotkeyState.VolumeUp))
{
_newVolume = MathF.Round((Device.GetVolume() + VolumeDelta), 2);
Device.SetVolume(_newVolume);
}
if (currentHotkeyState.HasFlag(KeyboardHotkeyState.VolumeDown) &&
!_prevHotkeyState.HasFlag(KeyboardHotkeyState.VolumeDown))
{
_newVolume = MathF.Round((Device.GetVolume() - VolumeDelta), 2);
Device.SetVolume(_newVolume);
}
_prevHotkeyState = currentHotkeyState;
}
@ -675,7 +691,9 @@ namespace Ryujinx.Ui
Pause = 1 << 3,
ToggleMute = 1 << 4,
ResScaleUp = 1 << 5,
ResScaleDown = 1 << 6
ResScaleDown = 1 << 6,
VolumeUp = 1 << 7,
VolumeDown = 1 << 8
}
private KeyboardHotkeyState GetHotkeyState()
@ -717,6 +735,16 @@ namespace Ryujinx.Ui
state |= KeyboardHotkeyState.ResScaleDown;
}
if (_keyboardInterface.IsPressed((Key)ConfigurationState.Instance.Hid.Hotkeys.Value.VolumeUp))
{
state |= KeyboardHotkeyState.VolumeUp;
}
if (_keyboardInterface.IsPressed((Key)ConfigurationState.Instance.Hid.Hotkeys.Value.VolumeDown))
{
state |= KeyboardHotkeyState.VolumeDown;
}
return state;
}
}