Change WMClient to go to layer model
[apps/agl-service-windowmanager-2017.git] / src / window_manager.cpp
index 818a3ac..beb8eac 100644 (file)
@@ -434,14 +434,14 @@ void WindowManager::api_activate_surface(char const *appid, char const *drawing_
     }
     auto client = g_app_list.lookUpClient(id);
 
-    unsigned srfc = client->surfaceID(role);
+    unsigned srfc = client->surfaceID();
     if(srfc == 0)
     {
         HMI_ERROR("wm", "role sould be set with surface");
         reply("role sould be set with surface");
         return;
     }
-    g_app_list.removeFloatingSurface(client->surfaceID(role));
+    g_app_list.removeFloatingSurface(client->surfaceID());
 
     Task task = Task::TASK_ALLOCATE;
     unsigned req_num = 0;
@@ -685,8 +685,8 @@ void WindowManager::send_event(char const *evname, char const *label, char const
 void WindowManager::surface_created(uint32_t surface_id)
 {
     // For set role function
-    HMI_DEBUG("wm", "Get surface pid");
-    this->controller->get_surface_properties(surface_id);
+    HMI_DEBUG("wm", "Get surface's owner");
+    this->controller->get_surface_properties(surface_id, IVI_WM_PARAM_SIZE);
 
     auto layer_id = this->layers.get_layer_id(surface_id);
     if (!layer_id)
@@ -716,18 +716,34 @@ void WindowManager::surface_properties(unsigned surface_id, unsigned pid)
     json_object *response;
     afb_service_call_sync("afm-main", "runners", nullptr, &response);
 
-    // pick up appid from pid from application manager
-    std::string appid;
+    // retrieve appid from pid from application manager
+    std::string appid = "";
     if(response == nullptr)
     {
         HMI_ERROR("wm", "No runners");
     }
     else
     {
+        // check appid then add it to the client
         HMI_INFO("wm", "Runners:%s", json_object_get_string(response));
+        int size = json_object_array_length(response);
+        for(int i = 0; i < size; i++)
+        {
+            json_object *j = json_object_array_get_idx(response, i);
+            const char* id = jh::getStringFromJson(j, "id");
+            int runid      = jh::getIntFromJson(j, "runid");
+            if(id && (runid > 0))
+            {
+                if(runid == pid)
+                {
+                    appid = id;
+                    break;
+                }
+            }
+        }
     }
+    json_object_put(response);
 
-    // check appid then add it to the client
     g_app_list.addFloatingSurface(appid, surface_id, pid);
 }
 
@@ -873,8 +889,6 @@ void WindowManager::surface_set_layout(int surface_id, const std::string& area)
               layer_id);
 
     // set destination to the display rectangle
-    s->set_source_rectangle(0, 0, w, h);
-    this->layout_commit();
     s->set_destination_rectangle(x, y, w, h);
 
     // update area information
@@ -1225,7 +1239,7 @@ WMError WindowManager::startTransition(unsigned req_num)
             if (g_app_list.contains(x.appid))
             {
                 auto client = g_app_list.lookUpClient(x.appid);
-                this->deactivate(client->surfaceID(x.role));
+                this->deactivate(client->surfaceID());
             }
         }
         ret = NO_LAYOUT_CHANGE;
@@ -1423,6 +1437,7 @@ WMError WindowManager::doEndDraw(unsigned req_num)
         HMI_SEQ_DEBUG(req_num, "visible %s", act.role.c_str());
         //this->lm_enddraw(act.role.c_str());
     }
+    this->layout_commit();
 
     // Change current state
     this->changeCurrentState(req_num);
@@ -1452,7 +1467,7 @@ WMError WindowManager::layoutChange(const WMAction &action)
         return WMError::SUCCESS;
     }
     auto client = g_app_list.lookUpClient(action.appid);
-    unsigned surface = client->surfaceID(action.role);
+    unsigned surface = client->surfaceID();
     if (surface == 0)
     {
         HMI_SEQ_ERROR(g_app_list.currentRequestNumber(),
@@ -1471,7 +1486,7 @@ WMError WindowManager::visibilityChange(const WMAction &action)
         return WMError::NOT_REGISTERED;
     }
     auto client = g_app_list.lookUpClient(action.appid);
-    unsigned surface = client->surfaceID(action.role);
+    unsigned surface = client->surfaceID();
     if(surface == 0)
     {
         HMI_SEQ_ERROR(g_app_list.currentRequestNumber(),
@@ -1518,7 +1533,7 @@ WMError WindowManager::changeCurrentState(unsigned req_num)
             return WMError::NOT_REGISTERED;
         }
         auto client = g_app_list.lookUpClient(action.appid);
-        auto pCurState = *this->layers.get_layout_state((int)client->surfaceID(action.role));
+        auto pCurState = *this->layers.get_layout_state((int)client->surfaceID());
         if(pCurState == nullptr)
         {
             HMI_SEQ_ERROR(req_num, "Counldn't find current status");
@@ -1532,7 +1547,7 @@ WMError WindowManager::changeCurrentState(unsigned req_num)
     for (const auto &action : actions)
     {
         auto client = g_app_list.lookUpClient(action.appid);
-        auto pLayerCurState = *this->layers.get_layout_state((int)client->surfaceID(action.role));
+        auto pLayerCurState = *this->layers.get_layout_state((int)client->surfaceID());
         if (pLayerCurState == nullptr)
         {
             HMI_SEQ_ERROR(req_num, "Counldn't find current status");
@@ -1542,7 +1557,7 @@ WMError WindowManager::changeCurrentState(unsigned req_num)
 
         if (action.visible != TaskVisible::INVISIBLE)
         {
-            surface = (int)client->surfaceID(action.role);
+            surface = (int)client->surfaceID();
             HMI_SEQ_INFO(req_num, "Change %s surface : %d, state visible area : %s",
                             action.role.c_str(), surface, action.area.c_str());
             // visible == true -> layout changes