Fix setRole
[apps/agl-service-windowmanager.git] / src / window_manager.cpp
index 4efae89..acfdab2 100644 (file)
@@ -198,6 +198,22 @@ result<int> WindowManager::api_request_surface(char const *appid, char const *dr
 char const *WindowManager::api_request_surface(char const *appid, char const *drawing_name,
                                      char const *ivi_id)
 {
+    unsigned sid = std::stol(ivi_id);
+
+    HMI_DEBUG("This API(requestSurfaceXDG) is for XDG Application using runXDG");
+    /*
+     * IVI-shell doesn't send surface_size event via ivi-wm protocol
+     * if the application is using XDG surface.
+     * So WM has to set surface size with original size here
+     */
+    WMError ret = this->lc->setXDGSurfaceOriginSize(sid);
+    if(ret != SUCCESS)
+    {
+        HMI_ERROR("%s", errorDescription(ret));
+        HMI_WARNING("The main user of this API is runXDG");
+        return "fail";
+    }
+
     // TODO: application requests by old role,
     //       so convert role old to new
     const char *role = this->convertRoleOldToNew(drawing_name);
@@ -226,31 +242,15 @@ char const *WindowManager::api_request_surface(char const *appid, char const *dr
         g_app_list.addClient(s_appid, l_id, s_role);
     }
 
-    unsigned sid = std::stol(ivi_id);
-
     auto rname = this->id_alloc.lookup(s_role);
     if (rname)
     {
         return "Surface already present";
     }
-    if(this->tmp_surface2app.count(sid) != 0)
-    {
-        this->tmp_surface2app.erase(sid);
-    }
-
 
     // register pair drawing_name and ivi_id
     this->id_alloc.register_name_id(role, sid);
-    // this->layers.add_surface(sid, *lid);
-
-    // this surface is already created
-    // HMI_DEBUG("surface_id is %u, layer_id is %u", sid, *lid);
-
-    // this->controller->layers[*lid]->add_surface(sid);
-    // this->layout_commit();
 
-    // add client into the db
-    // g_app_list.addClient(appid_str, lid, s_role);
     auto client = g_app_list.lookUpClient(s_appid);
     client->addSurface(sid);
 
@@ -260,7 +260,7 @@ char const *WindowManager::api_request_surface(char const *appid, char const *dr
     return nullptr;
 }
 
-bool WindowManager::api_set_role(char const *appid, char const *drawing_name, unsigned pid)
+bool WindowManager::api_set_role(char const *appid, char const *drawing_name)
 {
     bool ret = false;
 
@@ -296,13 +296,14 @@ bool WindowManager::api_set_role(char const *appid, char const *drawing_name, un
         this->rolenew2old[role] = s_role;
     }
 
-    for(auto itr = this->tmp_surface2app.begin();
-            itr != this->tmp_surface2app.end() ; ++itr)
+    // for(auto itr = this->tmp_surface2app.begin();
+    //         itr != this->tmp_surface2app.end() ; ++itr)
+    // {
+    for(auto& x : this->tmp_surface2app)
     {
-        // const auto& x : this->tmp_surface2app)
-        if(itr->second.appid == s_appid)
+        if(x.second.appid == s_appid)
         {
-            unsigned surface = itr->first;
+            unsigned surface = x.first;
             auto client = g_app_list.lookUpClient(s_appid);
             client->addSurface(surface);
             this->tmp_surface2app.erase(surface);
@@ -612,7 +613,7 @@ void WindowManager::surface_created(unsigned pid, unsigned surface_id)
         unsigned ppid = 0;
         if(!ifs.fail() && std::getline(ifs, str))
         {
-            std::sscanf(str.data(), "%*d %*s %*c %*d %d", &ppid);
+            std::sscanf(str.data(), "%*d %*s %*c %d", &ppid);
             HMI_INFO("Retrieve ppid %d", ppid);
         }
         else
@@ -662,8 +663,14 @@ void WindowManager::surface_created(unsigned pid, unsigned surface_id)
             client->addSurface(surface_id);
             this->id_alloc.register_name_id(client->role(), surface_id);
         }
-        struct TmpClient tmp_cl = {appid, ppid};
-        this->tmp_surface2app[surface_id] = tmp_cl; /* Store for requestSurfaceXDG */
+        else
+        {
+            /*
+             * Store tmp surface and appid for application
+             * who requests setRole after creating shell surface
+             */
+            this->tmp_surface2app.emplace(surface_id, TmpClient{appid, ppid});
+        }
     }
 }