Bug Fix for TIVI-1935.
[profile/ivi/ico-uxf-homescreen.git] / lib / system-controller / CicoSCWindowController.cpp
1 /*
2  * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
3  *
4  * This program is licensed under the terms and conditions of the
5  * Apache License, version 2.0.  The full text of the Apache License is at
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  */
9
10 //==========================================================================
11 /**
12  *  @file   CicoSCWindowController.cpp
13  *
14  *  @brief  This file implementation of CicoSCWindowController class
15  */
16 //==========================================================================
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <unistd.h>
21 #include <string.h>
22 #include <signal.h>
23 #include <errno.h>
24 #include <sys/ioctl.h>
25
26 #include <vector>
27 #include <algorithm>
28 using namespace std;
29
30 #include "CicoSCWindow.h"
31 #include "CicoSCWayland.h"
32 #include "CicoSCWindowController.h"
33 #include "CicoLog.h"
34
35 #include "CicoSCSystemConfig.h"
36 #include "CicoSCConf.h"
37 #include "CicoSCDisplay.h"
38 #include "CicoSCLayer.h"
39 #include "CicoSCDisplayZone.h"
40 #include "ico_syc_error.h"
41 #include "ico_syc_type.h"
42 #include "ico_syc_winctl.h"
43 #include "CicoSCCommand.h"
44 #include "ico_syc_msg_cmd_def.h"
45 #include "CicoSCServer.h"
46 #include "CicoSCMessage.h"
47 #include "CicoSCLifeCycleController.h"
48 #include "CicoSCResourceManager.h"
49
50 //--------------------------------------------------------------------------
51 /**
52  *  @brief  default constructor
53  */
54 //--------------------------------------------------------------------------
55 CicoSCWindowController::CicoSCWindowController()
56     : m_resMgr(NULL), m_physicalDisplayTotal(0)
57 {
58     CicoSCWayland* wayland = CicoSCWayland::getInstance();
59     wayland->getInstance()->addWaylandIF(ICO_WL_WIN_MGR_IF, this);
60     wayland->getInstance()->addWaylandIF(ICO_WL_OUTPUT_IF, this);
61     initDB();
62 }
63
64 //--------------------------------------------------------------------------
65 /**
66  *  @brief  destructor
67  */
68 //--------------------------------------------------------------------------
69 CicoSCWindowController::~CicoSCWindowController()
70 {
71 }
72
73 //--------------------------------------------------------------------------
74 /**
75  *  @brief  initialize display and window database
76  */
77 //--------------------------------------------------------------------------
78 int
79 CicoSCWindowController::initDB(void)
80 {
81     ICO_DBG("CicoSCWindowController::initDB: Enter");
82
83     const vector<CicoSCDisplayConf*>& displayList =
84             CicoSCSystemConfig::getInstance()->getDisplayConfList();
85     vector<CicoSCDisplayConf*>::const_iterator itr;
86     itr = displayList.begin();
87     for (; itr != displayList.end(); ++itr) {
88         CicoSCDisplay *display = new CicoSCDisplay();
89         display->displayid = (*itr)->id;
90         display->type      = (*itr)->type;
91         display->nodeid    = (*itr)->node;
92         display->displayno = (*itr)->no;
93         display->width     = (*itr)->width;
94         display->height    = (*itr)->height;
95         display->inch      = (*itr)->inch;
96         display->name      = (*itr)->name;
97
98         vector<CicoSCLayerConf*>::const_iterator itr2;
99         itr2 = (*itr)->layerConfList.begin();
100         for (; itr2 != (*itr)->layerConfList.end(); ++itr2) {
101             CicoSCLayer *layer = new CicoSCLayer();
102             layer->layerid     = (*itr2)->id;
103             layer->type        = (*itr2)->type;
104             layer->width       = display->width;
105             layer->height      = display->height;
106             layer->displayid   = display->displayid;
107             layer->menuoverlap = (*itr2)->menuoverlap;
108             display->layerList.push_back(layer);
109         }
110
111         vector<CicoSCDisplayZoneConf*>::const_iterator itr3;
112         itr3 = (*itr)->zoneConfList.begin();
113         for (; itr3 != (*itr)->zoneConfList.end(); ++itr3) {
114             CicoSCDisplayZone *zone = new CicoSCDisplayZone();
115             zone->zoneid   = (*itr3)->id;
116             zone->x        = (*itr3)->x;
117             zone->y        = (*itr3)->y;
118             zone->width    = (*itr3)->w;
119             zone->height   = (*itr3)->h;
120             zone->fullname = (*itr3)->fullname;
121             display->zoneList[zone->zoneid] = zone;
122         }
123         display->dump();
124         m_displayList.push_back(display);
125     }
126
127     ICO_DBG("CicoSCWindowController::initDB: Leave");
128     return ICO_SYC_EOK;
129 }
130
131 //--------------------------------------------------------------------------
132 /**
133  *  @brief   set resource manager instance
134  *
135  *  @param [in] resMgr  resource manager instance
136  */
137 //--------------------------------------------------------------------------
138 void
139 CicoSCWindowController::setResourceManager(CicoSCResourceManager *resMgr)
140 {
141     m_resMgr = resMgr;
142 }
143
144 //--------------------------------------------------------------------------
145 /**
146  *  @brief   show a target window
147  *
148  *  @param [in] surfaceid       wayland surface id
149  *  @param [in] animation       animation name
150  *  @param [in] animationTime   animation time
151  *
152  *  @return ICO_SYC_EOK on success, other on error
153  *  @retval ICO_SYC_EOK         success
154  *  @retval ICO_SYC_ESRCH       error(not initialized)
155  *  @retval ICO_SYC_ENOENT      error(not exist)
156  */
157 //--------------------------------------------------------------------------
158 int
159 CicoSCWindowController::show(int        surfaceid,
160                              const char *animation,
161                              int        animationTime)
162 {
163     ICO_DBG("CicoSCWindowController::show Enter"
164             "(surfaceid=0x%08X animation=%s animationTime=%d)",
165             surfaceid, animation, animationTime);
166
167     // find window information in window list
168     CicoSCWindow *window = findWindow(surfaceid);
169     if (NULL == window) {
170         ICO_WRN("CicoSCWindowController::show Leave(ENOENT)");
171         return ICO_SYC_ENOENT;
172     }
173
174     // update visible attr
175     window->visible = true;
176
177     // set animation request to Multi Window Manager
178     int animaFlag = ICO_WINDOW_MGR_FLAGS_NO_CONFIGURE;
179     int raiseFlag = ICO_WINDOW_MGR_V_NOCHANGE;
180     if (animationTime & ICO_SYC_WIN_SURF_RAISE) {
181         raiseFlag = ICO_WINDOW_MGR_RAISE_RAISE;
182         window->raise = true;
183     }
184     else if (animationTime & ICO_SYC_WIN_SURF_LOWER)    {
185         raiseFlag = ICO_WINDOW_MGR_RAISE_LOWER;
186         window->raise = false;
187     }
188     else if (((animationTime & ICO_SYC_WIN_SURF_NOCHANGE) == 0) &&
189              (false == window->raise))   {
190         raiseFlag = ICO_WINDOW_MGR_RAISE_RAISE;
191         window->raise = true;
192     }
193     if ((NULL != animation) && (animation[0] != '\0')) {
194         // set animation request to Multi Window Manager
195         CicoSCWlWinMgrIF::setAnimation(window->surfaceid,
196                                     ICO_WINDOW_MGR_ANIMATION_TYPE_SHOW,
197                                     animation, animationTime & ~ICO_SYC_WIN_SURF_FLAGS);
198         animaFlag = ICO_WINDOW_MGR_FLAGS_ANIMATION;
199     }
200
201     // set visible request to Multi Window Manager
202     CicoSCWlWinMgrIF::setVisible(window->surfaceid,
203                                  ICO_WINDOW_MGR_VISIBLE_SHOW,
204                                  raiseFlag, animaFlag);
205
206     // flush display
207     CicoSCWayland::getInstance()->flushDisplay();
208
209     ICO_DBG("CicoSCWindowController::show Leave(EOK)");
210     return ICO_SYC_EOK;
211 }
212
213 //--------------------------------------------------------------------------
214 /**
215  *  @brief   hide a target window
216  *
217  *  @param [in] surfaceid       wayland surface id
218  *  @param [in] animation       animation name
219  *  @param [in] animationTime   animation time
220  *
221  *  @return ICO_SYC_EOK on success, other on error
222  *  @retval ICO_SYC_EOK         success
223  *  @retval ICO_SYC_ESRCH       error(not initialized)
224  *  @retval ICO_SYC_ENOENT      error(not exist)
225  */
226 //--------------------------------------------------------------------------
227 int
228 CicoSCWindowController::hide(int        surfaceid,
229                              const char *animation,
230                              int        animationTime)
231 {
232     ICO_DBG("CicoSCWindowController::hide Enter"
233             "(surfaceid=0x%08X animation=%s animationTime=%d)",
234             surfaceid, animation, animationTime);
235
236     // find window information in window list
237     CicoSCWindow *window = findWindow(surfaceid);
238     if (NULL == window) {
239         ICO_WRN("CicoSCWindowController::hide Leave(ENOENT)");
240         return ICO_SYC_ENOENT;
241     }
242
243     // update window attr
244     window->visible = false;
245
246     // set animation request to Multi Window Manager
247     int animaFlag = ICO_WINDOW_MGR_FLAGS_NO_CONFIGURE;
248     if ((NULL != animation) && (animation[0] != '\0')) {
249         CicoSCWlWinMgrIF::setAnimation(window->surfaceid,
250                                        ICO_WINDOW_MGR_ANIMATION_TYPE_HIDE,
251                                        animation, animationTime & ~ICO_SYC_WIN_SURF_FLAGS);
252         animaFlag = ICO_WINDOW_MGR_FLAGS_ANIMATION;
253     }
254
255     // set visible request to Multi Window Manager
256     CicoSCWlWinMgrIF::setVisible(window->surfaceid,
257                                     ICO_WINDOW_MGR_VISIBLE_HIDE,
258                                     ICO_WINDOW_MGR_V_NOCHANGE, animaFlag);
259
260     // flush display
261     CicoSCWayland::getInstance()->flushDisplay();
262
263     ICO_DBG("CicoSCWindowController::hide Leave(EOK)");
264     return ICO_SYC_EOK;
265 }
266
267 //--------------------------------------------------------------------------
268 /**
269  *  @brief   resize window(surface) size
270  *
271  *  @param [in] surfaceid       wayland surface id
272  *  @param [in] w               window width
273  *  @param [in] h               window height
274  *  @param [in] animation       animation name
275  *  @param [in] animationTime   animation time
276  *
277  *  @return ICO_SYC_EOK on success, other on error
278  *  @retval ICO_SYC_EOK         success
279  *  @retval ICO_SYC_ESRCH       error(not initialized)
280  *  @retval ICO_SYC_ENOENT      error(window dose not exist)
281  */
282 //--------------------------------------------------------------------------
283 int
284 CicoSCWindowController::resize(int        surfaceid,
285                                int        w,
286                                int        h,
287                                const char *animation,
288                                int        animationTime)
289 {
290     ICO_DBG("CicoSCWindowController::resize Enter"
291             "(surfaceid=0x%08X h=%d w=%d animation=%s animationTime=%d)",
292             surfaceid, w, h, animation, animationTime);
293
294     // find window information in window list
295     CicoSCWindow *window = findWindow(surfaceid);
296     if (NULL == window) {
297         ICO_WRN("CicoSCWindowController::resize Leave(ENOENT)");
298         return ICO_SYC_ENOENT;
299     }
300
301     // set animation request to Multi Window Manager
302     int animaFlag = ICO_WINDOW_MGR_FLAGS_NO_CONFIGURE;
303     if ((NULL != animation) && (animation[0] != '\0')) {
304         CicoSCWlWinMgrIF::setAnimation(window->surfaceid,
305                                        ICO_WINDOW_MGR_ANIMATION_TYPE_RESIZE,
306                                        animation, animationTime);
307         animaFlag = ICO_WINDOW_MGR_FLAGS_ANIMATION;
308     }
309
310     // set visible request to Multi Window Manager
311     CicoSCWlWinMgrIF::setPositionsize(window->surfaceid, window->nodeid,
312                                       ICO_WINDOW_MGR_V_NOCHANGE,
313                                       ICO_WINDOW_MGR_V_NOCHANGE,
314                                       w, h, animaFlag);
315
316     // flush display
317     CicoSCWayland::getInstance()->flushDisplay();
318
319     ICO_DBG("CicoSCWindowController::resize Leave(EOK)");
320     return ICO_SYC_EOK;
321 }
322
323 //--------------------------------------------------------------------------
324 /**
325  *  @brief  move window(surface) size
326  *
327  *  @param [in] surfaceid       wayland surface id
328  *  @param [in] nodeid          node id
329  *  @param [in] x               window width
330  *  @param [in] y               window height
331  *  @param [in] animation       animation name
332  *  @param [in] animationTime   animation time
333  *
334  *  @return ICO_SYC_EOK on success, other on error
335  *  @retval ICO_SYC_EOK         success
336  *  @retval ICO_SYC_ESRCH       error(not initialized)
337  *  @retval ICO_SYC_ENOENT      error(window dose not exist)
338  */
339 //--------------------------------------------------------------------------
340 int
341 CicoSCWindowController::move(int        surfaceid,
342                              int        nodeid,
343                              int        x,
344                              int        y,
345                              const char *animation,
346                              int        animationTime)
347 {
348     ICO_DBG("CicoSCWindowController::move Enter"
349             "(surfaceid=0x%08X nodeid=%d x=%d y=%d "
350             "animation=%s animationTime=%d)",
351             surfaceid, nodeid, x, y, animation, animationTime);
352
353     // find window information in window list
354     CicoSCWindow *window = findWindow(surfaceid);
355     if (NULL == window) {
356         ICO_WRN("CicoSCWindowController::move Leave(ENOENT)");
357         return ICO_SYC_ENOENT;
358     }
359
360     // set animation request to Multi Window Manager
361     int animaFlag = ICO_WINDOW_MGR_FLAGS_NO_CONFIGURE;
362     if ((NULL != animation) && (animation[0] != '\0')) {
363         CicoSCWlWinMgrIF::setAnimation(window->surfaceid,
364                                        ICO_WINDOW_MGR_ANIMATION_TYPE_MOVE,
365                                        animation, animationTime);
366         animaFlag = ICO_WINDOW_MGR_FLAGS_ANIMATION;
367     }
368
369     int moveNodeId = ICO_WINDOW_MGR_V_NOCHANGE;
370     if ((nodeid >= 0) && (nodeid != INT_MAX)) {
371         moveNodeId = nodeid;
372     }
373
374     // set visible request to Multi Window Manager
375     CicoSCWlWinMgrIF::setPositionsize(window->surfaceid,
376                                       moveNodeId, x, y,
377                                       ICO_WINDOW_MGR_V_NOCHANGE,
378                                       ICO_WINDOW_MGR_V_NOCHANGE,
379                                       animaFlag);
380
381     // flush display
382     CicoSCWayland::getInstance()->flushDisplay();
383
384     ICO_DBG("CicoSCWindowController::move Leave(EOK)");
385     return ICO_SYC_EOK;
386 }
387
388 //--------------------------------------------------------------------------
389 /**
390  *  @brief  raise window(surface)
391  *
392  *  @param [in] surfaceid       wayland surface id
393  *  @param [in] animation       animation name
394  *  @param [in] animationTime   animation time
395  *
396  *  @return ICO_SYC_EOK on success, other on error
397  *  @retval ICO_SYC_EOK         success
398  *  @retval ICO_SYC_ESRCH       error(not initialized)
399  *  @retval ICO_SYC_ENOENT      error(layer dose not exist)
400  */
401 //--------------------------------------------------------------------------
402 int
403 CicoSCWindowController::raise(int        surfaceid,
404                               const char *animation,
405                               int        animationTime)
406 {
407     ICO_DBG("CicoSCWindowController::raise Enter"
408             "(surfaceid=0x%08X animation=%s animationTime=%d)",
409             surfaceid, animation, animationTime);
410
411     // find window information in window list
412     CicoSCWindow *window = findWindow(surfaceid);
413     if (NULL == window) {
414         ICO_WRN("CicoSCWindowController::raise Leave(ENOENT)");
415         return ICO_SYC_ENOENT;
416     }
417
418     // update visible attr
419     window->raise = true;
420
421     // set animation request to Multi Window Manager
422     int animaFlag = ICO_WINDOW_MGR_FLAGS_NO_CONFIGURE;
423     if ((NULL != animation) && (animation[0] != '\0')) {
424         CicoSCWindowController::setAnimation(window->surfaceid,
425                                              ICO_WINDOW_MGR_ANIMATION_TYPE_SHOW,
426                                              animation, animationTime);
427         animaFlag = ICO_WINDOW_MGR_FLAGS_ANIMATION;
428     }
429
430     // set visible request to Multi Window Manager
431     CicoSCWlWinMgrIF::setVisible(window->surfaceid,
432                                  ICO_WINDOW_MGR_V_NOCHANGE,
433                                  ICO_WINDOW_MGR_RAISE_RAISE, animaFlag);
434
435     // flush display
436     CicoSCWayland::getInstance()->flushDisplay();
437
438     ICO_DBG("CicoSCWindowController::raise Leave(EOK)");
439     return ICO_SYC_EOK;
440 }
441
442 //--------------------------------------------------------------------------
443 /**
444  *  @brief  set window(surface) geometry
445  *
446  *  @param [in] surfaceid           wayland surface id
447  *  @param [in] nodeid              node id
448  *  @param [in] x                   window x position
449  *  @param [in] y                   window y position
450  *  @param [in] w                   window width
451  *  @param [in] h                   window height
452  *  @param [in] resizeAnimation     resize animation name
453  *  @param [in] resizeAnimationTime resize animation time
454  *  @param [in] moveAnimation       move animation name
455  *  @param [in] moveanimationTime   move animation time
456  *
457  *  @return ICO_SYC_EOK on success, other on error
458  *  @retval ICO_SYC_EOK         success
459  *  @retval ICO_SYC_ESRCH       error(not initialized)
460  *  @retval ICO_SYC_ENOENT      error(window dose not exist)
461  */
462 //--------------------------------------------------------------------------
463 int
464 CicoSCWindowController::setGeometry(int        surfaceid,
465                                     int        nodeid,
466                                     int        x,
467                                     int        y,
468                                     int        w,
469                                     int        h,
470                                     const char *resizeAnimation,
471                                     int        resizeAnimationTime,
472                                     const char *moveAnimation,
473                                     int        moveAnimationTime)
474 {
475     ICO_DBG("CicoSCWindowController::setGeometry Enter"
476             "(surfaceid=0x%08X nodeid=%d x=%d y=%d w=%d h=%d "
477             "resizeAnimation=%s resizeAnimationTime=%d "
478             "moveAnimation=%s moveAnimationTime=%d)",
479             surfaceid, nodeid, x, y, w, h,
480             resizeAnimation, resizeAnimationTime,
481             moveAnimation, moveAnimationTime);
482
483     // find window information in window list
484     CicoSCWindow *window = findWindow(surfaceid);
485     if (NULL == window) {
486         ICO_WRN("CicoSCWindowController::setGeometry Leave(ENOENT)");
487         return ICO_SYC_ENOENT;
488     }
489
490     // set animation request to Multi Window Manager
491     const char *animation = "";
492     if (NULL != resizeAnimation) {
493         animation = resizeAnimation;
494     }
495     CicoSCWlWinMgrIF::setAnimation(window->surfaceid,
496                                    ICO_WINDOW_MGR_ANIMATION_TYPE_RESIZE,
497                                    animation, resizeAnimationTime);
498
499     if (NULL != moveAnimation) {
500         animation = moveAnimation;
501     }
502     CicoSCWlWinMgrIF::setAnimation(window->surfaceid,
503                                    ICO_WINDOW_MGR_ANIMATION_TYPE_MOVE,
504                                    animation, moveAnimationTime);
505
506     int moveNodeId = ICO_WINDOW_MGR_V_NOCHANGE;
507     if (nodeid >= 0) {
508         moveNodeId = nodeid;
509     }
510     else {
511         moveNodeId = window->nodeid;
512     }
513
514     if (m_physicalDisplayTotal <= (unsigned int)moveNodeId) {
515         ICO_WRN("nodeid(%d) is over physical display total(%d)",
516                 m_physicalDisplayTotal, nodeid);
517         ICO_WRN("CicoSCWindowController::setGeometry Leave(EINVAL)");
518         return ICO_SYC_EINVAL;
519     }
520
521     int moveX = ICO_WINDOW_MGR_V_NOCHANGE;
522     if (0 <= x) {
523         moveX = x;
524     }
525
526     int moveY = ICO_WINDOW_MGR_V_NOCHANGE;
527     if (0 <= y) {
528         moveY = y;
529     }
530
531     int moveW = ICO_WINDOW_MGR_V_NOCHANGE;
532     if (0 <= w) {
533         moveW = w;
534     }
535
536     int moveH = ICO_WINDOW_MGR_V_NOCHANGE;
537     if (0 <= h) {
538         moveH = h;
539     }
540
541     // set visible request to Multi Window Manager
542     CicoSCWlWinMgrIF::setPositionsize(window->surfaceid, moveNodeId,
543                                       moveX, moveY, moveW, moveH,
544                                       ICO_WINDOW_MGR_FLAGS_ANIMATION);
545
546     // flush display
547     CicoSCWayland::getInstance()->flushDisplay();
548
549     ICO_DBG("CicoSCWindowController::setGeometry Leave(EOK)");
550     return ICO_SYC_EOK;
551 }
552
553 //--------------------------------------------------------------------------
554 /**
555  *  @brief  set window(surface) geometry
556  *
557  *  @param [in] surfaceid           wayland surface id
558  *  @param [in] nodeid              node id
559  *  @param [in] zone                display zone name
560  *  @param [in] resizeAnimation     resize animation name
561  *  @param [in] resizeAnimationTime resize animation time
562  *  @param [in] moveAnimation       move animation name
563  *  @param [in] moveanimationTime   move animation time
564  *
565  *  @return ICO_SYC_EOK on success, other on error
566  *  @retval ICO_SYC_EOK         success
567  *  @retval ICO_SYC_ESRCH       error(not initialized)
568  *  @retval ICO_SYC_ENOENT      error(window dose not exist)
569  *  @retval ICO_SYC_EINVAL      error(zone is null, zone name is invalid)
570  */
571 //--------------------------------------------------------------------------
572 int
573 CicoSCWindowController::setGeometry(int        surfaceid,
574                                     const char *zone,
575                                     const char *resizeAnimation,
576                                     int        resizeAnimationTime,
577                                     const char *moveAnimation,
578                                     int        moveAnimationTime)
579 {
580     ICO_DBG("CicoSCWindowController::setGeometry Enter"
581             "(surfaceid=0x%08X zone=%s "
582             "resizeAnimation=%s resizeAnimationTime=%d "
583             "moveAnimation=%s moveAnimationTime=%d)",
584             surfaceid, zone,
585             resizeAnimation, resizeAnimationTime,
586             moveAnimation, moveAnimationTime);
587
588     // find window information in window list
589     CicoSCWindow *window = findWindow(surfaceid);
590     if (NULL == window) {
591         ICO_WRN("CicoSCWindowController::setGeometry Leave(ENOENT)");
592         return ICO_SYC_ENOENT;
593     }
594
595     if ((NULL == zone) || ('\0' == zone[0])) {
596         ICO_WRN("CicoSCWindowController::setGeometry Leave(EINVAL)");
597         return ICO_SYC_EINVAL;
598     }
599
600     vector<CicoSCDisplay*>::iterator itr;
601     itr = m_displayList.begin();
602     CicoSCDisplayZone* dispzone = NULL;
603     int displayno = 0;
604     for (; itr != m_displayList.end(); ++itr) {
605         dispzone = (*itr)->findDisplayZonebyFullName(zone);
606         if (NULL != dispzone) {
607             displayno = (*itr)->displayno;
608             break;
609         }
610     }
611
612     if (NULL == dispzone) {
613         ICO_WRN("display zone name(%s) is invalid.", zone);
614         ICO_WRN("CicoSCWindowController::setGeometry Leave(EINVAL)");
615         return ICO_SYC_EINVAL;
616     }
617
618     if (m_physicalDisplayTotal <= (unsigned int)displayno) {
619         ICO_WRN("nodeid(%d) is over physical display total(%d)",
620                 m_physicalDisplayTotal, displayno);
621         ICO_WRN("CicoSCWindowController::setGeometry Leave(EINVAL)");
622         return ICO_SYC_EINVAL;
623     }
624
625     // update window attr
626     window->zoneid = dispzone->zoneid;
627     window->zone = dispzone->fullname;
628
629     int ret = setGeometry(surfaceid, displayno,
630                           dispzone->x, dispzone->y,
631                           dispzone->width, dispzone->height,
632                           resizeAnimation, resizeAnimationTime,
633                           moveAnimation, moveAnimationTime);
634
635     ICO_DBG("CicoSCWindowController::setGeometry Leave(EOK)");
636     return ret;
637 }
638
639 //--------------------------------------------------------------------------
640 /**
641  *  @brief  lower window(surface)
642  *
643  *  @param [in] surfaceid       wayland surface id
644  *  @param [in] animation       animation name
645  *  @param [in] animationTime   animation time
646  *
647  *  @return ICO_SYC_EOK on success, other on error
648  *  @retval ICO_SYC_EOK         success
649  *  @retval ICO_SYC_ESRCH       error(not initialized)
650  *  @retval ICO_SYC_ENOENT      error(layer dose not exist)
651  */
652 //--------------------------------------------------------------------------
653 int
654 CicoSCWindowController::lower(int        surfaceid,
655                               const char *animation,
656                               int        animationTime)
657 {
658     ICO_DBG("CicoSCWindowController::lower Enter"
659             "(surfaceid=0x%08X animation=%s animationTime=%d)",
660             surfaceid, animation, animationTime);
661
662     // find window information in window list
663     CicoSCWindow *window = findWindow(surfaceid);
664     if (NULL == window) {
665         ICO_WRN("CicoSCWindowController::lower Leave(ENOENT)");
666         return ICO_SYC_ENOENT;
667     }
668
669     // update visible attr
670     window->raise = false;
671
672     // set animation request to Multi Window Manager
673     int animaFlag = ICO_WINDOW_MGR_FLAGS_NO_CONFIGURE;
674     if ((NULL != animation) && (animation[0] != '\0')) {
675         CicoSCWlWinMgrIF::setAnimation(window->surfaceid,
676                                        ICO_WINDOW_MGR_ANIMATION_TYPE_HIDE,
677                                        animation, animationTime);
678         animaFlag = ICO_WINDOW_MGR_FLAGS_ANIMATION;
679     }
680
681     // set visible request to Multi Window Manager
682     CicoSCWlWinMgrIF::setVisible(window->surfaceid, ICO_WINDOW_MGR_V_NOCHANGE,
683                                  ICO_WINDOW_MGR_RAISE_LOWER, animaFlag);
684
685     // flush display
686     CicoSCWayland::getInstance()->flushDisplay();
687
688     ICO_DBG("CicoSCWindowController::lower Leave(EOK)");
689     return ICO_SYC_EOK;
690 }
691
692 //--------------------------------------------------------------------------
693 /**
694  *  @brief  set window layer
695  *
696  *  @param [in] surfaceid       wayland surface id
697  *  @param [in] layer           layer id
698  *
699  *  @return ICO_SYC_EOK on success, other on error
700  *  @retval ICO_SYC_EOK         success
701  *  @retval ICO_SYC_ESRCH       error(not initialized)
702  *  @retval ICO_SYC_ENOENT      error(window or layer dose not exist)
703  */
704 //--------------------------------------------------------------------------
705 int
706 CicoSCWindowController::setWindowLayer(int surfaceid, int layerid)
707 {
708     ICO_DBG("CicoSCWindowController::setWindowLayer Enter"
709             "(surfaceid=0x%08X layerid=%x)", surfaceid, layerid);
710
711     // find window information in window list
712     CicoSCWindow *window = findWindow(surfaceid);
713     if (NULL == window) {
714         ICO_WRN("CicoSCWindowController::setWindowLayer Leave(ENOENT)");
715         return ICO_SYC_ENOENT;
716     }
717
718     // find layer information in layer list
719     CicoSCLayer* layer = findLayer(window->displayid, layerid);
720     if (NULL == layer) {
721         // check special layer
722         if ((layerid != ICO_WINDOW_MGR_V_LAYER_INPUT) &&
723             (layerid != ICO_WINDOW_MGR_V_LAYER_CURSOR)) {
724             ICO_WRN("CicoSCWindowController::setWindowLayer Leave(ENOENT[disp=%d,layer=%d])",
725                     window->displayid, layerid);
726             return ICO_SYC_ENOENT;
727         }
728     }
729
730     // update window attr
731     window->layerid = layerid;
732
733     // set window layer request to Multi Window Manager
734     CicoSCWlWinMgrIF::setWindowLayer(window->surfaceid, window->layerid);
735
736     // flush display
737     CicoSCWayland::getInstance()->flushDisplay();
738
739     ICO_DBG("CicoSCWindowController::setWindowLayer Leave(EOK)");
740     return ICO_SYC_EOK;
741 }
742
743 //--------------------------------------------------------------------------
744 /**
745  *  @brief   show layer
746  *
747  *  @param [in] displayid   display id
748  *  @param [in] layerid     layer id
749  *
750  *  @return ICO_SYC_EOK on success, other on error
751  *  @retval ICO_SYC_EOK     success
752  *  @retval ICO_SYC_ESRCH   error(not initialized)
753  *  @retval ICO_SYC_ENOENT  error(layer dose not exist)
754  */
755 //--------------------------------------------------------------------------
756 int
757 CicoSCWindowController::showLayer(int displayid, int layerid)
758 {
759     ICO_DBG("CicoSCWindowController::showLayer Enter"
760             "(displayid=%d layerid=%d)", displayid, layerid);
761
762     // find layer information in layer list
763     CicoSCLayer* layer = findLayer(displayid, layerid);
764     if (NULL == layer) {
765         ICO_WRN("CicoSCWindowController::showLayer Leave(ENOENT)");
766         return ICO_SYC_ENOENT;
767     }
768
769     CicoSCWlWinMgrIF::setLayerVisible(layerid, ICO_WINDOW_MGR_VISIBLE_SHOW);
770
771     // flush display
772     CicoSCWayland::getInstance()->flushDisplay();
773
774     ICO_DBG("CicoSCWindowController::showLayer Leave(EOK)");
775     return ICO_SYC_EOK;
776 }
777
778 //--------------------------------------------------------------------------
779 /**
780  *  @brief   show layer
781  *
782  *  @param [in] displayid   display id
783  *  @param [in] layerid     layer id
784  *
785  *  @return ICO_SYC_EOK on success, other on error
786  *  @retval ICO_SYC_EOK     success
787  *  @retval ICO_SYC_ESRCH   error(not initialized)
788  *  @retval ICO_SYC_ENOENT  error(layer dose not exist)
789  */
790 //--------------------------------------------------------------------------
791 int
792 CicoSCWindowController::hideLayer(int displayid, int layerid)
793 {
794     ICO_DBG("CicoSCWindowController::hideLayer Enter"
795             "displayid=%d layerid=%d)",
796             displayid, layerid);
797
798     // find layer information in layer list
799     CicoSCLayer* layer = findLayer(displayid, layerid);
800     if (NULL == layer) {
801         ICO_WRN("CicoSCWindowController::hideLayer Leave(ENOENT)");
802         return ICO_SYC_ENOENT;
803     }
804
805     CicoSCWlWinMgrIF::setLayerVisible(layerid, ICO_WINDOW_MGR_VISIBLE_HIDE);
806
807     // flush display
808     CicoSCWayland::getInstance()->flushDisplay();
809
810     ICO_DBG("CicoSCWindowController::hideVisible Leave(EOK)");
811     return ICO_SYC_EOK;
812 }
813
814 //--------------------------------------------------------------------------
815 /**
816  *  @brief   active window(surface)
817  *
818  *  @param [in] surfaceid   wayland surface id
819  *  @param [in] target      target(pointer and/or keyboard)
820  *
821  *  @return ICO_SYC_EOK on success, other on error
822  *  @retval ICO_SYC_EOK     success
823  *  @retval ICO_SYC_ESRCH   error(not initialized)
824  *  @retval ICO_SYC_ENOENT  error(layer dose not exist)
825  */
826 //--------------------------------------------------------------------------
827 int
828 CicoSCWindowController::active(int surfaceid, int target)
829 {
830     ICO_DBG("CicoSCWindowController::active Enter"
831             "(surfaceid=0x%08X, target=%08X)", surfaceid, target);
832
833     // find window information in window list
834     CicoSCWindow *window = findWindow(surfaceid);
835     if (NULL == window) {
836         ICO_WRN("CicoSCWindowController::active Leave(ENOENT)");
837         return ICO_SYC_ENOENT;
838     }
839
840     if (target < 0) {
841         target = ICO_WINDOW_MGR_ACTIVE_POINTER  |
842                  ICO_WINDOW_MGR_ACTIVE_KEYBOARD;
843     }
844
845     // set active request to Multi Window Manager
846     CicoSCWlWinMgrIF::setActive(window->surfaceid, target);
847
848     // flush display
849     CicoSCWayland::getInstance()->flushDisplay();
850
851     // update visible attr
852     window->raise = true;
853
854     // update active window
855     map<unsigned int, CicoSCWindow*>::iterator itr;
856     itr = m_windowList.begin();
857     for (; itr != m_windowList.end(); ++itr) {
858         CicoSCWindow* window = itr->second;
859         if (window->surfaceid == surfaceid) {
860             window->active = target;
861         }
862         else {
863             if (target == 0) {
864                 window->active = 0;
865             }
866             else {
867                 window->active &= ~target;
868             }
869         }
870     }
871
872     ICO_DBG("CicoSCWindowController::active Leave(EOK)");
873     return ICO_SYC_EOK;
874 }
875
876 //--------------------------------------------------------------------------
877 /**
878  *  @brief   map surface
879  *
880  *  @param [in] surfaceid   wayland surface id
881  *  @param [in] framerate   surface change frame rate(frames par sec)
882  *
883  *  @return ICO_SYC_EOK on success, other on error
884  *  @retval ICO_SYC_EOK     success
885  *  @retval ICO_SYC_ESRCH   error(not initialized)
886  *  @retval ICO_SYC_ENOENT  error(layer dose not exist)
887  */
888 //--------------------------------------------------------------------------
889 int
890 CicoSCWindowController::mapSurface(int surfaceid, int framerate)
891 {
892     ICO_WRN("CicoSCWindowController::mapSurface Enter");
893
894     // find window information in window list
895     CicoSCWindow *window = findWindow(surfaceid);
896     if (NULL == window) {
897         ICO_WRN("CicoSCWindowController::mapSurface Leave(ENOENT)");
898         return ICO_SYC_ENOENT;
899     }
900
901     if (framerate < 0) {
902         framerate = 0;
903     }
904
905     CicoSCWlWinMgrIF::mapSurface(surfaceid, framerate);
906
907     ICO_DBG("CicoSCWindowController::mapSurface Leave(EOK)");
908     return ICO_SYC_EOK;
909 }
910
911 //--------------------------------------------------------------------------
912 /**
913  *  @brief   unmap surface
914  *
915  *  @param [in] surfaceid   wayland surface id
916  *
917  *  @return ICO_SYC_EOK on success, other on error
918  *  @retval ICO_SYC_EOK     success
919  *  @retval ICO_SYC_ESRCH   error(not initialized)
920  *  @retval ICO_SYC_ENOENT  error(layer dose not exist)
921  */
922 //--------------------------------------------------------------------------
923 int
924 CicoSCWindowController::unmapSurface(int surfaceid)
925 {
926     ICO_DBG("CicoSCWindowController::unmapSurface Enter");
927
928     // find window information in window list
929     CicoSCWindow *window = findWindow(surfaceid);
930     if (NULL == window) {
931         ICO_WRN("CicoSCWindowController::unmapSurface Leave(ENOENT)");
932         return ICO_SYC_ENOENT;
933     }
934
935     CicoSCWlWinMgrIF::unmapSurface(surfaceid);
936
937     ICO_DBG("CicoSCWindowController::unmapSurface Leave(EOK)");
938     return ICO_SYC_EOK;
939 }
940
941 //--------------------------------------------------------------------------
942 /**
943  *  @brief   wayland surface create callback
944  *
945  *  @param [in] data            user data(unused)
946  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
947  *  @param [in] surfaceid       ico_window_mgr surface Id
948  *  @param [in] winname         surface window name(title)
949  *  @param [in] pid             wayland client process Id
950  *  @param [in] appid           wayland client application Id
951  */
952 //--------------------------------------------------------------------------
953 void
954 CicoSCWindowController::createdCB(void                  *data,
955                                   struct ico_window_mgr *ico_window_mgr,
956                                   uint32_t              surfaceid,
957                                   const char            *winname,
958                                   int32_t               pid,
959                                   const char            *appid)
960 {
961     ICO_DBG("CicoSCWindowController::createdCB Enter"
962             "(surfaceid=0x%08X winname=%s pid=%d appid=%s)",
963             surfaceid, winname, pid, appid);
964
965     CicoSCWindow* window = new CicoSCWindow();
966
967     window->surfaceid = surfaceid;
968     window->name      = winname;
969     window->appid     = appid;
970     window->pid       = pid;
971     window->displayid = ICO_SURFACEID_2_NODEID(surfaceid);
972
973     CicoSCLifeCycleController* appctrl;
974     appctrl = CicoSCLifeCycleController::getInstance();
975     const CicoSCAilItems *ailItem = appctrl->findAIL(appid);
976     if (NULL == ailItem) {
977         const CicoSCAulItems* aulitem = appctrl->findAUL(pid);
978         if (NULL != aulitem) {
979             window->appid = aulitem->m_appid;
980             ICO_DBG("appid=%s", window->appid.c_str());
981             ailItem = appctrl->findAIL(window->appid.c_str());
982         }
983         else {
984             ICO_DBG("application information not found.");
985         }
986     }
987
988     if (NULL != ailItem) {
989         window->layerid = ailItem->m_layer;
990         window->zoneid  = ailItem->m_displayZone;
991         window->nodeid  = ailItem->m_nodeID;
992         if ((window->displayid >= 0) && (window->zoneid >= 0)) {
993
994             const CicoSCDisplayZone* zone = findDisplayZone(window->zoneid);
995             if (NULL != zone) {
996                 window->zone   = zone->fullname;
997                 window->x      = zone->x;
998                 window->y      = zone->y;
999                 window->width  = zone->width;
1000                 window->height = zone->height;
1001             }
1002         }
1003     }
1004     else{
1005         ICO_WRN("ail item not found.");
1006         ICO_WRN("CicoSCWindowController::createdCB Leave(ENOENT)");
1007         return;
1008     }
1009
1010     appctrl->enterAUL(appid, pid, window);
1011
1012     // dump log window information
1013     window->dump();
1014
1015     m_windowList[surfaceid] = window;
1016
1017     // send message
1018     CicoSCMessage *message = new CicoSCMessage();
1019     message->addRootObject("command", MSG_CMD_CREATE);
1020     message->addRootObject("appid", window->appid);
1021     message->addRootObject("pid", window->pid);
1022     message->addArgObject("surface", window->surfaceid);
1023     message->addArgObject("winname", window->name);
1024     CicoSCServer::getInstance()->sendMessageToHomeScreen(message);
1025
1026 #if 1
1027     if (NULL != m_resMgr) {
1028         CicoSCCommand cmd;
1029         CicoSCCmdResCtrlOpt *opt = new CicoSCCmdResCtrlOpt();
1030
1031         cmd.cmdid = MSG_CMD_CREATE_RES;
1032         cmd.appid = window->appid;
1033         cmd.pid   = window->pid;
1034         cmd.opt = opt;
1035
1036         opt->dispres   = true;
1037         opt->winname   = window->name;
1038         opt->surfaceid = window->surfaceid;
1039
1040         string fullname;
1041         const CicoSCDisplayZone* zone = findDisplayZone(window->zoneid);
1042         if (NULL != zone) {
1043             opt->dispzone = zone->fullname;
1044         }
1045
1046 #if 1   //TODO
1047         opt->soundres  = true;
1048         opt->soundname = window->appid;
1049         opt->soundid   = 0;
1050         CicoSCSystemConfig *sysconf = CicoSCSystemConfig::getInstance();
1051         const CicoSCDefaultConf *defconf = sysconf->getDefaultConf();
1052         if (NULL != defconf) {
1053             const CicoSCSoundZoneConf *zoneconf =
1054                 sysconf->findSoundZoneConfbyId(defconf->soundzone);
1055             if (NULL != zoneconf) {
1056                 opt->soundzone = zoneconf->fullname;
1057             }
1058         }
1059 #endif
1060
1061
1062         m_resMgr->handleCommand((const CicoSCCommand&)cmd, true);
1063     }
1064     else {
1065         show(window->surfaceid, NULL, 0);
1066     }
1067 #endif
1068
1069     ICO_DBG("CicoSCWindowController::createdCB Leave");
1070 }
1071
1072 //--------------------------------------------------------------------------
1073 /**
1074  *  @brief  wayland change surface name callback
1075  *
1076  *  @param [in] data            user data(unused)
1077  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
1078  *  @param [in] surfaceid       ico_window_mgr surface Id
1079  *  @param [in] winname         surface window name(title)
1080  */
1081 //--------------------------------------------------------------------------
1082 void
1083 CicoSCWindowController::nameCB(void                  *data,
1084                                struct ico_window_mgr *ico_window_mgr,
1085                                uint32_t              surfaceid,
1086                                const char            *winname)
1087 {
1088     ICO_DBG("CicoSCWindowController::nameCB Enter"
1089             "(surfaceid=0x%08X winname=%s)", surfaceid, winname);
1090
1091     CicoSCWindow *window = findWindow(surfaceid);
1092     if (NULL == window) {
1093         ICO_DBG("CicoSCWindowController::nameCB Leave");
1094         return;
1095     }
1096
1097     ICO_DBG("nameCB: Update window name %s=>%s",
1098             window->name.c_str(), winname);
1099     window->name = winname;
1100
1101     // send message
1102     CicoSCMessage *message = new CicoSCMessage();
1103     message->addRootObject("command", MSG_CMD_NAME);
1104     message->addRootObject("appid", window->appid);
1105     message->addRootObject("pid", window->pid);
1106     message->addArgObject("surface", window->surfaceid);
1107     message->addArgObject("winname", window->name);
1108     CicoSCServer::getInstance()->sendMessageToHomeScreen(message);
1109
1110     ICO_DBG("CicoSCWindowController::nameCB Leave");
1111 }
1112
1113 //--------------------------------------------------------------------------
1114 /**
1115  *  @brief  wayland surface destroy callback
1116  *
1117  *  @param [in] data            user data(unused)
1118  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
1119  *  @param [in] surfaceid       ico_window_mgr surface Id
1120  */
1121 //--------------------------------------------------------------------------
1122 void
1123 CicoSCWindowController::destroyedCB(void                  *data,
1124                                     struct ico_window_mgr *ico_window_mgr,
1125                                     uint32_t              surfaceid)
1126 {
1127     ICO_DBG("CicoSCWindowController::destroyedCB Enter"
1128             "(surfaceid=0x%08X)", surfaceid);
1129
1130     CicoSCWindow *window = findWindow(surfaceid);
1131     if (NULL == window) {
1132         ICO_DBG("CicoSCWindowController::destroyedCB Leave");
1133         return;
1134     }
1135
1136     // send message
1137     CicoSCMessage *message = new CicoSCMessage();
1138     message->addRootObject("command", MSG_CMD_DESTROY);
1139     message->addRootObject("appid", window->appid);
1140     message->addRootObject("pid", window->pid);
1141     message->addArgObject("surface", window->surfaceid);
1142     message->addArgObject("winname", window->name);
1143     CicoSCServer::getInstance()->sendMessageToHomeScreen(message);
1144
1145     // TODO delete window in application
1146
1147     if (NULL != m_resMgr) {
1148         CicoSCCommand cmd;
1149         CicoSCCmdResCtrlOpt *opt = new CicoSCCmdResCtrlOpt();
1150
1151         cmd.cmdid = MSG_CMD_DESTORY_RES;
1152         cmd.appid = window->appid;
1153         cmd.pid   = window->pid;
1154         cmd.opt = opt;
1155
1156         opt->dispres   = true;
1157         opt->winname   = window->name;
1158         opt->surfaceid = window->surfaceid;
1159
1160         string fullname;
1161         const CicoSCDisplayZone* zone = findDisplayZone(window->zoneid);
1162         if (NULL != zone) {
1163             opt->dispzone = zone->fullname;
1164         }
1165
1166         opt->soundres  = true;
1167         opt->soundname = window->appid;
1168         opt->soundid   = 0;
1169         CicoSCSystemConfig *sysconf = CicoSCSystemConfig::getInstance();
1170         const CicoSCDefaultConf *defconf = sysconf->getDefaultConf();
1171         if (NULL != defconf) {
1172             const CicoSCSoundZoneConf *zoneconf =
1173                 sysconf->findSoundZoneConfbyId(defconf->soundzone);
1174             if (NULL != zoneconf) {
1175                 opt->soundzone = zoneconf->fullname;
1176             }
1177         }
1178
1179         m_resMgr->handleCommand((const CicoSCCommand&)cmd, true);
1180     }
1181
1182     // delete window in list
1183     m_windowList.erase(window->surfaceid);
1184     delete(window);
1185
1186     ICO_DBG("CicoSCWindowController::destroyedCB Leave");
1187 }
1188
1189 //--------------------------------------------------------------------------
1190 /**
1191  *  @brief  wayland surface visible callback
1192  *
1193  *  @param [in] data            user data(unused)
1194  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
1195  *  @param [in] surfaceid       ico_window_mgr surface Id
1196  *  @param [in] visible         surface visible
1197  *                              (1=visible/0=invisible/other=no-change)
1198  *  @param [in] raise           surface raise
1199  *                              (1=raise/0=lower/other=no change)
1200  *  @param [in] hint            client request
1201  *                              (1=client request(not changed)/0=changed)
1202  */
1203 //--------------------------------------------------------------------------
1204 void
1205 CicoSCWindowController::visibleCB(void                  *data,
1206                                   struct ico_window_mgr *ico_window_mgr,
1207                                   uint32_t              surfaceid,
1208                                   int32_t               visible,
1209                                   int32_t               raise,
1210                                   int32_t               hint)
1211 {
1212     ICO_DBG("CicoSCWindowController::visibleCB Enter"
1213             "(surfaceid=0x%08X visible=%d raise=%d hint=%d)",
1214             surfaceid, visible, raise, hint);
1215
1216     CicoSCWindow *window = findWindow(surfaceid);
1217     if (NULL == window) {
1218         ICO_DBG("CicoSCWindowController::visibleCB Leave");
1219         return;
1220     }
1221
1222     int newVisible = visible;
1223     int newRaise   = raise;
1224
1225     if (visible == ICO_WINDOW_MGR_V_NOCHANGE) {
1226         newVisible = window->visible;
1227     }
1228
1229     if (raise == ICO_WINDOW_MGR_V_NOCHANGE) {
1230         newVisible = window->raise;
1231     }
1232
1233     if ((window->visible == newVisible) && (window->raise == newRaise) ){
1234         ICO_DBG("CicoSCWindowController::visibleCB Leave");
1235         return;
1236     }
1237
1238     // update attr
1239     window->visible = newVisible;
1240     window->raise = newRaise;
1241
1242     // notify homescreen
1243     CicoSCMessage *message = new CicoSCMessage();
1244     message->addRootObject("command", MSG_CMD_CHANGE_ATTR);
1245     message->addRootObject("appid", window->appid);
1246     const CicoSCDisplayZone* zone = findDisplayZone(window->zoneid);
1247     if (NULL != zone) {
1248         message->addArgObject("zone", zone->fullname);
1249     }
1250     else {
1251         message->addArgObject("zone", "");
1252     }
1253     message->addArgObject("surface", window->surfaceid);
1254     message->addArgObject("winname", window->name);
1255     message->addArgObject("node", window->nodeid);
1256     message->addArgObject("layer", window->layerid);
1257     message->addArgObject("pos_x", window->x);
1258     message->addArgObject("pos_y", window->y);
1259     message->addArgObject("width", window->width);
1260     message->addArgObject("height", window->height);
1261     message->addArgObject("raise", window->raise ? 1 : 0);
1262     message->addArgObject("visible", window->visible ? 1 : 0);
1263     message->addArgObject("active", window->active ? 1 : 0);
1264     CicoSCServer::getInstance()->sendMessageToHomeScreen(message);
1265
1266     ICO_DBG("CicoSCWindowController::visibleCB Leave");
1267 }
1268
1269 //--------------------------------------------------------------------------
1270 /**
1271  *  @brief  wayland surface configure callback
1272  *
1273  *  @param [in] data            user data(unused)
1274  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
1275  *  @param [in] surfaceid       ico_window_mgr surface Id
1276  *  @param [in] node            surface node Id
1277  *  @param [in] x               surface upper-left X coordinate
1278  *  @param [in] y               surface upper-left Y coordinate
1279  *  @param [in] width           surface width
1280  *  @param [in] height          surface height
1281  *  @param [in] hint            client request
1282  *                              (1=client request(not changed)/0=changed)
1283  */
1284 //--------------------------------------------------------------------------
1285 void
1286 CicoSCWindowController::configureCB(void                  *data,
1287                                     struct ico_window_mgr *ico_window_mgr,
1288                                     uint32_t              surfaceid,
1289                                     uint32_t              node,
1290                                     uint32_t              layer,
1291                                     int32_t               x,
1292                                     int32_t               y,
1293                                     int32_t               width,
1294                                     int32_t               height,
1295                                     int32_t               hint)
1296 {
1297     ICO_DBG("CicoSCWindowController::configureCB Enter"
1298             "(surfaceid=0x%08X node=%d layer=%d x=%d y=%d "
1299             "width=%d height=%d hint=%d)",
1300             surfaceid, node, layer, x, y, width, height, hint);
1301
1302     CicoSCWindow *window = findWindow(surfaceid);
1303     if (NULL == window) {
1304         ICO_DBG("CicoSCWindowController::visibleCB Leave"
1305                 "(update window visible failed)");
1306         return;
1307     }
1308
1309     if (ICO_WINDOW_MGR_HINT_CHANGE == hint) {
1310         window->x      = x;
1311         window->y      = y;
1312         window->width  = width;
1313         window->height = height;
1314 #if 0
1315         if (window->layerid != layer) {
1316             window->layerid = layer;
1317             layer = findLayer(window->displayid, layer);
1318         }
1319 #endif
1320     }
1321
1322     // send message
1323     CicoSCMessage *message = new CicoSCMessage();
1324     message->addRootObject("command", MSG_CMD_CHANGE_ATTR);
1325     message->addRootObject("appid", window->appid);
1326     const CicoSCDisplayZone* zone = findDisplayZone(window->zoneid);
1327     if (NULL != zone) {
1328         message->addArgObject("zone", zone->fullname);
1329     }
1330     else {
1331         message->addArgObject("zone", "");
1332     }
1333     message->addArgObject("surface", window->surfaceid);
1334     message->addArgObject("winname", window->name);
1335     message->addArgObject("node", window->nodeid);
1336     message->addArgObject("layer", window->layerid);
1337     message->addArgObject("pos_x", window->x);
1338     message->addArgObject("pos_y", window->y);
1339     message->addArgObject("width", window->width);
1340     message->addArgObject("height", window->height);
1341     message->addArgObject("raise", window->raise ? 1 : 0);
1342     message->addArgObject("visible", window->visible ? 1 : 0);
1343     message->addArgObject("active", window->active ? 1 : 0);
1344     CicoSCServer::getInstance()->sendMessageToHomeScreen(message);
1345
1346     ICO_DBG("CicoSCWindowController::configureCB Leave");
1347 }
1348
1349 //--------------------------------------------------------------------------
1350 /**
1351  *  @brief  wayland surface active callback
1352  *
1353  *  @param [in] data            user data(unused)
1354  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
1355  *  @param [in] surfaceid       ico_window_mgr surface Id
1356  *  @param [in] active          surface active
1357  *                              (1=active/0=not active)
1358  */
1359 //--------------------------------------------------------------------------
1360 void
1361 CicoSCWindowController::activeCB(void                  *data,
1362                                  struct ico_window_mgr *ico_window_mgr,
1363                                  uint32_t              surfaceid,
1364                                  int32_t               active)
1365 {
1366     ICO_DBG("CicoSCWindowController::activeCB Enter"
1367             "(surfaceid=0x%08X active=%d)", surfaceid, active);
1368
1369     CicoSCWindow *window = findWindow(surfaceid);
1370     if (NULL == window) {
1371         ICO_DBG("CicoSCWindowController::activeCB Leave(not found window)");
1372         return;
1373     }
1374
1375     if (0 == active) {
1376         ICO_DBG("CicoSCWindowController::activeCB Leave(not active)");
1377         return;
1378     }
1379
1380     if (0 != window->active) {
1381         ICO_DBG("CicoSCWindowController::activeCB Leave(already active)");
1382         return;
1383     }
1384
1385     // send message
1386     CicoSCMessage *message = new CicoSCMessage();
1387     message->addRootObject("command", MSG_CMD_CHANGE_ACTIVE);
1388     message->addRootObject("appid", window->appid);
1389     message->addRootObject("pid", window->pid);
1390     message->addArgObject("surface", window->surfaceid);
1391     message->addArgObject("winname", window->name);
1392     CicoSCServer::getInstance()->sendMessageToHomeScreen(message);
1393
1394     if (true == window->visible) {
1395         (void)notifyResourceManager(window->surfaceid, NULL, NULL, 0);
1396     }
1397
1398     ICO_DBG("CicoSCWindowController::activeCB Leave");
1399 }
1400
1401 //--------------------------------------------------------------------------
1402 /**
1403  *  @brief  wayland layer visible callback
1404  *
1405  *  @param [in] data            user data(unused)
1406  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
1407  *  @param [in] layer           layer Id
1408  *  @param [in] visible         layer visible
1409  *                              (1=visible/0=invisible/other=no change)
1410  */
1411 //--------------------------------------------------------------------------
1412 void
1413 CicoSCWindowController::layerVisibleCB(void                  *data,
1414                                        struct ico_window_mgr *ico_window_mgr,
1415                                        uint32_t              layer,
1416                                        int32_t               visible)
1417 {
1418     ICO_DBG("CicoSCWindowController::layerVisibleCB Enter"
1419             "layer=%d visible=%d)", layer, visible);
1420
1421     // send message
1422     CicoSCMessage *message = new CicoSCMessage();
1423     message->addRootObject("command", MSG_CMD_CHANGE_LAYER_ATTR);
1424     message->addRootObject("appid", "");
1425     message->addArgObject("layer", layer);
1426     message->addArgObject("visible", visible);
1427     CicoSCServer::getInstance()->sendMessageToHomeScreen(message);
1428
1429     ICO_DBG("CicoSCWindowController::layerVisibleCB Leave");
1430 }
1431
1432 //--------------------------------------------------------------------------
1433 /**
1434  *  @brief  query application surface callback
1435  *
1436  *  @param [in] data            user data(unused)
1437  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
1438  *  @param [in] appid           application Id
1439  *  @param [in] surface         surface Id array
1440  */
1441 //--------------------------------------------------------------------------
1442 void
1443 CicoSCWindowController::appSurfacesCB(void                  *data,
1444                                       struct ico_window_mgr *ico_window_mgr,
1445                                       const char            *appid,
1446                                       struct wl_array       *surfaces)
1447 {
1448     ICO_DBG("CicoSCWindowController::appSurfacesCB Enter(appid=%s)", appid);
1449
1450     //struct wl_array {
1451     //  size_t size;
1452     //  size_t alloc;
1453     //  void *data;
1454     //};
1455     uint32_t **p;
1456     for (p = (uint32_t**)(surfaces)->data;
1457          (const char*) p < ((const char*) (surfaces)->data + (surfaces)->size);
1458          (p)++) {
1459         ICO_DBG("appSurfacesCB: surface=%d", (int)*p);
1460     }
1461
1462     ICO_DBG("CicoSCWindowController::appSurfacesCB Leave");
1463 }
1464
1465 //--------------------------------------------------------------------------
1466 /**
1467  *  @brief   surface map event callback
1468  *
1469  *  @param [in] data            user data(unused)
1470  *  @param [in] ico_window_mgr  wayland ico_window_mgr plugin interface
1471  *  @param [in] event           event
1472  *  @param [in] surfaceid       surface Id
1473  *  @param [in] width           surface width
1474  *  @param [in] height          surface height
1475  *  @param [in] stride          surface buffer(frame buffer) stride
1476  *  @param [in] format          surface buffer format
1477  */
1478 //--------------------------------------------------------------------------
1479 void
1480 CicoSCWindowController::mapSurfaceCB(void                  *data,
1481                                      struct ico_window_mgr *ico_window_mgr,
1482                                      int32_t               event,
1483                                      uint32_t              surfaceid,
1484                                      uint32_t              type,
1485                                      uint32_t              target,
1486                                      int32_t               width,
1487                                      int32_t               height,
1488                                      int32_t               stride,
1489                                      uint32_t               format)
1490 {
1491     ICO_DBG("CicoSCWindowController::mapSurfaceCB Enter"
1492             "(event=%d surface=%d type=%d target=%d "
1493             "width=%d height=%d stride=%d format=%d)",
1494             event, surfaceid, type, target,
1495             width, height, stride, format);
1496
1497     CicoSCWindow *window = findWindow(surfaceid);
1498     if (NULL == window) {
1499         return;
1500     }
1501
1502     // send message
1503     CicoSCMessage *message = new CicoSCMessage();
1504     message->addRootObject("command", MSG_CMD_MAP_THUMB);
1505     message->addRootObject("appid", window->appid);
1506     message->addArgObject("surface", window->surfaceid);
1507     message->addArgObject("width", width);
1508     message->addArgObject("height", height);
1509     message->addArgObject("stride", stride);
1510     message->addArgObject("format", format);
1511     CicoSCServer::getInstance()->sendMessageToHomeScreen(message);
1512
1513     ICO_DBG("CicoSCWindowController::mapSurfaceCB Leave");
1514 }
1515
1516 //--------------------------------------------------------------------------
1517 /**
1518  *  @brief   wayland display attribute callback
1519  *
1520  *  @param [in] data            user data(unused)
1521  *  @param [in] wl_output       wayland wl_output interface
1522  *  @param [in] x               display upper-left X coordinate
1523  *  @param [in] y               display upper-left Y coordinate
1524  *  @param [in] physical_width  display physical width
1525  *  @param [in] physical_height display physical height
1526  *  @param [in] subpixel        display sub pixel
1527  *  @param [in] make            display maker
1528  *  @param [in] model           display model
1529  *  @param [in] transform       transform
1530  */
1531 //--------------------------------------------------------------------------
1532 void
1533 CicoSCWindowController::outputGeometryCB(void             *data,
1534                                          struct wl_output *wl_output,
1535                                          int32_t          x,
1536                                          int32_t          y,
1537                                          int32_t          physical_width,
1538                                          int32_t          physical_height,
1539                                          int32_t          subpixel,
1540                                          const char       *make,
1541                                          const char       *model,
1542                                          int32_t          transform)
1543 {
1544     ICO_DBG("CicoSCWlWinMgrIF::outputGeometryCB Enter"
1545             "(x=%d y=%d physical_width=%d physical_height=%d "
1546             "subpixel=%d make=%s model=%s transform=%d)",
1547             x, y, physical_width, physical_height,
1548             subpixel, make, model, transform);
1549
1550     ++m_physicalDisplayTotal;
1551     if (0 == m_displayList.size()) {
1552         ICO_DBG("CicoSCWlWinMgrIF::outputGeometryCB Leave(display is zero)");
1553         return;
1554     }
1555
1556     if (m_displayList.size() < m_physicalDisplayTotal) {
1557         ICO_WRN("CicoSCWlWinMgrIF::outputGeometryCB Leave(display total unmatch)");
1558         return;
1559     }
1560
1561     CicoSCDisplay* display = m_displayList.at(m_physicalDisplayTotal-1);
1562     switch (transform) {
1563     case WL_OUTPUT_TRANSFORM_90:
1564     case WL_OUTPUT_TRANSFORM_270:
1565     case WL_OUTPUT_TRANSFORM_FLIPPED_90:
1566     case WL_OUTPUT_TRANSFORM_FLIPPED_270:
1567         display->pWidth      = physical_height;
1568         display->pHeight     = physical_width;
1569         display->orientation = CicoSCDisplay::ORIENTATION_VERTICAL;
1570         break;
1571     case WL_OUTPUT_TRANSFORM_NORMAL:
1572     case WL_OUTPUT_TRANSFORM_180:
1573     case WL_OUTPUT_TRANSFORM_FLIPPED:
1574     case WL_OUTPUT_TRANSFORM_FLIPPED_180:
1575     default:
1576         display->pWidth      = physical_width;
1577         display->pHeight     = physical_height;
1578         display->orientation = CicoSCDisplay::ORIENTATION_HORIZONTAL;
1579         break;
1580     }
1581     display->dump();
1582
1583     ICO_DBG("CicoSCWlWinMgrIF::outputGeometryCB Leave");
1584 }
1585
1586 //--------------------------------------------------------------------------
1587 /**
1588  *  @brief  wayland display mode callback
1589  *
1590  *  @param [in] data        user data(unused)
1591  *  @param [in] wl_output   wayland wl_output interface
1592  *  @param [in] flags       flags
1593  *  @param [in] width       display width
1594  *  @param [in] height      display height
1595  *  @param [in] refresh     display refresh rate
1596  */
1597 //--------------------------------------------------------------------------
1598 void
1599 CicoSCWindowController::outputModeCB(void             *data,
1600                                      struct wl_output *wl_output,
1601                                      uint32_t         flags,
1602                                      int32_t          width,
1603                                      int32_t          height,
1604                                      int32_t          refresh)
1605 {
1606     ICO_DBG("CicoSCWlWinMgrIF::outputModeCB Enter"
1607             "(flags=%d width=%d height=%d refresh=%d)",
1608             flags, width, height, refresh);
1609
1610     if (0 == m_displayList.size()) {
1611         ICO_DBG("CicoSCWlWinMgrIF::outputModeCB Leave(display is zero");
1612         return;
1613     }
1614
1615     CicoSCDisplay* display = m_displayList.at(0);
1616     if (flags & WL_OUTPUT_MODE_CURRENT) {
1617         if (display->orientation == CicoSCDisplay::ORIENTATION_VERTICAL) {
1618             display->pWidth  = height;
1619             display->pHeight = width;
1620         }
1621         else {
1622             display->pWidth  = width;
1623             display->pHeight = height;
1624         }
1625         display->dump();
1626     }
1627
1628     ICO_DBG("CicoSCWlWinMgrIF::outputModeCB Leave");
1629 }
1630
1631 //==========================================================================
1632 // private method
1633 //==========================================================================
1634
1635 //--------------------------------------------------------------------------
1636 /**
1637  *  @brief  find window object by surfaceid
1638  *
1639  *  @param [in] surfaceid   wayland surface id
1640  */
1641 //--------------------------------------------------------------------------
1642 CicoSCWindow*
1643 CicoSCWindowController::findWindow(int surfaceid)
1644 {
1645     map<unsigned int, CicoSCWindow*>::iterator itr;
1646     itr = m_windowList.find(surfaceid);
1647     if (m_windowList.end() == itr) {
1648         ICO_WRN("not found window object. surfaceid=0x%08X", surfaceid);
1649         return NULL;
1650     }
1651
1652     return itr->second;
1653 }
1654
1655 //--------------------------------------------------------------------------
1656 /**
1657  *  @brief  find window object by surfaceid
1658  *
1659  *  @param [in] surfaceid   wayland surface id
1660  */
1661 //--------------------------------------------------------------------------
1662 CicoSCLayer*
1663 CicoSCWindowController::findLayer(int displayid, int layerid)
1664 {
1665     vector<CicoSCDisplay*>::iterator itr;
1666     itr = m_displayList.begin();
1667     for (; itr != m_displayList.end(); ++itr) {
1668         if ((*itr)->displayid != displayid) {
1669             continue;
1670         }
1671         vector<CicoSCLayer*>::iterator itr2;
1672         itr2 = (*itr)->layerList.begin();
1673         for (; itr2 != (*itr)->layerList.end(); ++itr2) {
1674             if ((*itr2)->layerid == layerid) {
1675                 return *itr2;
1676             }
1677         }
1678     }
1679     return NULL;
1680 }
1681
1682 //--------------------------------------------------------------------------
1683 /**
1684  *  @brief  find display zone by id
1685  */
1686 //--------------------------------------------------------------------------
1687 const CicoSCDisplayZone *
1688 CicoSCWindowController::findDisplayZone(int zoneid)
1689 {
1690     vector<CicoSCDisplay*>::iterator itr;
1691     itr = m_displayList.begin();
1692     for (; itr != m_displayList.end(); ++itr) {
1693         std::map<unsigned int, CicoSCDisplayZone*>::iterator itr2;
1694         itr2 = (*itr)->zoneList.find(zoneid);
1695         if ((*itr)->zoneList.end() != itr2) {
1696             return itr2->second;
1697         }
1698     }
1699     return NULL;
1700 }
1701
1702 //--------------------------------------------------------------------------
1703 /**
1704  *  @brief  handle command
1705  *
1706  *  @param [in] cmd     control command
1707  */
1708 //--------------------------------------------------------------------------
1709 void
1710 CicoSCWindowController::handleCommand(const CicoSCCommand * cmd)
1711 {
1712 //    ICO_DBG("CicoSCWindowController::handleCommand Enter(%d)", cmd->cmdid);
1713
1714     CicoSCCmdWinCtrlOpt *opt = static_cast<CicoSCCmdWinCtrlOpt*>(cmd->opt);
1715
1716     switch (cmd->cmdid) {
1717     case MSG_CMD_SHOW:
1718         ICO_DBG("command: MSG_CMD_SHOW");
1719         if (opt->animationTime & ICO_SYC_WIN_SURF_NORESCTL) {
1720             /* show command but not resource control (for HomeScreen)   */
1721             (void)show(opt->surfaceid, opt->animation.c_str(), opt->animationTime);
1722         }
1723         else {
1724             /* show command (normal)    */
1725             (void)notifyResourceManager(opt->surfaceid,
1726                                         NULL,
1727                                         opt->animation.c_str(),
1728                                         opt->animationTime);
1729         }
1730         break;
1731     case MSG_CMD_HIDE:
1732         ICO_DBG("command: MSG_CMD_HIDE");
1733         (void)hide(opt->surfaceid, opt->animation.c_str(), opt->animationTime);
1734         break;
1735     case MSG_CMD_MOVE:
1736     {
1737         ICO_DBG("command: MSG_CMD_MOVE");
1738         CicoSCWindow *window = findWindow(opt->surfaceid);
1739         if (NULL == window) {
1740             break;
1741         }
1742         if (true == opt->zone.empty()) {
1743             (void)setGeometry(opt->surfaceid, opt->nodeid, opt->x, opt->y,
1744                               opt->width, opt->height,
1745                               opt->animation.c_str(), opt->animationTime,
1746                               opt->animation.c_str(), opt->animationTime);
1747         }
1748         else if (opt->zone == window->zone) {
1749             (void)setGeometry(opt->surfaceid, opt->zone.c_str(),
1750                               opt->animation.c_str(), opt->animationTime,
1751                               opt->animation.c_str(), opt->animationTime);
1752         }
1753         else {
1754             (void)notifyResourceManager(opt->surfaceid,
1755                                         opt->zone.c_str(),
1756                                         opt->animation.c_str(),
1757                                         opt->animationTime);
1758         }
1759         break;
1760     }
1761     case MSG_CMD_CHANGE_ACTIVE:
1762         ICO_DBG("command: MSG_CMD_CHANGE_ACTIVE");
1763         (void)active(opt->surfaceid, opt->active);
1764         break;
1765     case MSG_CMD_CHANGE_LAYER:
1766         ICO_DBG("command: MSG_CMD_CHANGE_LAYER");
1767         (void)setWindowLayer(opt->surfaceid, opt->layerid);
1768         break;
1769     case MSG_CMD_MAP_THUMB:
1770         ICO_DBG("command: MSG_CMD_MAP_THUMB");
1771         (void)mapSurface(opt->surfaceid, opt->framerate);
1772         break;
1773     case MSG_CMD_UNMAP_THUMB:
1774         ICO_DBG("command: MSG_CMD_UNMAP_THUMB");
1775         (void)unmapSurface(opt->surfaceid);
1776         break;
1777     case MSG_CMD_SHOW_LAYER:
1778         ICO_DBG("command: MSG_CMD_SHOW_LAYER");
1779         (void)showLayer(opt->displayid, opt->layerid);
1780         break;
1781     case MSG_CMD_HIDE_LAYER:
1782         ICO_DBG("command: MSG_CMD_HIDE_LAYER");
1783         (void)hideLayer(opt->displayid, opt->layerid);
1784         break;
1785     default:
1786         ICO_WRN("command: Unknown(0x%08X)", cmd->cmdid);
1787         break;
1788     }
1789
1790 //    ICO_DBG("CicoSCWindowController::handleCommand Leave");
1791 }
1792
1793 int
1794 CicoSCWindowController::notifyResourceManager(int        surfaceid,
1795                                               const char *zone,
1796                                               const char *animation,
1797                                               int        animationTime)
1798 {
1799     ICO_DBG("CicoSCWindowController::notifyResourceManager Enter"
1800             "(surfaceid=0x%08X zone=%s animation=%s animationTime=%d)",
1801             surfaceid, zone, animation, animationTime);
1802
1803     // find window information in window list
1804     CicoSCWindow *window = findWindow(surfaceid);
1805     if (NULL == window) {
1806         ICO_WRN("CicoSCWindowController::notifyResourceManager Leave(ENOENT)");
1807         return ICO_SYC_ENOENT;
1808     }
1809
1810     CicoSCCommand cmd;
1811     CicoSCCmdResCtrlOpt *opt = new CicoSCCmdResCtrlOpt();
1812
1813     cmd.cmdid = MSG_CMD_ACQUIRE_RES;
1814     cmd.appid = window->appid;
1815     cmd.pid   = window->pid;
1816     cmd.opt   = opt;
1817
1818     opt->dispres       = true;
1819     opt->winname       = window->name;
1820     opt->surfaceid     = window->surfaceid;
1821     opt->animation     = animation ? animation : "";
1822     opt->animationTime = animationTime;
1823     string fullname;
1824     if (NULL == zone) {
1825         const CicoSCDisplayZone* zone = findDisplayZone(window->zoneid);
1826         if (NULL != zone) {
1827             opt->dispzone = zone->fullname;
1828         }
1829         else {
1830             ICO_WRN("CicoSCWindowController::notifyResourceManager Leave(ENOENT)");
1831             return ICO_SYC_ENOENT;
1832         }
1833     }
1834     else {
1835         opt->dispzone = zone;
1836     }
1837 #if 1
1838     opt->soundres  = true;
1839     opt->soundname = window->appid;
1840     opt->soundid   = 0;
1841     CicoSCSystemConfig *sysconf = CicoSCSystemConfig::getInstance();
1842     const CicoSCDefaultConf *defconf = sysconf->getDefaultConf();
1843     if (NULL != defconf) {
1844         const CicoSCSoundZoneConf *zoneconf =
1845             sysconf->findSoundZoneConfbyId(defconf->soundzone);
1846         if (NULL != zoneconf) {
1847             opt->soundzone = zoneconf->fullname;
1848         }
1849     }
1850 #endif
1851
1852     m_resMgr->handleCommand((const CicoSCCommand&)cmd, true);
1853
1854     ICO_DBG("CicoSCWindowController::notifyResourceManager Leave(EOK)");
1855     return ICO_SYC_EOK;
1856 }
1857
1858 // vim:set expandtab ts=4 sw=4: