diff --git a/nx/include/switch/services/applet.h b/nx/include/switch/services/applet.h index c0b16eff..d7dcb101 100644 --- a/nx/include/switch/services/applet.h +++ b/nx/include/switch/services/applet.h @@ -519,6 +519,27 @@ Result appletSetDesirableKeyboardLayout(u32 layout); Result appletCreateManagedDisplayLayer(u64 *out); +/** + * @brief Checks whether SystemBufferSharing is enabled, throwing an error otherwise. + * @note Only available with [4.0.0+]. Not usable with AppletType_*Application. + */ +Result appletIsSystemBufferSharingEnabled(void); + +/** + * @brief Gets the System SharedBufferHandle and SharedLayerHandle. + * @note Only available with [4.0.0+]. Not usable with AppletType_*Application. + * @param[out] SharedBufferHandle Output System SharedBufferHandle. + * @param[out] SharedLayerHandle Output System SharedLayerHandle. + */ +Result appletGetSystemSharedLayerHandle(u64 *SharedBufferHandle, u64 *SharedLayerHandle); + +/** + * @brief Same as \ref appletGetSystemSharedLayerHandle except this just gets the SharedBufferHandle. + * @note Only available with [5.0.0+]. Not usable with AppletType_*Application. + * @param[out] SharedBufferHandle Output System SharedBufferHandle. + */ +Result appletGetSystemSharedBufferHandle(u64 *SharedBufferHandle); + /** * @brief Sets whether ::AppletNotificationMessage_RequestToDisplay is enabled. * @note Sets an internal state flag. When the input flag is 0, this will in additional run the same code as \ref appletApproveToDisplay. diff --git a/nx/source/services/applet.c b/nx/source/services/applet.c index 0b7a1e4b..8ee9d563 100644 --- a/nx/source/services/applet.c +++ b/nx/source/services/applet.c @@ -2242,7 +2242,6 @@ Result appletSetScreenShotAppletIdentityInfo(AppletIdentityInfo *info) { struct { u64 magic; u64 result; - AppletIdentityInfo info; } *resp; serviceIpcParse(&g_appletISelfController, &r, sizeof(*resp)); @@ -2290,6 +2289,60 @@ Result appletCreateManagedDisplayLayer(u64 *out) { return _appletCmdNoInOut64(&g_appletISelfController, out, 40); } +Result appletIsSystemBufferSharingEnabled(void) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _appletCmdNoIO(&g_appletISelfController, 41); +} + +Result appletGetSystemSharedLayerHandle(u64 *SharedBufferHandle, u64 *SharedLayerHandle) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + } *raw; + + raw = serviceIpcPrepareHeader(&g_appletISelfController, &c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 42; + + Result rc = serviceIpcDispatch(&g_appletISelfController); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + struct { + u64 magic; + u64 result; + u64 SharedBufferHandle; + u64 SharedLayerHandle; + } *resp; + + serviceIpcParse(&g_appletISelfController, &r, sizeof(*resp)); + resp = r.Raw; + + rc = resp->result; + + if (R_SUCCEEDED(rc) && SharedBufferHandle) *SharedBufferHandle = resp->SharedBufferHandle; + if (R_SUCCEEDED(rc) && SharedLayerHandle) *SharedLayerHandle = resp->SharedLayerHandle; + } + + return rc; +} + +Result appletGetSystemSharedBufferHandle(u64 *SharedBufferHandle) { + if (hosversionBefore(5,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _appletCmdNoInOut64(&g_appletISelfController, SharedBufferHandle, 43); +} + Result appletSetHandlesRequestToDisplay(bool flag) { return _appletCmdInBool(&g_appletISelfController, flag, 50); }