X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fwindow_manager.cpp;h=22f1e22f772441e38eb40ead63234794c62a940d;hb=ceb1049ca57b0fd0ce41e9eca631557ffa46993a;hp=9537be75403d39d233b9af33c4aff0102c780bd1;hpb=fb861c2f05e5f49f4009d0d7c91101259f904f1d;p=apps%2Fagl-service-windowmanager.git diff --git a/src/window_manager.cpp b/src/window_manager.cpp index 9537be7..22f1e22 100644 --- a/src/window_manager.cpp +++ b/src/window_manager.cpp @@ -28,6 +28,7 @@ extern "C" using std::string; using std::vector; +using std::unordered_map; namespace wm { @@ -69,6 +70,9 @@ static const vector kListEventName{ static sd_event_source *g_timer_ev_src = nullptr; static AppList g_app_list; static WindowManager *g_context; +static vector white_list_area_size_change = { + "homescreen", "settings" +}; namespace { @@ -380,6 +384,99 @@ void WindowManager::api_enddraw(char const *appid, char const *drawing_name) } } +json_object* WindowManager::api_get_area_list() +{ + json_object* ret = json_object_new_object(); + json_object* jarray = json_object_new_array(); + unordered_map area2size = this->lc->getAreaList(); + for(const auto& area : area2size) + { + json_object* j = json_object_new_object(); + json_object_object_add(j, "name", json_object_new_string(area.first.c_str())); + json_object* jrect = json_object_new_object(); + json_object_object_add(jrect, "x", json_object_new_int(area.second.x)); + json_object_object_add(jrect, "y", json_object_new_int(area.second.y)); + json_object_object_add(jrect, "w", json_object_new_int(area.second.w)); + json_object_object_add(jrect, "h", json_object_new_int(area.second.h)); + json_object_object_add(j, "rect", jrect); + json_object_array_add(jarray, j); + } + json_object_object_add(ret, "areas", jarray); + HMI_DEBUG("area_list: %s", json_object_get_string(ret)); + return ret; +} + +void WindowManager::api_change_area_size(ChangeAreaReq &areas) +{ + // Error check + areas.dump(); + auto client = g_app_list.lookUpClient(areas.appname); + WMError ret; + if(client == nullptr) + { + HMI_ERROR("Call register your role with setRole or requestSurface"); + return; + } + if(std::find(white_list_area_size_change.begin(), + white_list_area_size_change.end(), client->role()) == white_list_area_size_change.end()) + { + HMI_ERROR("Application %s which has the role %s is not allowed to change area size", client->appID().c_str(), client->role().c_str()); + return; + } + + // Update + ret = this->lc->updateAreaList(areas); + if(ret != WMError::SUCCESS) + { + HMI_ERROR("%d : %s", ret, errorDescription(ret)); + return; + } + ret = this->lc->getUpdateAreaList(&areas); + areas.dump(); + if(ret != WMError::SUCCESS) + { + HMI_ERROR("%d : %s", ret, errorDescription(ret)); + return; + } + + // Create Action + unsigned req_num; + bool found = false; + ret = this->setRequest(client->appID(), client->role(), "-", Task::TASK_CHANGE_AREA, &req_num); // area is null + if(ret != WMError::SUCCESS) + { + HMI_SEQ_ERROR(req_num, "%d : %s", ret, errorDescription(ret)); + return; + } + for(const auto &update: areas.update_app2area) + { + // create action + auto client = g_app_list.lookUpClient(update.first); + if(client == nullptr) + { + HMI_SEQ_ERROR(req_num, "%s : %s", update.first.c_str(), errorDescription(ret)); + g_app_list.removeRequest(req_num); + this->processNextRequest(); + return; + } + ret = g_app_list.setAction(req_num, client, client->role(), update.second, TaskVisible::VISIBLE); + if(ret != WMError::SUCCESS) + { + HMI_SEQ_ERROR(req_num, "Failed to set request"); + return; + } + } + HMI_SEQ_INFO(req_num, "Area change request"); + g_app_list.reqDump(); + + // Request change size to applications + for(const auto &action : g_app_list.getActions(req_num, &found)) + { + struct rect r = this->lc->getAreaSize(action.area); + action.client->emitSyncDraw(action.area, r); + } +} + bool WindowManager::api_subscribe(afb_req_t req, EventType event_id) { bool ret = false; @@ -802,7 +899,7 @@ void WindowManager::emitScreenUpdated(unsigned req_num) int ret = afb_event_push( this->map_afb_event[kListEventName[Event_ScreenUpdated]], j); - if (ret != 0) + if (ret < 0) { HMI_DEBUG("afb_event_push failed: %m"); }