Update windowmanager
authorKazumasa Mitsunari <knimitz@witz-inc.co.jp>
Mon, 27 Aug 2018 10:15:45 +0000 (19:15 +0900)
committerKazumasa Mitsunari <knimitz@witz-inc.co.jp>
Mon, 27 Aug 2018 10:17:24 +0000 (19:17 +0900)
Change-Id: I2b50eb89aefb4a1f5abd3c26055f4cd8961ec21d
Signed-off-by: Kazumasa Mitsunari <knimitz@witz-inc.co.jp>
src/window_manager.cpp

index 9c1a1c5..d284279 100644 (file)
@@ -183,6 +183,19 @@ int WindowManager::init()
         map_afb_event[kListEventName[i]] = afb_daemon_make_event(kListEventName[i]);
     }
 
+    const struct rect css_bg = this->lc->getAreaSize("fullscreen");
+    Screen screen = this->lc->getScreenInfo();
+    rectangle dp_bg(screen.width(), screen.height());
+
+    dp_bg.set_aspect(static_cast<double>(css_bg.w) / css_bg.h);
+    dp_bg.fit(screen.width(), screen.height());
+    dp_bg.center(screen.width(), screen.height());
+    HMI_DEBUG("SCALING: CSS BG(%dx%d) -> DDP %dx%d,(%dx%d)",
+              css_bg.w, css_bg.h, dp_bg.left(), dp_bg.top(), dp_bg.width(), dp_bg.height());
+
+    double scale = static_cast<double>(dp_bg.height()) / css_bg.h;
+    this->lc->setupArea(scale);
+
     /* this->display->add_global_handler(
         "wl_output", [this](wl_registry *r, uint32_t name, uint32_t v) {
             this->outputs.emplace_back(std::make_unique<wl::output>(r, name, v));
@@ -216,7 +229,7 @@ int WindowManager::init()
     // Third level objects
     this->display->roundtrip(); */
 
-    return init_layers();
+    return 0; //init_layers();
 }
 
 /* int WindowManager::dispatch_pending_events()
@@ -239,28 +252,29 @@ result<int> WindowManager::api_request_surface(char const *appid, char const *dr
     // TODO: application requests by old role,
     //       so convert role old to new
     const char *role = this->convertRoleOldToNew(drawing_name);
+    string l_name;
 
     // auto lid = this->layers.get_layer_id(string(role));
-    unsigned l_id = this->lc->getNewLayerID(role);
-    if (l_id != 0)
+    unsigned l_id = this->lc->getNewLayerID(role, &l_name);
+    if (l_id == 0)
     {
         /**
        * register drawing_name as fallback and make it displayed.
        */
         // lid = this->layers.get_layer_id(string("fallback"));
-        l_id = this->lc->getNewLayerID("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 (!lid)
+        if (l_id == 0)
         {
-            return Err<int>("Drawing name does not match any role, fallback is disabled");
-        } */
+            return Err<int>("Designated role does not match any role, fallback is disabled");
+        }
     }
 
     // generate surface ID for ivi-shell application
 
-    // auto rname = this->lookup_id(role);
-    // if (!rname)
-    // {
+    auto rname = this->lookup_id(role);
+    if (!rname)
+    {
         // name does not exist yet, allocate surface id...
         auto id = int(this->id_alloc.generate_id(role));
         // this->layers.add_surface(id, *lid);
@@ -275,7 +289,9 @@ result<int> WindowManager::api_request_surface(char const *appid, char const *dr
 
         // add client into the db
         string appid_str(appid);
-        if(g_app_list.contains(appid_str))
+        g_app_list.addClient(appid_str, l_id, l_name, id, string(role));
+
+        /* if(g_app_list.contains(appid_str))
         {
             // add surface into app
             auto client = g_app_list.lookUpClient(appid_str);
@@ -284,13 +300,13 @@ result<int> WindowManager::api_request_surface(char const *appid, char const *dr
         else
         {
             g_app_list.addClient(appid_str, l_id, id, string(role));
-        }
+        } */
 
         // Set role map of (new, old)
         this->rolenew2old[role] = string(drawing_name);
 
         return Ok<int>(id);
-    // }
+    }
 
     // Check currently registered drawing names if it is already there.
     return Err<int>("Surface already present");
@@ -299,27 +315,26 @@ 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)
 {
-    ;
-
     // TODO: application requests by old role,
     //       so convert role old to new
     const char *role = this->convertRoleOldToNew(drawing_name);
     string str = role;
+    string l_name;
 
     // auto lid = this->layers.get_layer_id(string(role));
-    unsigned lid = this->lc->getNewLayerID(str);
+    unsigned lid = this->lc->getNewLayerID(str, &l_name);
     unsigned sid = std::stol(ivi_id);
 
-    /* if (!lid)
+    if (lid == 0)
     {
         //register drawing_name as fallback and make it displayed.
-        // lid = this->layers.get_layer_id(string("fallback"));
+        lid = this->lc->getNewLayerID(str, &l_name);
         HMI_DEBUG("%s is not registered in layers.json, then fallback as normal app", role);
-        if (!lid)
+        if (lid == 0)
         {
             return "Drawing name does not match any role, fallback is disabled";
         }
-    } */
+    }
 
     auto rname = this->lookup_id(role);
 
@@ -340,7 +355,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, sid, string(role));
+    g_app_list.addClient(appid_str, lid, l_name, sid, string(role));
 
     // Set role map of (new, old)
     this->rolenew2old[role] = string(drawing_name);
@@ -362,27 +377,27 @@ char const *WindowManager::api_request_surface(char const *appid, char const *dr
 bool WindowManager::api_set_role(char const *appid, char const *drawing_name, unsigned pid){
     string id = appid;
     string role = drawing_name;
+    string l_name;
     unsigned surface = 0;
     WMError wm_err = WMError::UNKNOWN;
     bool ret = false;
 
     // get layer ID which role should be in
     // auto lid = this->layers.get_layer_id(role);
-    unsigned lid = this->lc->getNewLayerID(role);
-    /* if (!lid)
+    unsigned lid = this->lc->getNewLayerID(role, &l_name);
+    if (lid == 0)
     {
         // lid = this->layers.get_layer_id(string("fallback"));
         HMI_DEBUG("%s is not registered in layers.json, then fallback as normal app", role.c_str());
-        if (!lid)
+        if (lid == 0)
         {
             HMI_ERROR("Drawing name does not match any role, fallback is disabled");
             return ret;
         }
-    } */
+    }
 
     if(0 != pid){
         // search floating surfaceID from pid if pid is designated.
-        // It is not good that application request with its pid
         wm_err = g_app_list.popFloatingSurface(pid, &surface);
     }
     else{
@@ -402,15 +417,13 @@ bool WindowManager::api_set_role(char const *appid, char const *drawing_name, un
     {
         HMI_INFO("Add role: %s with surface: %d. Client %s has multi surfaces.",
                  role.c_str(), surface, id.c_str());
-        wm_err = g_app_list.appendRole(id, role, surface);
-        if(wm_err != WMError::SUCCESS){
-            HMI_INFO(errorDescription(wm_err));
-        }
+        auto client = g_app_list.lookUpClient(id);
+        client->appendRole(role);
     }
     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, surface, role);
+        g_app_list.addClient(id, lid, l_name, surface, role);
     }
 
     // register pair drawing_name and ivi_id
@@ -432,7 +445,7 @@ bool WindowManager::api_set_role(char const *appid, char const *drawing_name, un
     } */
 
     // this->controller->layers[*lid]->add_surface(surface);
-    this->layout_commit();
+    // this->layout_commit();
 
     return ret;
 }
@@ -472,6 +485,9 @@ void WindowManager::api_activate_surface(char const *appid, char const *drawing_
 
     ret = this->setRequest(id, role, area, task, &req_num);
 
+    //vector<WMLayerState> current_states = this->lc->getCurrentStates();
+    // ret = this->setRequest(id, role, area, task, current_states, &req_num);
+
     if(ret != WMError::SUCCESS)
     {
         HMI_ERROR(errorDescription(ret));
@@ -521,6 +537,8 @@ void WindowManager::api_deactivate_surface(char const *appid, char const *drawin
     WMError ret = WMError::UNKNOWN;
 
     ret = this->setRequest(id, role, area, task, &req_num);
+    //vector<WMLayerState> current_states = this->lc->getCurrentStates();
+    // ret = this->setRequest(id, role, area, task, current_states, &req_num);
 
     if (ret != WMError::SUCCESS)
     {
@@ -580,6 +598,7 @@ void WindowManager::api_enddraw(char const *appid, char const *drawing_name)
 
             // Undo state of PolicyManager
             this->pmw.undoState();
+            this->lc->undoUpdate();
         }
         this->emitScreenUpdated(current_req);
         HMI_SEQ_INFO(current_req, "Finish request status: %s", errorDescription(ret));
@@ -605,14 +624,16 @@ result<json_object *> WindowManager::api_get_display_info()
     // Set display info
 /*     size o_size = this->controller->output_size;
     size p_size = this->controller->physical_size; */
+    Screen screen = this->lc->getScreenInfo();
 
     json_object *object = json_object_new_object();
-/*     json_object_object_add(object, kKeyWidthPixel, json_object_new_int(o_size.w));
-    json_object_object_add(object, kKeyHeightPixel, json_object_new_int(o_size.h));
-    json_object_object_add(object, kKeyWidthMm, json_object_new_int(p_size.w));
-    json_object_object_add(object, kKeyHeightMm, json_object_new_int(p_size.h));
-    json_object_object_add(object, kKeyScale, json_object_new_double(this->controller->scale));
- */
+    json_object_object_add(object, kKeyWidthPixel, json_object_new_int(screen.width()));
+    json_object_object_add(object, kKeyHeightPixel, json_object_new_int(screen.height()));
+    // TODO: set size
+    json_object_object_add(object, kKeyWidthMm, json_object_new_int(0));
+    json_object_object_add(object, kKeyHeightMm, json_object_new_int(0));
+    json_object_object_add(object, kKeyScale, json_object_new_double(this->lc->scale()));
+
     return Ok<json_object *>(object);
 }