-/*
- ******* Private Functions *******
- */
-
-bool WindowManager::pop_pending_events()
-{
- bool x{true};
- return this->pending_events.compare_exchange_strong(
- x, false, std::memory_order_consume);
-}
-
-optional<int> WindowManager::lookup_id(char const *name)
-{
- return this->id_alloc.lookup(std::string(name));
-}
-optional<std::string> WindowManager::lookup_name(int id)
-{
- return this->id_alloc.lookup(id);
-}
-
-/**
- * init_layers()
- */
-int WindowManager::init_layers()
-{
- if (!this->controller)
- {
- HMI_ERROR("wm", "ivi_controller global not available");
- return -1;
- }
-
- if (this->outputs.empty())
- {
- HMI_ERROR("wm", "no output was set up!");
- return -1;
- }
-
- WMConfig wm_config;
- wm_config.loadConfigs();
-
- auto &c = this->controller;
-
- auto &o = this->outputs.front();
- auto &s = c->screens.begin()->second;
- auto &layers = c->layers;
-
- this->layers.loadAreaDb();
- const compositor::rect base = this->layers.getAreaSize("fullscreen");
-
- const std::string aspect_setting = wm_config.getConfigAspect();
- const compositor::rect scale_rect =
- this->layers.getScaleDestRect(o->width, o->height, aspect_setting);
-
- // Write output dimensions to ivi controller...
- c->output_size = compositor::size{uint32_t(o->width), uint32_t(o->height)};
- c->physical_size = compositor::size{uint32_t(o->physical_width),
- uint32_t(o->physical_height)};
-
- // Clear scene
- layers.clear();
-
- // Clear screen
- s->clear();
-
- // Quick and dirty setup of layers
- for (auto const &i : this->layers.mapping)
- {
- c->layer_create(i.second.layer_id, scale_rect.w, scale_rect.h);
- auto &l = layers[i.second.layer_id];
- l->set_source_rectangle(0, 0, base.w, base.h);
- l->set_destination_rectangle(
- scale_rect.x, scale_rect.y, scale_rect.w, scale_rect.h);
- l->set_visibility(1);
- HMI_DEBUG("wm", "Setting up layer %s (%d) for surface role match \"%s\"",
- i.second.name.c_str(), i.second.layer_id, i.second.role.c_str());
- }
-
- // Add layers to screen
- s->set_render_order(this->layers.layers);
-
- this->layout_commit();
-
- return 0;
-}
-
-void WindowManager::surface_set_layout(int surface_id, const std::string& area)
-{
- if (!this->controller->surface_exists(surface_id))
- {
- HMI_ERROR("wm", "Surface %d does not exist", surface_id);
- return;
- }
-
- auto o_layer_id = this->layers.get_layer_id(surface_id);
-
- if (!o_layer_id)
- {
- HMI_ERROR("wm", "Surface %d is not associated with any layer!", surface_id);
- return;
- }
-
- uint32_t layer_id = *o_layer_id;
-
- auto const &layer = this->layers.get_layer(layer_id);
- auto rect = this->layers.getAreaSize(area);
- HMI_SEQ_DEBUG(g_app_list.currentRequestNumber(), "%s : x:%d y:%d w:%d h:%d", area.c_str(),
- rect.x, rect.y, rect.w, rect.h);
- auto &s = this->controller->surfaces[surface_id];
-
- int x = rect.x;
- int y = rect.y;
- int w = rect.w;
- int h = rect.h;
-
- HMI_DEBUG("wm", "surface_set_layout for surface %u on layer %u", surface_id,
- layer_id);
-
- // set destination to the display rectangle
- s->set_destination_rectangle(x, y, w, h);
-
- // update area information
- this->area_info[surface_id].x = x;
- this->area_info[surface_id].y = y;
- this->area_info[surface_id].w = w;
- this->area_info[surface_id].h = h;
-
- HMI_DEBUG("wm", "Surface %u now on layer %u with rect { %d, %d, %d, %d }",
- surface_id, layer_id, x, y, w, h);
-}
-
-void WindowManager::layout_commit()
-{
- this->controller->commit_changes();
- this->display->flush();
-}
-
-void WindowManager::emit_activated(char const *label)
-{
- this->send_event(kListEventName[Event_Active], label);
-}
-
-void WindowManager::emit_deactivated(char const *label)
-{
- this->send_event(kListEventName[Event_Inactive], label);
-}
-
-void WindowManager::emit_syncdraw(char const *label, char const *area, int x, int y, int w, int h)
-{
- this->send_event(kListEventName[Event_SyncDraw], label, area, x, y, w, h);
-}
-
-void WindowManager::emit_syncdraw(const std::string &role, const std::string &area)
-{
- compositor::rect rect = this->layers.getAreaSize(area);
- this->send_event(kListEventName[Event_SyncDraw],
- role.c_str(), area.c_str(), rect.x, rect.y, rect.w, rect.h);
-}
-
-void WindowManager::emit_flushdraw(char const *label)
-{
- this->send_event(kListEventName[Event_FlushDraw], label);
-}
-
-void WindowManager::emit_visible(char const *label, bool is_visible)
-{
- this->send_event(is_visible ? kListEventName[Event_Visible] : kListEventName[Event_Invisible], label);
-}
-
-void WindowManager::emit_invisible(char const *label)
-{
- return emit_visible(label, false);
-}
-
-void WindowManager::emit_visible(char const *label) { return emit_visible(label, true); }
-
-void WindowManager::activate(int id)
-{
- auto ip = this->controller->sprops.find(id);
- if (ip != this->controller->sprops.end())
- {
- this->controller->surfaces[id]->set_visibility(1);
- char const *label =
- this->lookup_name(id).value_or("unknown-name").c_str();
-
- // FOR CES DEMO >>>
- if ((0 == strcmp(label, "radio")) ||
- (0 == strcmp(label, "music")) ||
- (0 == strcmp(label, "video")) ||
- (0 == strcmp(label, "map")))
- {
- for (auto i = surface_bg.begin(); i != surface_bg.end(); ++i)
- {
- if (id == *i)
- {
- // Remove id
- this->surface_bg.erase(i);
-
- // Remove from BG layer (999)
- HMI_DEBUG("wm", "Remove %s(%d) from BG layer", label, id);
- this->controller->layers[999]->remove_surface(id);
-
- // Add to FG layer (1001)
- HMI_DEBUG("wm", "Add %s(%d) to FG layer", label, id);
- this->controller->layers[1001]->add_surface(id);
-
- for (int j : this->surface_bg)
- {
- HMI_DEBUG("wm", "Stored id:%d", j);
- }
- break;
- }
- }
- }
- // <<< FOR CES DEMO
-
- this->layout_commit();
-
- // TODO: application requests by old role,
- // so convert role new to old for emitting event
- const char* old_role = this->rolenew2old[label].c_str();
-
- this->emit_visible(old_role);
- this->emit_activated(old_role);
- }
-}
-
-void WindowManager::deactivate(int id)
-{
- auto ip = this->controller->sprops.find(id);
- if (ip != this->controller->sprops.end())
- {
- char const *label =
- this->lookup_name(id).value_or("unknown-name").c_str();
-
- // FOR CES DEMO >>>
- if ((0 == strcmp(label, "radio")) ||
- (0 == strcmp(label, "music")) ||
- (0 == strcmp(label, "video")) ||
- (0 == strcmp(label, "map")))
- {
-
- // Store id
- this->surface_bg.push_back(id);
-
- // Remove from FG layer (1001)
- HMI_DEBUG("wm", "Remove %s(%d) from FG layer", label, id);
- this->controller->layers[1001]->remove_surface(id);
-
- // Add to BG layer (999)
- HMI_DEBUG("wm", "Add %s(%d) to BG layer", label, id);
- this->controller->layers[999]->add_surface(id);
-
- for (int j : surface_bg)
- {
- HMI_DEBUG("wm", "Stored id:%d", j);
- }
- }
- else
- {
- this->controller->surfaces[id]->set_visibility(0);
- }
- // <<< FOR CES DEMO
-
- this->layout_commit();
-
- // TODO: application requests by old role,
- // so convert role new to old for emitting event
- const char* old_role = this->rolenew2old[label].c_str();
-
- this->emit_deactivated(old_role);
- this->emit_invisible(old_role);
- }
-}
-
-WMError WindowManager::setRequest(const std::string& appid, const std::string &role, const std::string &area,