diff --git a/nx/include/switch/services/applet.h b/nx/include/switch/services/applet.h index 4165094a..68a9ad81 100644 --- a/nx/include/switch/services/applet.h +++ b/nx/include/switch/services/applet.h @@ -167,9 +167,6 @@ void appletExit(void); Result appletGetAppletResourceUserId(u64 *out); AppletType appletGetAppletType(void); -void appletNotifyRunning(u8 *out); -Result appletCreateManagedDisplayLayer(u64 *out); - /// Sets the state field for \ref AppletThemeColorType. void appletSetThemeColorType(AppletThemeColorType theme); @@ -215,6 +212,34 @@ Result appletSetTerminateResult(Result res); */ Result appletGetDisplayVersion(char *displayVersion); +/** + * @brief Blocks the usage of the home button, for short (Home Menu) and long (Overlay) presses. + * @note Only available with AppletType_*Application. + * @param val Unknown. Official sw only uses hard-coded value 0 for this. + */ +Result appletBeginBlockingHomeButtonShortAndLongPressed(s64 val); + +/** + * @brief Ends the blocking started by \ref appletBeginBlockingHomeButtonShortAndLongPressed. + * @note Only available with AppletType_*Application. + */ +Result appletEndBlockingHomeButtonShortAndLongPressed(void); + +/** + * @brief Blocks the usage of the home button, for short presses (Home Menu). + * @note Only available with AppletType_*Application. + * @param val Unknown nanoseconds. Value 0 can be used. + */ +Result appletBeginBlockingHomeButton(s64 val); + +/** + * @brief Ends the blocking started by \ref appletBeginBlockingHomeButton. + * @note Only available with AppletType_*Application. + */ +Result appletEndBlockingHomeButton(void); + +void appletNotifyRunning(u8 *out); + /// Set media playback state. /// If state is set to true, screen dimming and auto sleep is disabled. /// For *Application, this uses cmd SetMediaPlaybackStateForApplication, otherwise cmd SetMediaPlaybackState is used. @@ -234,15 +259,6 @@ Result appletSetGamePlayRecordingState(bool state); /// Only usable when running under a title which supports video recording. Using this is only needed when the host title control.nacp has VideoCaptureMode set to Enabled, with Automatic appletInitializeGamePlayRecording is not needed. Result appletInitializeGamePlayRecording(void); -/** - * @brief Blocks the usage of the home button. - * @param val Unknown nanoseconds. Value 0 can be used. - * @note Can only be used in regularapps. - */ -Result appletBeginBlockingHomeButton(s64 val); - -Result appletEndBlockingHomeButton(void); - /** * @brief Gets ApplicationPlayStatistics. * @note Only available with AppletType_*Application on 5.0.0+. @@ -293,6 +309,8 @@ Result appletSetScreenShotPermission(AppletScreenShotPermission permission); Result appletSetScreenShotImageOrientation(s32 val); +Result appletCreateManagedDisplayLayer(u64 *out); + /** * @brief Gets the current Illuminance from the light sensor. * @note Only available with [3.0.0+]. diff --git a/nx/source/services/applet.c b/nx/source/services/applet.c index 5503d255..166713a0 100644 --- a/nx/source/services/applet.c +++ b/nx/source/services/applet.c @@ -1362,51 +1362,25 @@ Result appletGetDisplayVersion(char *displayVersion) { return rc; } -Result appletSetMediaPlaybackState(bool state) { - if (!serviceIsActive(&g_appletSrv)) - return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); - - if (!_appletIsApplication()) - return _appletCmdInBool(&g_appletISelfController, state, 61);//SetMediaPlaybackState - - return _appletCmdInBool(&g_appletIFunctions, state, 60);//SetMediaPlaybackStateForApplication -} - -Result appletBeginBlockingHomeButton(s64 val) { - IpcCommand c; - ipcInitialize(&c); - +Result appletBeginBlockingHomeButtonShortAndLongPressed(s64 val) { if (!serviceIsActive(&g_appletSrv) || !_appletIsApplication()) return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); - struct { - u64 magic; - u64 cmd_id; - s64 val; - } *raw; + return _appletCmdInU64(&g_appletIFunctions, val, 30); +} - raw = serviceIpcPrepareHeader(&g_appletIFunctions, &c, sizeof(*raw)); +Result appletEndBlockingHomeButtonShortAndLongPressed(void) { + if (!serviceIsActive(&g_appletSrv) || !_appletIsApplication()) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); - raw->magic = SFCI_MAGIC; - raw->cmd_id = 32; - raw->val = val; + return _appletCmdNoIO(&g_appletIFunctions, 31); +} - Result rc = serviceIpcDispatch(&g_appletIFunctions); +Result appletBeginBlockingHomeButton(s64 val) { + if (!serviceIsActive(&g_appletSrv) || !_appletIsApplication()) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); - if (R_SUCCEEDED(rc)) { - IpcParsedCommand r; - struct { - u64 magic; - u64 result; - } *resp; - - serviceIpcParse(&g_appletIFunctions, &r, sizeof(*resp)); - resp = r.Raw; - - rc = resp->result; - } - - return rc; + return _appletCmdInU64(&g_appletIFunctions, val, 32); } Result appletEndBlockingHomeButton(void) { @@ -1456,6 +1430,16 @@ void appletNotifyRunning(u8 *out) { if (R_FAILED(rc)) fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadAppletNotifyRunning)); } +Result appletSetMediaPlaybackState(bool state) { + if (!serviceIsActive(&g_appletSrv)) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + + if (!_appletIsApplication()) + return _appletCmdInBool(&g_appletISelfController, state, 61);//SetMediaPlaybackState + + return _appletCmdInBool(&g_appletIFunctions, state, 60);//SetMediaPlaybackStateForApplication +} + Result appletIsGamePlayRecordingSupported(bool *flag) { IpcCommand c; ipcInitialize(&c);