From 7dd1f4dc833d48f0a87cadf8272d02b607ca6783 Mon Sep 17 00:00:00 2001 From: Maufeat Date: Sat, 8 Nov 2025 21:45:42 +0100 Subject: [PATCH] starter 1 --- src/core/hle/service/am/am_types.h | 1 + src/core/hle/service/am/button_poller.cpp | 11 +++++-- .../am/service/application_creator.cpp | 33 ++++++++++++++++++- .../service/am/service/application_creator.h | 1 + .../am/service/common_state_getter.cpp | 25 +++++++++++--- .../service/am/service/common_state_getter.h | 1 + 6 files changed, 64 insertions(+), 8 deletions(-) diff --git a/src/core/hle/service/am/am_types.h b/src/core/hle/service/am/am_types.h index cf1afa7afd..621a7b4921 100644 --- a/src/core/hle/service/am/am_types.h +++ b/src/core/hle/service/am/am_types.h @@ -150,6 +150,7 @@ enum class AppletMessage : u32 { ForceHideApplicationLogo = 57, FloatingApplicationDetected = 60, DetectShortPressingCaptureButton = 90, + DetectLongPressingCaptureButton = 91, AlbumScreenShotTaken = 92, AlbumRecordingSaved = 93, }; diff --git a/src/core/hle/service/am/button_poller.cpp b/src/core/hle/service/am/button_poller.cpp index aab397085f..bb915f9ea4 100644 --- a/src/core/hle/service/am/button_poller.cpp +++ b/src/core/hle/service/am/button_poller.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "core/core.h" +#include "core/hle/service/am/am_types.h" #include "core/hle/service/am/button_poller.h" #include "core/hle/service/am/window_system.h" #include "hid_core/frontend/emulated_controller.h" @@ -73,11 +74,17 @@ void ButtonPoller::OnButtonStateChanged() { // Buttons released which were previously held if (!home_button && m_home_button_press_start) { - m_window_system.OnHomeButtonPressed(ClassifyPressDuration(*m_home_button_press_start)); + const auto duration = ClassifyPressDuration(*m_home_button_press_start); + m_window_system.OnSystemButtonPress( + duration == ButtonPressDuration::ShortPressing ? SystemButtonType::HomeButtonShortPressing + : SystemButtonType::HomeButtonLongPressing); m_home_button_press_start = std::nullopt; } if (!capture_button && m_capture_button_press_start) { - // TODO + const auto duration = ClassifyPressDuration(*m_capture_button_press_start); + m_window_system.OnSystemButtonPress( + duration == ButtonPressDuration::ShortPressing ? SystemButtonType::CaptureButtonShortPressing + : SystemButtonType::CaptureButtonLongPressing); m_capture_button_press_start = std::nullopt; } // if (!power_button && m_power_button_press_start) { diff --git a/src/core/hle/service/am/service/application_creator.cpp b/src/core/hle/service/am/service/application_creator.cpp index 8df8120d68..bdb98aacb3 100644 --- a/src/core/hle/service/am/service/application_creator.cpp +++ b/src/core/hle/service/am/service/application_creator.cpp @@ -60,7 +60,7 @@ IApplicationCreator::IApplicationCreator(Core::System& system_, WindowSystem& wi static const FunctionInfo functions[] = { {0, D<&IApplicationCreator::CreateApplication>, "CreateApplication"}, {1, nullptr, "PopLaunchRequestedApplication"}, - {10, nullptr, "CreateSystemApplication"}, + {10, D<&IApplicationCreator::CreateSystemApplication>, "CreateSystemApplication"}, {100, nullptr, "PopFloatingApplicationForDevelopment"}, }; // clang-format on @@ -77,4 +77,35 @@ Result IApplicationCreator::CreateApplication( CreateGuestApplication(out_application_accessor, system, m_window_system, application_id)); } +Result IApplicationCreator::CreateSystemApplication( + Out> out_application_accessor, u64 application_id) { + + FileSys::VirtualFile nca_raw{}; + + auto& storage = system.GetContentProviderUnion(); + nca_raw = storage.GetEntryRaw(application_id, FileSys::ContentRecordType::Program); + + R_UNLESS(nca_raw != nullptr, ResultUnknown); + + std::vector control; + std::unique_ptr loader; + Loader::ResultStatus result; + + auto process = + CreateProcess(system, application_id, 1, 21); + R_UNLESS(process != nullptr, ResultUnknown); + + const auto applet = std::make_shared(system, std::move(process), true); + applet->program_id = application_id; + applet->applet_id = AppletId::Starter; + applet->type = AppletType::LibraryApplet; + applet->library_applet_mode = LibraryAppletMode::AllForeground; + + m_window_system.TrackApplet(applet, true); + + *out_application_accessor = + std::make_shared(system, applet, m_window_system); + R_SUCCEED(); +} + } // namespace Service::AM diff --git a/src/core/hle/service/am/service/application_creator.h b/src/core/hle/service/am/service/application_creator.h index 287745af85..ebbbdc1f5f 100644 --- a/src/core/hle/service/am/service/application_creator.h +++ b/src/core/hle/service/am/service/application_creator.h @@ -19,6 +19,7 @@ public: private: Result CreateApplication(Out>, u64 application_id); + Result CreateSystemApplication(Out>, u64 application_id); WindowSystem& m_window_system; }; diff --git a/src/core/hle/service/am/service/common_state_getter.cpp b/src/core/hle/service/am/service/common_state_getter.cpp index 93bded336c..d372e97708 100644 --- a/src/core/hle/service/am/service/common_state_getter.cpp +++ b/src/core/hle/service/am/service/common_state_getter.cpp @@ -61,7 +61,7 @@ ICommonStateGetter::ICommonStateGetter(Core::System& system_, std::shared_ptr, "PerformSystemButtonPressingIfInFocus"}, {90, nullptr, "SetPerformanceConfigurationChangedNotification"}, {91, nullptr, "GetCurrentPerformanceConfiguration"}, - {100, nullptr, "SetHandlingHomeButtonShortPressedEnabled"}, + {100, D<&ICommonStateGetter::SetHandlingHomeButtonShortPressedEnabled>, "SetHandlingHomeButtonShortPressedEnabled"}, {110, nullptr, "OpenMyGpuErrorHandler"}, {120, D<&ICommonStateGetter::GetAppletLaunchedHistory>, "GetAppletLaunchedHistory"}, {200, D<&ICommonStateGetter::GetOperationModeSystemInfo>, "GetOperationModeSystemInfo"}, @@ -268,6 +268,18 @@ Result ICommonStateGetter::PerformSystemButtonPressingIfInFocus(SystemButtonType AppletMessage::DetectLongPressingHomeButton); } break; + case SystemButtonType::CaptureButtonShortPressing: + if (m_applet->handling_capture_button_short_pressed_message_enabled_for_applet) { + m_applet->lifecycle_manager.PushUnorderedMessage( + AppletMessage::DetectShortPressingCaptureButton); + } + break; + case SystemButtonType::CaptureButtonLongPressing: + if (m_applet->handling_capture_button_long_pressed_message_enabled_for_applet) { + m_applet->lifecycle_manager.PushUnorderedMessage( + AppletMessage::DetectLongPressingCaptureButton); + } + break; default: // Other buttons ignored for now break; @@ -316,12 +328,15 @@ Result ICommonStateGetter::SetRequestExitToLibraryAppletAtExecuteNextProgramEnab Result ICommonStateGetter::PushToGeneralChannel(SharedPointer storage) { LOG_DEBUG(Service_AM, "called"); + system.PushGeneralChannelData(storage->GetData()); + R_SUCCEED(); +} - std::scoped_lock lk{m_applet->lock}; - // Push to a general-purpose channel and notify listeners via event - m_applet->user_channel_launch_parameter.push_back(storage->GetData()); - m_applet->pop_from_general_channel_event.Signal(); +Result ICommonStateGetter::SetHandlingHomeButtonShortPressedEnabled(bool enabled) { + LOG_DEBUG(Service_AM, "called, enabled={} applet_id={}", enabled, m_applet->applet_id); + std::scoped_lock lk{m_applet->lock}; + m_applet->home_button_short_pressed_blocked = !enabled; R_SUCCEED(); } diff --git a/src/core/hle/service/am/service/common_state_getter.h b/src/core/hle/service/am/service/common_state_getter.h index db1129feb0..c17edefd9a 100644 --- a/src/core/hle/service/am/service/common_state_getter.h +++ b/src/core/hle/service/am/service/common_state_getter.h @@ -60,6 +60,7 @@ private: Result GetSettingsPlatformRegion(Out out_settings_platform_region); Result SetRequestExitToLibraryAppletAtExecuteNextProgramEnabled(); Result PushToGeneralChannel(SharedPointer storage); // cmd 20 + Result SetHandlingHomeButtonShortPressedEnabled(bool enabled); void SetCpuBoostMode(HLERequestContext& ctx);