diff --git a/src/core/hle/service/am/lifecycle_manager.h b/src/core/hle/service/am/lifecycle_manager.h index ae041d3e29..15657a36d8 100644 --- a/src/core/hle/service/am/lifecycle_manager.h +++ b/src/core/hle/service/am/lifecycle_manager.h @@ -92,6 +92,13 @@ public: } } + void RequestFocusStateChangedNotification(Kernel::KernelCore& kernel) { + if (m_focus_state_changed_notification_enabled) { + m_has_focus_state_changed = true; + this->SignalSystemEventIfNeeded(kernel); + } + } + void OnOperationAndPerformanceModeChanged(Kernel::KernelCore& kernel); public: diff --git a/src/core/hle/service/am/service/library_applet_accessor.cpp b/src/core/hle/service/am/service/library_applet_accessor.cpp index c49b1f3f05..849e5794cf 100644 --- a/src/core/hle/service/am/service/library_applet_accessor.cpp +++ b/src/core/hle/service/am/service/library_applet_accessor.cpp @@ -164,14 +164,14 @@ Result ILibraryAppletAccessor::PushInData(SharedPointer storage) { Result ILibraryAppletAccessor::PopOutData(Out> out_storage) { LOG_DEBUG(Service_AM, "called"); - if (auto caller_applet = m_applet->caller_applet.lock(); caller_applet) { - caller_applet->lifecycle_manager.GetSystemEvent().Signal(system.Kernel()); - caller_applet->lifecycle_manager.RequestResumeNotification(); - caller_applet->lifecycle_manager.GetSystemEvent().Clear(system.Kernel()); - caller_applet->lifecycle_manager.UpdateRequestedFocusState(); - } - R_TRY(m_broker->GetOutData().Pop(system.Kernel(), out_storage.Get())); + if (auto caller_applet = m_applet->caller_applet.lock(); caller_applet) { + std::scoped_lock lk{caller_applet->lock}; + const bool focus_state_changed = caller_applet->lifecycle_manager.UpdateRequestedFocusState(); + const bool is_front_app = m_applet->frontend && caller_applet->lifecycle_manager.IsApplication(); + if (focus_state_changed) caller_applet->lifecycle_manager.SignalSystemEventIfNeeded(system.Kernel()); + else if (is_front_app) caller_applet->lifecycle_manager.RequestFocusStateChangedNotification(system.Kernel()); + } if (m_applet->applet_id == AppletId::ProfileSelect && *out_storage) { auto impl = (*out_storage)->GetImpl();