Fix window_manager.cpp used old_role
[apps/agl-service-windowmanager.git] / src / window_manager.cpp
index fc333d4..5b7f5d8 100644 (file)
@@ -260,25 +260,31 @@ result<int> WindowManager::api_request_surface(char const *appid, char const *dr
     //       so convert role old to new
     const char *role = this->convertRoleOldToNew(drawing_name);
     string l_name;
+    string s_appid = appid;
+    string s_role = role;
 
-    // auto lid = this->layers.get_layer_id(string(role));
-    unsigned l_id = this->lc->getNewLayerID(role, &l_name);
-    if (l_id == 0)
+    if(!g_app_list.contains(s_appid))
     {
-        /**
-       * register drawing_name as fallback and make it displayed.
-       */
-        // lid = this->layers.get_layer_id(string("fallback"));
-        l_id = this->lc->getNewLayerID("fallback", &l_name);
-        HMI_DEBUG("%s is not registered in layers.json, then fallback as normal app", role);
+        // auto lid = this->layers.get_layer_id(string(role));
+        unsigned l_id = this->lc->getNewLayerID(s_role, &l_name);
         if (l_id == 0)
         {
-            return Err<int>("Designated role does not match any role, fallback is disabled");
+            /**
+         * register drawing_name as fallback and make it displayed.
+         */
+            // lid = this->layers.get_layer_id(string("fallback"));
+            l_id = this->lc->getNewLayerID("fallback", &l_name);
+            HMI_DEBUG("%s is not registered in layers.json, then fallback as normal app", role);
+            if (l_id == 0)
+            {
+                return Err<int>("Designated role does not match any role, fallback is disabled");
+            }
         }
+        this->lc->createNewLayer(l_id);
+        // add client into the db
+        g_app_list.addClient(s_appid, l_id, s_role);
     }
 
-    this->lc->createNewLayer(l_id);
-
     // generate surface ID for ivi-shell application
 
     auto rname = this->id_alloc.lookup(string(role));
@@ -286,6 +292,8 @@ result<int> WindowManager::api_request_surface(char const *appid, char const *dr
     {
         // name does not exist yet, allocate surface id...
         auto id = int(this->id_alloc.generate_id(role));
+        this->tmp_surface2app[id] = s_appid;
+
         // this->layers.add_surface(id, *lid);
 
         // set the main_surface[_name] here and now
@@ -296,9 +304,7 @@ result<int> WindowManager::api_request_surface(char const *appid, char const *dr
         //     HMI_DEBUG("Set main_surface id to %u", id);
         // }
 
-        // add client into the db
-        string appid_str(appid);
-        g_app_list.addClient(appid_str, l_id, l_name, id, string(role));
+
 
         /* if(g_app_list.contains(appid_str))
         {
@@ -366,7 +372,7 @@ char const *WindowManager::api_request_surface(char const *appid, char const *dr
 
     // add client into the db
     string appid_str(appid);
-    g_app_list.addClient(appid_str, lid, l_name, sid, string(role));
+    g_app_list.addClient(appid_str, lid, string(role));
 
     // Set role map of (new, old)
     this->rolenew2old[role] = string(drawing_name);
@@ -434,7 +440,7 @@ bool WindowManager::api_set_role(char const *appid, char const *drawing_name, un
     else{
         HMI_INFO("Create new client: %s, surface: %d into layer: %d with role: %s",
                  id.c_str(), surface, lid, role.c_str());
-        g_app_list.addClient(id, lid, l_name, surface, role);
+        g_app_list.addClient(id, lid, role);
     }
 
     // register pair drawing_name and ivi_id
@@ -727,7 +733,25 @@ void WindowManager::send_event(char const *evname, char const *label, char const
  */
 void WindowManager::surface_created(uint32_t surface_id)
 {
-    HMI_DEBUG("current : %d", surface_id);
+    if(this->tmp_surface2app.count(surface_id) != 0)
+    {
+        string appid = this->tmp_surface2app[surface_id];
+        this->tmp_surface2app.erase(surface_id);
+        if(g_app_list.contains(appid))
+        {
+            auto client = g_app_list.lookUpClient(appid);
+            WMError ret = client->addSurface(surface_id);
+            HMI_INFO("Add surface %d to \"%s\"", appid.c_str());
+            if(ret != WMError::SUCCESS)
+            {
+                HMI_ERROR("Failed to add surface to client %s", client->appID().c_str());
+            }
+        }
+    }
+    else
+    {
+        HMI_NOTICE("Unknown surface %d", surface_id);
+    }
     /* this->controller->get_surface_properties(surface_id, IVI_WM_PARAM_SIZE);
 
     auto layer_id = this->layers.get_layer_id(surface_id);
@@ -841,7 +865,7 @@ void WindowManager::startTransitionWrapper(vector<WMAction> &actions)
         {
             bool found;
             auto const &surface_id = this->id_alloc.lookup(act.role);
-            string appid = g_app_list.getAppID(*surface_id, act.role, &found);
+            string appid = g_app_list.getAppID(*surface_id, &found);
             if (!found)
             {
                 if (TaskVisible::INVISIBLE == act.visible)