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.
21 #include "../include/json.hpp"
26 /* DrawingArea name used by "{layout}.{area}" */
27 const char kNameLayoutNormal[] = "normal";
28 const char kNameLayoutSplit[] = "split";
29 const char kNameAreaFull[] = "full";
30 const char kNameAreaMain[] = "main";
31 const char kNameAreaSub[] = "sub";
33 /* Key for json obejct */
34 const char kKeyDrawingName[] = "drawing_name";
35 const char kKeyDrawingArea[] = "drawing_area";
36 const char kKeyDrawingRect[] = "drawing_rect";
37 const char kKeyX[] = "x";
38 const char kKeyY[] = "y";
39 const char kKeyWidth[] = "width";
40 const char kKeyHeight[] = "height";
41 const char kKeyWidthPixel[] = "width_pixel";
42 const char kKeyHeightPixel[] = "height_pixel";
43 const char kKeyWidthMm[] = "width_mm";
44 const char kKeyHeightMm[] = "height_mm";
51 result<json> file_to_json(char const *filename)
54 std::ifstream i(filename);
57 HMI_DEBUG("wm", "Could not open config file, so use default layer information");
58 j = default_layers_json;
68 struct result<layer_map> load_layer_map(char const *filename)
70 HMI_DEBUG("wm", "loading IDs from %s", filename);
72 auto j = file_to_json(filename);
75 return Err<layer_map>(j.unwrap_err());
77 json jids = j.unwrap();
79 return to_layer_map(jids);
87 App::App(wl::display *d)
95 pending_events(false),
101 auto l = load_layer_map(
102 this->config.get_string("layers.json").value().c_str());
105 this->layers = l.unwrap();
109 HMI_ERROR("wm", "%s", l.err().value());
113 catch (std::exception &e)
115 HMI_ERROR("wm", "Loading of configuration failed: %s", e.what());
121 if (!this->display->ok())
126 if (this->layers.mapping.empty())
128 HMI_ERROR("wm", "No surface -> layer mapping loaded");
133 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()
176 if (this->pop_pending_events())
178 this->display->dispatch_pending();
184 bool App::pop_pending_events()
187 return this->pending_events.compare_exchange_strong(
188 x, false, std::memory_order_consume);
191 void App::set_pending_events()
193 this->pending_events.store(true, std::memory_order_release);
196 optional<int> App::lookup_id(char const *name)
198 return this->id_alloc.lookup(std::string(name));
200 optional<std::string> App::lookup_name(int id)
202 return this->id_alloc.lookup(id);
208 int App::init_layers()
210 if (!this->controller)
212 HMI_ERROR("wm", "ivi_controller global not available");
216 if (this->outputs.empty())
218 HMI_ERROR("wm", "no output was set up!");
222 auto &c = this->controller;
224 auto &o = this->outputs.front();
225 auto &s = c->screens.begin()->second;
226 auto &layers = c->layers;
228 // Write output dimensions to ivi controller...
229 c->output_size = compositor::size{uint32_t(o->width), uint32_t(o->height)};
230 c->physical_size = compositor::size{uint32_t(o->physical_width),
231 uint32_t(o->physical_height)};
239 // Quick and dirty setup of layers
240 for (auto const &i : this->layers.mapping)
242 c->layer_create(i.second.layer_id, o->width, o->height);
243 auto &l = layers[i.second.layer_id];
244 l->set_destination_rectangle(0, 0, o->width, o->height);
245 l->set_visibility(1);
246 HMI_DEBUG("wm", "Setting up layer %s (%d) for surface role match \"%s\"",
247 i.second.name.c_str(), i.second.layer_id, i.second.role.c_str());
250 // Add layers to screen
251 s->set_render_order(this->layers.layers);
253 this->layout_commit();
258 void App::surface_set_layout(int surface_id, optional<int> sub_surface_id)
260 if (!this->controller->surface_exists(surface_id))
262 HMI_ERROR("wm", "Surface %d does not exist", surface_id);
266 auto o_layer_id = this->layers.get_layer_id(surface_id);
270 HMI_ERROR("wm", "Surface %d is not associated with any layer!", surface_id);
274 uint32_t layer_id = *o_layer_id;
276 auto const &layer = this->layers.get_layer(layer_id);
277 auto rect = layer.value().rect;
278 auto &s = this->controller->surfaces[surface_id];
285 // less-than-0 values refer to MAX + 1 - $VALUE
286 // e.g. MAX is either screen width or height
289 w = this->controller->output_size.w + 1 + w;
293 h = this->controller->output_size.h + 1 + h;
298 if (o_layer_id != this->layers.get_layer_id(*sub_surface_id))
301 "surface_set_layout: layers of surfaces (%d and %d) don't match!",
302 surface_id, *sub_surface_id);
309 // split along major axis
321 auto &ss = this->controller->surfaces[*sub_surface_id];
323 HMI_DEBUG("wm", "surface_set_layout for sub surface %u on layer %u",
324 *sub_surface_id, layer_id);
326 // set destination to the display rectangle
327 ss->set_destination_rectangle(x + x_off, y + y_off, w, h);
329 this->area_info[*sub_surface_id].x = x;
330 this->area_info[*sub_surface_id].y = y;
331 this->area_info[*sub_surface_id].w = w;
332 this->area_info[*sub_surface_id].h = h;
335 HMI_DEBUG("wm", "surface_set_layout for surface %u on layer %u", surface_id,
338 // set destination to the display rectangle
339 s->set_destination_rectangle(x, y, w, h);
341 // update area information
342 this->area_info[surface_id].x = x;
343 this->area_info[surface_id].y = y;
344 this->area_info[surface_id].w = w;
345 this->area_info[surface_id].h = h;
347 HMI_DEBUG("wm", "Surface %u now on layer %u with rect { %d, %d, %d, %d }",
348 surface_id, layer_id, x, y, w, h);
351 void App::layout_commit()
353 this->controller->commit_changes();
354 this->display->flush();
357 void App::api_activate_surface(char const *drawing_name, char const *drawing_area, const reply_func &reply)
361 auto const &surface_id = this->lookup_id(drawing_name);
365 reply("Surface does not exist");
369 if (!this->controller->surface_exists(*surface_id))
371 reply("Surface does not exist in controller!");
375 auto layer_id = this->layers.get_layer_id(*surface_id);
379 reply("Surface is not on any layer!");
383 auto o_state = *this->layers.get_layout_state(*surface_id);
385 if (o_state == nullptr)
387 reply("Could not find layer for surface");
391 HMI_DEBUG("wm", "surface %d is detected", *surface_id);
394 struct LayoutState &state = *o_state;
396 // disable layers that are above our current layer
397 for (auto const &l : this->layers.mapping)
399 if (l.second.layer_id <= *layer_id)
405 if (l.second.state.main != -1)
407 this->deactivate(l.second.state.main);
408 l.second.state.main = -1;
412 if (l.second.state.sub != -1)
414 this->deactivate(l.second.state.sub);
415 l.second.state.sub = -1;
421 this->layout_commit();
425 auto layer = this->layers.get_layer(*layer_id);
427 if (state.main == -1)
430 state, LayoutState{*surface_id}, [&](LayoutState const &nl) {
431 HMI_DEBUG("wm", "Layout: %s", kNameLayoutNormal);
432 this->surface_set_layout(*surface_id);
435 // Commit for configuraton
436 this->layout_commit();
438 std::string str_area = std::string(kNameLayoutNormal) + "." + std::string(kNameAreaFull);
439 compositor::rect area_rect = this->area_info[*surface_id];
440 this->emit_syncdraw(drawing_name, str_area.c_str(),
441 area_rect.x, area_rect.y, area_rect.w, area_rect.h);
442 this->enqueue_flushdraw(state.main);
447 if (0 == strcmp(drawing_name, "HomeScreen"))
450 state, LayoutState{*surface_id}, [&](LayoutState const &nl) {
451 HMI_DEBUG("wm", "Layout: %s", kNameLayoutNormal);
452 std::string str_area = std::string(kNameLayoutNormal) + "." + std::string(kNameAreaFull);
453 compositor::rect area_rect = this->area_info[*surface_id];
454 this->emit_syncdraw(drawing_name, str_area.c_str(),
455 area_rect.x, area_rect.y, area_rect.w, area_rect.h);
456 this->enqueue_flushdraw(state.main);
461 bool can_split = this->can_split(state, *surface_id);
467 LayoutState{state.main, *surface_id},
468 [&](LayoutState const &nl) {
469 HMI_DEBUG("wm", "Layout: %s", kNameLayoutSplit);
471 std::move(*this->lookup_name(state.main));
473 this->surface_set_layout(state.main, surface_id);
474 if (state.sub != *surface_id)
478 this->deactivate(state.sub);
483 // Commit for configuration and visibility(0)
484 this->layout_commit();
486 std::string str_area_main = std::string(kNameLayoutSplit) + "." + std::string(kNameAreaMain);
487 std::string str_area_sub = std::string(kNameLayoutSplit) + "." + std::string(kNameAreaSub);
488 compositor::rect area_rect_main = this->area_info[state.main];
489 compositor::rect area_rect_sub = this->area_info[*surface_id];
490 this->emit_syncdraw(main.c_str(), str_area_main.c_str(),
491 area_rect_main.x, area_rect_main.y,
492 area_rect_main.w, area_rect_main.h);
493 this->emit_syncdraw(drawing_name, str_area_sub.c_str(),
494 area_rect_sub.x, area_rect_sub.y,
495 area_rect_sub.w, area_rect_sub.h);
496 this->enqueue_flushdraw(state.main);
497 this->enqueue_flushdraw(state.sub);
503 state, LayoutState{*surface_id}, [&](LayoutState const &nl) {
504 HMI_DEBUG("wm", "Layout: %s", kNameLayoutNormal);
506 this->surface_set_layout(*surface_id);
507 if (state.main != *surface_id)
509 this->deactivate(state.main);
513 if (state.sub != *surface_id)
515 this->deactivate(state.sub);
520 // Commit for configuraton and visibility(0)
521 this->layout_commit();
523 std::string str_area = std::string(kNameLayoutNormal) + "." + std::string(kNameAreaFull);
524 compositor::rect area_rect = this->area_info[*surface_id];
525 this->emit_syncdraw(drawing_name, str_area.c_str(),
526 area_rect.x, area_rect.y, area_rect.w, area_rect.h);
527 this->enqueue_flushdraw(state.main);
534 void App::api_deactivate_surface(char const *drawing_name, const reply_func &reply)
537 auto const &surface_id = this->lookup_id(drawing_name);
541 reply("Surface does not exist");
545 if (*surface_id == this->layers.main_surface)
547 reply("Cannot deactivate main_surface");
551 auto o_state = *this->layers.get_layout_state(*surface_id);
553 if (o_state == nullptr)
555 reply("Could not find layer for surface");
559 struct LayoutState &state = *o_state;
561 if (state.main == -1)
563 reply("No surface active");
567 // Check against main_surface, main_surface_name is the configuration item.
568 if (*surface_id == this->layers.main_surface)
570 HMI_DEBUG("wm", "Refusing to deactivate main_surface %d", *surface_id);
574 if ((state.main == *surface_id) && (state.sub == *surface_id))
576 reply("Surface is not active");
581 if (state.main == *surface_id)
586 state, LayoutState{state.sub, -1}, [&](LayoutState const &nl) {
587 std::string sub = std::move(*this->lookup_name(state.sub));
589 this->deactivate(*surface_id);
590 this->surface_set_layout(state.sub);
593 this->layout_commit();
594 std::string str_area = std::string(kNameLayoutNormal) + "." + std::string(kNameAreaFull);
595 compositor::rect area_rect = this->area_info[state.sub];
596 this->emit_syncdraw(sub.c_str(), str_area.c_str(),
597 area_rect.x, area_rect.y, area_rect.w, area_rect.h);
598 this->enqueue_flushdraw(state.sub);
603 this->try_layout(state, LayoutState{-1, -1}, [&](LayoutState const &nl) {
604 this->deactivate(*surface_id);
606 this->layout_commit();
610 else if (state.sub == *surface_id)
613 state, LayoutState{state.main, -1}, [&](LayoutState const &nl) {
614 std::string main = std::move(*this->lookup_name(state.main));
616 this->deactivate(*surface_id);
617 this->surface_set_layout(state.main);
620 this->layout_commit();
621 std::string str_area = std::string(kNameLayoutNormal) + "." + std::string(kNameAreaFull);
622 compositor::rect area_rect = this->area_info[state.main];
623 this->emit_syncdraw(main.c_str(), str_area.c_str(),
624 area_rect.x, area_rect.y, area_rect.w, area_rect.h);
625 this->enqueue_flushdraw(state.main);
630 void App::enqueue_flushdraw(int surface_id)
632 this->check_flushdraw(surface_id);
633 HMI_DEBUG("wm", "Enqueuing EndDraw for surface_id %d", surface_id);
634 this->pending_end_draw.push_back(surface_id);
637 void App::check_flushdraw(int surface_id)
639 auto i = std::find(std::begin(this->pending_end_draw),
640 std::end(this->pending_end_draw), surface_id);
641 if (i != std::end(this->pending_end_draw))
643 auto n = this->lookup_name(surface_id);
644 HMI_ERROR("wm", "Application %s (%d) has pending EndDraw call(s)!",
645 n ? n->c_str() : "unknown-name", surface_id);
646 std::swap(this->pending_end_draw[std::distance(
647 std::begin(this->pending_end_draw), i)],
648 this->pending_end_draw.back());
649 this->pending_end_draw.resize(this->pending_end_draw.size() - 1);
653 void App::api_enddraw(char const *drawing_name)
655 for (unsigned i = 0, iend = this->pending_end_draw.size(); i < iend; i++)
657 auto n = this->lookup_name(this->pending_end_draw[i]);
658 if (n && *n == drawing_name)
660 std::swap(this->pending_end_draw[i], this->pending_end_draw[iend - 1]);
661 this->pending_end_draw.resize(iend - 1);
662 this->activate(this->pending_end_draw[i]);
663 this->emit_flushdraw(drawing_name);
668 void App::api_ping() { this->dispatch_pending_events(); }
670 void App::send_event(char const *evname, char const *label)
672 HMI_DEBUG("wm", "%s: %s(%s)", __func__, evname, label);
674 json_object *j = json_object_new_object();
675 json_object_object_add(j, kKeyDrawingName, json_object_new_string(label));
677 int ret = afb_event_push(this->map_afb_event[evname], j);
680 HMI_DEBUG("wm", "afb_event_push failed: %m");
684 void App::send_event(char const *evname, char const *label, char const *area,
685 int x, int y, int w, int h)
687 HMI_DEBUG("wm", "%s: %s(%s, %s) x:%d y:%d w:%d h:%d",
688 __func__, evname, label, area, x, y, w, h);
690 json_object *j_rect = json_object_new_object();
691 json_object_object_add(j_rect, kKeyX, json_object_new_int(x));
692 json_object_object_add(j_rect, kKeyY, json_object_new_int(y));
693 json_object_object_add(j_rect, kKeyWidth, json_object_new_int(w));
694 json_object_object_add(j_rect, kKeyHeight, json_object_new_int(h));
696 json_object *j = json_object_new_object();
697 json_object_object_add(j, kKeyDrawingName, json_object_new_string(label));
698 json_object_object_add(j, kKeyDrawingArea, json_object_new_string(area));
699 json_object_object_add(j, kKeyDrawingRect, j_rect);
701 int ret = afb_event_push(this->map_afb_event[evname], j);
704 HMI_DEBUG("wm", "afb_event_push failed: %m");
711 void App::surface_created(uint32_t surface_id)
713 auto layer_id = this->layers.get_layer_id(surface_id);
716 HMI_DEBUG("wm", "Newly created surfce %d is not associated with any layer!",
721 HMI_DEBUG("wm", "surface_id is %u, layer_id is %u", surface_id, *layer_id);
723 this->controller->layers[*layer_id]->add_surface(surface_id);
724 this->layout_commit();
725 // activate the main_surface right away
726 /*if (surface_id == static_cast<unsigned>(this->layers.main_surface)) {
727 HMI_DEBUG("wm", "Activating main_surface (%d)", surface_id);
729 this->api_activate_surface(
730 this->lookup_name(surface_id).value_or("unknown-name").c_str());
734 void App::surface_removed(uint32_t surface_id)
736 HMI_DEBUG("wm", "surface_id is %u", surface_id);
738 // We cannot normally deactivate the main_surface, so be explicit
740 if (int(surface_id) == this->layers.main_surface)
742 this->deactivate_main_surface();
746 auto drawing_name = this->lookup_name(surface_id);
749 this->api_deactivate_surface(drawing_name->c_str(), [](const char *) {});
753 this->id_alloc.remove_id(surface_id);
754 this->layers.remove_surface(surface_id);
757 void App::emit_activated(char const *label)
759 this->send_event(kListEventName[Event_Active], label);
762 void App::emit_deactivated(char const *label)
764 this->send_event(kListEventName[Event_Inactive], label);
767 void App::emit_syncdraw(char const *label, char const *area, int x, int y, int w, int h)
769 this->send_event(kListEventName[Event_SyncDraw], label, area, x, y, w, h);
772 void App::emit_flushdraw(char const *label)
774 this->send_event(kListEventName[Event_FlushDraw], label);
777 void App::emit_visible(char const *label, bool is_visible)
779 this->send_event(is_visible ? kListEventName[Event_Visible] : kListEventName[Event_Invisible], label);
782 void App::emit_invisible(char const *label)
784 return emit_visible(label, false);
787 void App::emit_visible(char const *label) { return emit_visible(label, true); }
789 result<int> App::api_request_surface(char const *drawing_name)
791 auto lid = this->layers.get_layer_id(std::string(drawing_name));
795 * register drawing_name as fallback and make it displayed.
797 lid = this->layers.get_layer_id(std::string("Fallback"));
798 HMI_DEBUG("wm", "%s is not registered in layers.json, then fallback as normal app", drawing_name);
801 return Err<int>("Drawing name does not match any role, Fallback is disabled");
805 auto rname = this->lookup_id(drawing_name);
808 // name does not exist yet, allocate surface id...
809 auto id = int(this->id_alloc.generate_id(drawing_name));
810 this->layers.add_surface(id, *lid);
812 // set the main_surface[_name] here and now
813 if (!this->layers.main_surface_name.empty() &&
814 this->layers.main_surface_name == drawing_name)
816 this->layers.main_surface = id;
817 HMI_DEBUG("wm", "Set main_surface id to %u", id);
823 // Check currently registered drawing names if it is already there.
824 return Err<int>("Surface already present");
827 char const *App::api_request_surface(char const *drawing_name,
832 auto lid = this->layers.get_layer_id(std::string(drawing_name));
833 unsigned sid = std::stol(ivi_id);
838 * register drawing_name as fallback and make it displayed.
840 lid = this->layers.get_layer_id(std::string("Fallback"));
841 HMI_DEBUG("wm", "%s is not registered in layers.json, then fallback as normal app", drawing_name);
844 return "Drawing name does not match any role, Fallback is disabled";
848 auto rname = this->lookup_id(drawing_name);
852 return "Surface already present";
855 // register pair drawing_name and ivi_id
856 this->id_alloc.register_name_id(drawing_name, sid);
857 this->layers.add_surface(sid, *lid);
859 // this surface is already created
860 HMI_DEBUG("wm", "surface_id is %u, layer_id is %u", sid, *lid);
862 this->controller->layers[*lid]->add_surface(sid);
863 this->layout_commit();
868 result<json_object *> App::api_get_display_info()
871 if (!this->controller)
873 return Err<json_object *>("ivi_controller global not available");
877 compositor::size o_size = this->controller->output_size;
878 compositor::size p_size = this->controller->physical_size;
880 json_object *object = json_object_new_object();
881 json_object_object_add(object, kKeyWidthPixel, json_object_new_int(o_size.w));
882 json_object_object_add(object, kKeyHeightPixel, json_object_new_int(o_size.h));
883 json_object_object_add(object, kKeyWidthMm, json_object_new_int(p_size.w));
884 json_object_object_add(object, kKeyHeightMm, json_object_new_int(p_size.h));
886 return Ok<json_object *>(object);
889 result<json_object *> App::api_get_area_info(char const *drawing_name)
891 HMI_DEBUG("wm", "called");
893 // Check drawing name, surface/layer id
894 auto const &surface_id = this->lookup_id(drawing_name);
897 return Err<json_object *>("Surface does not exist");
900 if (!this->controller->surface_exists(*surface_id))
902 return Err<json_object *>("Surface does not exist in controller!");
905 auto layer_id = this->layers.get_layer_id(*surface_id);
908 return Err<json_object *>("Surface is not on any layer!");
911 auto o_state = *this->layers.get_layout_state(*surface_id);
912 if (o_state == nullptr)
914 return Err<json_object *>("Could not find layer for surface");
917 struct LayoutState &state = *o_state;
918 if ((state.main != *surface_id) && (state.sub != *surface_id))
920 return Err<json_object *>("Surface is inactive");
923 // Set area rectangle
924 compositor::rect area_info = this->area_info[*surface_id];
925 json_object *object = json_object_new_object();
926 json_object_object_add(object, kKeyX, json_object_new_int(area_info.x));
927 json_object_object_add(object, kKeyY, json_object_new_int(area_info.y));
928 json_object_object_add(object, kKeyWidth, json_object_new_int(area_info.w));
929 json_object_object_add(object, kKeyHeight, json_object_new_int(area_info.h));
931 return Ok<json_object *>(object);
934 void App::activate(int id)
936 auto ip = this->controller->sprops.find(id);
937 if (ip != this->controller->sprops.end())
939 this->controller->surfaces[id]->set_visibility(1);
941 this->lookup_name(id).value_or("unknown-name").c_str();
944 if ((0 == strcmp(label, "Radio")) || (0 == strcmp(label, "MediaPlayer")) || (0 == strcmp(label, "Music")) || (0 == strcmp(label, "Navigation")))
946 for (auto i = surface_bg.begin(); i != surface_bg.end(); ++i)
951 this->surface_bg.erase(i);
953 // Remove from BG layer (999)
954 HMI_DEBUG("wm", "Remove %s(%d) from BG layer", label, id);
955 this->controller->layers[999]->remove_surface(id);
957 // Add to FG layer (1001)
958 HMI_DEBUG("wm", "Add %s(%d) to FG layer", label, id);
959 this->controller->layers[1001]->add_surface(id);
961 for (int j : this->surface_bg)
963 HMI_DEBUG("wm", "Stored id:%d", j);
970 this->layout_commit();
972 this->emit_visible(label);
973 this->emit_activated(label);
977 void App::deactivate(int id)
979 auto ip = this->controller->sprops.find(id);
980 if (ip != this->controller->sprops.end())
983 this->lookup_name(id).value_or("unknown-name").c_str();
986 if ((0 == strcmp(label, "Radio")) ||
987 (0 == strcmp(label, "MediaPlayer")) ||
988 (0 == strcmp(label, "Music")) ||
989 (0 == strcmp(label, "Navigation")))
993 this->surface_bg.push_back(id);
995 // Remove from FG layer (1001)
996 HMI_DEBUG("wm", "Remove %s(%d) from FG layer", label, id);
997 this->controller->layers[1001]->remove_surface(id);
999 // Add to BG layer (999)
1000 HMI_DEBUG("wm", "Add %s(%d) to BG layer", label, id);
1001 this->controller->layers[999]->add_surface(id);
1003 for (int j : surface_bg)
1005 HMI_DEBUG("wm", "Stored id:%d", j);
1010 this->controller->surfaces[id]->set_visibility(0);
1014 this->emit_deactivated(label);
1015 this->emit_invisible(label);
1019 void App::deactivate_main_surface()
1021 this->layers.main_surface = -1;
1022 this->api_deactivate_surface(this->layers.main_surface_name.c_str(), [](const char *) {});
1025 bool App::can_split(struct LayoutState const &state, int new_id)
1027 if (state.main != -1 && state.main != new_id)
1029 auto new_id_layer = this->layers.get_layer_id(new_id).value();
1030 auto current_id_layer = this->layers.get_layer_id(state.main).value();
1032 // surfaces are on separate layers, don't bother.
1033 if (new_id_layer != current_id_layer)
1038 std::string const &new_id_str = this->lookup_name(new_id).value();
1039 std::string const &cur_id_str = this->lookup_name(state.main).value();
1041 auto const &layer = this->layers.get_layer(new_id_layer);
1043 HMI_DEBUG("wm", "layer info name: %s", layer->name.c_str());
1045 if (layer->layouts.empty())
1050 for (auto i = layer->layouts.cbegin(); i != layer->layouts.cend(); i++)
1052 HMI_DEBUG("wm", "%d main_match '%s'", new_id_layer, i->main_match.c_str());
1053 auto rem = std::regex(i->main_match);
1054 if (std::regex_match(cur_id_str, rem))
1056 // build the second one only if the first already matched
1057 HMI_DEBUG("wm", "%d sub_match '%s'", new_id_layer, i->sub_match.c_str());
1058 auto res = std::regex(i->sub_match);
1059 if (std::regex_match(new_id_str, res))
1061 HMI_DEBUG("wm", "layout matched!");
1071 void App::try_layout(struct LayoutState & /*state*/,
1072 struct LayoutState const &new_layout,
1073 std::function<void(LayoutState const &nl)> apply)
1075 if (this->policy.layout_is_valid(new_layout))
1084 void controller_hooks::surface_created(uint32_t surface_id)
1086 this->app->surface_created(surface_id);
1089 void controller_hooks::surface_removed(uint32_t surface_id)
1091 this->app->surface_removed(surface_id);
1094 void controller_hooks::surface_visibility(uint32_t /*surface_id*/,
1097 void controller_hooks::surface_destination_rectangle(uint32_t /*surface_id*/,