1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-12-12 14:52:02 +00:00

am/gui: Implement Wake-up message (#1750)

* am/gui: Implement Wake-up message.

This implement the ability to send a Wake-up (Resume) message to the guest.
Sometime games needs to Sleep and Wake-up the switch to unlock some ingame features.

* Address gdkchan feedback
This commit is contained in:
Ac_K 2020-12-16 01:41:42 +01:00 committed by GitHub
parent 3332b29f01
commit 808380690c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 26 deletions

View file

@ -278,8 +278,10 @@ namespace Ryujinx.HLE.HOS
State.DockedMode = e.NewValue; State.DockedMode = e.NewValue;
PerformanceState.PerformanceMode = State.DockedMode ? PerformanceMode.Boost : PerformanceMode.Default; PerformanceState.PerformanceMode = State.DockedMode ? PerformanceMode.Boost : PerformanceMode.Default;
AppletState.EnqueueMessage(MessageInfo.OperationModeChanged); AppletState.Messages.Enqueue(MessageInfo.OperationModeChanged);
AppletState.EnqueueMessage(MessageInfo.PerformanceModeChanged); AppletState.Messages.Enqueue(MessageInfo.PerformanceModeChanged);
AppletState.MessageEvent.ReadableEvent.Signal();
SignalDisplayResolutionChange(); SignalDisplayResolutionChange();
// Reconfigure controllers // Reconfigure controllers
@ -287,6 +289,12 @@ namespace Ryujinx.HLE.HOS
} }
} }
public void SimulateWakeUpMessage()
{
AppletState.Messages.Enqueue(MessageInfo.Resume);
AppletState.MessageEvent.ReadableEvent.Signal();
}
public void SignalDisplayResolutionChange() public void SignalDisplayResolutionChange()
{ {
DisplayResolutionChangeEvent.ReadableEvent.Signal(); DisplayResolutionChangeEvent.ReadableEvent.Signal();

View file

@ -46,11 +46,25 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys
// ReceiveMessage() -> nn::am::AppletMessage // ReceiveMessage() -> nn::am::AppletMessage
public ResultCode ReceiveMessage(ServiceCtx context) public ResultCode ReceiveMessage(ServiceCtx context)
{ {
if (!context.Device.System.AppletState.TryDequeueMessage(out MessageInfo message)) if (!context.Device.System.AppletState.Messages.TryDequeue(out MessageInfo message))
{ {
return ResultCode.NoMessages; return ResultCode.NoMessages;
} }
KEvent messageEvent = context.Device.System.AppletState.MessageEvent;
// NOTE: Service checks if current states are different than the stored ones.
// Since we don't support any states for now, it's fine to check if there is still messages available.
if (context.Device.System.AppletState.Messages.IsEmpty)
{
messageEvent.ReadableEvent.Clear();
}
else
{
messageEvent.ReadableEvent.Signal();
}
context.ResponseData.Write((int)message); context.ResponseData.Write((int)message);
return ResultCode.Success; return ResultCode.Success;

View file

@ -3,6 +3,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService.Sys
enum MessageInfo enum MessageInfo
{ {
FocusStateChanged = 0xf, FocusStateChanged = 0xf,
Resume = 0x10,
OperationModeChanged = 0x1e, OperationModeChanged = 0x1e,
PerformanceModeChanged = 0x1f PerformanceModeChanged = 0x1f
} }

View file

@ -6,7 +6,7 @@ namespace Ryujinx.HLE.HOS.SystemState
{ {
class AppletStateMgr class AppletStateMgr
{ {
private ConcurrentQueue<MessageInfo> _messages; public ConcurrentQueue<MessageInfo> Messages { get; }
public FocusState FocusState { get; private set; } public FocusState FocusState { get; private set; }
@ -16,8 +16,7 @@ namespace Ryujinx.HLE.HOS.SystemState
public AppletStateMgr(Horizon system) public AppletStateMgr(Horizon system)
{ {
_messages = new ConcurrentQueue<MessageInfo>(); Messages = new ConcurrentQueue<MessageInfo>();
MessageEvent = new KEvent(system.KernelContext); MessageEvent = new KEvent(system.KernelContext);
AppletResourceUserIds = new IdDictionary(); AppletResourceUserIds = new IdDictionary();
@ -25,28 +24,10 @@ namespace Ryujinx.HLE.HOS.SystemState
public void SetFocus(bool isFocused) public void SetFocus(bool isFocused)
{ {
FocusState = isFocused FocusState = isFocused ? FocusState.InFocus : FocusState.OutOfFocus;
? FocusState.InFocus
: FocusState.OutOfFocus;
EnqueueMessage(MessageInfo.FocusStateChanged);
}
public void EnqueueMessage(MessageInfo message)
{
_messages.Enqueue(message);
Messages.Enqueue(MessageInfo.FocusStateChanged);
MessageEvent.ReadableEvent.Signal(); MessageEvent.ReadableEvent.Signal();
} }
public bool TryDequeueMessage(out MessageInfo message)
{
if (_messages.Count < 2)
{
MessageEvent.ReadableEvent.Clear();
}
return _messages.TryDequeue(out message);
}
} }
} }

View file

@ -1205,6 +1205,11 @@ namespace Ryujinx.Ui
settingsWin.Show(); settingsWin.Show();
} }
private void Simulate_WakeUp_Message_Pressed(object sender, EventArgs args)
{
_emulationContext.System.SimulateWakeUpMessage();
}
private void Update_Pressed(object sender, EventArgs args) private void Update_Pressed(object sender, EventArgs args)
{ {
if (Updater.CanUpdate(true)) if (Updater.CanUpdate(true))

View file

@ -137,6 +137,16 @@
<signal name="activate" handler="StopEmulation_Pressed" swapped="no"/> <signal name="activate" handler="StopEmulation_Pressed" swapped="no"/>
</object> </object>
</child> </child>
<child>
<object class="GtkMenuItem" id="SimulateWakeUpMessage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">Simulate a Wake-up Message</property>
<property name="label" translatable="yes">Simulate Wake-up Message</property>
<property name="use_underline">True</property>
<signal name="activate" handler="Simulate_WakeUp_Message_Pressed" swapped="no"/>
</object>
</child>
<child> <child>
<object class="GtkSeparatorMenuItem"> <object class="GtkSeparatorMenuItem">
<property name="visible">True</property> <property name="visible">True</property>