From 9d536520b3446687467b04eac0745ab366d401e2 Mon Sep 17 00:00:00 2001 From: exelix Date: Mon, 25 Feb 2019 17:22:13 +0100 Subject: [PATCH] Better formatting, remove UnknownMessageHandler --- nx/include/switch/services/applet.h | 4 +- nx/include/switch/services/hidsys.h | 2 +- nx/source/services/applet.c | 79 ++++++++++++++--------------- nx/source/services/hidsys.c | 8 +-- 4 files changed, 44 insertions(+), 49 deletions(-) diff --git a/nx/include/switch/services/applet.h b/nx/include/switch/services/applet.h index 477a7bdb..a9fa1c2e 100644 --- a/nx/include/switch/services/applet.h +++ b/nx/include/switch/services/applet.h @@ -470,13 +470,13 @@ AppletFocusState appletGetFocusState(void); Result appletSetFocusHandlingMode(AppletFocusHandlingMode mode); /** - * @brief Stops forwarding the input to the foreground app, works only in the Overlay applet context + * @brief Stops forwarding the input to the foreground app, works only in the Overlay applet context. * @note You have to call this to receive inputs through the hid service when running as the overlay applet. */ Result appletBeginToWatchShortHomeButtonMessage(void); /** - * @brief Forwards input to the foreground app, works only in the Overlay applet context + * @brief Forwards input to the foreground app, works only in the Overlay applet context. * @note After calling this the overlay applet won't receive any input until \ref appletBeginToWatchShortHomeButtonMessage is called again. */ Result appletEndToWatchShortHomeButtonMessage(void); diff --git a/nx/include/switch/services/hidsys.h b/nx/include/switch/services/hidsys.h index b970294c..52e3093e 100644 --- a/nx/include/switch/services/hidsys.h +++ b/nx/include/switch/services/hidsys.h @@ -14,6 +14,6 @@ void hidsysExit(void); Result hidsysEnableAppletToGetInput(bool enable); /** -* @brief Returns an event that fires when the home button is pressed, this will prevent the home menu from opening when the button is pressed. This event does not auto clear +* @brief Returns an event that fires when the home button is pressed, this will prevent the home menu from opening when the button is pressed. This event does not auto clear. **/ Result hidsysAcquireHomeButtonEventHandle(Event* event_out); \ No newline at end of file diff --git a/nx/source/services/applet.c b/nx/source/services/applet.c index 1191a4c6..0a14c267 100644 --- a/nx/source/services/applet.c +++ b/nx/source/services/applet.c @@ -19,8 +19,6 @@ __attribute__((weak)) u32 __nx_applet_PerformanceConfiguration[2] = {/*0x9222000 //// Controls whether to use applet exit cmds during \ref appletExit. 0 (default): Only run exit cmds when running under a NSO. 1: Use exit cmds regardless. >1: Skip exit cmds. __attribute__((weak)) u32 __nx_applet_exit_mode = 0; -void __attribute__((weak)) __nx_applet_UnknownMessageHandler(u32); - static Service g_appletSrv; static Service g_appletProxySession; static u64 g_refCnt; @@ -1384,8 +1382,44 @@ Result appletQueryApplicationPlayStatistics(AppletApplicationPlayStatistics *sta return rc; } +// IOverlayFunctions + +Result appletBeginToWatchShortHomeButtonMessage(void) { + if (__nx_applet_type != AppletType_OverlayApplet) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + + return _appletCmdNoIO(&g_appletIFunctions, 0); +} + +Result appletEndToWatchShortHomeButtonMessage(void) { + if (__nx_applet_type != AppletType_OverlayApplet) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + + return _appletCmdNoIO(&g_appletIFunctions, 1); +} + // ICommonStateGetter +Result appletHomeButtonReaderLockAccessorGetEvent(Event *out_event) { + if (eventActive(&HomeButtonReaderLockAccessorEvent)) + { + *out_event = HomeButtonReaderLockAccessorEvent; + return 0; + } + + Service ILockAccessor = {0}; + Result rc = _appletGetSession(&g_appletICommonStateGetter, &ILockAccessor, 30); + if (R_FAILED(rc)) + return rc; + + rc = _appletGetEvent(&ILockAccessor, &HomeButtonReaderLockAccessorEvent, 3, false); + if (R_SUCCEEDED(rc)) + *out_event = HomeButtonReaderLockAccessorEvent; + + serviceClose(&ILockAccessor); + return rc; +} + static Result _appletReceiveMessage(u32 *out) { IpcCommand c; ipcInitialize(&c); @@ -2317,47 +2351,8 @@ bool appletMainLoop(void) { appletCallHook(AppletHookType_OnPerformanceMode); break; - - default: - if (__nx_applet_UnknownMessageHandler) - __nx_applet_UnknownMessageHandler(msg); - break; + } return true; } - -Result appletBeginToWatchShortHomeButtonMessage(void) { - if (__nx_applet_type != AppletType_OverlayApplet) - return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); - - return _appletCmdNoIO(&g_appletIFunctions, 0); -} - -Result appletEndToWatchShortHomeButtonMessage(void) { - if (__nx_applet_type != AppletType_OverlayApplet) - return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); - - return _appletCmdNoIO(&g_appletIFunctions, 1); -} - -Result appletHomeButtonReaderLockAccessorGetEvent(Event *out_event) -{ - if (eventActive(&HomeButtonReaderLockAccessorEvent)) - { - *out_event = HomeButtonReaderLockAccessorEvent; - return 0; - } - - Service ILockAccessor = {0}; - Result rc = _appletGetSession(&g_appletICommonStateGetter, &ILockAccessor, 30); - if (R_FAILED(rc)) - return rc; - - rc = _appletGetEvent(&ILockAccessor, &HomeButtonReaderLockAccessorEvent, 3, false); - if (R_SUCCEEDED(rc)) - *out_event = HomeButtonReaderLockAccessorEvent; - - serviceClose(&ILockAccessor); - return rc; -} diff --git a/nx/source/services/hidsys.c b/nx/source/services/hidsys.c index 653f98d9..103f6a29 100644 --- a/nx/source/services/hidsys.c +++ b/nx/source/services/hidsys.c @@ -53,7 +53,7 @@ Result hidsysEnableAppletToGetInput(bool enable) { struct { u64 magic; u64 cmdid; - bool permitInput; + u8 permitInput; u64 appletResourceUserId; } *raw; @@ -61,7 +61,7 @@ Result hidsysEnableAppletToGetInput(bool enable) { raw->magic = SFCI_MAGIC; raw->cmdid = 503; - raw->permitInput = enable; + raw->permitInput = enable != 0; raw->appletResourceUserId = g_hidsysAppletResourceUserId; Result rc = serviceIpcDispatch(&g_hidsysSrv); @@ -93,7 +93,7 @@ static Result _hidsysCmdWithResIdAndPid(u64 cmd_id) { } *raw; ipcSendPid(&c); - raw = serviceIpcPrepareHeader(&g_hidsysSrv,&c, sizeof(*raw)); + raw = serviceIpcPrepareHeader(&g_hidsysSrv, &c, sizeof(*raw)); raw->magic = SFCI_MAGIC; raw->cmd_id = cmd_id; @@ -128,7 +128,7 @@ static Result _hidsysGetHandle(Handle* handle_out, u64 cmd_id) { } *raw; ipcSendPid(&c); - raw = serviceIpcPrepareHeader(&g_hidsysSrv,&c, sizeof(*raw)); + raw = serviceIpcPrepareHeader(&g_hidsysSrv, &c, sizeof(*raw)); raw->magic = SFCI_MAGIC; raw->cmd_id = cmd_id;