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>
40 /* DrawingArea name used by "{layout}.{area}" */
41 const char kNameLayoutNormal[] = "normal";
42 const char kNameLayoutSplit[] = "split";
43 const char kNameAreaFull[] = "full";
44 const char kNameAreaMain[] = "main";
45 const char kNameAreaSub[] = "sub";
47 /* Key for json obejct */
48 const char kKeyDrawingName[] = "drawing_name";
49 const char kKeyDrawingArea[] = "drawing_area";
50 const char kKeyDrawingRect[] = "drawing_rect";
51 const char kKeyX[] = "x";
52 const char kKeyY[] = "y";
53 const char kKeyWidth[] = "width";
54 const char kKeyHeight[] = "height";
55 const char kKeyWidthPixel[] = "width_pixel";
56 const char kKeyHeightPixel[] = "height_pixel";
57 const char kKeyWidthMm[] = "width_mm";
58 const char kKeyHeightMm[] = "height_mm";
65 result<json> file_to_json(char const *filename)
68 std::ifstream i(filename);
71 HMI_DEBUG("wm", "Could not open config file, so use default layer information");
72 j = default_layers_json;
82 struct result<layer_map> load_layer_map(char const *filename)
84 HMI_DEBUG("wm", "loading IDs from %s", filename);
86 auto j = file_to_json(filename);
89 return Err<layer_map>(j.unwrap_err());
91 json jids = j.unwrap();
93 return to_layer_map(jids);
101 App::App(wl::display *d)
109 pending_events(false),
115 auto l = load_layer_map(
116 this->config.get_string("layers.json").value().c_str());
119 this->layers = l.unwrap();
123 HMI_ERROR("wm", "%s", l.err().value());
127 catch (std::exception &e)
129 HMI_ERROR("wm", "Loading of configuration failed: %s", e.what());
135 if (!this->display->ok())
140 if (this->layers.mapping.empty())
142 HMI_ERROR("wm", "No surface -> layer mapping loaded");
147 for (int i = Event_Val_Min; i <= Event_Val_Max; i++)
149 map_afb_event[kListEventName[i]] = afb_daemon_make_event(kListEventName[i]);
152 this->display->add_global_handler(
153 "wl_output", [this](wl_registry *r, uint32_t name, uint32_t v) {
154 this->outputs.emplace_back(std::make_unique<wl::output>(r, name, v));
157 this->display->add_global_handler(
158 "ivi_wm", [this](wl_registry *r, uint32_t name, uint32_t v) {
160 std::make_unique<struct compositor::controller>(r, name, v);
162 // Init controller hooks
163 this->controller->chooks = &this->chooks;
165 // This protocol needs the output, so lets just add our mapping here...
166 this->controller->add_proxy_to_id_mapping(
167 this->outputs.back()->proxy.get(),
168 wl_proxy_get_id(reinterpret_cast<struct wl_proxy *>(
169 this->outputs.back()->proxy.get())));
172 this->controller->create_screen(this->outputs.back()->proxy.get());
174 // Set display to controller
175 this->controller->display = this->display;
178 // First level objects
179 this->display->roundtrip();
180 // Second level objects
181 this->display->roundtrip();
182 // Third level objects
183 this->display->roundtrip();
185 return init_layers();
188 int App::dispatch_pending_events()
190 if (this->pop_pending_events())
192 this->display->dispatch_pending();
198 bool App::pop_pending_events()
201 return this->pending_events.compare_exchange_strong(
202 x, false, std::memory_order_consume);
205 void App::set_pending_events()
207 this->pending_events.store(true, std::memory_order_release);
210 optional<int> App::lookup_id(char const *name)
212 return this->id_alloc.lookup(std::string(name));
214 optional<std::string> App::lookup_name(int id)
216 return this->id_alloc.lookup(id);
222 int App::init_layers()
224 if (!this->controller)
226 HMI_ERROR("wm", "ivi_controller global not available");
230 if (this->outputs.empty())
232 HMI_ERROR("wm", "no output was set up!");
236 auto &c = this->controller;
238 auto &o = this->outputs.front();
239 auto &s = c->screens.begin()->second;
240 auto &layers = c->layers;
242 // Write output dimensions to ivi controller...
243 c->output_size = compositor::size{uint32_t(o->width), uint32_t(o->height)};
244 c->physical_size = compositor::size{uint32_t(o->physical_width),
245 uint32_t(o->physical_height)};
253 // Quick and dirty setup of layers
254 for (auto const &i : this->layers.mapping)
256 c->layer_create(i.second.layer_id, o->width, o->height);
257 auto &l = layers[i.second.layer_id];
258 l->set_destination_rectangle(0, 0, o->width, o->height);
259 l->set_visibility(1);
260 HMI_DEBUG("wm", "Setting up layer %s (%d) for surface role match \"%s\"",
261 i.second.name.c_str(), i.second.layer_id, i.second.role.c_str());
264 // Add layers to screen
265 s->set_render_order(this->layers.layers);
267 this->layout_commit();
272 void App::surface_set_layout(int surface_id, optional<int> sub_surface_id)
274 if (!this->controller->surface_exists(surface_id))
276 HMI_ERROR("wm", "Surface %d does not exist", surface_id);
280 auto o_layer_id = this->layers.get_layer_id(surface_id);
284 HMI_ERROR("wm", "Surface %d is not associated with any layer!", surface_id);
288 uint32_t layer_id = *o_layer_id;
290 auto const &layer = this->layers.get_layer(layer_id);
291 auto rect = layer.value().rect;
292 auto &s = this->controller->surfaces[surface_id];
299 // less-than-0 values refer to MAX + 1 - $VALUE
300 // e.g. MAX is either screen width or height
303 w = this->controller->output_size.w + 1 + w;
307 h = this->controller->output_size.h + 1 + h;
312 if (o_layer_id != this->layers.get_layer_id(*sub_surface_id))
315 "surface_set_layout: layers of surfaces (%d and %d) don't match!",
316 surface_id, *sub_surface_id);
323 // split along major axis
335 auto &ss = this->controller->surfaces[*sub_surface_id];
337 HMI_DEBUG("wm", "surface_set_layout for sub surface %u on layer %u",
338 *sub_surface_id, layer_id);
340 // set destination to the display rectangle
341 ss->set_destination_rectangle(x + x_off, y + y_off, w, h);
343 this->area_info[*sub_surface_id].x = x;
344 this->area_info[*sub_surface_id].y = y;
345 this->area_info[*sub_surface_id].w = w;
346 this->area_info[*sub_surface_id].h = h;
349 HMI_DEBUG("wm", "surface_set_layout for surface %u on layer %u", surface_id,
352 // set destination to the display rectangle
353 s->set_destination_rectangle(x, y, w, h);
355 // update area information
356 this->area_info[surface_id].x = x;
357 this->area_info[surface_id].y = y;
358 this->area_info[surface_id].w = w;
359 this->area_info[surface_id].h = h;
361 HMI_DEBUG("wm", "Surface %u now on layer %u with rect { %d, %d, %d, %d }",
362 surface_id, layer_id, x, y, w, h);
365 void App::layout_commit()
367 this->controller->commit_changes();
368 this->display->flush();
371 void App::api_activate_surface(char const *drawing_name, char const *drawing_area, const reply_func &reply)
375 auto const &surface_id = this->lookup_id(drawing_name);
379 reply("Surface does not exist");
383 if (!this->controller->surface_exists(*surface_id))
385 reply("Surface does not exist in controller!");
389 auto layer_id = this->layers.get_layer_id(*surface_id);
393 reply("Surface is not on any layer!");
397 auto o_state = *this->layers.get_layout_state(*surface_id);
399 if (o_state == nullptr)
401 reply("Could not find layer for surface");
405 HMI_DEBUG("wm", "surface %d is detected", *surface_id);
408 struct LayoutState &state = *o_state;
410 // disable layers that are above our current layer
411 for (auto const &l : this->layers.mapping)
413 if (l.second.layer_id <= *layer_id)
419 if (l.second.state.main != -1)
421 this->deactivate(l.second.state.main);
422 l.second.state.main = -1;
426 if (l.second.state.sub != -1)
428 this->deactivate(l.second.state.sub);
429 l.second.state.sub = -1;
435 this->layout_commit();
439 auto layer = this->layers.get_layer(*layer_id);
441 if (state.main == -1)
444 state, LayoutState{*surface_id}, [&](LayoutState const &nl) {
445 HMI_DEBUG("wm", "Layout: %s", kNameLayoutNormal);
446 this->surface_set_layout(*surface_id);
449 // Commit for configuraton
450 this->layout_commit();
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 if (0 == strcmp(drawing_name, "HomeScreen"))
464 state, LayoutState{*surface_id}, [&](LayoutState const &nl) {
465 HMI_DEBUG("wm", "Layout: %s", kNameLayoutNormal);
466 std::string str_area = std::string(kNameLayoutNormal) + "." + std::string(kNameAreaFull);
467 compositor::rect area_rect = this->area_info[*surface_id];
468 this->emit_syncdraw(drawing_name, str_area.c_str(),
469 area_rect.x, area_rect.y, area_rect.w, area_rect.h);
470 this->enqueue_flushdraw(state.main);
475 bool can_split = this->can_split(state, *surface_id);
481 LayoutState{state.main, *surface_id},
482 [&](LayoutState const &nl) {
483 HMI_DEBUG("wm", "Layout: %s", kNameLayoutSplit);
485 std::move(*this->lookup_name(state.main));
487 this->surface_set_layout(state.main, surface_id);
488 if (state.sub != *surface_id)
492 this->deactivate(state.sub);
497 // Commit for configuration and visibility(0)
498 this->layout_commit();
500 std::string str_area_main = std::string(kNameLayoutSplit) + "." + std::string(kNameAreaMain);
501 std::string str_area_sub = std::string(kNameLayoutSplit) + "." + std::string(kNameAreaSub);
502 compositor::rect area_rect_main = this->area_info[state.main];
503 compositor::rect area_rect_sub = this->area_info[*surface_id];
504 this->emit_syncdraw(main.c_str(), str_area_main.c_str(),
505 area_rect_main.x, area_rect_main.y,
506 area_rect_main.w, area_rect_main.h);
507 this->emit_syncdraw(drawing_name, str_area_sub.c_str(),
508 area_rect_sub.x, area_rect_sub.y,
509 area_rect_sub.w, area_rect_sub.h);
510 this->enqueue_flushdraw(state.main);
511 this->enqueue_flushdraw(state.sub);
517 state, LayoutState{*surface_id}, [&](LayoutState const &nl) {
518 HMI_DEBUG("wm", "Layout: %s", kNameLayoutNormal);
520 this->surface_set_layout(*surface_id);
521 if (state.main != *surface_id)
523 this->deactivate(state.main);
527 if (state.sub != *surface_id)
529 this->deactivate(state.sub);
534 // Commit for configuraton and visibility(0)
535 this->layout_commit();
537 std::string str_area = std::string(kNameLayoutNormal) + "." + std::string(kNameAreaFull);
538 compositor::rect area_rect = this->area_info[*surface_id];
539 this->emit_syncdraw(drawing_name, str_area.c_str(),
540 area_rect.x, area_rect.y, area_rect.w, area_rect.h);
541 this->enqueue_flushdraw(state.main);
548 void App::api_deactivate_surface(char const *drawing_name, const reply_func &reply)
551 auto const &surface_id = this->lookup_id(drawing_name);
555 reply("Surface does not exist");
559 if (*surface_id == this->layers.main_surface)
561 reply("Cannot deactivate main_surface");
565 auto o_state = *this->layers.get_layout_state(*surface_id);
567 if (o_state == nullptr)
569 reply("Could not find layer for surface");
573 struct LayoutState &state = *o_state;
575 if (state.main == -1)
577 reply("No surface active");
581 // Check against main_surface, main_surface_name is the configuration item.
582 if (*surface_id == this->layers.main_surface)
584 HMI_DEBUG("wm", "Refusing to deactivate main_surface %d", *surface_id);
588 if ((state.main == *surface_id) && (state.sub == *surface_id))
590 reply("Surface is not active");
595 if (state.main == *surface_id)
600 state, LayoutState{state.sub, -1}, [&](LayoutState const &nl) {
601 std::string sub = std::move(*this->lookup_name(state.sub));
603 this->deactivate(*surface_id);
604 this->surface_set_layout(state.sub);
607 this->layout_commit();
608 std::string str_area = std::string(kNameLayoutNormal) + "." + std::string(kNameAreaFull);
609 compositor::rect area_rect = this->area_info[state.sub];
610 this->emit_syncdraw(sub.c_str(), str_area.c_str(),
611 area_rect.x, area_rect.y, area_rect.w, area_rect.h);
612 this->enqueue_flushdraw(state.sub);
617 this->try_layout(state, LayoutState{-1, -1}, [&](LayoutState const &nl) {
618 this->deactivate(*surface_id);
620 this->layout_commit();
624 else if (state.sub == *surface_id)
627 state, LayoutState{state.main, -1}, [&](LayoutState const &nl) {
628 std::string main = std::move(*this->lookup_name(state.main));
630 this->deactivate(*surface_id);
631 this->surface_set_layout(state.main);
634 this->layout_commit();
635 std::string str_area = std::string(kNameLayoutNormal) + "." + std::string(kNameAreaFull);
636 compositor::rect area_rect = this->area_info[state.main];
637 this->emit_syncdraw(main.c_str(), str_area.c_str(),
638 area_rect.x, area_rect.y, area_rect.w, area_rect.h);
639 this->enqueue_flushdraw(state.main);
644 void App::enqueue_flushdraw(int surface_id)
646 this->check_flushdraw(surface_id);
647 HMI_DEBUG("wm", "Enqueuing EndDraw for surface_id %d", surface_id);
648 this->pending_end_draw.push_back(surface_id);
651 void App::check_flushdraw(int surface_id)
653 auto i = std::find(std::begin(this->pending_end_draw),
654 std::end(this->pending_end_draw), surface_id);
655 if (i != std::end(this->pending_end_draw))
657 auto n = this->lookup_name(surface_id);
658 HMI_ERROR("wm", "Application %s (%d) has pending EndDraw call(s)!",
659 n ? n->c_str() : "unknown-name", surface_id);
660 std::swap(this->pending_end_draw[std::distance(
661 std::begin(this->pending_end_draw), i)],
662 this->pending_end_draw.back());
663 this->pending_end_draw.resize(this->pending_end_draw.size() - 1);
667 void App::api_enddraw(char const *drawing_name)
669 for (unsigned i = 0, iend = this->pending_end_draw.size(); i < iend; i++)
671 auto n = this->lookup_name(this->pending_end_draw[i]);
672 if (n && *n == drawing_name)
674 std::swap(this->pending_end_draw[i], this->pending_end_draw[iend - 1]);
675 this->pending_end_draw.resize(iend - 1);
676 this->activate(this->pending_end_draw[i]);
677 this->emit_flushdraw(drawing_name);
682 void App::api_ping() { this->dispatch_pending_events(); }
684 void App::send_event(char const *evname, char const *label)
686 HMI_DEBUG("wm", "%s: %s(%s)", __func__, evname, label);
688 json_object *j = json_object_new_object();
689 json_object_object_add(j, kKeyDrawingName, json_object_new_string(label));
691 int ret = afb_event_push(this->map_afb_event[evname], j);
694 HMI_DEBUG("wm", "afb_event_push failed: %m");
698 void App::send_event(char const *evname, char const *label, char const *area,
699 int x, int y, int w, int h)
701 HMI_DEBUG("wm", "%s: %s(%s, %s) x:%d y:%d w:%d h:%d",
702 __func__, evname, label, area, x, y, w, h);
704 json_object *j_rect = json_object_new_object();
705 json_object_object_add(j_rect, kKeyX, json_object_new_int(x));
706 json_object_object_add(j_rect, kKeyY, json_object_new_int(y));
707 json_object_object_add(j_rect, kKeyWidth, json_object_new_int(w));
708 json_object_object_add(j_rect, kKeyHeight, json_object_new_int(h));
710 json_object *j = json_object_new_object();
711 json_object_object_add(j, kKeyDrawingName, json_object_new_string(label));
712 json_object_object_add(j, kKeyDrawingArea, json_object_new_string(area));
713 json_object_object_add(j, kKeyDrawingRect, j_rect);
715 int ret = afb_event_push(this->map_afb_event[evname], j);
718 HMI_DEBUG("wm", "afb_event_push failed: %m");
725 void App::surface_created(uint32_t surface_id)
727 auto layer_id = this->layers.get_layer_id(surface_id);
730 HMI_DEBUG("wm", "Newly created surfce %d is not associated with any layer!",
735 HMI_DEBUG("wm", "surface_id is %u, layer_id is %u", surface_id, *layer_id);
737 this->controller->layers[*layer_id]->add_surface(surface_id);
738 this->layout_commit();
739 // activate the main_surface right away
740 /*if (surface_id == static_cast<unsigned>(this->layers.main_surface)) {
741 HMI_DEBUG("wm", "Activating main_surface (%d)", surface_id);
743 this->api_activate_surface(
744 this->lookup_name(surface_id).value_or("unknown-name").c_str());
748 void App::surface_removed(uint32_t surface_id)
750 HMI_DEBUG("wm", "surface_id is %u", surface_id);
752 // We cannot normally deactivate the main_surface, so be explicit
754 if (int(surface_id) == this->layers.main_surface)
756 this->deactivate_main_surface();
760 auto drawing_name = this->lookup_name(surface_id);
763 this->api_deactivate_surface(drawing_name->c_str(), [](const char *) {});
767 this->id_alloc.remove_id(surface_id);
768 this->layers.remove_surface(surface_id);
771 void App::emit_activated(char const *label)
773 this->send_event(kListEventName[Event_Active], label);
776 void App::emit_deactivated(char const *label)
778 this->send_event(kListEventName[Event_Inactive], label);
781 void App::emit_syncdraw(char const *label, char const *area, int x, int y, int w, int h)
783 this->send_event(kListEventName[Event_SyncDraw], label, area, x, y, w, h);
786 void App::emit_flushdraw(char const *label)
788 this->send_event(kListEventName[Event_FlushDraw], label);
791 void App::emit_visible(char const *label, bool is_visible)
793 this->send_event(is_visible ? kListEventName[Event_Visible] : kListEventName[Event_Invisible], label);
796 void App::emit_invisible(char const *label)
798 return emit_visible(label, false);
801 void App::emit_visible(char const *label) { return emit_visible(label, true); }
803 result<int> App::api_request_surface(char const *drawing_name)
805 auto lid = this->layers.get_layer_id(std::string(drawing_name));
809 * register drawing_name as fallback and make it displayed.
811 lid = this->layers.get_layer_id(std::string("Fallback"));
812 HMI_DEBUG("wm", "%s is not registered in layers.json, then fallback as normal app", drawing_name);
815 return Err<int>("Drawing name does not match any role, Fallback is disabled");
819 auto rname = this->lookup_id(drawing_name);
822 // name does not exist yet, allocate surface id...
823 auto id = int(this->id_alloc.generate_id(drawing_name));
824 this->layers.add_surface(id, *lid);
826 // set the main_surface[_name] here and now
827 if (!this->layers.main_surface_name.empty() &&
828 this->layers.main_surface_name == drawing_name)
830 this->layers.main_surface = id;
831 HMI_DEBUG("wm", "Set main_surface id to %u", id);
837 // Check currently registered drawing names if it is already there.
838 return Err<int>("Surface already present");
841 char const *App::api_request_surface(char const *drawing_name,
846 auto lid = this->layers.get_layer_id(std::string(drawing_name));
847 unsigned sid = std::stol(ivi_id);
852 * register drawing_name as fallback and make it displayed.
854 lid = this->layers.get_layer_id(std::string("Fallback"));
855 HMI_DEBUG("wm", "%s is not registered in layers.json, then fallback as normal app", drawing_name);
858 return "Drawing name does not match any role, Fallback is disabled";
862 auto rname = this->lookup_id(drawing_name);
866 return "Surface already present";
869 // register pair drawing_name and ivi_id
870 this->id_alloc.register_name_id(drawing_name, sid);
871 this->layers.add_surface(sid, *lid);
873 // this surface is already created
874 HMI_DEBUG("wm", "surface_id is %u, layer_id is %u", sid, *lid);
876 this->controller->layers[*lid]->add_surface(sid);
877 this->layout_commit();
882 result<json_object *> App::api_get_display_info()
885 if (!this->controller)
887 return Err<json_object *>("ivi_controller global not available");
891 compositor::size o_size = this->controller->output_size;
892 compositor::size p_size = this->controller->physical_size;
894 json_object *object = json_object_new_object();
895 json_object_object_add(object, kKeyWidthPixel, json_object_new_int(o_size.w));
896 json_object_object_add(object, kKeyHeightPixel, json_object_new_int(o_size.h));
897 json_object_object_add(object, kKeyWidthMm, json_object_new_int(p_size.w));
898 json_object_object_add(object, kKeyHeightMm, json_object_new_int(p_size.h));
900 return Ok<json_object *>(object);
903 result<json_object *> App::api_get_area_info(char const *drawing_name)
905 HMI_DEBUG("wm", "called");
907 // Check drawing name, surface/layer id
908 auto const &surface_id = this->lookup_id(drawing_name);
911 return Err<json_object *>("Surface does not exist");
914 if (!this->controller->surface_exists(*surface_id))
916 return Err<json_object *>("Surface does not exist in controller!");
919 auto layer_id = this->layers.get_layer_id(*surface_id);
922 return Err<json_object *>("Surface is not on any layer!");
925 auto o_state = *this->layers.get_layout_state(*surface_id);
926 if (o_state == nullptr)
928 return Err<json_object *>("Could not find layer for surface");
931 struct LayoutState &state = *o_state;
932 if ((state.main != *surface_id) && (state.sub != *surface_id))
934 return Err<json_object *>("Surface is inactive");
937 // Set area rectangle
938 compositor::rect area_info = this->area_info[*surface_id];
939 json_object *object = json_object_new_object();
940 json_object_object_add(object, kKeyX, json_object_new_int(area_info.x));
941 json_object_object_add(object, kKeyY, json_object_new_int(area_info.y));
942 json_object_object_add(object, kKeyWidth, json_object_new_int(area_info.w));
943 json_object_object_add(object, kKeyHeight, json_object_new_int(area_info.h));
945 return Ok<json_object *>(object);
948 void App::activate(int id)
950 auto ip = this->controller->sprops.find(id);
951 if (ip != this->controller->sprops.end())
953 this->controller->surfaces[id]->set_visibility(1);
955 this->lookup_name(id).value_or("unknown-name").c_str();
958 if ((0 == strcmp(label, "Radio")) || (0 == strcmp(label, "MediaPlayer")) || (0 == strcmp(label, "Music")) || (0 == strcmp(label, "Navigation")))
960 for (auto i = surface_bg.begin(); i != surface_bg.end(); ++i)
965 this->surface_bg.erase(i);
967 // Remove from BG layer (999)
968 HMI_DEBUG("wm", "Remove %s(%d) from BG layer", label, id);
969 this->controller->layers[999]->remove_surface(id);
971 // Add to FG layer (1001)
972 HMI_DEBUG("wm", "Add %s(%d) to FG layer", label, id);
973 this->controller->layers[1001]->add_surface(id);
975 for (int j : this->surface_bg)
977 HMI_DEBUG("wm", "Stored id:%d", j);
984 this->layout_commit();
986 this->emit_visible(label);
987 this->emit_activated(label);
991 void App::deactivate(int id)
993 auto ip = this->controller->sprops.find(id);
994 if (ip != this->controller->sprops.end())
997 this->lookup_name(id).value_or("unknown-name").c_str();
1000 if ((0 == strcmp(label, "Radio")) ||
1001 (0 == strcmp(label, "MediaPlayer")) ||
1002 (0 == strcmp(label, "Music")) ||
1003 (0 == strcmp(label, "Navigation")))
1007 this->surface_bg.push_back(id);
1009 // Remove from FG layer (1001)
1010 HMI_DEBUG("wm", "Remove %s(%d) from FG layer", label, id);
1011 this->controller->layers[1001]->remove_surface(id);
1013 // Add to BG layer (999)
1014 HMI_DEBUG("wm", "Add %s(%d) to BG layer", label, id);
1015 this->controller->layers[999]->add_surface(id);
1017 for (int j : surface_bg)
1019 HMI_DEBUG("wm", "Stored id:%d", j);
1024 this->controller->surfaces[id]->set_visibility(0);
1028 this->emit_deactivated(label);
1029 this->emit_invisible(label);
1033 void App::deactivate_main_surface()
1035 this->layers.main_surface = -1;
1036 this->api_deactivate_surface(this->layers.main_surface_name.c_str(), [](const char *) {});
1039 bool App::can_split(struct LayoutState const &state, int new_id)
1041 if (state.main != -1 && state.main != new_id)
1043 auto new_id_layer = this->layers.get_layer_id(new_id).value();
1044 auto current_id_layer = this->layers.get_layer_id(state.main).value();
1046 // surfaces are on separate layers, don't bother.
1047 if (new_id_layer != current_id_layer)
1052 std::string const &new_id_str = this->lookup_name(new_id).value();
1053 std::string const &cur_id_str = this->lookup_name(state.main).value();
1055 auto const &layer = this->layers.get_layer(new_id_layer);
1057 HMI_DEBUG("wm", "layer info name: %s", layer->name.c_str());
1059 if (layer->layouts.empty())
1064 for (auto i = layer->layouts.cbegin(); i != layer->layouts.cend(); i++)
1066 HMI_DEBUG("wm", "%d main_match '%s'", new_id_layer, i->main_match.c_str());
1067 auto rem = std::regex(i->main_match);
1068 if (std::regex_match(cur_id_str, rem))
1070 // build the second one only if the first already matched
1071 HMI_DEBUG("wm", "%d sub_match '%s'", new_id_layer, i->sub_match.c_str());
1072 auto res = std::regex(i->sub_match);
1073 if (std::regex_match(new_id_str, res))
1075 HMI_DEBUG("wm", "layout matched!");
1085 void App::try_layout(struct LayoutState & /*state*/,
1086 struct LayoutState const &new_layout,
1087 std::function<void(LayoutState const &nl)> apply)
1089 if (this->policy.layout_is_valid(new_layout))
1098 void controller_hooks::surface_created(uint32_t surface_id)
1100 this->app->surface_created(surface_id);
1103 void controller_hooks::surface_removed(uint32_t surface_id)
1105 this->app->surface_removed(surface_id);
1108 void controller_hooks::surface_visibility(uint32_t /*surface_id*/,
1111 void controller_hooks::surface_destination_rectangle(uint32_t /*surface_id*/,