Move to launcher when the top application is terminated
[apps/agl-service-windowmanager-2017.git] / src / window_manager.cpp
index aa42d82..e785e4b 100644 (file)
@@ -37,6 +37,7 @@ const char kNameLayoutSplit[]  = "split";
 const char kNameAreaFull[]     = "full";
 const char kNameAreaMain[]     = "main";
 const char kNameAreaSub[]      = "sub";
+const char kNameAreaDefault[]  = "normal.full";
 
 /* Key for json obejct */
 const char kKeyDrawingName[] = "drawing_name";
@@ -620,6 +621,70 @@ void WindowManager::timerHandler()
     this->processNextRequest();
 }
 
+void WindowManager::onApplicationTerminated(const WMClientCtxt& ctxt)
+{
+    if(!g_app_list.contains(ctxt.name))
+    {
+        return;
+    }
+    struct LayoutState priv;
+    bool found = false;
+    auto client = g_app_list.lookUpClient(ctxt.name);
+    unsigned sid = client->surfaceID(ctxt.role);
+    if(sid == 0) {
+        auto pSid = this->id_alloc.lookup(ctxt.role.c_str());
+        if(pSid) {
+            sid = *pSid;
+        }
+    }
+    // reset state
+    if(sid != 0)
+    {
+        auto o_state = *this->layers.get_layout_state(sid);
+        if (o_state != nullptr)
+        {
+            priv = *o_state;
+            if (o_state->main == sid)
+            {
+                o_state->main = -1;
+            }
+            else if (o_state->sub == sid)
+            {
+                o_state->sub = -1;
+            }
+        }
+        this->id_alloc.remove_id(sid);
+        this->layers.remove_surface(sid);
+        HMI_INFO("wm", "delete surfaceID %d", sid);
+    }
+
+    // Recovery Phase
+    if(priv.main == sid)
+    {
+        HMI_DEBUG("wm", "go to launcher");
+        if(ctxt.role != "launcher")
+        {
+            // goto launcher
+            auto pSid = this->id_alloc.lookup("launcher");
+            std::string app = g_app_list.getAppID(*pSid, "launcher", &found);
+            if(found)
+            {
+                this->api_activate_surface(app.c_str(), "launcher", kNameAreaDefault,
+                    [](const char*){});
+            }
+        }
+    }
+    else if(priv.main != sid && priv.sub != sid)
+    {
+        // re-show top surface
+        this->deactivate(priv.main);
+        this->activate(priv.main);
+        this->layout_commit();
+    }
+    else {}
+    g_app_list.removeClient(ctxt.name);
+}
+
 /*
  ******* Private Functions *******
  */