From 2c18b246aef936962f5687b750971e3c10c0301c Mon Sep 17 00:00:00 2001 From: James Benton Date: Fri, 2 Jun 2017 11:48:59 +0100 Subject: [PATCH] whb: Fix proc to better support HBL launched applications. Should exit cleanly to HBL now. TODO: Is it possible to auto detect if we were launched from HBL? --- src/libwhb/include/whb/proc.h | 18 +++++++++++++- src/libwhb/src/proc.c | 45 +++++++++++++++++++++++++++++++---- 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/src/libwhb/include/whb/proc.h b/src/libwhb/include/whb/proc.h index fdc61b6..5c20e72 100644 --- a/src/libwhb/include/whb/proc.h +++ b/src/libwhb/include/whb/proc.h @@ -1,8 +1,18 @@ #pragma once #include +/** + * \defgroup whb_proc ProcUI Utilities + * \ingroup whb + * @{ + */ + +#ifdef __cplusplus +extern "C" { +#endif + void -WHBProcInit(); +WHBProcInit(BOOL fromHBL); void WHBProcShutdown(); @@ -12,3 +22,9 @@ WHBProcStopRunning(); BOOL WHBProcIsRunning(); + +#ifdef __cplusplus +} +#endif + +/** @} */ diff --git a/src/libwhb/src/proc.c b/src/libwhb/src/proc.c index 16ce7d6..7179ddb 100644 --- a/src/libwhb/src/proc.c +++ b/src/libwhb/src/proc.c @@ -1,8 +1,13 @@ -#include #include +#include #include +#include +#include #include #include +#include +#include +#include static uint32_t sMainCore; @@ -10,28 +15,59 @@ sMainCore; static BOOL sRunning = FALSE; +static BOOL +sFromHBL = FALSE; + static ProcUICallback sAcquireCallback = NULL; static uint32_t -ProcSaveCallback(void *context) +procSaveCallback(void *context) { OSSavesDone_ReadyToRelease(); return 0; } + +static uint32_t +procHomeButtonDenied(void *context) +{ + if (sFromHBL) { + WHBProcStopRunning(); + } + + return 0; +} + void -WHBProcInit() +WHBProcInit(BOOL fromHBL) { sMainCore = OSGetCoreId(); sRunning = TRUE; - ProcUIInitEx(&ProcSaveCallback, NULL); + + // Homebrew Launcher does not like the standard ProcUI application loop, + // so instead we disable the home buttom menu and use the home button + // to trigger an exit. + sFromHBL = fromHBL; + if (sFromHBL) { + // Important: OSEnableHomeButtonMenu must come before ProcUIInitEx. + OSEnableHomeButtonMenu(FALSE); + } + + ProcUIInitEx(&procSaveCallback, NULL); + ProcUIRegisterCallback(PROCUI_CALLBACK_HOME_BUTTON_DENIED, &procHomeButtonDenied, NULL, 100); } void WHBProcShutdown() { sRunning = FALSE; + + // If we're running from Homebrew Launcher we must do a SYSRelaunchTitle to + // correctly return to HBL. + if (sFromHBL) { + SYSRelaunchTitle(0, NULL); + } } void @@ -58,7 +94,6 @@ WHBProcIsRunning() } if (!sRunning) { - GX2DrawDone(); ProcUIShutdown(); }