Use instead enum of bool visible
[apps/agl-service-windowmanager.git] / src / app.cpp
index 2d82e95..c42ae9c 100644 (file)
@@ -578,13 +578,12 @@ WMError App::checkPolicy(unsigned req_num)
             HMI_SEQ_INFO(req_num, "Additional split app %s, role: %s, area: %s",
                          add_name.c_str(), add_role.c_str(), add_area.c_str());
             // Set split action
-            bool visible = true;
             bool end_draw_finished = false;
             WMAction split_action{
                 add_name,
                 add_role,
                 add_area,
-                visible,
+                TaskVisible::VISIBLE,
                 end_draw_finished};
             WMError ret = g_app_list.setAction(req_num, split_action);
             if (ret != WMError::SUCCESS)
@@ -610,8 +609,9 @@ WMError App::checkPolicy(unsigned req_num)
 
     /*  get new status from Policy Manager */
     HMI_SEQ_NOTICE(req_num, "ATM, Policy manager does't exist, then set WMAction as is");
+    TaskVisible task_visible = (trigger.task == Task::TASK_ALLOCATE) ? TaskVisible::VISIBLE : TaskVisible::INVISIBLE;
 
-    ret = g_app_list.setAction(req_num, trigger.appid, trigger.role, req_area, trigger.task);
+    ret = g_app_list.setAction(req_num, trigger.appid, trigger.role, req_area, task_visible);
     g_app_list.reqDump();
 
     return ret;
@@ -632,7 +632,7 @@ WMError App::startTransition(unsigned req_num)
 
     for (const auto &y : actions)
     {
-        if (y.visible)
+        if (y.visible != TaskVisible::INVISIBLE)
         {
             sync_draw_happen = true;
             this->emit_syncdraw(y.role, y.area);
@@ -676,7 +676,7 @@ WMError App::setInvisibleTask(const std::string &role, bool split)
     std::string add_name, add_role;
     std::string add_area = "";
     int surface;
-    bool visible = false;
+    TaskVisible task_visible = TaskVisible::INVISIBLE;
     bool end_draw_finished = true;
     bool found = false;
 
@@ -696,7 +696,7 @@ WMError App::setInvisibleTask(const std::string &role, bool split)
                 return WMError::NOT_REGISTERED;
             }
             HMI_SEQ_INFO(req, "Invisible %s", add_name.c_str());
-            WMAction act{add_name, add_role, add_area, visible, end_draw_finished};
+            WMAction act{add_name, add_role, add_area, task_visible, end_draw_finished};
             g_app_list.setAction(req, act);
             l.second.state.main = -1;
         }
@@ -712,7 +712,7 @@ WMError App::setInvisibleTask(const std::string &role, bool split)
                 return WMError::NOT_REGISTERED;
             }
             HMI_SEQ_INFO(req, "Invisible %s", add_name.c_str());
-            WMAction act{add_name, add_role, add_area, visible, end_draw_finished};
+            WMAction act{add_name, add_role, add_area, task_visible, end_draw_finished};
             g_app_list.setAction(req, act);
             l.second.state.sub = -1;
         }
@@ -756,7 +756,7 @@ WMError App::setInvisibleTask(const std::string &role, bool split)
                             HMI_SEQ_DEBUG(req, "sub surface ddoesn't exist");
                             return WMError::NOT_REGISTERED;
                         }
-                        deact_sub.visible = visible;
+                        deact_sub.visible = task_visible;
                         deact_sub.end_draw_finished = end_draw_finished;
                         HMI_SEQ_DEBUG(req, "sub surface ddoesn't exist");
                         g_app_list.setAction(req, deact_sub);
@@ -782,7 +782,7 @@ WMError App::setInvisibleTask(const std::string &role, bool split)
                         HMI_SEQ_DEBUG(req, "sub surface ddoesn't exist");
                         return WMError::NOT_REGISTERED;
                     }
-                    deact_main.visible = visible;
+                    deact_main.visible = task_visible;
                     deact_main.end_draw_finished = end_draw_finished;
                     HMI_SEQ_DEBUG(req, "sub surface doesn't exist");
                     g_app_list.setAction(req, deact_main);
@@ -802,7 +802,7 @@ WMError App::setInvisibleTask(const std::string &role, bool split)
                             HMI_SEQ_DEBUG(req, "sub surface ddoesn't exist");
                             return WMError::NOT_REGISTERED;
                         }
-                        deact_sub.visible = visible;
+                        deact_sub.visible = task_visible;
                         deact_sub.end_draw_finished = end_draw_finished;
                         HMI_SEQ_DEBUG(req, "sub surface ddoesn't exist");
                         g_app_list.setAction(req, deact_sub);
@@ -812,7 +812,6 @@ WMError App::setInvisibleTask(const std::string &role, bool split)
             }
         }
     }
-
     return WMError::SUCCESS;
 }
 
@@ -1020,8 +1019,8 @@ WMError App::doEndDraw(unsigned req_num)
     }
 
     HMI_SEQ_INFO(req_num, "do endDraw");
-    // layout change and make it visible
 
+    // layout change and make it visible
     for (const auto &act : actions)
     {
         // layout change
@@ -1044,11 +1043,14 @@ WMError App::doEndDraw(unsigned req_num)
         //this->lm_enddraw(act.role.c_str());
     }
 
+    // Change current state
+    this->changeCurrentState(req_num);
+
     HMI_SEQ_INFO(req_num, "emit flushDraw");
 
     for(const auto &act_flush : actions)
     {
-        if(act_flush.visible)
+        if(act_flush.visible != TaskVisible::INVISIBLE)
         {
             this->emit_flushdraw(act_flush.role.c_str());
         }
@@ -1066,8 +1068,9 @@ WMError App::setSurfaceSize(unsigned surface, const std::string &area)
 
 WMError App::layoutChange(const WMAction &action)
 {
-    if (action.visible == false)
+    if (action.visible == TaskVisible::INVISIBLE)
     {
+        // Visibility is not change -> no redraw is required
         return WMError::SUCCESS;
     }
     auto client = g_app_list.lookUpClient(action.appid);
@@ -1094,7 +1097,7 @@ WMError App::visibilityChange(const WMAction &action)
         return WMError::NOT_REGISTERED;
     }
 
-    if (action.visible)
+    if (action.visible != TaskVisible::INVISIBLE)
     {
         this->activate(surface); // Layout Manager task
     }
@@ -1105,6 +1108,52 @@ WMError App::visibilityChange(const WMAction &action)
     return WMError::SUCCESS;
 }
 
+WMError App::changeCurrentState(unsigned req_num)
+{
+    HMI_SEQ_DEBUG(req_num, "Change current layout status");
+    bool found = false;
+    auto actions = g_app_list.getActions(req_num, &found);
+    if(!found)
+    {
+        HMI_SEQ_ERROR(req_num, "Action not found");
+        return WMError::LAYOUT_CHANGE_FAIL;
+    }
+
+    struct LayoutState state;
+    std::vector<std::string> areas;
+    bool state_change = false;
+
+    for(const auto &action : actions)
+    {
+        if(action.visible != TaskVisible::INVISIBLE)
+        {
+            // visible == true -> layout changes
+            areas.push_back(action.area);
+            auto client = g_app_list.lookUpClient(action.appid);
+            if(action.area == "normal.full" || action.area == "split.main")
+            {
+                state.main = (int)client->surfaceID(action.role);
+            }
+            else if(action.role == "split.sub")
+            {
+                state.sub = (int)client->surfaceID(action.role);
+            }
+            state_change = true;
+        }
+    }
+
+    if(state_change)
+    {
+        auto trigger = g_app_list.getRequest(req_num, &found);
+        auto client = g_app_list.lookUpClient(trigger.appid);
+        auto pCurState = *this->layers.get_layout_state((int)client->surfaceID(trigger.role));
+        struct LayoutState &curState = *pCurState;
+        curState = state;
+    }
+
+    return WMError::SUCCESS;
+}
+
 void App::api_enddraw(char const *appid, char const *drawing_name)
 {
     std::string id = appid;
@@ -1440,8 +1489,11 @@ void App::activate(int id)
         char const *label =
             this->lookup_name(id).value_or("unknown-name").c_str();
 
-        // FOR CES DEMO >>>
-        if ((0 == strcmp(label, "Radio")) || (0 == strcmp(label, "MediaPlayer")) || (0 == strcmp(label, "Music")) || (0 == strcmp(label, "Navigation")))
+         // FOR CES DEMO >>>
+        if ((0 == strcmp(label, "Radio"))       ||
+            (0 == strcmp(label, "MediaPlayer")) ||
+            (0 == strcmp(label, "Music"))       ||
+            (0 == strcmp(label, "Navigation")))
         {
             for (auto i = surface_bg.begin(); i != surface_bg.end(); ++i)
             {