From 59b71196aca930c40f02b111ca28f98dddc51c67 Mon Sep 17 00:00:00 2001 From: Oreo639 <31916379+Oreo639@users.noreply.github.com> Date: Tue, 23 Apr 2019 19:33:55 -0700 Subject: [PATCH] Fix blocking and add aptIsHomePressed --- libctru/include/3ds/services/apt.h | 6 ++++++ libctru/source/services/apt.c | 25 +++++++++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/libctru/include/3ds/services/apt.h b/libctru/include/3ds/services/apt.h index 29d51ad..32374ae 100644 --- a/libctru/include/3ds/services/apt.h +++ b/libctru/include/3ds/services/apt.h @@ -170,6 +170,12 @@ bool aptIsHomeAllowed(void); */ void aptSetHomeAllowed(bool allowed); +/** + * @brief Returns when the HOME button is pressed. + * @return Whether the HOME button is being pressed. + */ +bool aptIsHomePressed(void); + /** * @brief Processes the current APT status. Generally used within a main loop. * @return Whether the application should continue running. diff --git a/libctru/source/services/apt.c b/libctru/source/services/apt.c index e431fa1..20d4c56 100644 --- a/libctru/source/services/apt.c +++ b/libctru/source/services/apt.c @@ -40,8 +40,9 @@ enum }; static u8 aptHomeButtonState; +static u8 aptRecentHomeButtonState; static u32 aptFlags = FLAG_ALLOWSLEEP; -static bool aptHomeAllowed = false; +static bool aptHomeAllowed = true; static u32 aptParameters[0x1000/4]; static u64 aptChainloadTid; static u8 aptChainloadMediatype; @@ -278,6 +279,11 @@ void aptSetHomeAllowed(bool allowed) aptHomeAllowed = allowed; } +bool aptIsHomePressed(void) +{ + return aptRecentHomeButtonState; +} + void aptSetChainloader(u64 programID, u8 mediatype) { aptChainloadTid = programID; @@ -349,10 +355,10 @@ void aptEventHandler(void *arg) switch (signal) { case APTSIGNAL_HOMEBUTTON: - if (!aptHomeButtonState && aptIsHomeAllowed()) aptHomeButtonState = 1; + if (!aptHomeButtonState) aptHomeButtonState = 1; break; case APTSIGNAL_HOMEBUTTON2: - if (!aptHomeButtonState && aptIsHomeAllowed()) aptHomeButtonState = 2; + if (!aptHomeButtonState) aptHomeButtonState = 2; break; case APTSIGNAL_SLEEP_QUERY: APT_ReplySleepQuery(envGetAptAppId(), aptIsSleepAllowed() ? APTREPLY_ACCEPT : APTREPLY_REJECT); @@ -512,6 +518,8 @@ bool aptMainLoop(void) if (aptIsCrippled()) return true; if (aptFlags & FLAG_EXITED) return false; + if (aptRecentHomeButtonState) aptRecentHomeButtonState = 0; + if (aptFlags & FLAG_WANTSTOSLEEP) { aptFlags = (aptFlags &~ FLAG_WANTSTOSLEEP) | FLAG_SLEEPING; @@ -525,7 +533,16 @@ bool aptMainLoop(void) aptCallHook(APTHOOK_ONWAKEUP); } else if ((aptFlags & FLAG_POWERBUTTON) || aptHomeButtonState) - aptProcessJumpToMenu(); + { + if (aptHomeAllowed || (aptFlags & FLAG_POWERBUTTON)) + aptProcessJumpToMenu(); + else + { + aptRecentHomeButtonState = aptHomeButtonState; + aptHomeButtonState = 0; + APT_UnlockTransition(0x01); + } + } if (aptFlags & (FLAG_ORDERTOCLOSE|FLAG_WKUPBYCANCEL)) {