diff --git a/nx/include/switch/services/applet.h b/nx/include/switch/services/applet.h index e6602c9f..42265fea 100644 --- a/nx/include/switch/services/applet.h +++ b/nx/include/switch/services/applet.h @@ -10,6 +10,7 @@ #include "../services/sm.h" #include "../services/apm.h" #include "../services/pdm.h" +#include "../services/caps.h" #include "../kernel/tmem.h" #include "../kernel/event.h" @@ -39,6 +40,7 @@ typedef enum { AppletHookType_OnRestart, ///< ::AppletNotificationMessage_Restart AppletHookType_OnCaptureButtonShortPressed, ///< ::AppletNotificationMessage_CaptureButtonShortPressed AppletHookType_OnAlbumImageTaken, ///< ::AppletNotificationMessage_AlbumImageTaken + AppletHookType_RequestToDisplay, ///< ::AppletNotificationMessage_RequestToDisplay AppletHookType_Max, ///< Number of applet hook types. } AppletHookType; @@ -50,6 +52,7 @@ typedef enum { AppletNotificationMessage_Restart = 0x10, ///< Current applet execution was resumed. AppletNotificationMessage_OperationModeChanged = 0x1E, ///< OperationMode changed. AppletNotificationMessage_PerformanceModeChanged = 0x1F, ///< PerformanceMode changed. + AppletNotificationMessage_RequestToDisplay = 0x33, ///< Display requested, see \ref appletApproveToDisplay. AppletNotificationMessage_CaptureButtonShortPressed = 0x5A, ///< Capture button was short-pressed. AppletNotificationMessage_AlbumImageTaken = 0x5C, ///< Screenshot was taken. } AppletNotificationMessage; @@ -133,6 +136,19 @@ typedef enum { AppletScreenShotPermission_Disable = 2, ///< Disable. } AppletScreenShotPermission; +/// Extension values for \ref appletSetIdleTimeDetectionExtension / \ref appletGetIdleTimeDetectionExtension, for extending user inactivity detection. +typedef enum { + AppletIdleTimeDetectionExtension_None = 0, ///< No extension. + AppletIdleTimeDetectionExtension_Extended = 1, ///< Extended + AppletIdleTimeDetectionExtension_ExtendedUnsafe = 2, ///< ExtendedUnsafe +} AppletIdleTimeDetectionExtension; + +/// Input mode values for \ref appletSetWirelessPriorityMode. +typedef enum { + AppletWirelessPriorityMode_Unknown1 = 1, ///< Unknown. + AppletWirelessPriorityMode_Unknown2 = 2, ///< Unknown. +} AppletWirelessPriorityMode; + /// applet hook function. typedef void (*AppletHookFn)(AppletHookType hook, void* param); @@ -390,6 +406,14 @@ Result appletSetScreenShotPermission(AppletScreenShotPermission permission); */ Result appletSetRestartMessageEnabled(bool flag); +/** + * @brief Sets ControllerFirmwareUpdateSection. + * @note Only available with [3.0.0+]. + * @note This throws error 0x40280 when the internal state flag already matches the input value. + * @param[in] flag Flag + */ +Result appletSetControllerFirmwareUpdateSection(bool flag); + /** * @brief Sets whether ::AppletNotificationMessage_CaptureButtonShortPressed is enabled. * @note Only available with [3.0.0+]. @@ -400,12 +424,65 @@ Result appletSetRequiresCaptureButtonShortPressedMessage(bool flag); /** * @brief Sets the Album screenshot ImageOrientation. - * @param[in] val Input value. + * @note Only available with [3.0.0+]. + * @param[in] orientation \ref AlbumImageOrientation */ -Result appletSetAlbumImageOrientation(s32 val); +Result appletSetAlbumImageOrientation(AlbumImageOrientation orientation); + +/** + * @brief Sets the DesirableKeyboardLayout. + * @note Only available with [4.0.0+]. + * @param[in] layout Input layout. + */ +Result appletSetDesirableKeyboardLayout(u32 layout); Result appletCreateManagedDisplayLayer(u64 *out); +/** + * @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. + * @param[in] flag Flag + */ +Result appletSetHandlesRequestToDisplay(bool flag); + +/** + * @brief Approve the display requested by ::AppletNotificationMessage_RequestToDisplay, see also \ref appletSetHandlesRequestToDisplay. + */ +Result appletApproveToDisplay(void); + +/** + * @brief OverrideAutoSleepTimeAndDimmingTime + * @param[in] inval0 Unknown input value. + * @param[in] inval1 Unknown input value. + * @param[in] inval2 Unknown input value. + * @param[in] inval3 Unknown input value. + */ +Result appletOverrideAutoSleepTimeAndDimmingTime(s32 inval0, s32 inval1, s32 inval2, s32 inval3); + +/** + * @brief Sets the IdleTimeDetectionExtension. + * @param[in] ext \ref AppletIdleTimeDetectionExtension Must be 0-2: 0 = disabled, 1 = Extended, and 2 = ExtendedUnsafe. + */ +Result appletSetIdleTimeDetectionExtension(AppletIdleTimeDetectionExtension ext); + +/** + * @brief Gets the value set by \ref appletSetIdleTimeDetectionExtension. + * @param[out] ext \ref AppletIdleTimeDetectionExtension + */ +Result appletGetIdleTimeDetectionExtension(AppletIdleTimeDetectionExtension *ext); + +/** + * @brief Sets the InputDetectionSourceSet. + * @param[in] val Input value. + */ +Result appletSetInputDetectionSourceSet(u32 val); + +/** + * @brief Reports that the user is active, for idle detection (screen dimming / auto-sleep). This is equivalent to when the user uses HID input. + * @note Only available with [2.0.0+]. + */ +Result appletReportUserIsActive(void); + /** * @brief Gets the current Illuminance from the light sensor. * @note Only available with [3.0.0+]. @@ -420,6 +497,20 @@ Result appletGetCurrentIlluminance(float *fLux); */ Result appletIsIlluminanceAvailable(bool *out); +/** + * @brief Sets AutoSleepDisabled. + * @note Only available with [5.0.0+]. + * @param[in] flag Flag + */ +Result appletSetAutoSleepDisabled(bool flag); + +/** + * @brief Gets AutoSleepDisabled. + * @note Only available with [5.0.0+]. + * @param[out] out Output flag + */ +Result appletIsAutoSleepDisabled(bool *out); + /** * @brief Gets the current Illuminance from the light sensor. Same as \ref appletGetCurrentIlluminance except for the additional param. * @note Only available with [5.0.0+]. @@ -428,6 +519,13 @@ Result appletIsIlluminanceAvailable(bool *out); */ Result appletGetCurrentIlluminanceEx(bool *bOverLimit, float *fLux); +/** + * @brief Sets the WirelessPriorityMode. + * @note Only available with [4.0.0+]. + * @param[in] mode \ref AppletWirelessPriorityMode + */ +Result appletSetWirelessPriorityMode(AppletWirelessPriorityMode mode); + /** * @brief Sets whether ::AppletNotificationMessage_AlbumImageTaken is enabled. * @note Only available with [7.0.0+]. diff --git a/nx/include/switch/services/caps.h b/nx/include/switch/services/caps.h index 8f5ad3d0..22aa2db7 100644 --- a/nx/include/switch/services/caps.h +++ b/nx/include/switch/services/caps.h @@ -23,3 +23,11 @@ typedef struct { u8 unk_x0[0x20]; } CapsApplicationAlbumEntry; +/// ImageOrientation +typedef enum { + AlbumImageOrientation_Unknown0 = 0, ///< Unknown. + AlbumImageOrientation_Unknown1 = 1, ///< Unknown. + AlbumImageOrientation_Unknown2 = 2, ///< Unknown. + AlbumImageOrientation_Unknown3 = 3, ///< Unknown. +} AlbumImageOrientation; + diff --git a/nx/source/services/applet.c b/nx/source/services/applet.c index 6c252d56..6f84b1de 100644 --- a/nx/source/services/applet.c +++ b/nx/source/services/applet.c @@ -8,6 +8,7 @@ #include "services/fatal.h" #include "services/applet.h" #include "services/apm.h" +#include "services/caps.h" #include "services/sm.h" #include "runtime/env.h" #include "runtime/hosversion.h" @@ -2163,6 +2164,13 @@ static Result _appletSetOutOfFocusSuspendingEnabled(bool flag) { return _appletCmdInBool(&g_appletISelfController, flag, 16); } +Result appletSetControllerFirmwareUpdateSection(bool flag) { + if (hosversionBefore(3,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _appletCmdInBool(&g_appletISelfController, flag, 17); +} + Result appletSetRequiresCaptureButtonShortPressedMessage(bool flag) { if (hosversionBefore(3,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); @@ -2170,16 +2178,91 @@ Result appletSetRequiresCaptureButtonShortPressedMessage(bool flag) { return _appletCmdInBool(&g_appletISelfController, flag, 18); } -Result appletSetAlbumImageOrientation(s32 val) { +Result appletSetAlbumImageOrientation(AlbumImageOrientation orientation) { if (hosversionBefore(3,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); - return _appletCmdInU32(&g_appletISelfController, val, 19); + + return _appletCmdInU32(&g_appletISelfController, orientation, 19); +} + +Result appletSetDesirableKeyboardLayout(u32 layout) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _appletCmdInU32(&g_appletISelfController, layout, 20); } Result appletCreateManagedDisplayLayer(u64 *out) { return _appletCmdNoInOut64(&g_appletISelfController, out, 40); } +Result appletSetHandlesRequestToDisplay(bool flag) { + return _appletCmdInBool(&g_appletISelfController, flag, 50); +} + +Result appletApproveToDisplay(void) { + return _appletCmdNoIO(&g_appletISelfController, 51); +} + +Result appletOverrideAutoSleepTimeAndDimmingTime(s32 inval0, s32 inval1, s32 inval2, s32 inval3) { + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + s32 inval0; + s32 inval1; + s32 inval2; + s32 inval3; + } *raw; + + raw = serviceIpcPrepareHeader(&g_appletISelfController, &c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 60; + raw->inval0 = inval0; + raw->inval1 = inval1; + raw->inval2 = inval2; + raw->inval3 = inval3; + + Result rc = serviceIpcDispatch(&g_appletISelfController); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + struct { + u64 magic; + u64 result; + } *resp; + + serviceIpcParse(&g_appletISelfController, &r, sizeof(*resp)); + resp = r.Raw; + + rc = resp->result; + } + + return rc; +} + +Result appletSetIdleTimeDetectionExtension(AppletIdleTimeDetectionExtension ext) { + return _appletCmdInU32(&g_appletISelfController, ext, 62); +} + +Result appletGetIdleTimeDetectionExtension(AppletIdleTimeDetectionExtension *ext) { + return _appletCmdNoInOut32(&g_appletISelfController, ext, 63); +} + +Result appletSetInputDetectionSourceSet(u32 val) { + return _appletCmdInU32(&g_appletISelfController, val, 64); +} + +Result appletReportUserIsActive(void) { + if (hosversionBefore(2,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _appletCmdNoIO(&g_appletISelfController, 65); +} + Result appletGetCurrentIlluminance(float *fLux) { if (hosversionBefore(3,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); @@ -2225,6 +2308,20 @@ Result appletIsIlluminanceAvailable(bool *out) { return _appletCmdNoInOutBool(&g_appletISelfController, out, 67); } +Result appletSetAutoSleepDisabled(bool flag) { + if (hosversionBefore(5,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _appletCmdInBool(&g_appletISelfController, flag, 68); +} + +Result appletIsAutoSleepDisabled(bool *out) { + if (hosversionBefore(5,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _appletCmdNoInOutBool(&g_appletISelfController, out, 69); +} + Result appletGetCurrentIlluminanceEx(bool *bOverLimit, float *fLux) { if (hosversionBefore(5,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); @@ -2265,6 +2362,13 @@ Result appletGetCurrentIlluminanceEx(bool *bOverLimit, float *fLux) { return rc; } +Result appletSetWirelessPriorityMode(AppletWirelessPriorityMode mode) { + if (hosversionBefore(4,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return _appletCmdInU32(&g_appletISelfController, mode, 80); +} + Result appletSetAlbumImageTakenNotificationEnabled(bool flag) { if (hosversionBefore(7,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); @@ -2871,6 +2975,10 @@ bool appletProcessMessage(u32 msg) { appletCallHook(AppletHookType_OnPerformanceMode); break; + case AppletNotificationMessage_RequestToDisplay: + appletCallHook(AppletHookType_RequestToDisplay); + break; + case AppletNotificationMessage_CaptureButtonShortPressed: appletCallHook(AppletHookType_OnCaptureButtonShortPressed); break;