- lid = this->layers.get_layer_id(std::string("Fallback"));
- HMI_DEBUG("wm", "%s is not registered in layers.json, then fallback as normal app", drawing_name);
- if(!lid){
- return "Drawing name does not match any role, Fallback is disabled";
- }
- }
-
- auto rname = this->lookup_id(drawing_name);
-
- if (rname) {
- return "Surface already present";
- }
-
- // register pair drawing_name and ivi_id
- this->id_alloc.register_name_id(drawing_name, sid);
- this->layers.add_surface(sid, *lid);
-
- // this surface is already created
- HMI_DEBUG("wm", "surface_id is %u, layer_id is %u", sid, *lid);
-
- this->controller->layers[*lid]->add_surface(sid);
- this->layout_commit();
-
- return nullptr;
-}
-
-result<json_object *> App::api_get_display_info() {
- // Check controller
- if (!this->controller) {
- return Err<json_object *>("ivi_controller global not available");
- }
-
- // Set display info
- compositor::size o_size = this->controller->output_size;
- compositor::size p_size = this->controller->physical_size;
-
- 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));
-
- return Ok<json_object *>(object);
-}
-
-result<json_object *> App::api_get_area_info(char const *drawing_name) {
- HMI_DEBUG("wm", "called");
-
- // Check drawing name, surface/layer id
- auto const &surface_id = this->lookup_id(drawing_name);
- if (!surface_id) {
- return Err<json_object *>("Surface does not exist");
- }
-
- if (!this->controller->surface_exists(*surface_id)) {
- return Err<json_object *>("Surface does not exist in controller!");
- }
-
- auto layer_id = this->layers.get_layer_id(*surface_id);
- if (!layer_id) {
- return Err<json_object *>("Surface is not on any layer!");
- }
-
- auto o_state = *this->layers.get_layout_state(*surface_id);
- if (o_state == nullptr) {
- return Err<json_object *>("Could not find layer for surface");
- }
-
- struct LayoutState &state = *o_state;
- if ((state.main != *surface_id) && (state.sub != *surface_id)) {
- return Err<json_object *>("Surface is inactive");
- }
-
- // Set area rectangle
- compositor::rect area_info = this->area_info[*surface_id];
- json_object *object = json_object_new_object();
- json_object_object_add(object, kKeyX, json_object_new_int(area_info.x));
- json_object_object_add(object, kKeyY, json_object_new_int(area_info.y));
- json_object_object_add(object, kKeyWidth, json_object_new_int(area_info.w));
- json_object_object_add(object, kKeyHeight, json_object_new_int(area_info.h));
-
- return Ok<json_object *>(object);
-}
-
-void App::activate(int id) {
- auto ip = this->controller->sprops.find(id);
- if (ip != this->controller->sprops.end()) {
- this->controller->surfaces[id]->set_visibility(1);
- 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 (auto i = surface_bg.begin(); i != surface_bg.end(); ++i) {
- if (id == *i) {
- // Remove id
- this->surface_bg.erase(i);
-
- // Remove from BG layer (999)
- HMI_DEBUG("wm", "Remove %s(%d) from BG layer", label, id);
- this->controller->layers[999]->remove_surface(id);
-
- // Add to FG layer (1001)
- HMI_DEBUG("wm", "Add %s(%d) to FG layer", label, id);
- this->controller->layers[1001]->add_surface(id);
-
- for (int j : this->surface_bg) {
- HMI_DEBUG("wm", "Stored id:%d", j);
- }
- break;
+ lid = this->layers.get_layer_id(std::string("Fallback"));
+ HMI_DEBUG("wm", "%s is not registered in layers.json, then fallback as normal app", role.c_str());
+ if (!lid)
+ {
+ HMI_ERROR("wm", "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{
+ // get floating surface with appid. If WM queries appid from pid,
+ // WM can bind surface and role with appid(not implemented yet)
+ //wm_err = g_app_list.popFloatingSurface(id);
+ }
+ if(wm_err != WMError::SUCCESS){
+ HMI_ERROR("wm", "No floating surface for app: %s", id.c_str());
+ g_app_list.addFloatingClient(id, *lid, role);
+ HMI_NOTICE("wm", "%s : Waiting for surface creation", id.c_str());
+ return ret;
+ }
+
+ ret = true;
+ if (g_app_list.contains(id))
+ {
+ HMI_INFO("wm", "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("wm", errorDescription(wm_err));
+ }
+ }
+ else{
+ HMI_INFO("wm", "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);
+ }
+
+ // register pair drawing_name and ivi_id
+ this->id_alloc.register_name_id(role.c_str(), surface);
+ this->layers.add_surface(surface, *lid);
+
+ // this surface is already created
+ HMI_DEBUG("wm", "surface_id is %u, layer_id is %u", surface, *lid);
+
+ const auto &o_layer = this->layers.get_layer(*lid);
+ auto rect = o_layer.value().rect;
+ if(rect.w < 0)
+ {
+ rect.w = this->controller->output_size.w + 1 + rect.w;
+ }
+ if(rect.h < 0)
+ {
+ rect.h = this->controller->output_size.h + 1 + rect.h;
+ }
+ this->controller->surfaces[surface]->set_source_rectangle(0, 0, rect.w, rect.h);
+
+ this->controller->layers[*lid]->add_surface(surface);
+ this->layout_commit();
+
+ return ret;
+}
+
+result<json_object *> App::api_get_display_info()
+{
+ // Check controller
+ if (!this->controller)
+ {
+ return Err<json_object *>("ivi_controller global not available");
+ }
+
+ // Set display info
+ compositor::size o_size = this->controller->output_size;
+ compositor::size p_size = this->controller->physical_size;
+
+ 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));
+
+ return Ok<json_object *>(object);
+}
+
+result<json_object *> App::api_get_area_info(char const *drawing_name)
+{
+ HMI_DEBUG("wm", "called");
+
+ // Check drawing name, surface/layer id
+ auto const &surface_id = this->lookup_id(drawing_name);
+ if (!surface_id)
+ {
+ return Err<json_object *>("Surface does not exist");
+ }
+
+ if (!this->controller->surface_exists(*surface_id))
+ {
+ return Err<json_object *>("Surface does not exist in controller!");
+ }
+
+ auto layer_id = this->layers.get_layer_id(*surface_id);
+ if (!layer_id)
+ {
+ return Err<json_object *>("Surface is not on any layer!");
+ }
+
+ auto o_state = *this->layers.get_layout_state(*surface_id);
+ if (o_state == nullptr)
+ {
+ return Err<json_object *>("Could not find layer for surface");
+ }
+
+ struct LayoutState &state = *o_state;
+ if ((state.main != *surface_id) && (state.sub != *surface_id))
+ {
+ return Err<json_object *>("Surface is inactive");
+ }
+
+ // Set area rectangle
+ compositor::rect area_info = this->area_info[*surface_id];
+ json_object *object = json_object_new_object();
+ json_object_object_add(object, kKeyX, json_object_new_int(area_info.x));
+ json_object_object_add(object, kKeyY, json_object_new_int(area_info.y));
+ json_object_object_add(object, kKeyWidth, json_object_new_int(area_info.w));
+ json_object_object_add(object, kKeyHeight, json_object_new_int(area_info.h));
+
+ return Ok<json_object *>(object);
+}
+
+void App::activate(int id)
+{
+ auto ip = this->controller->sprops.find(id);
+ if (ip != this->controller->sprops.end())
+ {
+ this->controller->surfaces[id]->set_visibility(1);
+ 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 (auto i = surface_bg.begin(); i != surface_bg.end(); ++i)
+ {
+ if (id == *i)
+ {
+ // Remove id
+ this->surface_bg.erase(i);
+
+ // Remove from BG layer (999)
+ HMI_DEBUG("wm", "Remove %s(%d) from BG layer", label, id);
+ this->controller->layers[999]->remove_surface(id);
+
+ // Add to FG layer (1001)
+ HMI_DEBUG("wm", "Add %s(%d) to FG layer", label, id);
+ this->controller->layers[1001]->add_surface(id);
+
+ for (int j : this->surface_bg)
+ {
+ HMI_DEBUG("wm", "Stored id:%d", j);
+ }
+ break;
+ }