Fixed some RPMlint errors - group name, duplicate files, etc.
[profile/ivi/ico-uxf-homescreen.git] / ico-app-framework / ico_uxf_window.c
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  * @brief   header file of Window control for HomeScreen
11  *
12  * @date    Feb-28-2013
13  */
14
15 #include    <stdio.h>
16 #include    <stdlib.h>
17 #include    <unistd.h>
18 #include    <string.h>
19 #include    <signal.h>
20 #include    <errno.h>
21
22 #include    "ico_uxf.h"
23 #include    "ico_uxf_conf.h"
24 #include    "ico_uxf_private.h"
25 #include    "ico_window_mgr-client-protocol.h"
26
27 extern Ico_Uxf_Api_Mng         gIco_Uxf_Api_Mng;
28
29 /*--------------------------------------------------------------------------*/
30 /**
31  * @brief   ico_uxf_window_visible_control: window visible control(internal function)
32  *
33  * @param[in]   winmng          process management table
34  * @param[in]   show            show(1)/hide(0)/nochange(other)
35  * @param[in]   raise           raise(1)/lower(0)/nochange(other)
36  * @return      none
37  */
38 /*--------------------------------------------------------------------------*/
39 void
40 ico_uxf_window_visible_control(Ico_Uxf_Mng_Window *winmng, const int show, const int raise)
41 {
42     int showshow = show & 0x0ffff;
43
44     uifw_trace("ico_uxf_window_visible_control: send visible to weston(%s,%08x,%x,%d)",
45                (winmng->mng_process)->attr.process, winmng->attr.window, showshow, raise);
46
47     if ((showshow & (~ICO_UXF_WITHANIMA)) == ICO_WINDOW_MGR_VISIBLE_SHOW)   {
48
49         if (((winmng->mng_process)->attr.invisiblecpu == 0) &&
50             ((winmng->mng_process)->attr.suspend != 0))   {
51
52             /* change to show, application resume   */
53             (winmng->mng_process)->attr.suspend = 0;
54             (winmng->mng_process)->susptimer = 0;
55             if ((winmng->mng_process)->susp)    {
56                 (winmng->mng_process)->susp = 0;
57                 (winmng->mng_process)->showmode = showshow;
58                 (winmng->mng_process)->susptimer = ICO_UXF_SUSP_DELAY;
59                 gIco_Uxf_Api_Mng.NeedTimer = 1;
60                 kill((winmng->mng_process)->attr.internalid, SIGCONT);
61                 uifw_trace("ico_uxf_window_visible_control: CPU resume(%s)",
62                            (winmng->mng_process)->attr.process);
63                 if ((raise == ICO_WINDOW_MGR_RAISE_RAISE) ||
64                     (raise == ICO_WINDOW_MGR_RAISE_LOWER))  {
65                     ico_window_mgr_set_visible(gIco_Uxf_Api_Mng.Wayland_WindowMgr,
66                                                winmng->attr.window,
67                                                ICO_WINDOW_MGR_V_NOCHANGE, raise,
68                                                ICO_WINDOW_MGR_ANIMATION_NOANIMATION);
69                     if ((show & 0x00010000) == 0)   {
70                         wl_display_flush(gIco_Uxf_Api_Mng.Wayland_Display);
71                     }
72                 }
73                 return;
74             }
75         }
76         else if (((winmng->mng_process)->showmode & (~ICO_UXF_WITHANIMA)) ==
77                  ICO_WINDOW_MGR_VISIBLE_SHOW)   {
78             return;
79         }
80     }
81
82     /* send visible control to Weston(Multi Window Manager)     */
83     ico_window_mgr_set_visible(gIco_Uxf_Api_Mng.Wayland_WindowMgr,
84                                winmng->attr.window, showshow & (~ICO_UXF_WITHANIMA), raise,
85                                (showshow & ICO_UXF_WITHANIMA) ?
86                                  ICO_WINDOW_MGR_ANIMATION_ANIMATION :
87                                  ICO_WINDOW_MGR_ANIMATION_NOANIMATION);
88     if ((show & 0x00010000) == 0)   {
89         wl_display_flush(gIco_Uxf_Api_Mng.Wayland_Display);
90     }
91     if (((showshow & (~ICO_UXF_WITHANIMA)) == ICO_WINDOW_MGR_VISIBLE_HIDE) &&
92         ((winmng->mng_process)->attr.invisiblecpu == 0) &&
93         ((winmng->mng_process)->attr.suspend == 0))   {
94         /* change to hide, application suspend  */
95         (winmng->mng_process)->attr.suspend = 1;
96         (winmng->mng_process)->showmode = showshow;
97         (winmng->mng_process)->susptimer = ICO_UXF_SUSP_DELAY;
98         gIco_Uxf_Api_Mng.NeedTimer = 1;
99         uifw_trace("ico_uxf_window_visible_control: set CPU suspend(%s)",
100                    (winmng->mng_process)->attr.process);
101     }
102     else    {
103         (winmng->mng_process)->showmode = 0xff;
104         (winmng->mng_process)->susptimer = 0;
105     }
106 }
107
108 /*--------------------------------------------------------------------------*/
109 /**
110  * @brief   ico_uxf_window_layer: Set window layer
111  *
112  * @param[in]   window          window Id
113  * @param[in]   layer           layer Id
114  * @return      result
115  * @retval      ICO_UXF_EOK     success
116  * @retval      ICO_UXF_ESRCH   error(not initialized)
117  * @retval      ICO_UXF_ENOENT  error(window or layer dose not exist)
118  */
119 /*--------------------------------------------------------------------------*/
120 ICO_APF_API int
121 ico_uxf_window_layer(const int window, const int layer)
122 {
123     Ico_Uxf_Mng_Window  *winmng;
124     Ico_Uxf_Mng_Layer   *layermng;
125
126     uifw_trace("ico_uxf_window_layer: Enter(%08x,%d)", window, layer);
127
128     if (gIco_Uxf_Api_Mng.Initialized <= 0) {
129         uifw_warn("ico_uxf_window_layer: Leave(ESRCH)");
130         return ICO_UXF_ESRCH;
131     }
132
133     winmng = ico_uxf_mng_window(window, 0);
134     if ((! winmng) || (! winmng->mng_display)) {
135         uifw_warn("ico_uxf_window_layer: Leave(ENOENT)");
136         return ICO_UXF_ENOENT;
137     }
138
139     layermng = ico_uxf_mng_layer(winmng->attr.display, layer, 0);
140     if ((! layermng) || (! layermng->mng_display)) {
141         uifw_warn("ico_uxf_window_layer: Leave(ENOENT)");
142         return ICO_UXF_ENOENT;
143     }
144
145     uifw_trace("ico_uxf_window_layer: ico_window_mgr_set_window_layer(%08x,%d)",
146                window, layer);
147     winmng->mng_layer = layermng;
148     ico_window_mgr_set_window_layer(gIco_Uxf_Api_Mng.Wayland_WindowMgr, window, layer);
149     wl_display_flush(gIco_Uxf_Api_Mng.Wayland_Display);
150
151     uifw_trace("ico_uxf_window_layer: Leave(EOK)");
152     return ICO_UXF_EOK;
153 }
154
155 /*--------------------------------------------------------------------------*/
156 /**
157  * @brief   ico_uxf_layer_visible: Control layer visibility
158  *
159  * @param[in]   display         display Id
160  * @param[in]   layer           layer Id
161  * @param[in]   visible         layer show(1)/hide(0)
162  * @return      result
163  * @retval      ICO_UXF_EOK     success
164  * @retval      ICO_UXF_ESRCH   error(not initialized)
165  * @retval      ICO_UXF_ENOENT  error(layer dose not exist)
166  */
167 /*--------------------------------------------------------------------------*/
168 ICO_APF_API int
169 ico_uxf_layer_visible(const int display, const int layer, const int visible)
170 {
171     Ico_Uxf_Mng_Layer   *layermng;
172
173     uifw_trace("ico_uxf_layer_visible: Enter(%d,%d,%d)", display, layer, visible);
174
175     if (gIco_Uxf_Api_Mng.Initialized <= 0) {
176         uifw_warn("ico_uxf_layer_visible: Leave(ESRCH)");
177         return ICO_UXF_ESRCH;
178     }
179
180     layermng = ico_uxf_mng_layer(display, layer, 0);
181     if ((! layermng) || (! layermng->mng_display)) {
182         uifw_warn("ico_uxf_layer_visible: Leave(ENOENT)");
183         return ICO_UXF_ENOENT;
184     }
185
186     uifw_trace("ico_uxf_layer_visible: ico_window_mgr_set_layer_visible(%d,%d)",
187                layer, visible);
188     ico_window_mgr_set_layer_visible(gIco_Uxf_Api_Mng.Wayland_WindowMgr, layer, visible);
189     wl_display_flush(gIco_Uxf_Api_Mng.Wayland_Display);
190
191     uifw_trace("ico_uxf_layer_visible: Leave(EOK)");
192     return ICO_UXF_EOK;
193 }
194
195 /*--------------------------------------------------------------------------*/
196 /**
197  * @brief   ico_uxf_window_resize: resize window(surface) size
198  *
199  * @param[in]   window          window Id(same as ico_window_mgr surface Id)
200  * @param[in]   w               window width
201  * @param[in]   h               window height
202  * @return      result
203  * @retval      ICO_UXF_EOK     success
204  * @retval      ICO_UXF_ESRCH   error(not initialized)
205  * @retval      ICO_UXF_ENOENT  error(layer dose not exist)
206  */
207 /*--------------------------------------------------------------------------*/
208 ICO_APF_API int
209 ico_uxf_window_resize(const int window, const int w, const int h)
210 {
211     Ico_Uxf_Mng_Window  *winmng;
212
213     uifw_trace("ico_uxf_window_resize: Enter(%08x,%d,%d)", window, w, h);
214
215     if (gIco_Uxf_Api_Mng.Initialized <= 0) {
216         uifw_warn("ico_uxf_window_resize: Leave(ESRCH)");
217         return ICO_UXF_ESRCH;
218     }
219
220     winmng = ico_uxf_mng_window(window, 0);
221     if ((! winmng) || (! winmng->mng_layer))   {
222         uifw_warn("ico_uxf_window_resize: Leave(ENOENT)");
223         return ICO_UXF_ENOENT;
224     }
225
226     if ((w <= 0) || (w > winmng->mng_layer->attr.w) ||
227         (h <= 0) || (h > winmng->mng_layer->attr.h))   {
228         uifw_warn("ico_uxf_window_resize: Leave(EINVAL)");
229         return ICO_UXF_EINVAL;
230     }
231
232     winmng->attr.w = w;
233     winmng->attr.h = h;
234
235     ico_window_mgr_set_positionsize(gIco_Uxf_Api_Mng.Wayland_WindowMgr, window,
236                                     winmng->attr.node,
237                                     ICO_WINDOW_MGR_V_NOCHANGE, ICO_WINDOW_MGR_V_NOCHANGE,
238                                     winmng->attr.w, winmng->attr.h,
239                                     ICO_WINDOW_MGR_ANIMATION_NOANIMATION);
240     wl_display_flush(gIco_Uxf_Api_Mng.Wayland_Display);
241
242     uifw_trace("ico_uxf_window_resize: Leave(EOK)");
243     return ICO_UXF_EOK;
244 }
245
246 /*--------------------------------------------------------------------------*/
247 /**
248  * @brief   ico_uxf_window_move: move window(surface) geometry
249  *
250  * @param[in]   window          window Id(same as ico_window_mgr surface Id)
251  * @param[in]   x               window upper-left X coodinate of display
252  * @param[in]   y               window upper-left Y coodinate of display
253  * @param[in]   animation       move with animation(=1)/no animation(=0)
254  * @return      result
255  * @retval      ICO_UXF_EOK     success
256  * @retval      ICO_UXF_ESRCH   error(not initialized)
257  * @retval      ICO_UXF_ENOENT  error(layer dose not exist)
258  */
259 /*--------------------------------------------------------------------------*/
260 ICO_APF_API int
261 ico_uxf_window_move(const int window, const int x, const int y, const int animation)
262 {
263     Ico_Uxf_Mng_Window  *winmng;
264
265     uifw_trace("ico_uxf_window_move: Enter(%08x,%d,%d,%d)", window, x, y, animation);
266
267     if(gIco_Uxf_Api_Mng.Initialized <= 0)   {
268         uifw_warn("ico_uxf_window_move: Leave(ESRCH)");
269         return ICO_UXF_ESRCH;
270     }
271
272     winmng = ico_uxf_mng_window(window, 0);
273     if ((! winmng) || (! winmng->mng_layer))   {
274         uifw_warn("ico_uxf_window_move: Leave(ENOENT)");
275         return ICO_UXF_ENOENT;
276     }
277
278     winmng->attr.x = x;
279     winmng->attr.y = y;
280
281     ico_window_mgr_set_positionsize(gIco_Uxf_Api_Mng.Wayland_WindowMgr, window,
282                                     winmng->attr.node, winmng->attr.x, winmng->attr.y,
283                                     ICO_WINDOW_MGR_V_NOCHANGE, ICO_WINDOW_MGR_V_NOCHANGE,
284                                     (animation == 0) ?
285                                       ICO_WINDOW_MGR_ANIMATION_NOANIMATION :
286                                       ICO_WINDOW_MGR_ANIMATION_ANIMATION);
287     wl_display_flush(gIco_Uxf_Api_Mng.Wayland_Display);
288
289     uifw_trace("ico_uxf_window_move: Leave(EOK)");
290     return ICO_UXF_EOK;
291 }
292
293 /*--------------------------------------------------------------------------*/
294 /**
295  * @brief   ico_uxf_window_raise: raise window(surface)
296  *
297  * @param[in]   window          window Id(same as ico_window_mgr surface Id)
298  * @return      result
299  * @retval      ICO_UXF_EOK     success
300  * @retval      ICO_UXF_ESRCH   error(not initialized)
301  * @retval      ICO_UXF_ENOENT  error(layer dose not exist)
302  */
303 /*--------------------------------------------------------------------------*/
304 ICO_APF_API int
305 ico_uxf_window_raise(const int window)
306 {
307     Ico_Uxf_Mng_Window  *winmng;
308
309     uifw_trace("ico_uxf_window_raise: Enter(%08x)", window);
310
311     if (gIco_Uxf_Api_Mng.Initialized <= 0) {
312         uifw_warn("ico_uxf_window_raise: Leave(ESRCH)");
313         return ICO_UXF_ESRCH;
314     }
315
316     winmng = ico_uxf_mng_window(window, 0);
317     if ((! winmng) || (! winmng->mng_display)) {
318         uifw_warn("ico_uxf_window_raise: Leave(ENOENT)");
319         return ICO_UXF_ENOENT;
320     }
321
322     ico_uxf_window_visible_control(winmng, ICO_WINDOW_MGR_V_NOCHANGE,
323                                    ICO_WINDOW_MGR_RAISE_RAISE);
324
325     uifw_trace("ico_uxf_window_raise: Leave(EOK)");
326     return ICO_UXF_EOK;
327 }
328
329 /*--------------------------------------------------------------------------*/
330 /**
331  * @brief   ico_uxf_window_lower: lower window(surface)
332  *
333  * @param[in]   window          window Id(same as ico_window_mgr surface Id)
334  * @return      result
335  * @retval      ICO_UXF_EOK     success
336  * @retval      ICO_UXF_ESRCH   error(not initialized)
337  * @retval      ICO_UXF_ENOENT  error(layer dose not exist)
338  */
339 /*--------------------------------------------------------------------------*/
340 ICO_APF_API int
341 ico_uxf_window_lower(const int window)
342 {
343     Ico_Uxf_Mng_Window  *winmng;
344
345     uifw_trace("ico_uxf_window_lower: Enter(%08x)", window);
346
347     if (gIco_Uxf_Api_Mng.Initialized <= 0) {
348         uifw_warn("ico_uxf_window_lower: Leave(ESRCH)");
349         return ICO_UXF_ESRCH;
350     }
351
352     winmng = ico_uxf_mng_window(window, 0);
353     if ((! winmng) || (! winmng->mng_display)) {
354         uifw_warn("ico_uxf_window_lower: Leave(ENOENT)");
355         return ICO_UXF_ENOENT;
356     }
357
358     ico_uxf_window_visible_control(winmng, ICO_WINDOW_MGR_V_NOCHANGE,
359                                    ICO_WINDOW_MGR_RAISE_LOWER);
360
361     uifw_trace("ico_uxf_window_lower: Leave(EOK)");
362     return ICO_UXF_EOK;
363 }
364
365 /*--------------------------------------------------------------------------*/
366 /**
367  * @brief   ico_uxf_window_active: active window(surface)
368  *
369  * @param[in]   window          window Id(same as ico_window_mgr surface Id)
370  * @param[in]   target          target(pointer and/or keyboard)
371  * @return      result
372  * @retval      ICO_UXF_EOK     success
373  * @retval      ICO_UXF_ESRCH   error(not initialized)
374  * @retval      ICO_UXF_ENOENT  error(layer dose not exist)
375  */
376 /*--------------------------------------------------------------------------*/
377 ICO_APF_API int
378 ico_uxf_window_active(const int window, const int target)
379 {
380     Ico_Uxf_Mng_Window  *winmng;
381     Ico_Uxf_Mng_Process *proc;
382     Ico_Uxf_Mng_Process *aproc;
383     int                 hash;
384
385     uifw_trace("ico_uxf_window_active: Enter(%08x,%x)", window, target);
386
387     if (gIco_Uxf_Api_Mng.Initialized <= 0) {
388         uifw_warn("ico_uxf_window_active: Leave(ESRCH)");
389         return ICO_UXF_ESRCH;
390     }
391
392     winmng = ico_uxf_mng_window(window, 0);
393     if ((! winmng) || (! winmng->mng_display)) {
394         uifw_warn("ico_uxf_window_active: Leave(ENOENT)");
395         return ICO_UXF_ENOENT;
396     }
397
398     uifw_trace("ico_uxf_window_active: ico_window_mgr_set_active(%08x)", window);
399     ico_window_mgr_set_active(gIco_Uxf_Api_Mng.Wayland_WindowMgr, window, target);
400     wl_display_flush(gIco_Uxf_Api_Mng.Wayland_Display);
401
402     /* reset all active window widthout target window   */
403     for (hash = 0; hash < ICO_UXF_MISC_HASHSIZE; hash++)   {
404         winmng = gIco_Uxf_Api_Mng.Hash_WindowId[hash];
405         while (winmng) {
406             if (winmng->attr.window == window)  {
407                 winmng->attr.active = target;
408             }
409             else    {
410                 if (target == 0)    {
411                     winmng->attr.active = 0;
412                 }
413                 else    {
414                     winmng->attr.active &= ~target;
415                 }
416             }
417             winmng = winmng->nextidhash;
418         }
419     }
420
421     /* reset all active application without this application    */
422     aproc = NULL;
423     for (hash = 0; hash < ICO_UXF_MISC_HASHSIZE; hash++)    {
424         proc = gIco_Uxf_Api_Mng.Hash_ProcessId[hash];
425         while (proc)    {
426             if (proc->attr.mainwin.window == window)    {
427                 aproc = proc;
428             }
429             else    {
430                 if (target == 0)    {
431                     proc->attr.active = 0;
432                 }
433                 else    {
434                     proc->attr.active &= ~target;
435                 }
436             }
437             proc = proc->nextidhash;
438         }
439     }
440     if (aproc)  {
441         aproc->attr.active = target;
442     }
443     uifw_trace("ico_uxf_window_active: Leave(EOK)");
444     return ICO_UXF_EOK;
445 }
446
447 /*--------------------------------------------------------------------------*/
448 /**
449  * @brief   ico_uxf_window_event_mask: set window(surface) event mask
450  *
451  * @param[in]   window          window Id(same as ico_window_mgr surface Id)
452  * @param[in]   mask            event mask
453  * @return      result
454  * @retval      ICO_UXF_EOK     success
455  * @retval      ICO_UXF_ESRCH   error(not initialized)
456  * @retval      ICO_UXF_ENOENT  error(layer dose not exist)
457  */
458 /*--------------------------------------------------------------------------*/
459 ICO_APF_API int
460 ico_uxf_window_event_mask(const int window, const unsigned int mask)
461 {
462     Ico_Uxf_Mng_Window  *winmng;
463
464     uifw_trace("ico_uxf_window_event_mask: Enter(%08x,%08x)", window, mask);
465
466     if (gIco_Uxf_Api_Mng.Initialized <= 0) {
467         uifw_warn("ico_uxf_window_event_mask: Leave(ESRCH)");
468         return ICO_UXF_ESRCH;
469     }
470
471     winmng = ico_uxf_mng_window(window, 0);
472     if (! winmng)  {
473         uifw_warn("ico_uxf_window_event_mask: Leave(ENOENT)");
474         return ICO_UXF_ENOENT;
475     }
476
477     winmng->attr.eventmask = mask;
478
479     uifw_trace("ico_uxf_window_event_mask: Leave(EOK)");
480     return ICO_UXF_EOK;
481 }
482
483 /*--------------------------------------------------------------------------*/
484 /**
485  * @brief   ico_uxf_window_attribute_get: get window(surface) attribute
486  *
487  * @param[in]   window          window Id(same as ico_window_mgr surface Id)
488  * @param[out]  attr            window attribute
489  * @return      result
490  * @retval      ICO_UXF_EOK     success
491  * @retval      ICO_UXF_ESRCH   error(not initialized)
492  * @retval      ICO_UXF_ENOENT  error(layer dose not exist)
493  */
494 /*--------------------------------------------------------------------------*/
495 ICO_APF_API int
496 ico_uxf_window_attribute_get(const int window, Ico_Uxf_WindowAttr *attr)
497 {
498     Ico_Uxf_Mng_Window  *winmng;
499
500     uifw_trace("ico_uxf_window_attribute_get: Enter(%08x)", window);
501
502     if (gIco_Uxf_Api_Mng.Initialized <= 0) {
503         uifw_warn("ico_uxf_window_attribute_get: Leave(ESRCH)");
504         return ICO_UXF_ESRCH;
505     }
506
507     winmng = ico_uxf_mng_window(window, 0);
508     if (! winmng)  {
509         uifw_warn("ico_uxf_window_attribute_get: Leave(ENOENT)");
510         return ICO_UXF_ENOENT;
511     }
512
513     memcpy((char *)attr, (char *)&(winmng->attr), sizeof(Ico_Uxf_WindowAttr));
514
515     uifw_trace("ico_uxf_window_attribute_get: Leave(EOK)");
516     return ICO_UXF_EOK;
517 }
518
519 /*--------------------------------------------------------------------------*/
520 /**
521  * @brief   ico_uxf_window_query_windows: get all windows attribute
522  *
523  * @param[in]   display         target display Id
524  * @param[out]  attr            window attribute array
525  * @param[in]   num             number of window attribute area
526  * @return      result
527  * @retval      >= 0            success(number of windows)
528  * @retval      ICO_UXF_ESRCH   error(not initialized)
529  * @retval      ICO_UXF_EINVAL  error(illegal parameter 'num')
530  * @retval      ICO_UXF_E2BIG   error(number of windows over 'num')
531  */
532 /*--------------------------------------------------------------------------*/
533 ICO_APF_API int
534 ico_uxf_window_query_windows(const int display, Ico_Uxf_WindowAttr attr[], const int num)
535 {
536     int                 n;
537     Ico_Uxf_Mng_Window  *winmng;
538     int                 hash;
539
540     uifw_trace("ico_uxf_window_query_windows: Enter(%d,,%d)", display, num);
541
542     if (gIco_Uxf_Api_Mng.Initialized <= 0) {
543         uifw_warn("ico_uxf_window_query_windows: Leave(ESRCH)");
544         return ICO_UXF_ESRCH;
545     }
546
547     if (num <= 0)  {
548         uifw_warn("ico_uxf_window_query_windows: Leave(EINVAL)");
549         return ICO_UXF_EINVAL;
550     }
551
552     n = 0;
553     for (hash = 0; hash < ICO_UXF_MISC_HASHSIZE; hash++)   {
554         winmng = gIco_Uxf_Api_Mng.Hash_WindowId[hash];
555         while (winmng) {
556             if (n >= num)      break;
557             memcpy((char *)(&attr[n]), (char *)&(winmng->attr), sizeof(Ico_Uxf_WindowAttr));
558             n ++;
559             winmng = winmng->nextidhash;
560         }
561         if (winmng)    break;
562     }
563     if (winmng)    {
564         n = ICO_UXF_E2BIG;
565         uifw_trace("ico_uxf_window_query_windows: Leave(E2BIG)");
566     }
567     else    {
568         uifw_trace("ico_uxf_window_query_windows: Leave(%d)", n);
569     }
570     return n;
571 }
572
573 /*--------------------------------------------------------------------------*/
574 /**
575  * @brief   ico_uxf_window_control: target window control from AppsController
576  *
577  * @param[in]   appid       Application Id
578  * @param[in]   winidx      Window index
579  * @param[in]   control     Window control
580  *                            ICO_UXF_APPSCTL_INVISIBLE:   Invisible by low priority
581  *                            ICO_UXF_APPSCTL_REGULATION:  Invisible by regulation
582  *                            ICO_UXF_APPSCTL_TEMPVISIBLE: Visible as HomeScreen menu
583  * @param[in]   onoff       Flag On(1)/Off(0)
584  *                            ICO_UXF_APPSCTL_INVISIBLE:   On(1) is invisible
585  *                            ICO_UXF_APPSCTL_REGULATION:  On(1) is invisible
586  *                            ICO_UXF_APPSCTL_TEMPVISIBLE: On(1) is visible(menu)
587  * @return  result
588  * @retval  ICO_UXF_EOK         success
589  * @retval  ICO_UXF_ESRCH       error(not initialized)
590  * @retval  ICO_UXF_ENOENT      error(not exist)
591  */
592 /*--------------------------------------------------------------------------*/
593 ICO_APF_API int
594 ico_uxf_window_control(const char *appid, const int winidx,
595                        const int control, const int onoff)
596 {
597 #define MAX_APP_WINDOWS 20
598     Ico_Uxf_ProcessWin  procattr[MAX_APP_WINDOWS];
599     int         nwin;
600     Ico_Uxf_Mng_Window  *winmng;            /* window management table      */
601     int         hash;
602     int         newcontrol;
603     int         i;
604
605     uifw_trace("ico_uxf_window_control: Enter(%s,%d,%x,%d)",
606                appid, winidx, control, onoff);
607
608     if (gIco_Uxf_Api_Mng.Initialized <= 0)  {
609         uifw_warn("ico_uxf_window_control: Leave(ESRCH)");
610         return ICO_UXF_ESRCH;
611     }
612
613     if (control == ICO_UXF_APPSCTL_TEMPVISIBLE) {
614         if (onoff != gIco_Uxf_Api_Mng.AppsCtlVisible)   {
615             if (onoff > 0)  gIco_Uxf_Api_Mng.AppsCtlVisible = 1;
616             else            gIco_Uxf_Api_Mng.AppsCtlVisible = 0;
617
618             /* control all windows          */
619             for (hash = 0; hash < ICO_UXF_MISC_HASHSIZE; hash++)    {
620                 winmng = gIco_Uxf_Api_Mng.Hash_WindowId[hash];
621                 while (winmng)  {
622                     if ((winmng->attr.window > 0) && (winmng->attr.visible))    {
623                         if ((winmng->mng_process)->attr.noicon == 0)    {
624                             if ((gIco_Uxf_Api_Mng.AppsCtlVisible != 0) ||
625                                 (winmng->attr.control == 0))    {
626                                 i = ICO_WINDOW_MGR_VISIBLE_SHOW;
627                             }
628                             else    {
629                                 i = ICO_WINDOW_MGR_VISIBLE_HIDE;
630                             }
631                         }
632                         else    {
633                             if ((gIco_Uxf_Api_Mng.AppsCtlVisible == 0) &&
634                                 (winmng->attr.control == 0))    {
635                                 i = ICO_WINDOW_MGR_VISIBLE_SHOW;
636                             }
637                             else    {
638                                 i = ICO_WINDOW_MGR_VISIBLE_HIDE;
639                             }
640                         }
641                         ico_uxf_window_visible_control(winmng, i | 0x00010000,
642                                                        ICO_WINDOW_MGR_V_NOCHANGE);
643                     }
644                     winmng = winmng->nextidhash;
645                 }
646             }
647             wl_display_flush(gIco_Uxf_Api_Mng.Wayland_Display);
648         }
649         uifw_trace("ico_uxf_window_control: Leave(EOK)");
650     }
651     else    {
652         /* get current application status       */
653         if (winidx >= 0)    {
654             nwin = ico_uxf_process_window_get_one(appid, procattr, winidx);
655             if (nwin == 0)  nwin = 1;
656         }
657         else    {
658             /* all window           */
659             nwin = ico_uxf_process_window_get(appid, procattr, MAX_APP_WINDOWS);
660         }
661         if (nwin == ICO_UXF_E2BIG)  nwin = MAX_APP_WINDOWS;
662         if (nwin < 0)  {
663             uifw_trace("ico_uxf_window_control: Leave(Unknown appid(%s))", appid);
664             return ICO_UXF_ENOENT;
665         }
666         for (i = 0; i < nwin; i++)  {
667             if (procattr[i].window == 0)    continue;
668             winmng = ico_uxf_mng_window(procattr[i].window, 0);
669             if (! winmng)   {
670                 uifw_trace("ico_uxf_window_control: winid=%08x not exist",
671                            procattr[i].window);
672                 continue;
673             }
674             newcontrol = winmng->attr.control;
675             if (onoff)  newcontrol |= control;
676             else        newcontrol &= (~control);
677
678             uifw_trace("ico_uxf_window_control: control %08x(%s) %02x=>%02x vis=%d icon=%d",
679                        procattr[i].window, (winmng->mng_process)->attr.process,
680                        winmng->attr.control, newcontrol, winmng->attr.visible,
681                        (winmng->mng_process)->attr.noicon);
682             if (winmng->attr.control != newcontrol) {
683                 winmng->attr.control = newcontrol;
684                 if (winmng->attr.visible != 0)  {
685                     if ((gIco_Uxf_Api_Mng.AppsCtlVisible != 0) &&
686                         (((winmng->mng_process)->appconf == NULL) ||
687                          ((((Ico_Uxf_conf_application *)(winmng->mng_process)->appconf)->
688                            menuoverlap == 0) &&
689                           (winmng->mng_layer->attr.menuoverlap == 0)))) {
690                         if ((winmng->mng_process)->attr.noicon == 0)    newcontrol = 0;
691                         else                                            newcontrol = 1;
692                     }
693                     /* request to Weston(Multi Window Manager)  */
694                     if (newcontrol == 0)    {
695                         i = ICO_WINDOW_MGR_VISIBLE_SHOW;
696                         if (gIco_Uxf_Api_Mng.Win_Show_Anima)
697                             i |= ICO_UXF_WITHANIMA;
698                     }
699                     else    {
700                         i = ICO_WINDOW_MGR_VISIBLE_HIDE;
701                         if (gIco_Uxf_Api_Mng.Win_Hide_Anima)
702                             i |= ICO_UXF_WITHANIMA;
703                     }
704                     ico_uxf_window_visible_control(winmng, i,
705                                                    ICO_WINDOW_MGR_V_NOCHANGE);
706                 }
707             }
708             uifw_trace("ico_uxf_window_control: Leave(EOK) control=%x(%d) visible=%d",
709                        winmng->attr.control, gIco_Uxf_Api_Mng.AppsCtlVisible,
710                        winmng->attr.visible);
711         }
712     }
713     return ICO_UXF_EOK;
714 }
715
716 /*--------------------------------------------------------------------------*/
717 /**
718  * @brief   ico_uxf_window_control: target window control from AppsController
719  *
720  * @param[in]   control     Control Target(0=Hide/1=Show)
721  * @param[in]   animation   Animation(0=Without Animation/1=With Animation)
722  * @return      none
723  */
724 /*--------------------------------------------------------------------------*/
725 ICO_APF_API void
726 ico_uxf_window_animation_control(const int control, const int animation)
727 {
728     uifw_trace("ico_uxf_window_animation_control: %s to %s",
729         control ? "Show" : "Hide", animation ? "Animation" : "No Animation");
730     if (control)    {
731         gIco_Uxf_Api_Mng.Win_Show_Anima = animation;
732     }
733     else    {
734         gIco_Uxf_Api_Mng.Win_Hide_Anima = animation;
735     }
736 }
737
738 /*--------------------------------------------------------------------------*/
739 /**
740  * @brief   ico_uxf_window_show: show a target window
741  *          if target window's state is visible, do nothing and return success
742  *
743  * @param[in]   window      Window identity
744  * @return  result
745  * @retval  ICO_UXF_EOK         success
746  * @retval  ICO_UXF_ESRCH       error(not initialized)
747  * @retval  ICO_UXF_ENOENT      error(not exist)
748  */
749 /*--------------------------------------------------------------------------*/
750 ICO_APF_API int
751 ico_uxf_window_show(const int window)
752 {
753     Ico_Uxf_Mng_Window  *winmng;            /* window management table      */
754
755     uifw_trace("ico_uxf_window_show: Enter(%08x)", window);
756
757     if (gIco_Uxf_Api_Mng.Initialized <= 0) {
758         uifw_warn("ico_uxf_window_show: Leave(ESRCH)");
759         return ICO_UXF_ESRCH;
760     }
761
762     winmng = ico_uxf_mng_window(window, 0);
763     if ((! winmng) || (! winmng->mng_display)) {
764         uifw_warn("ico_uxf_window_show: Leave(ENOENT)");
765         return ICO_UXF_ENOENT;
766     }
767     winmng->attr.visible = 1;
768
769     if (winmng->attr.control == 0)  {
770         /* request to display to Weston(Multi Window Manager)   */
771         ico_uxf_window_visible_control(winmng, ICO_WINDOW_MGR_VISIBLE_SHOW,
772                                        ICO_WINDOW_MGR_V_NOCHANGE);
773     }
774     uifw_trace("ico_uxf_window_show: Leave(EOK) control=%x", winmng->attr.control);
775     return ICO_UXF_EOK;
776 }
777
778 /*--------------------------------------------------------------------------*/
779 /**
780  * @brief   ico_uxf_window_hide: hide a target window
781  *          if target window's state is unvisible, do nothing and return success
782  *
783  * @param[in]   window      target window identity
784  * @return  result
785  * @retval  ICO_UXF_EOK         success
786  * @retval  ICO_UXF_ESRCH       error(not initialized)
787  * @retval  ICO_UXF_ENOENT      error(not exist)
788  */
789 /*--------------------------------------------------------------------------*/
790 ICO_APF_API int
791 ico_uxf_window_hide(const int window)
792 {
793     Ico_Uxf_Mng_Window  *winmng;            /* window management table      */
794
795     uifw_trace("ico_uxf_window_hide: Enter(%08x)", window);
796
797     if (gIco_Uxf_Api_Mng.Initialized <= 0) {
798         uifw_warn("ico_uxf_window_hide: Leave(ESRCH)");
799         return ICO_UXF_ESRCH;
800     }
801
802     winmng = ico_uxf_mng_window(window, 0);
803     if ((! winmng) || (! winmng->mng_display)) {
804         uifw_warn("ico_uxf_window_hide: Leave(ENOENT)");
805         return ICO_UXF_ENOENT;
806     }
807     winmng->attr.visible = 0;
808
809     /* request to hide to Weston(Multi Window Manager)  */
810     ico_uxf_window_visible_control(winmng, ICO_WINDOW_MGR_VISIBLE_HIDE,
811                                    ICO_WINDOW_MGR_V_NOCHANGE);
812
813     uifw_trace("ico_uxf_window_hide: Leave(EOK)");
814     return ICO_UXF_EOK;
815 }
816
817 /*--------------------------------------------------------------------------*/
818 /**
819  * @brief   ico_uxf_window_visible_raise: control status of visible(show/hide)
820  *                                        and order(raise/lower)
821  *
822  * @param[in]   window      target window identity
823  * @param[in]   visible     visible(1)/unvisible(0)/nochange(other)
824  * @param[in]   raise       forefront(1)/maximum back(0)/nochange(other)
825  * @return  result
826  * @retval  ICO_UXF_EOK         success
827  * @retval  ICO_UXF_ESRCH       error(not initialized)
828  * @retval  ICO_UXF_ENOENT      error(not exist)
829  */
830 /*--------------------------------------------------------------------------*/
831 ICO_APF_API int
832 ico_uxf_window_visible_raise(const int window, const int visible, const int raise)
833 {
834     Ico_Uxf_Mng_Window  *winmng;            /* window management table      */
835     int                 vis = visible;
836     int                 rai = raise;
837
838     uifw_trace("ico_uxf_window_visible_raise: Enter(%08x,%d,%d)", window, visible, raise);
839
840     if (gIco_Uxf_Api_Mng.Initialized <= 0)  {
841         uifw_warn("ico_uxf_window_visible_raise: Leave(ESRCH)");
842         return ICO_UXF_ESRCH;
843     }
844
845     winmng = ico_uxf_mng_window(window, 0);
846     if ((! winmng) || (! winmng->mng_display))  {
847         uifw_warn("ico_uxf_window_visible_raise: Leave(ENOENT)");
848         return ICO_UXF_ENOENT;
849     }
850
851     if (vis == 0)   {
852         winmng->attr.visible = 0;
853         vis = ICO_WINDOW_MGR_VISIBLE_HIDE;
854     }
855     else if (vis == 1)  {
856         winmng->attr.visible = 1;
857         vis = ICO_WINDOW_MGR_VISIBLE_SHOW;
858         if (gIco_Uxf_Api_Mng.AppsCtlVisible == 0)   {
859             /* application screen       */
860             if (winmng->attr.control != 0)  {
861                 uifw_trace("ico_uxf_window_visible_raise: change to hide(ctrl=%x menu=0)",
862                            winmng->attr.control);
863                 vis = ICO_WINDOW_MGR_VISIBLE_HIDE;
864             }
865         }
866         else    {
867             /* HomeScreen menu screen   */
868             if ((winmng->mng_process)->attr.noicon != 0)    {
869                 uifw_trace("ico_uxf_window_visible_raise: change to hide(ctrl=%x menu=1)",
870                            winmng->attr.control);
871                 vis = ICO_WINDOW_MGR_VISIBLE_HIDE;
872             }
873         }
874     }
875     else    {
876         vis = ICO_WINDOW_MGR_V_NOCHANGE;
877     }
878     if (raise == 0) {
879         rai = ICO_WINDOW_MGR_RAISE_LOWER;
880     }
881     else if (raise == 1)    {
882         rai = ICO_WINDOW_MGR_RAISE_RAISE;
883     }
884     else    {
885         rai = ICO_WINDOW_MGR_V_NOCHANGE;
886     }
887
888     if ((vis != ICO_WINDOW_MGR_V_NOCHANGE) ||
889         (rai != ICO_WINDOW_MGR_V_NOCHANGE)) {
890         /* request to visible status and order status to Weston(Multi Window Manager)   */
891         ico_uxf_window_visible_control(winmng, vis, rai);
892     }
893     uifw_trace("ico_uxf_window_visible_raise: Leave(EOK)");
894     return ICO_UXF_EOK;
895 }
896
897 /*--------------------------------------------------------------------------*/
898 /**
899  * @brief   ico_uxf_window_visible_animation: show/hide a target window with animation
900  *
901  * @param[in]   window      Window identity
902  * @param[in]   show        Show(1)/Hide(0)
903  * @return  result
904  * @retval  ICO_UXF_EOK         success
905  * @retval  ICO_UXF_ESRCH       error(not initialized)
906  * @retval  ICO_UXF_ENOENT      error(not exist)
907  */
908 /*--------------------------------------------------------------------------*/
909 ICO_APF_API int
910 ico_uxf_window_visible_animation(const int window, const int show)
911 {
912     Ico_Uxf_Mng_Window  *winmng;            /* window management table      */
913
914     uifw_trace("ico_uxf_window_visible_animation: Enter(%08x,%d)", window, show);
915
916     if (gIco_Uxf_Api_Mng.Initialized <= 0) {
917         uifw_warn("ico_uxf_window_visible_animation: Leave(ESRCH)");
918         return ICO_UXF_ESRCH;
919     }
920
921     winmng = ico_uxf_mng_window(window, 0);
922     if ((! winmng) || (! winmng->mng_display)) {
923         uifw_warn("ico_uxf_window_visible_animation: Leave(ENOENT)");
924         return ICO_UXF_ENOENT;
925     }
926     winmng->attr.visible = show ? 1 : 0;
927
928     if (show)   {
929         if (winmng->attr.control == 0)  {
930             /* request to display to Weston(Multi Window Manager)   */
931             ico_uxf_window_visible_control(winmng,
932                                            ICO_WINDOW_MGR_VISIBLE_SHOW|ICO_UXF_WITHANIMA,
933                                            ICO_WINDOW_MGR_V_NOCHANGE);
934         }
935     }
936     else    {
937         ico_uxf_window_visible_control(winmng,
938                                        ICO_WINDOW_MGR_VISIBLE_HIDE|ICO_UXF_WITHANIMA,
939                                        ICO_WINDOW_MGR_V_NOCHANGE);
940     }
941     uifw_trace("ico_uxf_window_visible_animation: Leave(EOK) control=%x",
942                winmng->attr.control);
943     return ICO_UXF_EOK;
944 }
945
946 /*--------------------------------------------------------------------------*/
947 /**
948  * @brief   ico_uxf_window_animation: set window animation
949  *
950  * @param[in]   window              Window identity
951  * @param[in]   type                Target animation type,
952  * @param[in]   animation           Animation name, if NULL, no change
953  * @param[in]   time                Animation time(ms), if 0, default time
954  * @return  result
955  * @retval  ICO_UXF_EOK         success
956  * @retval  ICO_UXF_ESRCH       error(not initialized)
957  * @retval  ICO_UXF_ENOENT      error(not exist)
958  */
959 /*--------------------------------------------------------------------------*/
960 ICO_APF_API int
961 ico_uxf_window_animation(const int window, const int type,
962                          const char *animation, const int time)
963 {
964     Ico_Uxf_Mng_Window  *winmng;            /* window management table      */
965
966     uifw_trace("ico_uxf_window_animation: Enter(%08x,%x,%s,%d)",
967                window, type, animation ? animation : "NULL", time);
968
969     if (gIco_Uxf_Api_Mng.Initialized <= 0) {
970         uifw_warn("ico_uxf_window_animation: Leave(ESRCH)");
971         return ICO_UXF_ESRCH;
972     }
973
974     winmng = ico_uxf_mng_window(window, 0);
975     if ((! winmng) || (! winmng->mng_display)) {
976         uifw_warn("ico_uxf_window_animation: Leave(ENOENT)");
977         return ICO_UXF_ENOENT;
978     }
979
980     if (animation)  {
981         ico_window_mgr_set_animation(gIco_Uxf_Api_Mng.Wayland_WindowMgr,
982                                      winmng->attr.window, type, animation, time);
983     }
984     else    {
985         ico_window_mgr_set_animation(gIco_Uxf_Api_Mng.Wayland_WindowMgr,
986                                      winmng->attr.window, type, " ", time);
987     }
988     uifw_trace("ico_uxf_window_animation: Leave(EOK)");
989     return ICO_UXF_EOK;
990 }
991