Add remote display support
[apps/agl-service-windowmanager.git] / src / wm_layer_control.cpp
1 /*
2  * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
3  * Copyright (c) 2018,2019 Konsulko Group
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #include <assert.h>
18 #include <unistd.h>
19 #include "wm_layer_control.hpp"
20 #include "wm_layer.hpp"
21 #include "wm_client.hpp"
22 #include "request.hpp"
23 #include "json_helper.hpp"
24
25 #define LC_AREA_FILE "areas.json"
26 #define LC_LAYER_SETTING_FILE "layers.json"
27 #define LC_DEFAULT_AREA "fullscreen"
28 #define LC_REMOTE_DEFAULT_AREA "remote.fullscreen"
29 #define BACK_GROUND_LAYER "BackGroundLayer"
30
31 using std::string;
32 using std::vector;
33 using std::shared_ptr;
34
35 namespace wm {
36
37 LayerControl* g_lc_ctxt;
38
39 static void createCallback_static(ilmObjectType object,
40                             t_ilm_uint id,
41                             t_ilm_bool created,
42                             void* data)
43 {
44     static_cast<LayerControl*>(data)->dispatchCreateEvent(object, id, created);
45 }
46
47 static void surfaceCallback_static(t_ilm_surface surface,
48             struct ilmSurfaceProperties* surface_prop,
49             t_ilm_notification_mask mask)
50 {
51     g_lc_ctxt->dispatchSurfacePropChangeEvent(surface, surface_prop, mask);
52 }
53
54 static void layerCallback_static(t_ilm_layer layer,
55             struct ilmLayerProperties* layer_prop,
56             t_ilm_notification_mask mask)
57 {
58     g_lc_ctxt->dispatchLayerPropChangeEvent(layer, layer_prop, mask);
59 }
60
61 LayerControl::LayerControl(const std::string& root)
62 {
63     string area_path(get_file_path(LC_AREA_FILE, root.c_str()));
64     string layer_path(get_file_path(LC_LAYER_SETTING_FILE, root.c_str()));
65     // load layers.setting.json
66     WMError ret = this->loadLayerSetting(layer_path);
67     assert(ret == WMError::SUCCESS);
68     // load areas.json
69     ret = this->loadAreaDb(area_path);
70     assert(ret == WMError::SUCCESS);
71 }
72
73 WMError LayerControl::init(const LayerControlCallbacks& cb)
74 {
75     HMI_DEBUG("Initialize of ilm library and display");
76     t_ilm_uint num = 0;
77     t_ilm_uint *ids;
78     int cnt = 0;
79     ilmErrorTypes rc = ilm_init();
80
81     while (rc != ILM_SUCCESS)
82     {
83         cnt++;
84         if (20 <= cnt)
85         {
86             HMI_ERROR("Could not connect to compositor");
87             goto lc_init_error;
88         }
89         HMI_ERROR("Wait to start weston ...");
90         sleep(1);
91         rc = ilm_init();
92     }
93     if(rc != ILM_SUCCESS) goto lc_init_error;
94
95     // Get current screen setting
96     rc = ilm_getScreenIDs(&num, &ids);
97
98     if(rc != ILM_SUCCESS) goto lc_init_error;
99
100     for(unsigned i = 0; i < num; i++)
101     {
102         HMI_INFO("get screen: %d", ids[i]);
103     }
104     // Currently, 0 is only available
105     this->screenID = ids[0];
106
107     if (1 < num)
108     {
109         // TODO: set remote screen id
110         HMI_INFO("There is remote screen (id:%d)", ids[1]);
111         this->remoteScreenID = ids[1];
112     }
113     else
114     {
115         HMI_INFO("There is no remote screen");
116         this->remoteScreenID = -1;
117     }
118
119     rc = ilm_getPropertiesOfScreen(this->screenID, &this->screen_prop);
120
121     if(rc != ILM_SUCCESS) goto lc_init_error;
122
123     // Register Callback to Window Manager and from ILM
124     this->cb = cb;
125     ilm_registerNotification(createCallback_static, this);
126
127     return WMError::SUCCESS;
128
129 lc_init_error:
130     HMI_ERROR("Failed to initialize. Terminate WM");
131
132     return WMError::FAIL;
133 }
134
135 void LayerControl::createNewLayer(unsigned id, bool remote)
136 {
137     HMI_INFO("create new ID :%d%s", id, remote ? " (For remote layer)" : "");
138     struct rect rct = this->area2size[remote ? LC_REMOTE_DEFAULT_AREA : LC_DEFAULT_AREA];
139     ilm_layerCreateWithDimension(&id, rct.w, rct.h);
140     //ilm_layerSetSourceRectangle(id, rct.x, rct.y, rct.w, rct.h);
141     ilm_layerSetDestinationRectangle(id, this->offset_x, this->offset_y, rct.w, rct.h);
142     ilm_layerSetOpacity(id, 1.0);
143     ilm_layerSetVisibility(id, ILM_FALSE);
144     ilm_commitChanges();
145     auto wm_layer = getWMLayer(id);
146     wm_layer->addLayerToState(id);
147     wm_layer->setRemote(remote);
148     this->renderLayers();
149 }
150
151 unsigned LayerControl::getNewLayerID(const string& role, std::string* layer_name)
152 {
153     unsigned ret = 0;
154     for(const auto& l: this->wm_layers)
155     {
156         ret = l->getNewLayerID(role);
157         if(ret != 0)
158         {
159             unsigned wmlid = l->getWMLayerID();
160             this->lid2wmlid[ret] = wmlid;
161             if(layer_name)
162             {
163                 *layer_name = l->layerName();
164             }
165             break;
166         }
167     }
168     return ret;
169 }
170
171 shared_ptr<WMLayer> LayerControl::getWMLayer(unsigned layer)
172 {
173     unsigned wm_lid = this->lid2wmlid[layer];
174     return this->wm_layers[wm_lid];
175 }
176
177 std::shared_ptr<WMLayer> LayerControl::getWMLayer(std::string layer_name)
178 {
179     for(auto &l : this->wm_layers)
180     {
181         if(l->layerName() == layer_name)
182         {
183             return l;
184         }
185     }
186     return nullptr;
187 }
188
189 struct rect LayerControl::getAreaSize(const std::string& area)
190 {
191     return area2size[area];
192 }
193
194 void LayerControl::setupArea(const rectangle& base_rct, double scaling)
195 {
196     this->scaling = scaling;
197     this->offset_x = base_rct.left();
198     this->offset_y = base_rct.top();
199
200     for (auto &i : this->area2size)
201     {
202         i.second.x = static_cast<int>(scaling * i.second.x + 0.5);
203         i.second.y = static_cast<int>(scaling * i.second.y + 0.5);
204         i.second.w = static_cast<int>(scaling * i.second.w + 0.5);
205         i.second.h = static_cast<int>(scaling * i.second.h + 0.5);
206
207         HMI_DEBUG("area:%s size(after) : x:%d y:%d w:%d h:%d",
208             i.first.c_str(), i.second.x, i.second.y, i.second.w, i.second.h);
209     }
210 }
211
212 Screen LayerControl::getScreenInfo()
213 {
214     return Screen(this->screen_prop.screenWidth, this->screen_prop.screenHeight);
215 }
216
217 double LayerControl::scale()
218 {
219     return this->scaling;
220 }
221
222 WMError LayerControl::renderLayers()
223 {
224     HMI_INFO("Commit change");
225     WMError rc = WMError::SUCCESS;
226
227     bool haveRemoteDisplay = remoteScreenID > 0;
228
229     // Check the number of layers
230     vector<unsigned> ivi_l_ids;
231     vector<unsigned> ivi_remote_l_ids;
232     for(auto& l : this->wm_layers)
233     {
234         auto state = l->getLayerState();
235         HMI_DEBUG("layer %s", l->layerName().c_str());
236         if (!l->isRemote())
237         {
238             for(const auto& id : state.getIviIdList())
239             {
240                 HMI_DEBUG("Add %d", id);
241                 ivi_l_ids.push_back(id);
242             }
243         } else if (haveRemoteDisplay) {
244             for(const auto& id : state.getIviIdList())
245             {
246                 HMI_DEBUG("Add remote %d", id);
247                 ivi_remote_l_ids.push_back(id);
248             }
249         }
250     }
251
252     // Create render order
253     t_ilm_layer* id_array = new t_ilm_layer[ivi_l_ids.size()];
254     if(id_array == nullptr)
255     {
256         HMI_WARNING("short memory");
257         this->undoUpdate();
258         return WMError::FAIL;
259     }
260     int count = 0;
261     for(const auto& i : ivi_l_ids)
262     {
263         id_array[count++] = i;
264     }
265
266     t_ilm_layer* remote_id_array = nullptr;
267     if(haveRemoteDisplay && ivi_remote_l_ids.size() != 0) {
268         remote_id_array = new t_ilm_layer[ivi_remote_l_ids.size()];
269         if(remote_id_array == nullptr)
270         {
271             HMI_WARNING("short memory");
272             this->undoUpdate();
273             return WMError::FAIL;
274         }
275         count = 0;
276         for(const auto& i : ivi_remote_l_ids)
277         {
278             remote_id_array[count++] = i;
279         }
280     }
281
282     // Display
283     ilmErrorTypes ret = ilm_displaySetRenderOrder(this->screenID, id_array, ivi_l_ids.size());
284     if(ret == ILM_SUCCESS && haveRemoteDisplay)
285     {
286         ret = ilm_displaySetRenderOrder(this->remoteScreenID, remote_id_array, ivi_remote_l_ids.size());
287     }
288     if(ret != ILM_SUCCESS)
289     {
290         this->undoUpdate();
291         rc = WMError::FAIL;
292     }
293     else
294     {
295         for(auto& l : this->wm_layers)
296         {
297             l->update();
298         }
299     }
300     ilm_commitChanges();
301     delete id_array;
302     delete remote_id_array;
303     return rc;
304 }
305
306 WMError LayerControl::setXDGSurfaceOriginSize(unsigned surface)
307 {
308     WMError ret = WMError::NOT_REGISTERED;
309     ilmSurfaceProperties prop;
310     ilmErrorTypes rc = ilm_getPropertiesOfSurface(surface, &prop);
311     if(rc == ILM_SUCCESS)
312     {
313         HMI_INFO("xdg surface info %d, %d", prop.origSourceWidth, prop.origSourceHeight);
314         ilm_surfaceSetSourceRectangle(surface, 0, 0, prop.origSourceWidth, prop.origSourceHeight);
315         ret = WMError::SUCCESS;
316     }
317     return ret;
318 }
319
320
321 void LayerControl::undoUpdate()
322 {
323     for(auto& l : this->wm_layers)
324     {
325         l->undo();
326     }
327 }
328
329 WMError LayerControl::loadLayerSetting(const string &path)
330 {
331     HMI_DEBUG("loading WMLayer(Application Containers) Setting from %s", path.c_str());
332
333     json_object *json_obj, *json_cfg;
334     int ret = jh::inputJsonFilie(path.c_str(), &json_obj);
335     if (0 > ret)
336     {
337         HMI_ERROR("Could not open %s", path.c_str());
338         return WMError::FAIL;
339     }
340     HMI_INFO("json_obj dump:%s", json_object_get_string(json_obj));
341
342     if (!json_object_object_get_ex(json_obj, "mappings", &json_cfg))
343     {
344         HMI_ERROR("Parse Error!!");
345         return WMError::FAIL;
346     }
347
348     int len = json_object_array_length(json_cfg);
349     HMI_DEBUG("json_cfg len:%d", len);
350
351     for (int i = 0; i < len; i++)
352     {
353         json_object *json_tmp = json_object_array_get_idx(json_cfg, i);
354         HMI_DEBUG("> json_tmp dump:%s", json_object_get_string(json_tmp));
355
356         this->wm_layers.emplace_back(std::make_shared<WMLayer>(json_tmp, i));
357     }
358     json_object_put(json_obj);
359
360     return WMError::SUCCESS;
361 }
362
363 WMError LayerControl::loadAreaDb(const std::string& path)
364 {
365     // Load area.db
366     json_object *json_obj;
367     int ret = jh::inputJsonFilie(path.c_str(), &json_obj);
368     if (0 > ret)
369     {
370         HMI_ERROR("Could not open %s", path.c_str());
371         return WMError::FAIL;
372     }
373     HMI_INFO("json_obj dump:%s", json_object_get_string(json_obj));
374
375     // Perse areas
376     json_object *json_cfg;
377     if (!json_object_object_get_ex(json_obj, "areas", &json_cfg))
378     {
379         HMI_ERROR("Parse Error!!");
380         return WMError::FAIL;
381     }
382
383     int len = json_object_array_length(json_cfg);
384     HMI_DEBUG("json_cfg len:%d", len);
385
386     const char *area;
387     for (int i = 0; i < len; i++)
388     {
389         json_object *json_tmp = json_object_array_get_idx(json_cfg, i);
390         HMI_DEBUG("> json_tmp dump:%s", json_object_get_string(json_tmp));
391
392         area = jh::getStringFromJson(json_tmp, "name");
393         if (nullptr == area)
394         {
395             HMI_ERROR("Parse Error!!");
396             return WMError::FAIL;
397         }
398         HMI_DEBUG("> area:%s", area);
399
400         json_object *json_rect;
401         if (!json_object_object_get_ex(json_tmp, "rect", &json_rect))
402         {
403             HMI_ERROR("Parse Error!!");
404             return WMError::FAIL;
405         }
406         HMI_DEBUG("> json_rect dump:%s", json_object_get_string(json_rect));
407
408         struct rect area_size;
409         area_size.x = jh::getIntFromJson(json_rect, "x");
410         area_size.y = jh::getIntFromJson(json_rect, "y");
411         area_size.w = jh::getIntFromJson(json_rect, "w");
412         area_size.h = jh::getIntFromJson(json_rect, "h");
413
414         this->area2size[area] = area_size;
415     }
416
417     // Check
418     for (const auto& itr : this->area2size)
419     {
420         HMI_DEBUG("area:%s x:%d y:%d w:%d h:%d",
421                   itr.first.c_str(), itr.second.x, itr.second.y,
422                   itr.second.w, itr.second.h);
423     }
424
425     // Release json_object
426     json_object_put(json_obj);
427
428     return WMError::SUCCESS;
429 }
430
431 WMError LayerControl::layoutChange(const WMAction& action)
432 {
433     if (action.visible == TaskVisible::INVISIBLE)
434     {
435         // Visibility is not change -> no redraw is required
436         return WMError::SUCCESS;
437     }
438     if(action.client == nullptr)
439     {
440         HMI_SEQ_ERROR(action.req_num, "client may vanish");
441         return WMError::NOT_REGISTERED;
442     }
443     unsigned layer = action.client->layerID();
444     unsigned surface = action.client->surfaceID();
445
446     auto rect = this->getAreaSize(action.area);
447     HMI_SEQ_INFO(action.req_num, "Set layout %d, %d, %d, %d",rect.x, rect.y, rect.w, rect.h);
448
449     // Sometimes, ivi_wm_surface_size signal doesn't reach window manager,
450     // then, Window Manager set set source size = 0.
451     if(!action.client->isSourceSizeSet())
452     {
453         ilmSurfaceProperties sp;
454         if (ILM_SUCCESS != ilm_getPropertiesOfSurface(surface, &sp))
455             return WMError::FAIL;
456
457         if  (sp.origSourceHeight != sp.sourceHeight ||
458              sp.origSourceWidth  != sp.sourceWidth)
459         {
460             HMI_SEQ_NOTICE(action.req_num, "set source size w:%d h%d", sp.origSourceWidth, sp.origSourceHeight);
461             ilm_surfaceSetSourceRectangle(surface, 0, 0, sp.origSourceWidth, sp.origSourceHeight);
462             ilm_commitChanges();
463             action.client->setSurfaceSizeCorrectly();
464         }
465     }
466
467     ilm_surfaceSetDestinationRectangle(surface, rect.x, rect.y, rect.w, rect.h);
468     ilm_commitChanges();
469     action.client->setArea(action.area);
470     for(auto &wm_layer: this->wm_layers)
471     {
472         // Store the state who is assigned to the area
473         if(wm_layer->hasLayerID(layer))
474         {
475             wm_layer->attachAppToArea(action.client->appID(), action.area);
476             /* TODO: manipulate state directly
477             LayerState ls = wm_layer->getLayerState();
478             ls.seattachAppToAreatArea(action.client->appID(), action.area);
479             wm_layer->dump(); */
480         }
481     }
482
483     return WMError::SUCCESS;
484 }
485
486 WMError LayerControl::visibilityChange(const WMAction& action)
487 {
488     WMError ret = WMError::FAIL;
489     if(action.client == nullptr)
490     {
491         HMI_SEQ_ERROR(action.req_num, "client may vanish");
492         return WMError::NOT_REGISTERED;
493     }
494
495     if (action.visible == TaskVisible::VISIBLE)
496     {
497         ret = this->makeVisible(action.client);
498     }
499     else if (action.visible == TaskVisible::INVISIBLE)
500     {
501         ret = this->makeInvisible(action.client);
502     }
503     ilm_commitChanges();
504     return ret;
505 }
506
507 WMError LayerControl::updateAreaList(const ChangeAreaReq& req)
508 {
509     // error check
510     for(const auto& elem : req.area_req)
511     {
512         if(this->area2size.find(elem.first) == this->area2size.end())
513         {
514             HMI_ERROR("requested area %s is not registered in area list", elem.first.c_str());
515             return WMError::NOT_REGISTERED;
516         }
517     }
518     // update list
519     for(const auto& elem : req.area_req)
520     {
521         this->area2size[elem.first] = elem.second;
522     }
523     if(req.save)
524     {
525         HMI_NOTICE("Not implemented");
526         // TODO
527     }
528     return WMError::SUCCESS;
529 }
530
531 WMError LayerControl::getUpdateAreaList(ChangeAreaReq *req)
532 {
533     for(const auto& wm_layer : this->wm_layers)
534     {
535         // get area name and compare it with elem
536         for(const auto& area : req->area_req)
537         {
538             string app = wm_layer->attachedApp(area.first);
539             if(!app.empty())
540             {
541                 HMI_INFO("app %s changes area %s", app.c_str(), area.first.c_str());
542                 req->update_app2area[app] = area.first;
543             }
544         }
545     }
546     return WMError::SUCCESS;
547 }
548
549 void LayerControl::appTerminated(const shared_ptr<WMClient> client)
550 {
551     for(auto& l : this->wm_layers)
552     {
553         if(l->hasLayerID(client->layerID()))
554         {
555             l->appTerminated(client->layerID());
556         }
557     }
558 }
559
560 void LayerControl::dispatchCreateEvent(ilmObjectType object, unsigned id, bool created)
561 {
562     if (ILM_SURFACE == object)
563     {
564         if (created)
565         {
566             ilmSurfaceProperties sp;
567             ilmErrorTypes rc;
568             rc = ilm_getPropertiesOfSurface(id, &sp);
569             if(rc != ILM_SUCCESS)
570             {
571                 HMI_ERROR("Failed to get surface %d property due to %d", id, ilm_getError());
572                 return;
573             }
574             this->cb.surfaceCreated(sp.creatorPid, id);
575             ilm_surfaceAddNotification(id, surfaceCallback_static);
576             ilm_surfaceSetVisibility(id, ILM_TRUE);
577             ilm_surfaceSetType(id, ILM_SURFACETYPE_DESKTOP);
578         }
579         else
580         {
581             this->cb.surfaceDestroyed(id);
582         }
583     }
584     if (ILM_LAYER == object)
585     {
586         if(created)
587         {
588             ilm_layerAddNotification(id, layerCallback_static);
589         }
590         else
591         {
592             // Ignore here. Nothing to do currently.
593             // Process of application dead is handled by Window Manager
594             // from binder notification
595         }
596     }
597 }
598
599 void LayerControl::dispatchSurfacePropChangeEvent(unsigned id,
600         struct ilmSurfaceProperties* sprop,
601         t_ilm_notification_mask mask)
602 {
603     /*
604       ILM_NOTIFICATION_CONTENT_AVAILABLE & ILM_NOTIFICATION_CONTENT_REMOVED
605       are not handled here, handled in create/destroy event
606      */
607     if (ILM_NOTIFICATION_VISIBILITY & mask)
608     {
609         HMI_DEBUG("surface %d turns visibility %d", id, sprop->visibility);
610     }
611     if (ILM_NOTIFICATION_OPACITY & mask)
612     {
613         HMI_DEBUG("surface %d turns opacity %f", id, sprop->opacity);
614     }
615     if (ILM_NOTIFICATION_SOURCE_RECT & mask)
616     {
617         HMI_DEBUG("surface %d source rect changes", id);
618     }
619     if (ILM_NOTIFICATION_DEST_RECT & mask)
620     {
621         HMI_DEBUG("surface %d dest rect changes", id);
622     }
623     if (ILM_NOTIFICATION_CONFIGURED & mask)
624     {
625         HMI_DEBUG("surface %d size %d, %d, %d, %d", id,
626             sprop->sourceX, sprop->sourceY, sprop->origSourceWidth, sprop->origSourceHeight);
627         ilm_surfaceSetSourceRectangle(id, 0, 0, sprop->origSourceWidth, sprop->origSourceHeight);
628     }
629 }
630
631 void LayerControl::dispatchLayerPropChangeEvent(unsigned id,
632         struct ilmLayerProperties* lprop,
633         t_ilm_notification_mask mask)
634 {
635     if (ILM_NOTIFICATION_VISIBILITY & mask)
636     {
637         HMI_DEBUG("layer %d turns visibility %d", id, lprop->visibility);
638     }
639     if (ILM_NOTIFICATION_OPACITY & mask)
640     {
641         HMI_DEBUG("layer %d turns opacity %f", id, lprop->opacity);
642     }
643     if (ILM_NOTIFICATION_SOURCE_RECT & mask)
644     {
645         HMI_DEBUG("layer %d source rect changes", id);
646     }
647     if (ILM_NOTIFICATION_DEST_RECT & mask)
648     {
649         HMI_DEBUG("layer %d dest rect changes", id);
650     }
651 }
652
653 WMError LayerControl::makeVisible(const shared_ptr<WMClient> client)
654 {
655     WMError ret = WMError::SUCCESS;
656     // Don't check here wheher client is nullptr or not
657     unsigned layer_id = client->layerID();
658     auto layer = getWMLayer(layer_id);
659
660     if (!layer->isRemote())
661     {
662        this->moveForeGround(client);
663     }
664     else if (0 > this->remoteScreenID) {
665         return ret;
666     }
667
668     ilm_layerSetVisibility(layer_id, ILM_TRUE);
669
670     return ret;
671 }
672
673 WMError LayerControl::makeInvisible(const shared_ptr<WMClient> client)
674 {
675     WMError ret = WMError::SUCCESS;
676     // Don't check here the client is not nullptr
677     unsigned layer_id = client->layerID();
678     auto layer = getWMLayer(layer_id);
679
680     bool set_invisible = true;
681     if (!layer->isRemote())
682     {
683         if(this->moveBackGround(client))
684         {
685             set_invisible = false;
686         }
687         else
688         {
689             HMI_INFO("make invisible client %s", client->appID().c_str());
690         }
691     }
692     else if (0 > this->remoteScreenID) {
693         return ret;
694     }
695
696     if (set_invisible)
697     {
698         ilm_layerSetVisibility(layer_id, ILM_FALSE);
699     }
700
701     return ret;
702 }
703
704 bool LayerControl::moveBackGround(const shared_ptr<WMClient> client)
705 {
706     bool ret = false;
707
708     // Move background from foreground layer
709     auto bg = this->getWMLayer(BACK_GROUND_LAYER);
710     if(bg != nullptr)
711     {
712         HMI_DEBUG("client %s role %s", client->appID().c_str(), client->role().c_str());
713         unsigned layer = client->layerID();
714         if(bg->hasRole(client->role()))
715         {
716             HMI_INFO("%s go to background", client->appID().c_str());
717             bg->addLayerToState(layer);
718             auto wm_layer = this->getWMLayer(layer);
719             wm_layer->removeLayerFromState(layer);
720             /* TODO: manipulate state directly
721             LayerState bg_ls = bg->getLayerState();
722             bg_ls.addLayer(layer);
723             LayerState ls = wm_layer->getLayerState();
724             ls.removeLayer(layer); */
725             bg->dump();
726             wm_layer->dump();
727             ret = true;
728         }
729     }
730     return ret;
731 }
732
733 bool LayerControl::moveForeGround(const shared_ptr<WMClient> client)
734 {
735     bool ret = false;
736
737     // Move foreground from foreground layer
738     auto bg = this->getWMLayer(BACK_GROUND_LAYER);
739     if(bg != nullptr)
740     {
741         if(bg->hasRole(client->role()))
742         {
743             unsigned layer = client->layerID();
744             HMI_INFO("%s go to foreground", client->appID().c_str());
745             bg->removeLayerFromState(layer);
746             auto wm_layer = this->getWMLayer(layer);
747             wm_layer->addLayerToState(layer);
748             /* TODO: manipulate state directly
749             LayerState bg_ls = bg->getLayerState();
750             bg_ls.removeLayer(layer);
751             LayerState ls = wm_layer->getLayerState();
752             ls.addLayer(layer); */
753             bg->dump();
754             wm_layer->dump();
755             ret = true;
756         }
757     }
758     return ret;
759 }
760
761 } // namespace wm