Earlier than brew 3.x, background applications did not respond to suspend and resume events at all, and also handled interactive operations related to end users, such as key events.
After brew 3.x, any application can process the key event, which can be simply implemented by registering a notification with the nmask_shell_key mask. Use the ishell_startbackgroundapplet () to directly start a background application. The background application can directly process the evt_app_start_background event rather than the evt_app_start event. In brew 2. in X, you can set * (dwparam) to false when you call ishell_closeapplet () and receive evt_app_stop, for example (* (oolean *) dwparam) = false.
A brew application communicates with a background application, or the background application and another background application by event transmission. There are three conditions for terminating the background running status of a background application. The first is to receive events from other applications. The other is to call the ishell_closeapplet () the other is that the background application calls ishell_startapplet () to make itself in the foreground running state, and then closes itself through user interaction.
The following is an example of using backend applications in brew2.x:
Typedef struct _ bgapp
{
Aeeapplet;
Oolean m_bgobg; // used to toggle whether to run in background Mode
} Bgapp;
......
Switch (ecode)
{
Case evt_app_start:
If (PME-> m_bgobg)
Ishell_closeapplet (PME-> A. m_pishell, false); // send applet to background
Return true;
Case evt_app_stop:
If (PME-> m_bgobg)
* (Oolean *) dwparam) = false; // set dwparam to run in BG
Return true;
Case evt_user:
If (PME-> m_bgobg)
{
PME-> m_bgobg = false;
Ishell_startapplet (PME-> A. m_pishell, aeeclsid_bgapp); // make applet active
} Else {
PME-> m_bgobg = true;
// Trigger evt_app_stop to send app to background
Ishell_closeapplet (PME-> A. m_pishell, false );
}
Return true;
}