nn::applet::CTR::ProcessHomeButton Function

Syntax

bool ProcessHomeButton(
     void
);

Parameters

None.

Return Values

Returns a value indicating whether it is necessary to wait.

Description

Processes transitions to the HOME Menu.

This function is used to jump to the HOME Menu when this is required by the nn::applet::CTR::IsExpectedToProcessHomeButton function.

The return value indicates whether it is necessary to wait with the nn::applet::CTR::WaitForStarting function after this function is called. If this is true, call the function. If this is false, you do not need to call the function. (Of course, even if you call the function it will simply exit without waiting.)

To ensure mutual exclusion with Sleep Mode, you must call nn::applet::CTR::DisableSleep(true) before calling this function. You must call nn::applet::CTR::EnableSleep(true) after waiting and determining to finish waiting. (Note that the above constraint is specific to the current version and may change in the future.)

You must also initialize the graphics library using the nngxInitialize function before calling this function. Also, after the display buffer has been set and buffers have been swapped once, you must turn on the LCD screens.

If the LCD screens are not turned on, the upper and lower screens will remain black even if you return to the HOME Menu. (Background music and sound effects will play normally, and key input will be handled as usual.) Although this function can be called even if a display buffer has not been configured, the image shown when the LCDs are turned on may be undefined.

Example

   // HOME Button transition check
   if ( applet::IsExpectedToProcessHomeButton() )
   {
       _save_my_data();
       applet::DisableSleep(true);

       // HOME Button transition process
       applet::ProcessHomeButton();

       // Wait
       applet::WaitForStarting();

       if( applet::IsExpectedToCloseApplication() )
       {
             _close_application();
       }

       applet::EnableSleep(true);
       _recover_my_data();
   }

Before calling this function, be sure that rendering has finished by calling the nngxWaitCmdlistDone function. For frameworks where multiple command lists will be swapped and commands will be created in parallel with rendering, pay close attention to the timing of nngxRunCmdlist function calls.
The GPU may hang if rendering has not completed before this function is called.
If rendering has not yet completed at the time that this function is called (while a command request is processing), execution halts on an assertion (only for the Development/Debug builds).
In addition, after returning from an applet such as the HOME Menu, be sure to reset all necessary registers because GPU register values will have been updated if the return value of nn::applet::CTR::IsExpectedToCloseApplication is false.

   /* When using the GL library */
   nngxUpdateState(NN_GX_STATE_ALL);

   /* When using the GD library */
   nn::gd::System::ForceDirty(nn::gd::MODULE_ALL);

   /* When using the GR library */
   // There is no API for returning settings because internal settings are not maintained.
   // Create all necessary commands for the next rendering pass.

   /* Others */
   // Reset all necessary registers for the next rendering pass.

If HomeButtonCallback has been set by the nn::applet::CTR::SetHomeButtonCallback function, do not call this function until after the process has left the callback. (If you call the function beforehand, the process might become deadlocked.)

Although old versions of the library had the nn::applet::CTR::ProcessHomeButtonIfPrepared function, it has the exact same behavior as this function. Use this function instead.

If any library applets have been preloaded, calling this function cancels those preloads when the transition occurs.

You need to pay attention to race conditions with this function when you preload library applets in another thread. For example, if the nn::applet::CTR::IsExpectedToProcessHomeButton function detects the HOME Button and this function is later called in the same thread but library applets are preloaded in another, an assert statement will trigger a warning because of an inconsistency in internal states.

Revision History

2012/02/07
Noted that execution halts on an assertion if rendering has not yet completed at the time this function is called.
2012/01/16
Added a specific example about limitations when calling this function (the need to wait for rendering to complete).
2011/11/01
Added precautions related to race conditions associated with preloading library applets.
2011/09/08
Added information about rendering before and after calling this function.
2011/08/01
Added information about limitations related to display buffer swapping and the LCD screens when calling this function.
2011/07/11
Added the fact that preloading of library applets is canceled when this function is called.
2011/03/30
Added note about the need for the nngxInitialize function.
2011/02/17
Added a cautionary note about setting the callback.
2011/01/24
Added mention of the DisableSleep and EnableSleep functions.
2010/12/10
Added information about the removal of ProcessHomeButtonIfPrepared.
2010/11/10
Initial version.

CONFIDENTIAL