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.
18 #include "json_helper.hpp"
22 #include "wayland_ivi_wm.hpp"
29 #include <json-c/json.h>
41 /* DrawingArea name used by "{layout}.{area}" */
42 const char kNameLayoutNormal[] = "normal";
43 const char kNameLayoutSplit[] = "split";
44 const char kNameAreaFull[] = "full";
45 const char kNameAreaMain[] = "main";
46 const char kNameAreaSub[] = "sub";
48 /* Key for json obejct */
49 const char kKeyDrawingName[] = "drawing_name";
50 const char kKeyDrawingArea[] = "drawing_area";
51 const char kKeyDrawingRect[] = "drawing_rect";
52 const char kKeyX[] = "x";
53 const char kKeyY[] = "y";
54 const char kKeyWidth[] = "width";
55 const char kKeyHeight[] = "height";
56 const char kKeyWidthPixel[] = "width_pixel";
57 const char kKeyHeightPixel[] = "height_pixel";
58 const char kKeyWidthMm[] = "width_mm";
59 const char kKeyHeightMm[] = "height_mm";
66 result<json> file_to_json(char const *filename) {
68 std::ifstream i(filename);
70 HMI_DEBUG("wm", "Could not open config file, so use default layer information");
71 j = default_layers_json;
80 struct result<layer_map> load_layer_map(char const *filename) {
81 HMI_DEBUG("wm", "loading IDs from %s", filename);
83 auto j = file_to_json(filename);
85 return Err<layer_map>(j.unwrap_err());
87 json jids = j.unwrap();
89 return to_layer_map(jids);
98 App::App(wl::display *d)
106 pending_events(false),
110 auto l = load_layer_map(
111 this->config.get_string("layers.json").value().c_str());
113 this->layers = l.unwrap();
115 HMI_ERROR("wm", "%s", l.err().value());
118 } catch (std::exception &e) {
119 HMI_ERROR("wm", "Loading of configuration failed: %s", e.what());
124 if (!this->display->ok()) {
128 if (this->layers.mapping.empty()) {
129 HMI_ERROR("wm", "No surface -> layer mapping loaded");
134 for (int i=Event_Val_Min; i<=Event_Val_Max; i++) {
135 map_afb_event[kListEventName[i]] = afb_daemon_make_event(kListEventName[i]);
138 this->display->add_global_handler(
139 "wl_output", [this](wl_registry *r, uint32_t name, uint32_t v) {
140 this->outputs.emplace_back(std::make_unique<wl::output>(r, name, v));
143 this->display->add_global_handler(
144 "ivi_wm", [this](wl_registry *r, uint32_t name, uint32_t v) {
146 std::make_unique<struct compositor::controller>(r, name, v);
148 // Init controller hooks
149 this->controller->chooks = &this->chooks;
151 // This protocol needs the output, so lets just add our mapping here...
152 this->controller->add_proxy_to_id_mapping(
153 this->outputs.back()->proxy.get(),
154 wl_proxy_get_id(reinterpret_cast<struct wl_proxy *>(
155 this->outputs.back()->proxy.get())));
158 this->controller->create_screen(this->outputs.back()->proxy.get());
160 // Set display to controller
161 this->controller->display = this->display;
164 // First level objects
165 this->display->roundtrip();
166 // Second level objects
167 this->display->roundtrip();
168 // Third level objects
169 this->display->roundtrip();
171 return init_layers();
174 int App::dispatch_pending_events() {
175 if (this->pop_pending_events()) {
176 this->display->dispatch_pending();
182 bool App::pop_pending_events() {
184 return this->pending_events.compare_exchange_strong(
185 x, false, std::memory_order_consume);
188 void App::set_pending_events() {
189 this->pending_events.store(true, std::memory_order_release);
192 optional<int> App::lookup_id(char const *name) {
193 return this->id_alloc.lookup(std::string(name));
195 optional<std::string> App::lookup_name(int id) {
196 return this->id_alloc.lookup(id);
202 int App::init_layers() {
203 if (!this->controller) {
204 HMI_ERROR("wm", "ivi_controller global not available");
208 if (this->outputs.empty()) {
209 HMI_ERROR("wm", "no output was set up!");
213 auto &c = this->controller;
215 auto &o = this->outputs.front();
216 auto &s = c->screens.begin()->second;
217 auto &layers = c->layers;
219 // Write output dimensions to ivi controller...
220 c->output_size = compositor::size{uint32_t(o->width), uint32_t(o->height)};
221 c->physical_size = compositor::size{uint32_t(o->physical_width),
222 uint32_t(o->physical_height)};
230 // Quick and dirty setup of layers
231 for (auto const &i : this->layers.mapping) {
232 c->layer_create(i.second.layer_id, o->width, o->height);
233 auto &l = layers[i.second.layer_id];
234 l->set_destination_rectangle(0, 0, o->width, o->height);
235 l->set_visibility(1);
236 HMI_DEBUG("wm", "Setting up layer %s (%d) for surface role match \"%s\"",
237 i.second.name.c_str(), i.second.layer_id, i.second.role.c_str());
240 // Add layers to screen
241 s->set_render_order(this->layers.layers);
243 this->layout_commit();
248 void App::surface_set_layout(int surface_id, optional<int> sub_surface_id) {
249 if (!this->controller->surface_exists(surface_id)) {
250 HMI_ERROR("wm", "Surface %d does not exist", surface_id);
254 auto o_layer_id = this->layers.get_layer_id(surface_id);
257 HMI_ERROR("wm", "Surface %d is not associated with any layer!", surface_id);
261 uint32_t layer_id = *o_layer_id;
263 auto const &layer = this->layers.get_layer(layer_id);
264 auto rect = layer.value().rect;
265 auto &s = this->controller->surfaces[surface_id];
272 // less-than-0 values refer to MAX + 1 - $VALUE
273 // e.g. MAX is either screen width or height
275 w = this->controller->output_size.w + 1 + w;
278 h = this->controller->output_size.h + 1 + h;
281 if (sub_surface_id) {
282 if (o_layer_id != this->layers.get_layer_id(*sub_surface_id)) {
284 "surface_set_layout: layers of surfaces (%d and %d) don't match!",
285 surface_id, *sub_surface_id);
292 // split along major axis
301 auto &ss = this->controller->surfaces[*sub_surface_id];
303 HMI_DEBUG("wm", "surface_set_layout for sub surface %u on layer %u",
304 *sub_surface_id, layer_id);
306 // set destination to the display rectangle
307 ss->set_destination_rectangle(x + x_off, y + y_off, w, h);
309 this->area_info[*sub_surface_id].x = x;
310 this->area_info[*sub_surface_id].y = y;
311 this->area_info[*sub_surface_id].w = w;
312 this->area_info[*sub_surface_id].h = h;
315 HMI_DEBUG("wm", "surface_set_layout for surface %u on layer %u", surface_id,
318 // set destination to the display rectangle
319 s->set_destination_rectangle(x, y, w, h);
321 // update area information
322 this->area_info[surface_id].x = x;
323 this->area_info[surface_id].y = y;
324 this->area_info[surface_id].w = w;
325 this->area_info[surface_id].h = h;
327 HMI_DEBUG("wm", "Surface %u now on layer %u with rect { %d, %d, %d, %d }",
328 surface_id, layer_id, x, y, w, h);
331 void App::layout_commit() {
332 this->controller->commit_changes();
333 this->display->flush();
336 char const *App::api_activate_surface(char const *drawing_name, char const *drawing_area) {
339 auto const &surface_id = this->lookup_id(drawing_name);
342 return "Surface does not exist";
345 if (!this->controller->surface_exists(*surface_id)) {
346 return "Surface does not exist in controller!";
349 auto layer_id = this->layers.get_layer_id(*surface_id);
352 return "Surface is not on any layer!";
355 auto o_state = *this->layers.get_layout_state(*surface_id);
357 if (o_state == nullptr) {
358 return "Could not find layer for surface";
361 struct LayoutState &state = *o_state;
363 // disable layers that are above our current layer
364 for (auto const &l : this->layers.mapping) {
365 if (l.second.layer_id <= *layer_id) {
370 if (l.second.state.main != -1) {
371 this->deactivate(l.second.state.main);
372 l.second.state.main = -1;
376 if (l.second.state.sub != -1) {
377 this->deactivate(l.second.state.sub);
378 l.second.state.sub = -1;
383 this->layout_commit();
387 auto layer = this->layers.get_layer(*layer_id);
389 if (state.main == -1) {
391 state, LayoutState{*surface_id}, [&] (LayoutState const &nl) {
392 HMI_DEBUG("wm", "Layout: %s", kNameLayoutNormal);
393 this->surface_set_layout(*surface_id);
396 // Commit for configuraton
397 this->layout_commit();
399 std::string str_area = std::string(kNameLayoutNormal) + "." + std::string(kNameAreaFull);
400 compositor::rect area_rect = this->area_info[*surface_id];
401 this->emit_syncdraw(drawing_name, str_area.c_str(),
402 area_rect.x, area_rect.y, area_rect.w, area_rect.h);
403 this->enqueue_flushdraw(state.main);
406 if (0 == strcmp(drawing_name, "HomeScreen")) {
408 state, LayoutState{*surface_id}, [&] (LayoutState const &nl) {
409 HMI_DEBUG("wm", "Layout: %s", kNameLayoutNormal);
410 std::string str_area = std::string(kNameLayoutNormal) + "." + std::string(kNameAreaFull);
411 compositor::rect area_rect = this->area_info[*surface_id];
412 this->emit_syncdraw(drawing_name, str_area.c_str(),
413 area_rect.x, area_rect.y, area_rect.w, area_rect.h);
414 this->enqueue_flushdraw(state.main);
417 bool can_split = this->can_split(state, *surface_id);
422 LayoutState{state.main, *surface_id},
423 [&] (LayoutState const &nl) {
424 HMI_DEBUG("wm", "Layout: %s", kNameLayoutSplit);
426 std::move(*this->lookup_name(state.main));
428 this->surface_set_layout(state.main, surface_id);
429 if (state.sub != *surface_id) {
430 if (state.sub != -1) {
431 this->deactivate(state.sub);
436 // Commit for configuration and visibility(0)
437 this->layout_commit();
439 std::string str_area_main = std::string(kNameLayoutSplit) + "." + std::string(kNameAreaMain);
440 std::string str_area_sub = std::string(kNameLayoutSplit) + "." + std::string(kNameAreaSub);
441 compositor::rect area_rect_main = this->area_info[state.main];
442 compositor::rect area_rect_sub = this->area_info[*surface_id];
443 this->emit_syncdraw(main.c_str(), str_area_main.c_str(),
444 area_rect_main.x, area_rect_main.y,
445 area_rect_main.w, area_rect_main.h);
446 this->emit_syncdraw(drawing_name, str_area_sub.c_str(),
447 area_rect_sub.x, area_rect_sub.y,
448 area_rect_sub.w, area_rect_sub.h);
449 this->enqueue_flushdraw(state.main);
450 this->enqueue_flushdraw(state.sub);
454 state, LayoutState{*surface_id}, [&] (LayoutState const &nl) {
455 HMI_DEBUG("wm", "Layout: %s", kNameLayoutNormal);
457 this->surface_set_layout(*surface_id);
458 if (state.main != *surface_id) {
459 this->deactivate(state.main);
461 if (state.sub != -1) {
462 if (state.sub != *surface_id) {
463 this->deactivate(state.sub);
468 // Commit for configuraton and visibility(0)
469 this->layout_commit();
471 std::string str_area = std::string(kNameLayoutNormal) + "." + std::string(kNameAreaFull);
472 compositor::rect area_rect = this->area_info[*surface_id];
473 this->emit_syncdraw(drawing_name, str_area.c_str(),
474 area_rect.x, area_rect.y, area_rect.w, area_rect.h);
475 this->enqueue_flushdraw(state.main);
485 char const *App::api_deactivate_surface(char const *drawing_name) {
487 auto const &surface_id = this->lookup_id(drawing_name);
490 return "Surface does not exist";
493 if (*surface_id == this->layers.main_surface) {
494 return "Cannot deactivate main_surface";
497 auto o_state = *this->layers.get_layout_state(*surface_id);
499 if (o_state == nullptr) {
500 return "Could not find layer for surface";
503 struct LayoutState &state = *o_state;
505 if (state.main == -1) {
506 return "No surface active";
509 // Check against main_surface, main_surface_name is the configuration item.
510 if (*surface_id == this->layers.main_surface) {
511 HMI_DEBUG("wm", "Refusing to deactivate main_surface %d", *surface_id);
515 if (state.main == *surface_id) {
516 if (state.sub != -1) {
518 state, LayoutState{state.sub, -1}, [&] (LayoutState const &nl) {
519 std::string sub = std::move(*this->lookup_name(state.sub));
521 this->deactivate(*surface_id);
522 this->surface_set_layout(state.sub);
525 this->layout_commit();
526 std::string str_area = std::string(kNameLayoutNormal) + "." + std::string(kNameAreaFull);
527 compositor::rect area_rect = this->area_info[state.sub];
528 this->emit_syncdraw(sub.c_str(), str_area.c_str(),
529 area_rect.x, area_rect.y, area_rect.w, area_rect.h);
530 this->enqueue_flushdraw(state.sub);
533 this->try_layout(state, LayoutState{-1, -1}, [&] (LayoutState const &nl) {
534 this->deactivate(*surface_id);
536 this->layout_commit();
539 } else if (state.sub == *surface_id) {
541 state, LayoutState{state.main, -1}, [&] (LayoutState const &nl) {
542 std::string main = std::move(*this->lookup_name(state.main));
544 this->deactivate(*surface_id);
545 this->surface_set_layout(state.main);
548 this->layout_commit();
549 std::string str_area = std::string(kNameLayoutNormal) + "." + std::string(kNameAreaFull);
550 compositor::rect area_rect = this->area_info[state.main];
551 this->emit_syncdraw(main.c_str(), str_area.c_str(),
552 area_rect.x, area_rect.y, area_rect.w, area_rect.h);
553 this->enqueue_flushdraw(state.main);
556 return "Surface is not active";
562 void App::enqueue_flushdraw(int surface_id) {
563 this->check_flushdraw(surface_id);
564 HMI_DEBUG("wm", "Enqueuing EndDraw for surface_id %d", surface_id);
565 this->pending_end_draw.push_back(surface_id);
568 void App::check_flushdraw(int surface_id) {
569 auto i = std::find(std::begin(this->pending_end_draw),
570 std::end(this->pending_end_draw), surface_id);
571 if (i != std::end(this->pending_end_draw)) {
572 auto n = this->lookup_name(surface_id);
573 HMI_ERROR("wm", "Application %s (%d) has pending EndDraw call(s)!",
574 n ? n->c_str() : "unknown-name", surface_id);
575 std::swap(this->pending_end_draw[std::distance(
576 std::begin(this->pending_end_draw), i)],
577 this->pending_end_draw.back());
578 this->pending_end_draw.resize(this->pending_end_draw.size() - 1);
582 char const *App::api_enddraw(char const *drawing_name) {
583 for (unsigned i = 0, iend = this->pending_end_draw.size(); i < iend; i++) {
584 auto n = this->lookup_name(this->pending_end_draw[i]);
585 if (n && *n == drawing_name) {
586 std::swap(this->pending_end_draw[i], this->pending_end_draw[iend - 1]);
587 this->pending_end_draw.resize(iend - 1);
588 this->activate(this->pending_end_draw[i]);
589 this->emit_flushdraw(drawing_name);
593 return "No EndDraw pending for surface";
596 void App::api_ping() { this->dispatch_pending_events(); }
598 void App::send_event(char const *evname, char const *label){
599 HMI_DEBUG("wm", "%s: %s(%s)", __func__, evname, label);
601 json_object *j = json_object_new_object();
602 json_object_object_add(j, kKeyDrawingName, json_object_new_string(label));
604 int ret = afb_event_push(this->map_afb_event[evname], j);
606 HMI_DEBUG("wm", "afb_event_push failed: %m");
610 void App::send_event(char const *evname, char const *label, char const *area,
611 int x, int y, int w, int h) {
612 HMI_DEBUG("wm", "%s: %s(%s, %s) x:%d y:%d w:%d h:%d",
613 __func__, evname, label, area, x, y, w, h);
615 json_object *j_rect = json_object_new_object();
616 json_object_object_add(j_rect, kKeyX, json_object_new_int(x));
617 json_object_object_add(j_rect, kKeyY, json_object_new_int(y));
618 json_object_object_add(j_rect, kKeyWidth, json_object_new_int(w));
619 json_object_object_add(j_rect, kKeyHeight, json_object_new_int(h));
621 json_object *j = json_object_new_object();
622 json_object_object_add(j, kKeyDrawingName, json_object_new_string(label));
623 json_object_object_add(j, kKeyDrawingArea, json_object_new_string(area));
624 json_object_object_add(j, kKeyDrawingRect, j_rect);
626 int ret = afb_event_push(this->map_afb_event[evname], j);
628 HMI_DEBUG("wm", "afb_event_push failed: %m");
635 void App::surface_created(uint32_t surface_id) {
636 auto layer_id = this->layers.get_layer_id(surface_id);
638 HMI_DEBUG("wm", "Newly created surfce %d is not associated with any layer!",
643 HMI_DEBUG("wm", "surface_id is %u, layer_id is %u", surface_id, *layer_id);
645 this->controller->layers[*layer_id]->add_surface(surface_id);
646 this->layout_commit();
647 // activate the main_surface right away
648 /*if (surface_id == static_cast<unsigned>(this->layers.main_surface)) {
649 HMI_DEBUG("wm", "Activating main_surface (%d)", surface_id);
651 this->api_activate_surface(
652 this->lookup_name(surface_id).value_or("unknown-name").c_str());
656 void App::surface_removed(uint32_t surface_id) {
657 HMI_DEBUG("wm", "surface_id is %u", surface_id);
659 // We cannot normally deactivate the main_surface, so be explicit
661 if (int(surface_id) == this->layers.main_surface) {
662 this->deactivate_main_surface();
664 auto drawing_name = this->lookup_name(surface_id);
666 this->api_deactivate_surface(drawing_name->c_str());
670 this->id_alloc.remove_id(surface_id);
671 this->layers.remove_surface(surface_id);
674 void App::emit_activated(char const *label) {
675 this->send_event(kListEventName[Event_Active], label);
678 void App::emit_deactivated(char const *label) {
679 this->send_event(kListEventName[Event_Inactive], label);
682 void App::emit_syncdraw(char const *label, char const *area, int x, int y, int w, int h) {
683 this->send_event(kListEventName[Event_SyncDraw], label, area, x, y, w, h);
686 void App::emit_flushdraw(char const *label) {
687 this->send_event(kListEventName[Event_FlushDraw], label);
690 void App::emit_visible(char const *label, bool is_visible) {
691 this->send_event(is_visible ? kListEventName[Event_Visible] : kListEventName[Event_Invisible], label);
694 void App::emit_invisible(char const *label) {
695 return emit_visible(label, false);
698 void App::emit_visible(char const *label) { return emit_visible(label, true); }
700 result<int> App::api_request_surface(char const *drawing_name) {
701 auto lid = this->layers.get_layer_id(std::string(drawing_name));
704 * register drawing_name as fallback and make it displayed.
706 lid = this->layers.get_layer_id(std::string("Fallback"));
707 HMI_DEBUG("wm", "%s is not registered in layers.json, then fallback as normal app", drawing_name);
709 return Err<int>("Drawing name does not match any role, Fallback is disabled");
713 auto rname = this->lookup_id(drawing_name);
715 // name does not exist yet, allocate surface id...
716 auto id = int(this->id_alloc.generate_id(drawing_name));
717 this->layers.add_surface(id, *lid);
719 // set the main_surface[_name] here and now
720 if (!this->layers.main_surface_name.empty() &&
721 this->layers.main_surface_name == drawing_name) {
722 this->layers.main_surface = id;
723 HMI_DEBUG("wm", "Set main_surface id to %u", id);
729 // Check currently registered drawing names if it is already there.
730 return Err<int>("Surface already present");
733 char const *App::api_request_surface(char const *drawing_name,
734 char const *ivi_id) {
737 auto lid = this->layers.get_layer_id(std::string(drawing_name));
738 unsigned sid = std::stol(ivi_id);
742 * register drawing_name as fallback and make it displayed.
744 lid = this->layers.get_layer_id(std::string("Fallback"));
745 HMI_DEBUG("wm", "%s is not registered in layers.json, then fallback as normal app", drawing_name);
747 return "Drawing name does not match any role, Fallback is disabled";
751 auto rname = this->lookup_id(drawing_name);
754 return "Surface already present";
757 // register pair drawing_name and ivi_id
758 this->id_alloc.register_name_id(drawing_name, sid);
759 this->layers.add_surface(sid, *lid);
761 // this surface is already created
762 HMI_DEBUG("wm", "surface_id is %u, layer_id is %u", sid, *lid);
764 this->controller->layers[*lid]->add_surface(sid);
765 this->layout_commit();
770 result<json_object *> App::api_get_display_info() {
772 if (!this->controller) {
773 return Err<json_object *>("ivi_controller global not available");
777 compositor::size o_size = this->controller->output_size;
778 compositor::size p_size = this->controller->physical_size;
780 json_object *object = json_object_new_object();
781 json_object_object_add(object, kKeyWidthPixel, json_object_new_int(o_size.w));
782 json_object_object_add(object, kKeyHeightPixel, json_object_new_int(o_size.h));
783 json_object_object_add(object, kKeyWidthMm, json_object_new_int(p_size.w));
784 json_object_object_add(object, kKeyHeightMm, json_object_new_int(p_size.h));
786 return Ok<json_object *>(object);
789 result<json_object *> App::api_get_area_info(char const *drawing_name) {
790 HMI_DEBUG("wm", "called");
792 // Check drawing name, surface/layer id
793 auto const &surface_id = this->lookup_id(drawing_name);
795 return Err<json_object *>("Surface does not exist");
798 if (!this->controller->surface_exists(*surface_id)) {
799 return Err<json_object *>("Surface does not exist in controller!");
802 auto layer_id = this->layers.get_layer_id(*surface_id);
804 return Err<json_object *>("Surface is not on any layer!");
807 auto o_state = *this->layers.get_layout_state(*surface_id);
808 if (o_state == nullptr) {
809 return Err<json_object *>("Could not find layer for surface");
812 struct LayoutState &state = *o_state;
813 if ((state.main != *surface_id) && (state.sub != *surface_id)) {
814 return Err<json_object *>("Surface is inactive");
817 // Set area rectangle
818 compositor::rect area_info = this->area_info[*surface_id];
819 json_object *object = json_object_new_object();
820 json_object_object_add(object, kKeyX, json_object_new_int(area_info.x));
821 json_object_object_add(object, kKeyY, json_object_new_int(area_info.y));
822 json_object_object_add(object, kKeyWidth, json_object_new_int(area_info.w));
823 json_object_object_add(object, kKeyHeight, json_object_new_int(area_info.h));
825 return Ok<json_object *>(object);
828 void App::activate(int id) {
829 auto ip = this->controller->sprops.find(id);
830 if (ip != this->controller->sprops.end()) {
831 this->controller->surfaces[id]->set_visibility(1);
833 this->lookup_name(id).value_or("unknown-name").c_str();
836 if ((0 == strcmp(label, "Radio"))
837 || (0 == strcmp(label, "MediaPlayer"))
838 || (0 == strcmp(label, "Music"))
839 || (0 == strcmp(label, "Navigation"))) {
840 for (auto i = surface_bg.begin(); i != surface_bg.end(); ++i) {
843 this->surface_bg.erase(i);
845 // Remove from BG layer (999)
846 HMI_DEBUG("wm", "Remove %s(%d) from BG layer", label, id);
847 this->controller->layers[999]->remove_surface(id);
849 // Add to FG layer (1001)
850 HMI_DEBUG("wm", "Add %s(%d) to FG layer", label, id);
851 this->controller->layers[1001]->add_surface(id);
853 for (int j : this->surface_bg) {
854 HMI_DEBUG("wm", "Stored id:%d", j);
861 this->layout_commit();
863 this->emit_visible(label);
864 this->emit_activated(label);
868 void App::deactivate(int id) {
869 auto ip = this->controller->sprops.find(id);
870 if (ip != this->controller->sprops.end()) {
872 this->lookup_name(id).value_or("unknown-name").c_str();
875 if ((0 == strcmp(label, "Radio"))
876 || (0 == strcmp(label, "MediaPlayer"))
877 || (0 == strcmp(label, "Music"))
878 || (0 == strcmp(label, "Navigation"))) {
881 this->surface_bg.push_back(id);
883 // Remove from FG layer (1001)
884 HMI_DEBUG("wm", "Remove %s(%d) from FG layer", label, id);
885 this->controller->layers[1001]->remove_surface(id);
887 // Add to BG layer (999)
888 HMI_DEBUG("wm", "Add %s(%d) to BG layer", label, id);
889 this->controller->layers[999]->add_surface(id);
891 for (int j : surface_bg) {
892 HMI_DEBUG("wm", "Stored id:%d", j);
896 this->controller->surfaces[id]->set_visibility(0);
900 this->emit_deactivated(label);
901 this->emit_invisible(label);
905 void App::deactivate_main_surface() {
906 this->layers.main_surface = -1;
907 this->api_deactivate_surface(this->layers.main_surface_name.c_str());
910 bool App::can_split(struct LayoutState const &state, int new_id) {
911 if (state.main != -1 && state.main != new_id) {
912 auto new_id_layer = this->layers.get_layer_id(new_id).value();
913 auto current_id_layer = this->layers.get_layer_id(state.main).value();
915 // surfaces are on separate layers, don't bother.
916 if (new_id_layer != current_id_layer) {
920 std::string const &new_id_str = this->lookup_name(new_id).value();
921 std::string const &cur_id_str = this->lookup_name(state.main).value();
923 auto const &layer = this->layers.get_layer(new_id_layer);
925 HMI_DEBUG("wm", "layer info name: %s", layer->name.c_str());
927 if (layer->layouts.empty()) {
931 for (auto i = layer->layouts.cbegin(); i != layer->layouts.cend(); i++) {
932 HMI_DEBUG("wm", "%d main_match '%s'", new_id_layer, i->main_match.c_str());
933 auto rem = std::regex(i->main_match);
934 if (std::regex_match(cur_id_str, rem)) {
935 // build the second one only if the first already matched
936 HMI_DEBUG("wm", "%d sub_match '%s'", new_id_layer, i->sub_match.c_str());
937 auto res = std::regex(i->sub_match);
938 if (std::regex_match(new_id_str, res)) {
939 HMI_DEBUG("wm", "layout matched!");
949 void App::try_layout(struct LayoutState & /*state*/,
950 struct LayoutState const &new_layout,
951 std::function<void(LayoutState const &nl)> apply) {
952 if (this->policy.layout_is_valid(new_layout)) {
960 void controller_hooks::surface_created(uint32_t surface_id) {
961 this->app->surface_created(surface_id);
964 void controller_hooks::surface_removed(uint32_t surface_id) {
965 this->app->surface_removed(surface_id);
968 void controller_hooks::surface_visibility(uint32_t /*surface_id*/,
971 void controller_hooks::surface_destination_rectangle(uint32_t /*surface_id*/,