2 * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include "window_manager.hpp"
21 #include "json_helper.hpp"
22 #include "wm_config.hpp"
23 #include "applist.hpp"
27 #include <systemd/sd-event.h>
33 static const uint64_t kTimeOut = 3ULL; /* 3s */
35 /* DrawingArea name used by "{layout}.{area}" */
36 const char kNameLayoutNormal[] = "normal";
37 const char kNameLayoutSplit[] = "split";
38 const char kNameAreaFull[] = "full";
39 const char kNameAreaMain[] = "main";
40 const char kNameAreaSub[] = "sub";
42 /* Key for json obejct */
43 const char kKeyDrawingName[] = "drawing_name";
44 const char kKeyDrawingArea[] = "drawing_area";
45 const char kKeyDrawingRect[] = "drawing_rect";
46 const char kKeyX[] = "x";
47 const char kKeyY[] = "y";
48 const char kKeyWidth[] = "width";
49 const char kKeyHeight[] = "height";
50 const char kKeyWidthPixel[] = "width_pixel";
51 const char kKeyHeightPixel[] = "height_pixel";
52 const char kKeyWidthMm[] = "width_mm";
53 const char kKeyHeightMm[] = "height_mm";
54 const char kKeyIds[] = "ids";
56 static sd_event_source *g_timer_ev_src = nullptr;
57 static AppList g_app_list;
64 result<json> file_to_json(char const *filename)
67 std::ifstream i(filename);
70 HMI_DEBUG("wm", "Could not open config file, so use default layer information");
71 j = default_layers_json;
81 struct result<layer_map> load_layer_map(char const *filename)
83 HMI_DEBUG("wm", "loading IDs from %s", filename);
85 auto j = file_to_json(filename);
88 return Err<layer_map>(j.unwrap_err());
90 json jids = j.unwrap();
92 return to_layer_map(jids);
95 static int processTimerHandler(sd_event_source *s, uint64_t usec, void *userdata)
97 HMI_NOTICE("wm", "Time out occurs because the client replys endDraw slow, so revert the request");
98 reinterpret_cast<wm::WindowManager *>(userdata)->timerHandler();
107 WindowManager::WindowManager(wl::display *d)
114 pending_events(false)
116 char const *path_layers_json = getenv("AFM_APP_INSTALL_DIR");
118 if (!path_layers_json)
120 HMI_ERROR("wm", "AFM_APP_INSTALL_DIR is not defined");
121 path = std::string(path_layers_json);
125 path = std::string(path_layers_json) + std::string("/etc/layers.json");
131 auto l = load_layer_map(path.c_str());
134 this->layers = l.unwrap();
138 HMI_ERROR("wm", "%s", l.err().value());
142 catch (std::exception &e)
144 HMI_ERROR("wm", "Loading of configuration failed: %s", e.what());
148 int WindowManager::init()
151 if (!this->display->ok())
156 if (this->layers.mapping.empty())
158 HMI_ERROR("wm", "No surface -> layer mapping loaded");
162 // TODO: application requests by old role,
163 // so create role map (old, new)
165 this->loadOldRoleDb();
168 for (int i = Event_Val_Min; i <= Event_Val_Max; i++)
170 map_afb_event[kListEventName[i]] = afb_daemon_make_event(kListEventName[i]);
173 this->display->add_global_handler(
174 "wl_output", [this](wl_registry *r, uint32_t name, uint32_t v) {
175 this->outputs.emplace_back(std::make_unique<wl::output>(r, name, v));
178 this->display->add_global_handler(
179 "ivi_wm", [this](wl_registry *r, uint32_t name, uint32_t v) {
181 std::make_unique<struct compositor::controller>(r, name, v);
183 // Init controller hooks
184 this->controller->chooks = &this->chooks;
186 // This protocol needs the output, so lets just add our mapping here...
187 this->controller->add_proxy_to_id_mapping(
188 this->outputs.back()->proxy.get(),
189 wl_proxy_get_id(reinterpret_cast<struct wl_proxy *>(
190 this->outputs.back()->proxy.get())));
193 this->controller->create_screen(this->outputs.back()->proxy.get());
195 // Set display to controller
196 this->controller->display = this->display;
199 // First level objects
200 this->display->roundtrip();
201 // Second level objects
202 this->display->roundtrip();
203 // Third level objects
204 this->display->roundtrip();
210 int WindowManager::dispatch_pending_events()
212 if (this->pop_pending_events())
214 this->display->dispatch_pending();
220 void WindowManager::set_pending_events()
222 this->pending_events.store(true, std::memory_order_release);
225 result<int> WindowManager::api_request_surface(char const *appid, char const *drawing_name)
227 // TODO: application requests by old role,
228 // so convert role old to new
229 const char *role = this->convertRoleOldToNew(drawing_name);
231 auto lid = this->layers.get_layer_id(std::string(role));
235 * register drawing_name as fallback and make it displayed.
237 lid = this->layers.get_layer_id(std::string("fallback"));
238 HMI_DEBUG("wm", "%s is not registered in layers.json, then fallback as normal app", role);
241 return Err<int>("Drawing name does not match any role, fallback is disabled");
245 auto rname = this->lookup_id(role);
248 // name does not exist yet, allocate surface id...
249 auto id = int(this->id_alloc.generate_id(role));
250 this->layers.add_surface(id, *lid);
252 // set the main_surface[_name] here and now
253 if (!this->layers.main_surface_name.empty() &&
254 this->layers.main_surface_name == drawing_name)
256 this->layers.main_surface = id;
257 HMI_DEBUG("wm", "Set main_surface id to %u", id);
260 // add client into the db
261 std::string appid_str(appid);
262 g_app_list.addClient(appid_str, *lid, id, std::string(role));
264 // Set role map of (new, old)
265 this->rolenew2old[role] = std::string(drawing_name);
270 // Check currently registered drawing names if it is already there.
271 return Err<int>("Surface already present");
274 char const *WindowManager::api_request_surface(char const *appid, char const *drawing_name,
279 // TODO: application requests by old role,
280 // so convert role old to new
281 const char *role = this->convertRoleOldToNew(drawing_name);
283 auto lid = this->layers.get_layer_id(std::string(role));
284 unsigned sid = std::stol(ivi_id);
289 * register drawing_name as fallback and make it displayed.
291 lid = this->layers.get_layer_id(std::string("fallback"));
292 HMI_DEBUG("wm", "%s is not registered in layers.json, then fallback as normal app", role);
295 return "Drawing name does not match any role, fallback is disabled";
299 auto rname = this->lookup_id(role);
303 return "Surface already present";
306 // register pair drawing_name and ivi_id
307 this->id_alloc.register_name_id(role, sid);
308 this->layers.add_surface(sid, *lid);
310 // this surface is already created
311 HMI_DEBUG("wm", "surface_id is %u, layer_id is %u", sid, *lid);
313 this->controller->layers[*lid]->add_surface(sid);
314 this->layout_commit();
316 // add client into the db
317 std::string appid_str(appid);
318 g_app_list.addClient(appid_str, *lid, sid, std::string(role));
320 // Set role map of (new, old)
321 this->rolenew2old[role] = std::string(drawing_name);
327 * This function is substitute of requestSurface
328 * If surface creation is faster than application request of this function,
329 * WM will bind surfaceID with application and role.
330 * If surface creation is slower than application request of thie function,
331 * WM will put Client into pending list.
334 * Application can request with pid but this is temporary solution for now.
335 * This will be removed.
337 bool WindowManager::api_set_role(char const *appid, char const *drawing_name, unsigned pid){
338 std::string id = appid;
339 std::string role = drawing_name;
340 unsigned surface = 0;
341 WMError wm_err = WMError::UNKNOWN;
344 // get layer ID which role should be in
345 auto lid = this->layers.get_layer_id(role);
349 * register drawing_name as fallback and make it displayed.
351 lid = this->layers.get_layer_id(std::string("fallback"));
352 HMI_DEBUG("wm", "%s is not registered in layers.json, then fallback as normal app", role.c_str());
355 HMI_ERROR("wm", "Drawing name does not match any role, fallback is disabled");
361 // search floating surfaceID from pid if pid is designated.
362 // It is not good that application request with its pid
363 wm_err = g_app_list.popFloatingSurface(pid, &surface);
366 // get floating surface with appid. If WM queries appid from pid,
367 // WM can bind surface and role with appid(not implemented yet)
368 //wm_err = g_app_list.popFloatingSurface(id);
370 if(wm_err != WMError::SUCCESS){
371 HMI_ERROR("wm", "No floating surface for app: %s", id.c_str());
372 g_app_list.addFloatingClient(id, *lid, role);
373 HMI_NOTICE("wm", "%s : Waiting for surface creation", id.c_str());
378 if (g_app_list.contains(id))
380 HMI_INFO("wm", "Add role: %s with surface: %d. Client %s has multi surfaces.",
381 role.c_str(), surface, id.c_str());
382 wm_err = g_app_list.appendRole(id, role, surface);
383 if(wm_err != WMError::SUCCESS){
384 HMI_INFO("wm", errorDescription(wm_err));
388 HMI_INFO("wm", "Create new client: %s, surface: %d into layer: %d with role: %s",
389 id.c_str(), surface, *lid, role.c_str());
390 g_app_list.addClient(id, *lid, surface, role);
393 // register pair drawing_name and ivi_id
394 this->id_alloc.register_name_id(role.c_str(), surface);
395 this->layers.add_surface(surface, *lid);
397 // this surface is already created
398 HMI_DEBUG("wm", "surface_id is %u, layer_id is %u", surface, *lid);
400 const auto &o_layer = this->layers.get_layer(*lid);
401 auto rect = o_layer.value().rect;
404 rect.w = this->controller->output_size.w + 1 + rect.w;
408 rect.h = this->controller->output_size.h + 1 + rect.h;
411 this->controller->layers[*lid]->add_surface(surface);
412 this->layout_commit();
417 void WindowManager::api_activate_surface(char const *appid, char const *drawing_name,
418 char const *drawing_area, const reply_func &reply)
422 // TODO: application requests by old role,
423 // so convert role old to new
424 const char *c_role = this->convertRoleOldToNew(drawing_name);
426 std::string id = appid;
427 std::string role = c_role;
428 std::string area = drawing_area;
430 if(!g_app_list.contains(id))
432 reply("app doesn't request 'requestSurface' or 'setRole' yet");
435 auto client = g_app_list.lookUpClient(id);
437 unsigned srfc = client->surfaceID();
440 HMI_ERROR("wm", "role sould be set with surface");
441 reply("role sould be set with surface");
444 g_app_list.removeFloatingSurface(client->surfaceID());
446 Task task = Task::TASK_ALLOCATE;
447 unsigned req_num = 0;
448 WMError ret = WMError::UNKNOWN;
450 ret = this->setRequest(id, role, area, task, &req_num);
452 if(ret != WMError::SUCCESS)
454 HMI_ERROR("wm", errorDescription(ret));
455 reply("Failed to set request");
460 if (req_num != g_app_list.currentRequestNumber())
462 // Add request, then invoked after the previous task is finished
463 HMI_SEQ_DEBUG(req_num, "request is accepted");
470 ret = this->doTransition(req_num);
472 if (ret != WMError::SUCCESS)
475 HMI_SEQ_ERROR(req_num, errorDescription(ret));
476 g_app_list.removeRequest(req_num);
477 this->processNextRequest();
481 void WindowManager::api_deactivate_surface(char const *appid, char const *drawing_name,
482 const reply_func &reply)
486 // TODO: application requests by old role,
487 // so convert role old to new
488 const char *c_role = this->convertRoleOldToNew(drawing_name);
493 std::string id = appid;
494 std::string role = c_role;
495 std::string area = ""; //drawing_area;
496 Task task = Task::TASK_RELEASE;
497 unsigned req_num = 0;
498 WMError ret = WMError::UNKNOWN;
500 ret = this->setRequest(id, role, area, task, &req_num);
502 if (ret != WMError::SUCCESS)
504 HMI_ERROR("wm", errorDescription(ret));
505 reply("Failed to set request");
510 if (req_num != g_app_list.currentRequestNumber())
512 // Add request, then invoked after the previous task is finished
513 HMI_SEQ_DEBUG(req_num, "request is accepted");
520 ret = this->doTransition(req_num);
522 if (ret != WMError::SUCCESS)
525 HMI_SEQ_ERROR(req_num, errorDescription(ret));
526 g_app_list.removeRequest(req_num);
527 this->processNextRequest();
531 void WindowManager::api_enddraw(char const *appid, char const *drawing_name)
533 // TODO: application requests by old role,
534 // so convert role old to new
535 const char *c_role = this->convertRoleOldToNew(drawing_name);
537 std::string id = appid;
538 std::string role = c_role;
539 unsigned current_req = g_app_list.currentRequestNumber();
540 bool result = g_app_list.setEndDrawFinished(current_req, id, role);
544 HMI_ERROR("wm", "%s is not in transition state", id.c_str());
548 if (g_app_list.endDrawFullfilled(current_req))
550 // do task for endDraw
552 WMError ret = this->doEndDraw(current_req);
554 if(ret != WMError::SUCCESS)
556 //this->emit_error();
558 this->emitScreenUpdated(current_req);
559 HMI_SEQ_INFO(current_req, "Finish request status: %s", errorDescription(ret));
561 g_app_list.removeRequest(current_req);
563 this->processNextRequest();
567 HMI_SEQ_INFO(current_req, "Wait other App call endDraw");
572 result<json_object *> WindowManager::api_get_display_info()
575 if (!this->controller)
577 return Err<json_object *>("ivi_controller global not available");
581 compositor::size o_size = this->controller->output_size;
582 compositor::size p_size = this->controller->physical_size;
584 json_object *object = json_object_new_object();
585 json_object_object_add(object, kKeyWidthPixel, json_object_new_int(o_size.w));
586 json_object_object_add(object, kKeyHeightPixel, json_object_new_int(o_size.h));
587 json_object_object_add(object, kKeyWidthMm, json_object_new_int(p_size.w));
588 json_object_object_add(object, kKeyHeightMm, json_object_new_int(p_size.h));
590 return Ok<json_object *>(object);
593 result<json_object *> WindowManager::api_get_area_info(char const *drawing_name)
595 HMI_DEBUG("wm", "called");
597 // TODO: application requests by old role,
598 // so convert role old to new
599 const char *role = this->convertRoleOldToNew(drawing_name);
601 // Check drawing name, surface/layer id
602 auto const &surface_id = this->lookup_id(role);
605 return Err<json_object *>("Surface does not exist");
608 if (!this->controller->surface_exists(*surface_id))
610 return Err<json_object *>("Surface does not exist in controller!");
613 auto layer_id = this->layers.get_layer_id(*surface_id);
616 return Err<json_object *>("Surface is not on any layer!");
619 auto o_state = *this->layers.get_layout_state(*surface_id);
620 if (o_state == nullptr)
622 return Err<json_object *>("Could not find layer for surface");
625 struct LayoutState &state = *o_state;
626 if ((state.main != *surface_id) && (state.sub != *surface_id))
628 return Err<json_object *>("Surface is inactive");
631 // Set area rectangle
632 compositor::rect area_info = this->area_info[*surface_id];
633 json_object *object = json_object_new_object();
634 json_object_object_add(object, kKeyX, json_object_new_int(area_info.x));
635 json_object_object_add(object, kKeyY, json_object_new_int(area_info.y));
636 json_object_object_add(object, kKeyWidth, json_object_new_int(area_info.w));
637 json_object_object_add(object, kKeyHeight, json_object_new_int(area_info.h));
639 return Ok<json_object *>(object);
642 void WindowManager::api_ping() { this->dispatch_pending_events(); }
644 void WindowManager::send_event(char const *evname, char const *label)
646 HMI_DEBUG("wm", "%s: %s(%s)", __func__, evname, label);
648 json_object *j = json_object_new_object();
649 json_object_object_add(j, kKeyDrawingName, json_object_new_string(label));
651 int ret = afb_event_push(this->map_afb_event[evname], j);
654 HMI_DEBUG("wm", "afb_event_push failed: %m");
658 void WindowManager::send_event(char const *evname, char const *label, char const *area,
659 int x, int y, int w, int h)
661 HMI_DEBUG("wm", "%s: %s(%s, %s) x:%d y:%d w:%d h:%d",
662 __func__, evname, label, area, x, y, w, h);
664 json_object *j_rect = json_object_new_object();
665 json_object_object_add(j_rect, kKeyX, json_object_new_int(x));
666 json_object_object_add(j_rect, kKeyY, json_object_new_int(y));
667 json_object_object_add(j_rect, kKeyWidth, json_object_new_int(w));
668 json_object_object_add(j_rect, kKeyHeight, json_object_new_int(h));
670 json_object *j = json_object_new_object();
671 json_object_object_add(j, kKeyDrawingName, json_object_new_string(label));
672 json_object_object_add(j, kKeyDrawingArea, json_object_new_string(area));
673 json_object_object_add(j, kKeyDrawingRect, j_rect);
675 int ret = afb_event_push(this->map_afb_event[evname], j);
678 HMI_DEBUG("wm", "afb_event_push failed: %m");
685 void WindowManager::surface_created(uint32_t surface_id)
687 this->controller->get_surface_properties(surface_id, IVI_WM_PARAM_SIZE);
689 auto layer_id = this->layers.get_layer_id(surface_id);
692 HMI_DEBUG("wm", "Newly created surfce %d is not associated with any layer!",
697 HMI_DEBUG("wm", "surface_id is %u, layer_id is %u", surface_id, *layer_id);
699 this->controller->layers[*layer_id]->add_surface(surface_id);
700 this->layout_commit();
703 void WindowManager::surface_removed(uint32_t surface_id)
705 HMI_DEBUG("wm", "surface_id is %u", surface_id);
706 g_app_list.removeSurface(surface_id);
709 void WindowManager::surface_properties(unsigned surface_id, unsigned pid)
711 HMI_DEBUG("wm", "get surface properties");
713 // search pid from surfaceID
714 json_object *response;
715 afb_service_call_sync("afm-main", "runners", nullptr, &response);
717 // retrieve appid from pid from application manager
718 std::string appid = "";
719 if(response == nullptr)
721 HMI_ERROR("wm", "No runners");
725 // check appid then add it to the client
726 HMI_INFO("wm", "Runners:%s", json_object_get_string(response));
727 int size = json_object_array_length(response);
728 for(int i = 0; i < size; i++)
730 json_object *j = json_object_array_get_idx(response, i);
731 const char* id = jh::getStringFromJson(j, "id");
732 int runid = jh::getIntFromJson(j, "runid");
733 if(id && (runid > 0))
743 json_object_put(response);
745 g_app_list.addFloatingSurface(appid, surface_id, pid);
748 void WindowManager::removeClient(const std::string &appid)
750 HMI_DEBUG("wm", "Remove clinet %s from list", appid.c_str());
751 g_app_list.removeClient(appid);
754 void WindowManager::exceptionProcessForTransition()
756 unsigned req_num = g_app_list.currentRequestNumber();
757 HMI_SEQ_NOTICE(req_num, "Process exception handling for request. Remove current request %d", req_num);
758 g_app_list.removeRequest(req_num);
759 HMI_SEQ_NOTICE(g_app_list.currentRequestNumber(), "Process next request if exists");
760 this->processNextRequest();
763 void WindowManager::timerHandler()
765 unsigned req_num = g_app_list.currentRequestNumber();
766 HMI_SEQ_DEBUG(req_num, "Timer expired remove Request");
767 g_app_list.reqDump();
768 g_app_list.removeRequest(req_num);
769 this->processNextRequest();
773 ******* Private Functions *******
776 bool WindowManager::pop_pending_events()
779 return this->pending_events.compare_exchange_strong(
780 x, false, std::memory_order_consume);
783 optional<int> WindowManager::lookup_id(char const *name)
785 return this->id_alloc.lookup(std::string(name));
787 optional<std::string> WindowManager::lookup_name(int id)
789 return this->id_alloc.lookup(id);
795 int WindowManager::init_layers()
797 if (!this->controller)
799 HMI_ERROR("wm", "ivi_controller global not available");
803 if (this->outputs.empty())
805 HMI_ERROR("wm", "no output was set up!");
810 wm_config.loadConfigs();
812 auto &c = this->controller;
814 auto &o = this->outputs.front();
815 auto &s = c->screens.begin()->second;
816 auto &layers = c->layers;
818 this->layers.loadAreaDb();
819 const compositor::rect base = this->layers.getAreaSize("fullscreen");
821 const std::string aspect_setting = wm_config.getConfigAspect();
822 const compositor::rect scale_rect =
823 this->layers.getScaleDestRect(o->width, o->height, aspect_setting);
825 // Write output dimensions to ivi controller...
826 c->output_size = compositor::size{uint32_t(o->width), uint32_t(o->height)};
827 c->physical_size = compositor::size{uint32_t(o->physical_width),
828 uint32_t(o->physical_height)};
836 // Quick and dirty setup of layers
837 for (auto const &i : this->layers.mapping)
839 c->layer_create(i.second.layer_id, scale_rect.w, scale_rect.h);
840 auto &l = layers[i.second.layer_id];
841 l->set_source_rectangle(0, 0, base.w, base.h);
842 l->set_destination_rectangle(
843 scale_rect.x, scale_rect.y, scale_rect.w, scale_rect.h);
844 l->set_visibility(1);
845 HMI_DEBUG("wm", "Setting up layer %s (%d) for surface role match \"%s\"",
846 i.second.name.c_str(), i.second.layer_id, i.second.role.c_str());
849 // Add layers to screen
850 s->set_render_order(this->layers.layers);
852 this->layout_commit();
857 void WindowManager::surface_set_layout(int surface_id, const std::string& area)
859 if (!this->controller->surface_exists(surface_id))
861 HMI_ERROR("wm", "Surface %d does not exist", surface_id);
865 auto o_layer_id = this->layers.get_layer_id(surface_id);
869 HMI_ERROR("wm", "Surface %d is not associated with any layer!", surface_id);
873 uint32_t layer_id = *o_layer_id;
875 auto const &layer = this->layers.get_layer(layer_id);
876 auto rect = this->layers.getAreaSize(area);
877 HMI_SEQ_DEBUG(g_app_list.currentRequestNumber(), "%s : x:%d y:%d w:%d h:%d", area.c_str(),
878 rect.x, rect.y, rect.w, rect.h);
879 auto &s = this->controller->surfaces[surface_id];
886 HMI_DEBUG("wm", "surface_set_layout for surface %u on layer %u", surface_id,
889 // set destination to the display rectangle
890 s->set_destination_rectangle(x, y, w, h);
892 // update area information
893 this->area_info[surface_id].x = x;
894 this->area_info[surface_id].y = y;
895 this->area_info[surface_id].w = w;
896 this->area_info[surface_id].h = h;
898 HMI_DEBUG("wm", "Surface %u now on layer %u with rect { %d, %d, %d, %d }",
899 surface_id, layer_id, x, y, w, h);
902 void WindowManager::layout_commit()
904 this->controller->commit_changes();
905 this->display->flush();
908 void WindowManager::emit_activated(char const *label)
910 this->send_event(kListEventName[Event_Active], label);
913 void WindowManager::emit_deactivated(char const *label)
915 this->send_event(kListEventName[Event_Inactive], label);
918 void WindowManager::emit_syncdraw(char const *label, char const *area, int x, int y, int w, int h)
920 this->send_event(kListEventName[Event_SyncDraw], label, area, x, y, w, h);
923 void WindowManager::emit_syncdraw(const std::string &role, const std::string &area)
925 compositor::rect rect = this->layers.getAreaSize(area);
926 this->send_event(kListEventName[Event_SyncDraw],
927 role.c_str(), area.c_str(), rect.x, rect.y, rect.w, rect.h);
930 void WindowManager::emit_flushdraw(char const *label)
932 this->send_event(kListEventName[Event_FlushDraw], label);
935 void WindowManager::emit_visible(char const *label, bool is_visible)
937 this->send_event(is_visible ? kListEventName[Event_Visible] : kListEventName[Event_Invisible], label);
940 void WindowManager::emit_invisible(char const *label)
942 return emit_visible(label, false);
945 void WindowManager::emit_visible(char const *label) { return emit_visible(label, true); }
947 void WindowManager::activate(int id)
949 auto ip = this->controller->sprops.find(id);
950 if (ip != this->controller->sprops.end())
952 this->controller->surfaces[id]->set_visibility(1);
954 this->lookup_name(id).value_or("unknown-name").c_str();
957 if ((0 == strcmp(label, "radio")) ||
958 (0 == strcmp(label, "music")) ||
959 (0 == strcmp(label, "video")) ||
960 (0 == strcmp(label, "map")))
962 for (auto i = surface_bg.begin(); i != surface_bg.end(); ++i)
967 this->surface_bg.erase(i);
969 // Remove from BG layer (999)
970 HMI_DEBUG("wm", "Remove %s(%d) from BG layer", label, id);
971 this->controller->layers[999]->remove_surface(id);
973 // Add to FG layer (1001)
974 HMI_DEBUG("wm", "Add %s(%d) to FG layer", label, id);
975 this->controller->layers[1001]->add_surface(id);
977 for (int j : this->surface_bg)
979 HMI_DEBUG("wm", "Stored id:%d", j);
987 this->layout_commit();
989 // TODO: application requests by old role,
990 // so convert role new to old for emitting event
991 const char* old_role = this->rolenew2old[label].c_str();
993 this->emit_visible(old_role);
994 this->emit_activated(old_role);
998 void WindowManager::deactivate(int id)
1000 auto ip = this->controller->sprops.find(id);
1001 if (ip != this->controller->sprops.end())
1004 this->lookup_name(id).value_or("unknown-name").c_str();
1007 if ((0 == strcmp(label, "radio")) ||
1008 (0 == strcmp(label, "music")) ||
1009 (0 == strcmp(label, "video")) ||
1010 (0 == strcmp(label, "map")))
1014 this->surface_bg.push_back(id);
1016 // Remove from FG layer (1001)
1017 HMI_DEBUG("wm", "Remove %s(%d) from FG layer", label, id);
1018 this->controller->layers[1001]->remove_surface(id);
1020 // Add to BG layer (999)
1021 HMI_DEBUG("wm", "Add %s(%d) to BG layer", label, id);
1022 this->controller->layers[999]->add_surface(id);
1024 for (int j : surface_bg)
1026 HMI_DEBUG("wm", "Stored id:%d", j);
1031 this->controller->surfaces[id]->set_visibility(0);
1035 this->layout_commit();
1037 // TODO: application requests by old role,
1038 // so convert role new to old for emitting event
1039 const char* old_role = this->rolenew2old[label].c_str();
1041 this->emit_deactivated(old_role);
1042 this->emit_invisible(old_role);
1046 WMError WindowManager::setRequest(const std::string& appid, const std::string &role, const std::string &area,
1047 Task task, unsigned* req_num)
1049 if (!g_app_list.contains(appid))
1051 return WMError::NOT_REGISTERED;
1054 auto client = g_app_list.lookUpClient(appid);
1059 unsigned current = g_app_list.currentRequestNumber();
1060 unsigned requested_num = g_app_list.getRequestNumber(appid);
1061 if (requested_num != 0)
1063 HMI_SEQ_INFO(requested_num,
1064 "%s %s %s request is already queued", appid.c_str(), role.c_str(), area.c_str());
1065 return REQ_REJECTED;
1068 WMRequest req = WMRequest(appid, role, area, task);
1069 unsigned new_req = g_app_list.addRequest(req);
1071 g_app_list.reqDump();
1073 HMI_SEQ_DEBUG(current, "%s start sequence with %s, %s", appid.c_str(), role.c_str(), area.c_str());
1075 return WMError::SUCCESS;
1078 WMError WindowManager::doTransition(unsigned req_num)
1080 HMI_SEQ_DEBUG(req_num, "check policy");
1081 WMError ret = this->checkPolicy(req_num);
1082 if (ret != WMError::SUCCESS)
1086 HMI_SEQ_DEBUG(req_num, "Start transition.");
1087 ret = this->startTransition(req_num);
1091 WMError WindowManager::checkPolicy(unsigned req_num)
1096 // get current trigger
1099 WMError ret = WMError::LAYOUT_CHANGE_FAIL;
1100 auto trigger = g_app_list.getRequest(req_num, &found);
1103 ret = WMError::NO_ENTRY;
1106 std::string req_area = trigger.area;
1108 // >>>> Compatible with current window manager until policy manager coming
1109 if (trigger.task == Task::TASK_ALLOCATE)
1111 HMI_SEQ_DEBUG(req_num, "Check split or not");
1112 const char *msg = this->check_surface_exist(trigger.role.c_str());
1116 HMI_SEQ_ERROR(req_num, msg);
1117 ret = WMError::LAYOUT_CHANGE_FAIL;
1121 auto const &surface_id = this->lookup_id(trigger.role.c_str());
1122 auto o_state = *this->layers.get_layout_state(*surface_id);
1123 struct LayoutState &state = *o_state;
1125 unsigned curernt_sid = state.main;
1126 split = this->can_split(state, *surface_id);
1130 HMI_SEQ_DEBUG(req_num, "Split happens");
1131 // Get current visible role
1132 std::string add_role = this->lookup_name(state.main).value();
1134 std::string add_area = std::string(kNameLayoutSplit) + "." + std::string(kNameAreaMain);
1135 // Change request area
1136 req_area = std::string(kNameLayoutSplit) + "." + std::string(kNameAreaSub);
1137 HMI_SEQ_NOTICE(req_num, "Change request area from %s to %s, because split happens",
1138 trigger.area.c_str(), req_area.c_str());
1139 // set another action
1140 std::string add_name = g_app_list.getAppID(curernt_sid, add_role, &found);
1143 HMI_SEQ_ERROR(req_num, "Couldn't widhdraw with surfaceID : %d", curernt_sid);
1144 ret = WMError::NOT_REGISTERED;
1147 HMI_SEQ_INFO(req_num, "Additional split app %s, role: %s, area: %s",
1148 add_name.c_str(), add_role.c_str(), add_area.c_str());
1150 bool end_draw_finished = false;
1151 WMAction split_action{
1155 TaskVisible::VISIBLE,
1157 WMError ret = g_app_list.setAction(req_num, split_action);
1158 if (ret != WMError::SUCCESS)
1160 HMI_SEQ_ERROR(req_num, "Failed to set action");
1163 g_app_list.reqDump();
1168 HMI_SEQ_DEBUG(req_num, "split doesn't happen");
1171 // Set invisible task(Remove if policy manager finish)
1172 ret = this->setInvisibleTask(trigger.role, split);
1173 if(ret != WMError::SUCCESS)
1175 HMI_SEQ_ERROR(req_num, "Failed to set invisible task: %s", errorDescription(ret));
1179 /* get new status from Policy Manager */
1180 HMI_SEQ_NOTICE(req_num, "ATM, Policy manager does't exist, then set WMAction as is");
1181 if(trigger.role == "homescreen")
1183 // TODO : Remove when Policy Manager completed
1184 HMI_SEQ_NOTICE(req_num, "Hack. This process will be removed. Change HomeScreen code!!");
1185 req_area = "fullscreen";
1187 TaskVisible task_visible =
1188 (trigger.task == Task::TASK_ALLOCATE) ? TaskVisible::VISIBLE : TaskVisible::INVISIBLE;
1190 ret = g_app_list.setAction(req_num, trigger.appid, trigger.role, req_area, task_visible);
1191 g_app_list.reqDump();
1196 WMError WindowManager::startTransition(unsigned req_num)
1198 bool sync_draw_happen = false;
1200 WMError ret = WMError::SUCCESS;
1201 auto actions = g_app_list.getActions(req_num, &found);
1204 ret = WMError::NO_ENTRY;
1205 HMI_SEQ_ERROR(req_num,
1206 "Window Manager bug :%s : Action is not set", errorDescription(ret));
1210 for (const auto &action : actions)
1212 if (action.visible != TaskVisible::INVISIBLE)
1214 sync_draw_happen = true;
1216 // TODO: application requests by old role,
1217 // so convert role new to old for emitting event
1218 std::string old_role = this->rolenew2old[action.role];
1220 this->emit_syncdraw(old_role, action.area);
1221 /* TODO: emit event for app not subscriber
1222 if(g_app_list.contains(y.appid))
1223 g_app_list.lookUpClient(y.appid)->emit_syncdraw(y.role, y.area); */
1227 if (sync_draw_happen)
1233 // deactivate only, no syncDraw
1234 // Make it deactivate here
1235 for (const auto &x : actions)
1237 if (g_app_list.contains(x.appid))
1239 auto client = g_app_list.lookUpClient(x.appid);
1240 this->deactivate(client->surfaceID());
1243 ret = NO_LAYOUT_CHANGE;
1248 WMError WindowManager::setInvisibleTask(const std::string &role, bool split)
1250 unsigned req_num = g_app_list.currentRequestNumber();
1251 HMI_SEQ_DEBUG(req_num, "set current visible app to invisible task");
1253 auto trigger = g_app_list.getRequest(req_num, &found);
1254 // I don't check found == true here because this is checked in caller.
1255 if(trigger.role == "homescreen")
1257 HMI_SEQ_INFO(req_num, "In case of 'homescreen' visible, don't change app to invisible");
1258 return WMError::SUCCESS;
1261 // This task is copied from original actiavete surface
1262 const char *drawing_name = this->rolenew2old[role].c_str();
1263 auto const &surface_id = this->lookup_id(role.c_str());
1264 auto layer_id = this->layers.get_layer_id(*surface_id);
1265 auto o_state = *this->layers.get_layout_state(*surface_id);
1266 struct LayoutState &state = *o_state;
1267 std::string add_name, add_role;
1268 std::string add_area = "";
1270 TaskVisible task_visible = TaskVisible::INVISIBLE;
1271 bool end_draw_finished = true;
1273 for (auto const &l : this->layers.mapping)
1275 if (l.second.layer_id <= *layer_id)
1279 HMI_DEBUG("wm", "debug: main %d , sub : %d", l.second.state.main, l.second.state.sub);
1280 if (l.second.state.main != -1)
1282 //this->deactivate(l.second.state.main);
1283 surface = l.second.state.main;
1284 add_role = *this->id_alloc.lookup(surface);
1285 add_name = g_app_list.getAppID(surface, add_role, &found);
1287 return WMError::NOT_REGISTERED;
1289 HMI_SEQ_INFO(req_num, "Invisible %s", add_name.c_str());
1290 WMAction act{add_name, add_role, add_area, task_visible, end_draw_finished};
1291 g_app_list.setAction(req_num, act);
1292 l.second.state.main = -1;
1295 if (l.second.state.sub != -1)
1297 //this->deactivate(l.second.state.sub);
1298 surface = l.second.state.sub;
1299 add_role = *this->id_alloc.lookup(surface);
1300 add_name = g_app_list.getAppID(surface, add_role, &found);
1303 return WMError::NOT_REGISTERED;
1305 HMI_SEQ_INFO(req_num, "Invisible %s", add_name.c_str());
1306 WMAction act{add_name, add_role, add_area, task_visible, end_draw_finished};
1307 g_app_list.setAction(req_num, act);
1308 l.second.state.sub = -1;
1312 // change current state here, but this is hack
1313 auto layer = this->layers.get_layer(*layer_id);
1315 if (state.main == -1)
1317 HMI_DEBUG("wm", "Layout: %s", kNameLayoutNormal);
1321 if (0 != strcmp(drawing_name, "HomeScreen"))
1325 if (state.sub != *surface_id)
1327 if (state.sub != -1)
1329 //this->deactivate(state.sub);
1332 std::move(*this->id_alloc.lookup(state.sub));
1333 deact_sub.area = add_area;
1334 deact_sub.appid = g_app_list.getAppID(state.sub, deact_sub.role, &found);
1337 HMI_SEQ_ERROR(req_num, "App doesn't exist for role : %s",
1338 deact_sub.role.c_str());
1339 return WMError::NOT_REGISTERED;
1341 deact_sub.visible = task_visible;
1342 deact_sub.end_draw_finished = end_draw_finished;
1343 HMI_SEQ_DEBUG(req_num, "Set invisible task for %s", deact_sub.appid.c_str());
1344 g_app_list.setAction(req_num, deact_sub);
1347 //state = LayoutState{state.main, *surface_id};
1351 HMI_DEBUG("wm", "Layout: %s", kNameLayoutNormal);
1353 //this->surface_set_layout(*surface_id);
1354 if (state.main != *surface_id)
1356 // this->deactivate(state.main);
1357 WMAction deact_main;
1358 deact_main.role = std::move(*this->id_alloc.lookup(state.main));
1360 deact_main.area = add_area;
1361 deact_main.appid = g_app_list.getAppID(state.main, deact_main.role, &found);
1364 HMI_SEQ_DEBUG(req_num, "sub surface ddoesn't exist");
1365 return WMError::NOT_REGISTERED;
1367 deact_main.visible = task_visible;
1368 deact_main.end_draw_finished = end_draw_finished;
1369 HMI_SEQ_DEBUG(req_num, "sub surface doesn't exist");
1370 g_app_list.setAction(req_num, deact_main);
1372 if (state.sub != -1)
1374 if (state.sub != *surface_id)
1376 //this->deactivate(state.sub);
1378 deact_sub.role = std::move(*this->id_alloc.lookup(state.sub));
1380 deact_sub.area = add_area;
1381 deact_sub.appid = g_app_list.getAppID(state.sub, deact_sub.role, &found);
1384 HMI_SEQ_DEBUG(req_num, "sub surface ddoesn't exist");
1385 return WMError::NOT_REGISTERED;
1387 deact_sub.visible = task_visible;
1388 deact_sub.end_draw_finished = end_draw_finished;
1389 HMI_SEQ_DEBUG(req_num, "sub surface doesn't exist");
1390 g_app_list.setAction(req_num, deact_sub);
1393 //state = LayoutState{*surface_id};
1397 return WMError::SUCCESS;
1400 WMError WindowManager::doEndDraw(unsigned req_num)
1404 auto actions = g_app_list.getActions(req_num, &found);
1405 WMError ret = WMError::SUCCESS;
1408 ret = WMError::NO_ENTRY;
1412 HMI_SEQ_INFO(req_num, "do endDraw");
1414 // layout change and make it visible
1415 for (const auto &act : actions)
1418 if(!g_app_list.contains(act.appid)){
1419 ret = WMError::NOT_REGISTERED;
1421 ret = this->layoutChange(act);
1422 if(ret != WMError::SUCCESS)
1424 HMI_SEQ_WARNING(req_num,
1425 "Failed to manipulate surfaces while state change : %s", errorDescription(ret));
1428 ret = this->visibilityChange(act);
1429 if (ret != WMError::SUCCESS)
1431 HMI_SEQ_WARNING(req_num,
1432 "Failed to manipulate surfaces while state change : %s", errorDescription(ret));
1435 HMI_SEQ_DEBUG(req_num, "visible %s", act.role.c_str());
1436 //this->lm_enddraw(act.role.c_str());
1438 this->layout_commit();
1440 // Change current state
1441 this->changeCurrentState(req_num);
1443 HMI_SEQ_INFO(req_num, "emit flushDraw");
1445 for(const auto &act_flush : actions)
1447 if(act_flush.visible != TaskVisible::INVISIBLE)
1449 // TODO: application requests by old role,
1450 // so convert role new to old for emitting event
1451 std::string old_role = this->rolenew2old[act_flush.role];
1453 this->emit_flushdraw(old_role.c_str());
1460 WMError WindowManager::layoutChange(const WMAction &action)
1462 if (action.visible == TaskVisible::INVISIBLE)
1464 // Visibility is not change -> no redraw is required
1465 return WMError::SUCCESS;
1467 auto client = g_app_list.lookUpClient(action.appid);
1468 unsigned surface = client->surfaceID();
1471 HMI_SEQ_ERROR(g_app_list.currentRequestNumber(),
1472 "client doesn't have surface with role(%s)", action.role.c_str());
1473 return WMError::NOT_REGISTERED;
1476 WMError ret = this->setSurfaceSize(surface, action.area);
1480 WMError WindowManager::visibilityChange(const WMAction &action)
1482 HMI_SEQ_DEBUG(g_app_list.currentRequestNumber(), "Change visibility");
1483 if(!g_app_list.contains(action.appid)){
1484 return WMError::NOT_REGISTERED;
1486 auto client = g_app_list.lookUpClient(action.appid);
1487 unsigned surface = client->surfaceID();
1490 HMI_SEQ_ERROR(g_app_list.currentRequestNumber(),
1491 "client doesn't have surface with role(%s)", action.role.c_str());
1492 return WMError::NOT_REGISTERED;
1495 if (action.visible != TaskVisible::INVISIBLE)
1497 this->activate(surface); // Layout Manager task
1501 this->deactivate(surface); // Layout Manager task
1503 return WMError::SUCCESS;
1506 WMError WindowManager::setSurfaceSize(unsigned surface, const std::string &area)
1508 this->surface_set_layout(surface, area);
1510 return WMError::SUCCESS;
1513 WMError WindowManager::changeCurrentState(unsigned req_num)
1515 HMI_SEQ_DEBUG(req_num, "Change current layout state");
1516 bool trigger_found = false, action_found = false;
1517 auto trigger = g_app_list.getRequest(req_num, &trigger_found);
1518 auto actions = g_app_list.getActions(req_num, &action_found);
1519 if (!trigger_found || !action_found)
1521 HMI_SEQ_ERROR(req_num, "Action not found");
1522 return WMError::LAYOUT_CHANGE_FAIL;
1525 // Layout state reset
1526 struct LayoutState reset_state{-1, -1};
1527 HMI_SEQ_DEBUG(req_num,"Reset layout state");
1528 for (const auto &action : actions)
1530 if(!g_app_list.contains(action.appid)){
1531 return WMError::NOT_REGISTERED;
1533 auto client = g_app_list.lookUpClient(action.appid);
1534 auto pCurState = *this->layers.get_layout_state((int)client->surfaceID());
1535 if(pCurState == nullptr)
1537 HMI_SEQ_ERROR(req_num, "Counldn't find current status");
1540 pCurState->main = reset_state.main;
1541 pCurState->sub = reset_state.sub;
1544 HMI_SEQ_DEBUG(req_num, "Change state");
1545 for (const auto &action : actions)
1547 auto client = g_app_list.lookUpClient(action.appid);
1548 auto pLayerCurState = *this->layers.get_layout_state((int)client->surfaceID());
1549 if (pLayerCurState == nullptr)
1551 HMI_SEQ_ERROR(req_num, "Counldn't find current status");
1556 if (action.visible != TaskVisible::INVISIBLE)
1558 surface = (int)client->surfaceID();
1559 HMI_SEQ_INFO(req_num, "Change %s surface : %d, state visible area : %s",
1560 action.role.c_str(), surface, action.area.c_str());
1561 // visible == true -> layout changes
1562 if(action.area == "normal.full" || action.area == "split.main")
1564 pLayerCurState->main = surface;
1566 else if (action.area == "split.sub")
1568 pLayerCurState->sub = surface;
1573 pLayerCurState->main = surface;
1578 return WMError::SUCCESS;
1581 void WindowManager::emitScreenUpdated(unsigned req_num)
1584 HMI_SEQ_DEBUG(req_num, "emit screen updated");
1586 auto actions = g_app_list.getActions(req_num, &found);
1588 // create json object
1589 json_object *j = json_object_new_object();
1590 json_object *jarray = json_object_new_array();
1592 for(const auto& action: actions)
1594 if(action.visible != TaskVisible::INVISIBLE)
1596 json_object_array_add(jarray, json_object_new_string(action.appid.c_str()));
1599 json_object_object_add(j, kKeyIds, jarray);
1600 HMI_SEQ_INFO(req_num, "Visible app: %s", json_object_get_string(j));
1602 int ret = afb_event_push(
1603 this->map_afb_event[kListEventName[Event_ScreenUpdated]], j);
1606 HMI_DEBUG("wm", "afb_event_push failed: %m");
1610 void WindowManager::setTimer()
1613 if (clock_gettime(CLOCK_BOOTTIME, &ts) != 0) {
1614 HMI_ERROR("wm", "Could't set time (clock_gettime() returns with error");
1618 HMI_SEQ_DEBUG(g_app_list.currentRequestNumber(), "Timer set activate");
1619 if (g_timer_ev_src == nullptr)
1621 // firsttime set into sd_event
1622 int ret = sd_event_add_time(afb_daemon_get_event_loop(), &g_timer_ev_src,
1623 CLOCK_BOOTTIME, (uint64_t)(ts.tv_sec + kTimeOut) * 1000000ULL, 1, processTimerHandler, this);
1626 HMI_ERROR("wm", "Could't set timer");
1631 // update timer limitation after second time
1632 sd_event_source_set_time(g_timer_ev_src, (uint64_t)(ts.tv_sec + kTimeOut) * 1000000ULL);
1633 sd_event_source_set_enabled(g_timer_ev_src, SD_EVENT_ONESHOT);
1637 void WindowManager::stopTimer()
1639 unsigned req_num = g_app_list.currentRequestNumber();
1640 HMI_SEQ_DEBUG(req_num, "Timer stop");
1641 int rc = sd_event_source_set_enabled(g_timer_ev_src, SD_EVENT_OFF);
1644 HMI_SEQ_ERROR(req_num, "Timer stop failed");
1648 void WindowManager::processNextRequest()
1651 g_app_list.reqDump();
1652 unsigned req_num = g_app_list.currentRequestNumber();
1653 if (g_app_list.haveRequest())
1655 HMI_SEQ_DEBUG(req_num, "Process next request");
1656 WMError rc = doTransition(req_num);
1657 if (rc != WMError::SUCCESS)
1659 HMI_SEQ_ERROR(req_num, errorDescription(rc));
1664 HMI_SEQ_DEBUG(req_num, "Nothing Request. Waiting Request");
1668 const char* WindowManager::convertRoleOldToNew(char const *old_role)
1670 const char *new_role = nullptr;
1672 for (auto const &on : this->roleold2new)
1674 std::regex regex = std::regex(on.first);
1675 if (std::regex_match(old_role, regex))
1677 // role is old. So convert to new.
1678 new_role = on.second.c_str();
1683 if (nullptr == new_role)
1685 // role is new or fallback.
1686 new_role = old_role;
1689 HMI_DEBUG("wm", "old:%s -> new:%s", old_role, new_role);
1694 int WindowManager::loadOldRoleDb()
1696 // Get afm application installed dir
1697 char const *afm_app_install_dir = getenv("AFM_APP_INSTALL_DIR");
1698 HMI_DEBUG("wm", "afm_app_install_dir:%s", afm_app_install_dir);
1700 std::string file_name;
1701 if (!afm_app_install_dir)
1703 HMI_ERROR("wm", "AFM_APP_INSTALL_DIR is not defined");
1707 file_name = std::string(afm_app_install_dir) + std::string("/etc/old_roles.db");
1711 json_object* json_obj;
1712 int ret = jh::inputJsonFilie(file_name.c_str(), &json_obj);
1715 HMI_ERROR("wm", "Could not open old_role.db, so use default old_role information");
1716 json_obj = json_tokener_parse(kDefaultOldRoleDb);
1718 HMI_DEBUG("wm", "json_obj dump:%s", json_object_get_string(json_obj));
1721 json_object* json_cfg;
1722 if (!json_object_object_get_ex(json_obj, "old_roles", &json_cfg))
1724 HMI_ERROR("wm", "Parse Error!!");
1728 int len = json_object_array_length(json_cfg);
1729 HMI_DEBUG("wm", "json_cfg len:%d", len);
1730 HMI_DEBUG("wm", "json_cfg dump:%s", json_object_get_string(json_cfg));
1732 for (int i=0; i<len; i++)
1734 json_object* json_tmp = json_object_array_get_idx(json_cfg, i);
1736 const char* old_role = jh::getStringFromJson(json_tmp, "name");
1737 if (nullptr == old_role)
1739 HMI_ERROR("wm", "Parse Error!!");
1743 const char* new_role = jh::getStringFromJson(json_tmp, "new");
1744 if (nullptr == new_role)
1746 HMI_ERROR("wm", "Parse Error!!");
1750 this->roleold2new[old_role] = std::string(new_role);
1754 for(auto itr = this->roleold2new.begin();
1755 itr != this->roleold2new.end(); ++itr)
1757 HMI_DEBUG("wm", ">>> role old:%s new:%s",
1758 itr->first.c_str(), itr->second.c_str());
1761 // Release json_object
1762 json_object_put(json_obj);
1767 const char *WindowManager::check_surface_exist(const char *drawing_name)
1769 auto const &surface_id = this->lookup_id(drawing_name);
1772 return "Surface does not exist";
1775 if (!this->controller->surface_exists(*surface_id))
1777 return "Surface does not exist in controller!";
1780 auto layer_id = this->layers.get_layer_id(*surface_id);
1784 return "Surface is not on any layer!";
1787 auto o_state = *this->layers.get_layout_state(*surface_id);
1789 if (o_state == nullptr)
1791 return "Could not find layer for surface";
1794 HMI_DEBUG("wm", "surface %d is detected", *surface_id);
1798 bool WindowManager::can_split(struct LayoutState const &state, int new_id)
1800 if (state.main != -1 && state.main != new_id)
1802 auto new_id_layer = this->layers.get_layer_id(new_id).value();
1803 auto current_id_layer = this->layers.get_layer_id(state.main).value();
1805 // surfaces are on separate layers, don't bother.
1806 if (new_id_layer != current_id_layer)
1811 std::string const &new_id_str = this->lookup_name(new_id).value();
1812 std::string const &cur_id_str = this->lookup_name(state.main).value();
1814 auto const &layer = this->layers.get_layer(new_id_layer);
1816 HMI_DEBUG("wm", "layer info name: %s", layer->name.c_str());
1818 if (layer->layouts.empty())
1823 for (auto i = layer->layouts.cbegin(); i != layer->layouts.cend(); i++)
1825 HMI_DEBUG("wm", "%d main_match '%s'", new_id_layer, i->main_match.c_str());
1826 auto rem = std::regex(i->main_match);
1827 if (std::regex_match(cur_id_str, rem))
1829 // build the second one only if the first already matched
1830 HMI_DEBUG("wm", "%d sub_match '%s'", new_id_layer, i->sub_match.c_str());
1831 auto res = std::regex(i->sub_match);
1832 if (std::regex_match(new_id_str, res))
1834 HMI_DEBUG("wm", "layout matched!");
1844 const char* WindowManager::kDefaultOldRoleDb = "{ \
1847 \"name\": \"HomeScreen\", \
1848 \"new\": \"homescreen\" \
1851 \"name\": \"Music\", \
1852 \"new\": \"music\" \
1855 \"name\": \"MediaPlayer\", \
1856 \"new\": \"music\" \
1859 \"name\": \"Video\", \
1860 \"new\": \"video\" \
1863 \"name\": \"VideoPlayer\", \
1864 \"new\": \"video\" \
1867 \"name\": \"WebBrowser\", \
1868 \"new\": \"browser\" \
1871 \"name\": \"Radio\", \
1872 \"new\": \"radio\" \
1875 \"name\": \"Phone\", \
1876 \"new\": \"phone\" \
1879 \"name\": \"Navigation\", \
1883 \"name\": \"HVAC\", \
1887 \"name\": \"Settings\", \
1888 \"new\": \"settings\" \
1891 \"name\": \"Dashboard\", \
1892 \"new\": \"dashboard\" \
1895 \"name\": \"POI\", \
1899 \"name\": \"Mixer\", \
1900 \"new\": \"mixer\" \
1903 \"name\": \"Restriction\", \
1904 \"new\": \"restriction\" \
1907 \"name\": \"^OnScreen.*\", \
1908 \"new\": \"on_screen\" \
1916 void controller_hooks::surface_created(uint32_t surface_id)
1918 this->wmgr->surface_created(surface_id);
1921 void controller_hooks::surface_removed(uint32_t surface_id)
1923 this->wmgr->surface_removed(surface_id);
1926 void controller_hooks::surface_visibility(uint32_t /*surface_id*/,
1929 void controller_hooks::surface_destination_rectangle(uint32_t /*surface_id*/,
1935 void controller_hooks::surface_properties(uint32_t surface_id, uint32_t pid)
1937 this->wmgr->surface_properties(surface_id, pid);