From 8b334ae2eff70c1097121acf7b58217217e81266 Mon Sep 17 00:00:00 2001 From: LiquidFenrir Date: Mon, 28 May 2018 22:40:49 +0200 Subject: [PATCH] Allow blocking HOME button Signed-off-by: Alex Taber --- libctru/include/3ds/services/apt.h | 12 ++++++++++++ libctru/source/services/apt.c | 15 +++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/libctru/include/3ds/services/apt.h b/libctru/include/3ds/services/apt.h index 0285ab7..29d51ad 100644 --- a/libctru/include/3ds/services/apt.h +++ b/libctru/include/3ds/services/apt.h @@ -158,6 +158,18 @@ bool aptIsSleepAllowed(void); */ void aptSetSleepAllowed(bool allowed); +/** + * @brief Gets whether to allow the system to go back to HOME menu. + * @return Whether going back to HOME menu is allowed. + */ +bool aptIsHomeAllowed(void); + +/** + * @brief Sets whether to allow the system to go back to HOME menu. + * @param allowed Whether going back to HOME menu is allowed. + */ +void aptSetHomeAllowed(bool allowed); + /** * @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 9cbfca6..96e6618 100644 --- a/libctru/source/services/apt.c +++ b/libctru/source/services/apt.c @@ -41,6 +41,7 @@ enum static u8 aptHomeButtonState; static u32 aptFlags = FLAG_ALLOWSLEEP; +static bool home_allowed = false; static u32 aptParameters[0x1000/4]; static u64 aptChainloadTid; static u8 aptChainloadMediatype; @@ -267,6 +268,16 @@ void aptSetSleepAllowed(bool allowed) } } +bool aptIsHomeAllowed(void) +{ + return home_allowed; +} + +void aptSetHomeAllowed(bool allowed) +{ + home_allowed = allowed; +} + void aptSetChainloader(u64 programID, u8 mediatype) { aptChainloadTid = programID; @@ -338,10 +349,10 @@ void aptEventHandler(void *arg) switch (signal) { case APTSIGNAL_HOMEBUTTON: - if (!aptHomeButtonState) aptHomeButtonState = 1; + if (!aptHomeButtonState && aptIsHomeAllowed()) aptHomeButtonState = 1; break; case APTSIGNAL_HOMEBUTTON2: - if (!aptHomeButtonState) aptHomeButtonState = 2; + if (!aptHomeButtonState && aptIsHomeAllowed()) aptHomeButtonState = 2; break; case APTSIGNAL_SLEEP_QUERY: APT_ReplySleepQuery(envGetAptAppId(), aptIsSleepAllowed() ? APTREPLY_ACCEPT : APTREPLY_REJECT);