2 * Copyright © 2010-2011 Intel Corporation
3 * Copyright © 2008-2011 Kristian Høgsberg
4 * Copyright © 2013 TOYOTA MOTOR CORPORATION.
6 * Permission to use, copy, modify, distribute, and sell this software and
7 * its documentation for any purpose is hereby granted without fee, provided
8 * that the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of the copyright holders not be used in
11 * advertising or publicity pertaining to distribution of the software
12 * without specific, written prior permission. The copyright holders make
13 * no representations about the suitability of this software for any
14 * purpose. It is provided "as is" without express or implied warranty.
16 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
17 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
18 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
20 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
21 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
22 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 * @brief Multi Window Manager (Weston(Wayland) PlugIn)
37 #include <linux/input.h>
42 #include <sys/types.h>
45 #include <wayland-server.h>
49 #include <weston/compositor.h>
50 #include "ico_ivi_common.h"
51 #include "ico_ivi_shell.h"
52 #include "ico_window_mgr.h"
53 #include "desktop-shell-server-protocol.h"
54 #include "ico_window_mgr-server-protocol.h"
57 #define INIT_SURFACE_IDS 1024 /* SurfaceId table initiale size */
58 #define ADD_SURFACE_IDS 512 /* SurfaceId table additional size */
59 #define SURCAFE_ID_MASK 0x0ffff /* SurfaceId bit mask pattern */
60 #define UIFW_HASH 64 /* Hash value (2's compliment) */
62 /* Client attribute table */
63 #define MAX_CLIENT_ATTR 4
64 struct uifw_client_attr {
65 char appid[ICO_IVI_APPID_LENGTH]; /* ApplicationId */
66 struct _uifw_client_attr_value {
70 } attrs[MAX_CLIENT_ATTR];
76 struct wl_resource *resource; /* Manager resource */
77 int manager; /* Manager(=event send flag) */
78 struct wl_list link; /* link to next manager */
81 /* Multi Windiw Manager */
83 struct weston_compositor *compositor; /* Weston compositor */
84 void *shell; /* shell(ico_ivi_shell) table address */
85 int32_t surface_head; /* (HostID << 24) | (DisplayNo << 16) */
87 struct wl_list client_list; /* Clients */
88 struct wl_list manager_list; /* Manager(ex.HomeScreen) list */
89 int num_manager; /* Number of managers */
90 struct wl_list ivi_layer_list; /* Layer management table list */
91 struct uifw_win_surface *active_pointer_usurf; /* Active Pointer Surface */
92 struct uifw_win_surface *active_keyboard_usurf; /* Active Keyboard Surface */
94 struct uifw_win_surface *idhash[UIFW_HASH]; /* UIFW SerfaceID */
95 struct uifw_win_surface *wshash[UIFW_HASH]; /* Weston Surface */
97 uint32_t surfaceid_count; /* Number of surface id */
98 uint32_t surfaceid_max; /* Maximum number of surface id */
99 uint16_t *surfaceid_map; /* SurfaceId assign bit map */
101 char shell_init; /* shell initialize flag */
102 char res; /* (unused) */
105 /* Internal macros */
107 #define MAKE_IDHASH(v) (((uint32_t)v) & (UIFW_HASH-1))
109 #define MAKE_WSHASH(v) ((((uint32_t)v) >> 5) & (UIFW_HASH-1))
111 /* function prototype */
112 /* get surface table from surfece id */
113 static struct uifw_win_surface* find_uifw_win_surface_by_id(uint32_t surfaceid);
114 /* get surface table from weston surface*/
115 static struct uifw_win_surface* find_uifw_win_surface_by_ws(
116 struct weston_surface *wsurf);
117 /* get client table from weston client */
118 static struct uifw_client* find_client_from_client(struct wl_client* client);
119 /* assign new surface id */
120 static uint32_t generate_id(void);
121 /* bind shell client */
122 static void win_mgr_bind_client(struct wl_client *client, void *shell);
123 /* unind shell client */
124 static void win_mgr_unbind_client(struct wl_client *client);
125 /* create new surface */
126 static void win_mgr_register_surface(
127 struct wl_client *client, struct wl_resource *resource,
128 struct weston_surface *surface, struct shell_surface *shsurf);
129 /* surface destory */
130 static void win_mgr_destroy_surface(struct weston_surface *surface);
131 /* map new surface */
132 static void win_mgr_map_surface(struct weston_surface *surface, int32_t *width,
133 int32_t *height, int32_t *sx, int32_t *sy);
134 /* send surface change event to manager */
135 static void win_mgr_change_surface(struct weston_surface *surface,
136 const int to, const int manager);
138 static void win_mgr_select_surface(struct weston_surface *surface);
139 /* surface set title */
140 static void win_mgr_set_title(struct weston_surface *surface, const char *title);
141 /* surface move request from shell */
142 static void win_mgr_surface_move(struct weston_surface *surface, int *dx, int *dy);
144 static void win_mgr_set_raise(struct uifw_win_surface *usurf, const int raise);
145 /* surface change from manager */
146 static int win_mgr_surface_change_mgr(struct weston_surface *surface, const int x,
147 const int y, const int width, const int height);
148 /* restack surface list */
149 static void win_mgr_restack_ivi_layer(struct uifw_win_surface *usurf);
150 /* create new layer */
151 static struct uifw_win_layer *win_mgr_create_layer(struct uifw_win_surface *usurf,
152 const uint32_t layer);
153 /* set surface layer */
154 static void win_mgr_set_layer(struct uifw_win_surface *usurf, const uint32_t layer);
155 /* change weston surface */
156 static void win_mgr_set_weston_surface(struct uifw_win_surface *usurf);
157 /* set active surface */
158 static void win_mgr_set_active(struct uifw_win_surface *usurf, const int target);
160 /* declare manager */
161 static void uifw_declare_manager(struct wl_client *client, struct wl_resource *resource,
163 /* create layer and set attribute */
164 static void uifw_create_layer(struct wl_client *client, struct wl_resource *resource,
165 uint32_t layer, int32_t attribute);
166 /* set window layer */
167 static void uifw_set_window_layer(struct wl_client *client,
168 struct wl_resource *resource,
169 uint32_t surfaceid, uint32_t layer);
170 /* set surface size and position */
171 static void uifw_set_positionsize(struct wl_client *client, struct wl_resource *resource,
172 uint32_t surfaceid, uint32_t node, int32_t x, int32_t y,
173 int32_t width, int32_t height, int32_t animation);
174 /* show/hide and raise/lower surface */
175 static void uifw_set_visible(struct wl_client *client, struct wl_resource *resource,
176 uint32_t surfaceid, int32_t visible, int32_t raise,
178 /* set surface animation */
179 static void uifw_set_animation(struct wl_client *client, struct wl_resource *resource,
180 uint32_t surfaceid, int32_t type,
181 const char *animation, int32_t time);
182 /* set active surface (form HomeScreen) */
183 static void uifw_set_active(struct wl_client *client, struct wl_resource *resource,
184 uint32_t surfaceid, int32_t active);
185 /* layer visibility control */
186 static void uifw_set_layer_visible(struct wl_client *client, struct wl_resource *resource,
187 uint32_t layer, int32_t visible);
188 /* get application surfaces */
189 static void uifw_get_surfaces(struct wl_client *client, struct wl_resource *resource,
191 /* map surface buffer to shared memory */
192 static void uifw_map_surface(struct wl_client *client, struct wl_resource *resource,
193 uint32_t surfaceid, const char *mapname, int32_t framerate);
194 /* unmap surface buffer */
195 static void uifw_unmap_surface(struct wl_client *client, struct wl_resource *resource,
198 static void bind_ico_win_mgr(struct wl_client *client,
199 void *data, uint32_t version, uint32_t id);
201 static void unbind_ico_win_mgr(struct wl_resource *resource);
202 /* send event to manager */
203 static int ico_win_mgr_send_to_mgr(const int event, struct uifw_win_surface *usurf,
204 const int param1, const int param2, const int param3,
205 const int param4, const int param5);
206 /* convert animation name to Id value */
207 static int ico_get_animation_name(const char *animation);
208 /* hook for animation */
209 static int (*win_mgr_hook_animation)(const int op, void *data) = NULL;
212 /* Multi Window Manager interface */
213 static const struct ico_window_mgr_interface ico_window_mgr_implementation = {
214 uifw_declare_manager,
216 uifw_set_window_layer,
217 uifw_set_positionsize,
221 uifw_set_layer_visible,
227 /* plugin common value(without ico_plugin_loader) */
228 static int _ico_ivi_debug_flag = 0; /* Debug flags */
229 static int _ico_ivi_debug_level = 3; /* Debug Level */
230 static char *_ico_ivi_animation_name = NULL; /* Default animation name */
231 static int _ico_ivi_animation_time = 500; /* Default animation time */
232 static int _ico_ivi_animation_fps = 15; /* Animation frame rate */
234 /* static management table */
235 static struct ico_win_mgr *_ico_win_mgr = NULL;
236 static int _ico_num_nodes = 0;
237 static struct uifw_node_table _ico_node_table[ICO_IVI_MAX_DISPLAY];
240 /*--------------------------------------------------------------------------*/
242 * @brief ico_ivi_debugflag: get debug flags
245 * @return debug flags
247 /*--------------------------------------------------------------------------*/
249 ico_ivi_debugflag(void)
251 return _ico_ivi_debug_flag;
254 /*--------------------------------------------------------------------------*/
256 * @brief ico_ivi_debuglevel: answer debug output level.
259 * @return debug output level
260 * @retval 0 No debug output
261 * @retval 1 Only error output
262 * @retval 2 Error and Warning output
263 * @retval 3 Error, Warning and information output
264 * @retval 4 All output with debug write
266 /*--------------------------------------------------------------------------*/
268 ico_ivi_debuglevel(void)
270 return _ico_ivi_debug_level;
273 /*--------------------------------------------------------------------------*/
275 * @brief ico_ivi_default_animation_name: get default animation name
278 * @return Default animation name
280 /*--------------------------------------------------------------------------*/
281 WL_EXPORT const char *
282 ico_ivi_default_animation_name(void)
284 return _ico_ivi_animation_name;
287 /*--------------------------------------------------------------------------*/
289 * @brief ico_ivi_default_animation_time: get default animation time
292 * @return Default animation time(miri sec)
294 /*--------------------------------------------------------------------------*/
296 ico_ivi_default_animation_time(void)
298 return _ico_ivi_animation_time;
301 /*--------------------------------------------------------------------------*/
303 * @brief ico_ivi_default_animation_fps: get default animation frame rate
306 * @return Default animation frame rate(frames/sec)
308 /*--------------------------------------------------------------------------*/
310 ico_ivi_default_animation_fps(void)
312 return _ico_ivi_animation_fps;
315 /*--------------------------------------------------------------------------*/
317 * @brief ico_ivi_get_mynode: Get my NodeId
320 * @return NodeId of my node
322 /*--------------------------------------------------------------------------*/
324 ico_ivi_get_mynode(void)
326 /* Reference Platform 0.90 only support 1 ECU */
330 /*--------------------------------------------------------------------------*/
332 * @brief find_uifw_win_surface_by_id: find UIFW surface by surface id
334 * @param[in] surfaceid UIFW surface id
335 * @return UIFW surface table address
336 * @retval !=NULL success(surface table address)
337 * @retval NULL error(surface id dose not exist)
339 /*--------------------------------------------------------------------------*/
340 static struct uifw_win_surface*
341 find_uifw_win_surface_by_id(uint32_t surfaceid)
343 struct uifw_win_surface* usurf;
345 usurf = _ico_win_mgr->idhash[MAKE_IDHASH(surfaceid)];
348 if (usurf->surfaceid == surfaceid) {
351 usurf = usurf->next_idhash;
353 uifw_trace("find_uifw_win_surface_by_id: NULL");
357 /*--------------------------------------------------------------------------*/
359 * @brief find_uifw_win_surface_by_ws: find UIFW surface by weston surface
361 * @param[in] wsurf Weston surface
362 * @return UIFW surface table address
363 * @retval !=NULL success(surface table address)
364 * @retval NULL error(surface dose not exist)
366 /*--------------------------------------------------------------------------*/
367 static struct uifw_win_surface*
368 find_uifw_win_surface_by_ws(struct weston_surface *wsurf)
370 struct uifw_win_surface* usurf;
372 usurf = _ico_win_mgr->wshash[MAKE_WSHASH(wsurf)];
375 if (usurf->surface == wsurf) {
378 usurf = usurf->next_wshash;
380 uifw_trace("find_uifw_win_surface_by_ws: NULL");
384 /*--------------------------------------------------------------------------*/
386 * @brief find_client_from_client: find UIFW client by wayland client
388 * @param[in] client Wayland client
389 * @return UIFW client table address
390 * @retval !=NULL success(client table address)
391 * @retval NULL error(client dose not exist)
393 /*--------------------------------------------------------------------------*/
394 static struct uifw_client*
395 find_client_from_client(struct wl_client* client)
397 struct uifw_client *uclient;
399 wl_list_for_each (uclient, &_ico_win_mgr->client_list, link) {
400 if (uclient->client == client) {
404 uifw_trace("find_client_from_client: client.%08x is NULL", (int)client);
408 /*--------------------------------------------------------------------------*/
410 * @brief ico_window_mgr_get_appid: find application id by wayland client
412 * @param[in] client Wayland client
413 * @return application id
414 * @retval !=NULL success(application id)
415 * @retval NULL error(client dose not exist)
417 /*--------------------------------------------------------------------------*/
419 ico_window_mgr_get_appid(struct wl_client* client)
421 struct uifw_client *uclient;
423 uclient = find_client_from_client(client);
428 return uclient->appid;
431 /*--------------------------------------------------------------------------*/
433 * @brief generate_id: generate uniq id for UIFW surface id
436 * @return uniq id for UIFW surface id
438 /*--------------------------------------------------------------------------*/
449 _ico_win_mgr->surfaceid_count ++;
451 /* serach free id from bitmap */
452 for (rep = 0; rep < (int)(_ico_win_mgr->surfaceid_max/16); rep++) {
453 if (_ico_win_mgr->surfaceid_count >= _ico_win_mgr->surfaceid_max) {
454 _ico_win_mgr->surfaceid_count = 0;
456 if (_ico_win_mgr->surfaceid_map[_ico_win_mgr->surfaceid_count/16] != 0xffff) {
457 /* find free id from bitmap */
458 map = 1 << (_ico_win_mgr->surfaceid_count % 16);
459 for (i = (_ico_win_mgr->surfaceid_count % 16); i < 16; i++) {
460 if ((_ico_win_mgr->surfaceid_map[_ico_win_mgr->surfaceid_count/16] & map)
462 _ico_win_mgr->surfaceid_map[_ico_win_mgr->surfaceid_count/16] |= map;
463 _ico_win_mgr->surfaceid_count
464 = (_ico_win_mgr->surfaceid_count/16)*16 + i;
466 surfaceId = (_ico_win_mgr->surfaceid_count + 1)
467 | _ico_win_mgr->surface_head;
468 uifw_trace("generate_id: SurfaceId=%08x", surfaceId);
474 _ico_win_mgr->surfaceid_count += 16;
477 /* no free id in bitmap, extend bitmap */
478 if ((_ico_win_mgr->surfaceid_max + ADD_SURFACE_IDS) > SURCAFE_ID_MASK) {
479 /* too many surfaces, system error */
480 uifw_trace("generate_id: SurffaceId Overflow(%d, Max=%d), Abort",
481 _ico_win_mgr->surfaceid_max + ADD_SURFACE_IDS, SURCAFE_ID_MASK);
482 fprintf(stderr, "generate_id: SurffaceId Overflow(%d, Max=%d), Abort\n",
483 _ico_win_mgr->surfaceid_max + ADD_SURFACE_IDS, SURCAFE_ID_MASK);
487 new_map = (uint16_t *) malloc((_ico_win_mgr->surfaceid_max + ADD_SURFACE_IDS) / 8);
488 memcpy(new_map, _ico_win_mgr->surfaceid_map, _ico_win_mgr->surfaceid_max/8);
489 memset(&new_map[_ico_win_mgr->surfaceid_max/16], 0, ADD_SURFACE_IDS/8);
490 _ico_win_mgr->surfaceid_count = _ico_win_mgr->surfaceid_max;
491 new_map[_ico_win_mgr->surfaceid_count/16] |= 1;
492 _ico_win_mgr->surfaceid_max += ADD_SURFACE_IDS;
493 free(_ico_win_mgr->surfaceid_map);
494 _ico_win_mgr->surfaceid_map = new_map;
496 uifw_trace("generate_id: Extent SurfaceId=%d(Max.%d)",
497 _ico_win_mgr->surfaceid_count+1, _ico_win_mgr->surfaceid_max);
498 surfaceId = (_ico_win_mgr->surfaceid_count + 1) | _ico_win_mgr->surface_head;
500 uifw_trace("generate_id: SurfaceId=%08x", surfaceId);
504 /*--------------------------------------------------------------------------*/
506 * @brief win_mgr_bind_client: desktop_shell from client
508 * @param[in] client Wayland client
509 * @param[in] shell shell(ico_ivi_shell) table address
512 /*--------------------------------------------------------------------------*/
514 win_mgr_bind_client(struct wl_client *client, void *shell)
516 struct uifw_client *uclient;
527 uifw_trace("win_mgr_bind_client: Enter(client=%08x, sjell=%08x)",
528 (int)client, (int)shell);
530 /* save shell table address */
532 _ico_win_mgr->shell = shell;
536 uclient = find_client_from_client(client);
538 /* client not exist, create client management table */
539 uifw_trace("win_mgr_bind_client: Create Client");
540 uclient = (struct uifw_client *)malloc(sizeof(struct uifw_client));
542 uifw_error("win_mgr_bind_client: Error, No Memory");
545 memset(uclient, 0, sizeof(struct uifw_client));
546 uclient->client = client;
552 wl_client_get_credentials(client, &pid, &uid, &gid);
553 uifw_trace("win_mgr_bind_client: client=%08x pid=%d uid=%d gid=%d",
554 (int)client, (int)pid, (int)uid, (int)gid);
556 uclient->pid = (int)pid;
557 /* get applicationId from AppCore(AUL) */
558 if (aul_app_get_appid_bypid(uclient->pid, uclient->appid, ICO_IVI_APPID_LENGTH)
560 uifw_trace("win_mgr_bind_client: client=%08x pid=%d appid=<%s>",
561 (int)client, uclient->pid, uclient->appid);
564 /* client dose not exist in AppCore, search Linux process table */
565 uifw_trace("win_mgr_bind_client: pid=%d dose not exist in AppCore(AUL)",
568 memset(uclient->appid, 0, ICO_IVI_APPID_LENGTH);
569 snprintf(procpath, sizeof(procpath)-1, "/proc/%d/cmdline", uclient->pid);
570 fd = open(procpath, O_RDONLY);
572 size = read(fd, procpath, sizeof(procpath));
573 for (; size > 0; size--) {
574 if (procpath[size-1]) break;
577 /* get program base name */
579 for (j = 0; j < size; j++) {
580 if (procpath[j] == 0) break;
581 if (procpath[j] == '/') i = j + 1;
584 for (; i < size; i++) {
585 uclient->appid[j] = procpath[i];
586 if ((uclient->appid[j] == 0) ||
587 (j >= (ICO_IVI_APPID_LENGTH-1))) break;
590 /* search application number in apprication start option */
591 if ((uclient->appid[j] == 0) && (j < (ICO_IVI_APPID_LENGTH-2))) {
592 for (; i < size; i++) {
593 if ((procpath[i] == 0) &&
594 (procpath[i+1] == '@')) {
595 strncpy(&uclient->appid[j], &procpath[i+1],
596 ICO_IVI_APPID_LENGTH - j - 2);
603 if (uclient->appid[0]) {
604 uifw_trace("win_mgr_bind_client: client=%08x pid=%d appid=<%s> from "
605 "Process table", (int)client, uclient->pid, uclient->appid);
606 /* weston internal client, not manage */
607 if (strcmp(uclient->appid, "weston") == 0) {
608 newclient = -newclient;
612 uifw_trace("win_mgr_bind_client: pid=%d dose not exist in Process table",
614 sprintf(uclient->appid, "?%d?", uclient->pid);
618 wl_list_insert(&_ico_win_mgr->client_list, &uclient->link);
620 else if (newclient < 0) {
622 uifw_trace("win_mgr_bind_client: client=%08x is internal, delete", (int)client);
626 uifw_trace("win_mgr_bind_client: client=%08x pid dose not exist", (int)client);
628 uifw_trace("win_mgr_bind_client: Leave");
631 /*--------------------------------------------------------------------------*/
633 * @brief win_mgr_unbind_client: unbind desktop_shell from client
635 * @param[in] client Wayland client
638 /*--------------------------------------------------------------------------*/
640 win_mgr_unbind_client(struct wl_client *client)
642 struct uifw_client *uclient;
644 uifw_trace("win_mgr_unbind_client: Enter(client=%08x)", (int)client);
646 uclient = find_client_from_client(client);
648 /* Client exist, Destory client management table */
649 wl_list_remove(&uclient->link);
652 uifw_trace("win_mgr_unbind_client: Leave");
655 /*--------------------------------------------------------------------------*/
657 * @brief ico_get_animation_name: convert animation name to Id value
659 * @param[in] animation animation name
660 * @return animation Id value
662 /*--------------------------------------------------------------------------*/
664 ico_get_animation_name(const char *animation)
666 int anima = ICO_WINDOW_MGR_ANIMATION_NONE;
668 if (strcasecmp(animation, "none") == 0) {
669 return ICO_WINDOW_MGR_ANIMATION_NONE;
672 if (win_mgr_hook_animation) {
673 anima = (*win_mgr_hook_animation)(ICO_WINDOW_MGR_ANIMATION_NAME, (void *)animation);
676 anima = ICO_WINDOW_MGR_ANIMATION_NONE;
681 /*--------------------------------------------------------------------------*/
683 * @brief win_mgr_register_surface: create UIFW surface
685 * @param[in] client Wayland client
686 * @param[in] resource client resource
687 * @param[in] surface Weston surface
688 * @param[in] shsurf shell surface
691 /*--------------------------------------------------------------------------*/
693 win_mgr_register_surface(struct wl_client *client, struct wl_resource *resource,
694 struct weston_surface *surface, struct shell_surface *shsurf)
696 struct uifw_win_surface *usurf;
697 struct uifw_win_surface *phash;
698 struct uifw_win_surface *bhash;
701 uifw_trace("win_mgr_register_surface: Enter(surf=%08x,client=%08x,res=%08x)",
702 (int)surface, (int)client, (int)resource);
704 /* check new surface */
705 if (find_uifw_win_surface_by_ws(surface)) {
706 /* surface exist, NOP */
707 uifw_trace("win_mgr_register_surface: Leave(Already Exist)");
711 /* set default color and shader */
712 weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1);
714 /* create UIFW surface management table */
715 usurf = malloc(sizeof(struct uifw_win_surface));
717 uifw_error("win_mgr_register_surface: No Memory");
721 memset(usurf, 0, sizeof(struct uifw_win_surface));
723 usurf->surfaceid = generate_id();
724 usurf->surface = surface;
725 usurf->shsurf = shsurf;
726 usurf->node_tbl = &_ico_node_table[0]; /* set default node table (display no=0) */
727 wl_list_init(&usurf->ivi_layer);
728 wl_list_init(&usurf->animation.animation.link);
729 usurf->animation.hide_name = ico_get_animation_name(ico_ivi_default_animation_name());
730 usurf->animation.hide_time = ico_ivi_default_animation_time();;
731 usurf->animation.show_name = usurf->animation.hide_name;
732 usurf->animation.show_time = usurf->animation.hide_time;
733 usurf->animation.move_name = usurf->animation.hide_name;
734 usurf->animation.move_time = usurf->animation.hide_time;
735 usurf->animation.resize_name = usurf->animation.hide_name;
736 usurf->animation.resize_time = usurf->animation.hide_time;
738 if ((_ico_win_mgr->num_manager <= 0) ||
739 (ico_ivi_debugflag() & ICO_IVI_DEBUG_SHOW_SURFACE)) {
740 uifw_trace("win_mgr_register_surface: No Manager, Force visible");
744 uifw_trace("win_mgr_register_surface: Manager exist, Not visible");
749 usurf->uclient = find_client_from_client(client);
750 if (! usurf->uclient) {
751 /* client not exist, create client management table */
752 uifw_trace("win_mgr_register_surface: Create Client");
753 win_mgr_bind_client(client, NULL);
754 usurf->uclient = find_client_from_client(client);
755 if (! usurf->uclient) {
756 uifw_error("win_mgr_register_surface: No Memory");
761 /* make surface id hash table */
762 hash = MAKE_IDHASH(usurf->surfaceid);
763 phash = _ico_win_mgr->idhash[hash];
767 phash = phash->next_idhash;
770 bhash->next_idhash = usurf;
773 _ico_win_mgr->idhash[hash] = usurf;
776 /* make weston surface hash table */
777 hash = MAKE_WSHASH(usurf->surface);
778 phash = _ico_win_mgr->wshash[hash];
782 phash = phash->next_wshash;
785 bhash->next_wshash = usurf;
788 _ico_win_mgr->wshash[hash] = usurf;
790 /* set default layer id */
791 win_mgr_set_layer(usurf, ICO_IVI_DEFAULT_LAYER);
793 uifw_trace("win_mgr_register_surface: Leave(surfaceId=%08x)", usurf->surfaceid);
796 /*--------------------------------------------------------------------------*/
798 * @brief win_mgr_map_surface: map surface
800 * @param[in] surface Weston surface
801 * @param[in] width surface width
802 * @param[in] height surface height
803 * @param[in] sx X coordinate on screen
804 * @param[in] sy Y coordinate on screen
807 /*--------------------------------------------------------------------------*/
809 win_mgr_map_surface(struct weston_surface *surface, int32_t *width, int32_t *height,
810 int32_t *sx, int32_t *sy)
812 struct uifw_win_surface *usurf;
814 uifw_trace("win_mgr_map_surface: Enter(%08x, x/y=%d/%d w/h=%d/%d)",
815 (int)surface, *sx, *sy, *width, *height);
817 usurf = find_uifw_win_surface_by_ws(surface);
820 uifw_trace("win_mgr_map_surface: surf=%08x w/h=%d/%d vis=%d",
821 usurf->surfaceid, usurf->width, usurf->height, usurf->visible);
822 if ((usurf->width > 0) && (usurf->height > 0)) {
823 uifw_trace("win_mgr_map_surface: HomeScreen registed, PositionSize"
824 "(surf=%08x x/y=%d/%d w/h=%d/%d vis=%d",
825 usurf->surfaceid, usurf->x, usurf->y, usurf->width, usurf->height,
827 *width = usurf->width;
828 *height = usurf->height;
829 weston_surface_configure(surface, usurf->node_tbl->disp_x + usurf->x,
830 usurf->node_tbl->disp_y + usurf->y,
831 usurf->width, usurf->height);
834 uifw_trace("win_mgr_map_surface: HomeScreen not regist Surface, "
835 "Change PositionSize(surf=%08x x/y=%d/%d w/h=%d/%d)",
836 usurf->surfaceid, *sx, *sy, *width, *height);
837 usurf->width = *width;
838 usurf->height = *height;
841 if (usurf->x < 0) usurf->x = 0;
842 if (usurf->y < 0) usurf->y = 0;
844 if (_ico_win_mgr->num_manager > 0) {
845 /* HomeScreen exist, coodinate set by HomeScreen */
846 if (usurf->visible) {
847 weston_surface_configure(surface, usurf->node_tbl->disp_x + usurf->x,
848 usurf->node_tbl->disp_y + usurf->y,
849 usurf->width, usurf->height);
852 weston_surface_configure(surface, ICO_IVI_MAX_COORDINATE+1,
853 ICO_IVI_MAX_COORDINATE+1,
854 usurf->width, usurf->height);
856 uifw_trace("win_mgr_map_surface: Change size/position x/y=%d/%d w/h=%d/%d",
857 (int)surface->geometry.x, (int)surface->geometry.y,
858 surface->geometry.width, surface->geometry.height);
860 if ((_ico_win_mgr->num_manager <= 0) ||
861 (ico_ivi_debugflag() & ICO_IVI_DEBUG_SHOW_SURFACE)) {
862 uifw_trace("win_mgr_map_surface: Np HomeScreen, chaneg to Visible");
863 ico_window_mgr_set_visible(usurf, 1);
867 if (usurf->visible) {
868 win_mgr_restack_ivi_layer(NULL);
870 uifw_trace("win_mgr_map_surface: Leave");
873 uifw_trace("win_mgr_map_surface: Leave(No UIFW Surface)");
877 /*--------------------------------------------------------------------------*/
879 * @brief win_mgr_restack_ivi_layer: restack surface list
881 * @param[in] usurf UIFW surface
884 /*--------------------------------------------------------------------------*/
886 win_mgr_restack_ivi_layer(struct uifw_win_surface *usurf)
888 struct uifw_win_surface *es;
889 struct uifw_win_layer *el;
890 int32_t buf_width, buf_height;
892 struct weston_layer *wlayer;
895 uifw_trace("win_mgr_restack_ivi_layer: Enter(surf=%08x)", (int)usurf);
897 /* make compositor surface list */
898 wlayer = ico_ivi_shell_current_layer();
900 wl_list_init(&wlayer->surface_list);
901 wl_list_for_each (el, &_ico_win_mgr->ivi_layer_list, link) {
902 wl_list_for_each (es, &el->surface_list, ivi_layer) {
903 if ((es->mapped != 0) && (es->surface != NULL)) {
904 if ((el->visible == FALSE) || (es->visible == FALSE)) {
905 new_x = (float)(ICO_IVI_MAX_COORDINATE+1);
906 new_y = (float)(ICO_IVI_MAX_COORDINATE+1);
908 else if (es->surface->buffer_ref.buffer) {
909 buf_width = weston_surface_buffer_width(es->surface);
910 buf_height = weston_surface_buffer_height(es->surface);
911 if (es->width > buf_width) {
912 new_x = (float)(es->x +
913 (es->width - es->surface->geometry.width)/2);
916 new_x = (float)es->x;
918 if (es->height > buf_height) {
919 new_y = (float) (es->y +
920 (es->height - es->surface->geometry.height)/2);
923 new_y = (float)es->y;
925 new_x += es->node_tbl->disp_x;
926 new_y += es->node_tbl->disp_y;
930 new_x = (float)(ICO_IVI_MAX_COORDINATE+1);
931 new_y = (float)(ICO_IVI_MAX_COORDINATE+1);
933 wl_list_insert(wlayer->surface_list.prev, &es->surface->layer_link);
934 if ((new_x != es->surface->geometry.x) ||
935 (new_y != es->surface->geometry.y)) {
936 weston_surface_damage_below(es->surface);
937 weston_surface_set_position(es->surface, (float)new_x, (float)new_y);
938 weston_surface_damage(es->surface);
940 uifw_trace("win_mgr_restack_ivi_layer: %08x x/y=%d/%d w/h=%d/%d",
942 (int)es->surface->geometry.x, (int)es->surface->geometry.y,
943 es->surface->geometry.width, es->surface->geometry.height);
948 /* damage(redraw) target surfacem if target exist */
950 weston_surface_damage(usurf->surface);
953 /* composit and draw screen(plane) */
954 weston_compositor_schedule_repaint(_ico_win_mgr->compositor);
956 if ((_ico_win_mgr->shell_init == 0) && (num_visible > 0) &&
957 (_ico_win_mgr->shell != NULL) && (_ico_win_mgr->num_manager > 0)) {
958 /* start shell fade */
959 _ico_win_mgr->shell_init = 1;
960 ico_ivi_shell_startup(_ico_win_mgr->shell);
962 uifw_trace("win_mgr_restack_ivi_layer: Leave");
965 /*--------------------------------------------------------------------------*/
967 * @brief win_mgr_create_layer: create new layer
969 * @param[in] usurf UIFW surface, (if need)
970 * @param[in] layer layer id
972 * @retval != NULL success(layer management table)
973 * @retval == NULL error(No Memory)
975 /*--------------------------------------------------------------------------*/
976 static struct uifw_win_layer *
977 win_mgr_create_layer(struct uifw_win_surface *usurf, const uint32_t layer)
979 struct uifw_win_layer *el;
980 struct uifw_win_layer *new_el;
982 new_el = malloc(sizeof(struct uifw_win_layer));
984 uifw_trace("win_mgr_create_layer: Leave(No Memory)");
988 memset(new_el, 0, sizeof(struct uifw_win_layer));
989 new_el->layer = layer;
990 new_el->attribute = ICO_WINDOW_MGR_LAYER_ATTR_NORMAL;
991 new_el->visible = TRUE;
992 wl_list_init(&new_el->surface_list);
993 wl_list_init(&new_el->link);
995 wl_list_for_each (el, &_ico_win_mgr->ivi_layer_list, link) {
996 if (layer >= el->layer) break;
998 if (&el->link == &_ico_win_mgr->ivi_layer_list) {
999 wl_list_insert(_ico_win_mgr->ivi_layer_list.prev, &new_el->link);
1002 wl_list_insert(el->link.prev, &new_el->link);
1006 wl_list_remove(&usurf->ivi_layer);
1007 wl_list_insert(&new_el->surface_list, &usurf->ivi_layer);
1008 usurf->win_layer = new_el;
1013 /*--------------------------------------------------------------------------*/
1015 * @brief win_mgr_set_layer: set(or change) surface layer
1017 * @param[in] usurf UIFW surface
1018 * @param[in] layer layer id
1021 /*--------------------------------------------------------------------------*/
1023 win_mgr_set_layer(struct uifw_win_surface *usurf, const uint32_t layer)
1025 struct uifw_win_layer *el;
1026 struct uifw_win_layer *new_el;
1028 uifw_trace("win_mgr_set_layer: Enter([%08x],%08x,%x)",
1029 (int)usurf, (int)usurf->surface, layer);
1031 /* check if same layer */
1032 if ((usurf->win_layer != NULL) && (usurf->win_layer->layer == layer)) {
1033 uifw_trace("win_mgr_set_layer: Leave(Same Layer)");
1037 /* search existing layer */
1038 wl_list_for_each (el, &_ico_win_mgr->ivi_layer_list, link) {
1039 if (el->layer == layer) break;
1042 if (&el->link == &_ico_win_mgr->ivi_layer_list) {
1043 /* layer not exist, create new layer */
1044 uifw_trace("win_mgr_set_layer: New Layer %d", layer);
1045 new_el = win_mgr_create_layer(usurf, layer);
1047 uifw_trace("win_mgr_set_layer: Leave(No Memory)");
1052 uifw_trace("win_mgr_set_layer: Add surface to Layer %d", layer);
1053 wl_list_remove(&usurf->ivi_layer);
1054 wl_list_insert(&el->surface_list, &usurf->ivi_layer);
1055 usurf->win_layer = el;
1058 /* rebild compositor surface list */
1059 if (usurf->visible) {
1060 win_mgr_restack_ivi_layer(usurf);
1062 uifw_trace("win_mgr_set_layer: Leave");
1065 /*--------------------------------------------------------------------------*/
1067 * @brief win_mgr_set_active: set(or change) active surface
1069 * @param[in] usurf UIFW surface
1070 * @param[in] target target device
1073 /*--------------------------------------------------------------------------*/
1075 win_mgr_set_active(struct uifw_win_surface *usurf, const int target)
1077 struct weston_seat *seat;
1078 struct weston_surface *surface;
1079 int object = target;
1082 uifw_trace("win_mgr_set_active: Enter(%08x,%x)", (int)usurf, target);
1084 if ((usurf) && (usurf->shsurf) && (usurf->surface)) {
1085 surface = usurf->surface;
1086 if ((target & (ICO_WINDOW_MGR_ACTIVE_POINTER|ICO_WINDOW_MGR_ACTIVE_KEYBOARD)) == 0) {
1088 if (_ico_win_mgr->active_pointer_usurf == usurf) {
1089 object |= ICO_WINDOW_MGR_ACTIVE_POINTER;
1091 if (_ico_win_mgr->active_keyboard_usurf == usurf) {
1092 object |= ICO_WINDOW_MGR_ACTIVE_KEYBOARD;
1096 if (object & ICO_WINDOW_MGR_ACTIVE_POINTER) {
1097 _ico_win_mgr->active_pointer_usurf = usurf;
1099 if (object & ICO_WINDOW_MGR_ACTIVE_KEYBOARD) {
1100 _ico_win_mgr->active_keyboard_usurf = usurf;
1107 object = ICO_WINDOW_MGR_ACTIVE_POINTER | ICO_WINDOW_MGR_ACTIVE_KEYBOARD;
1109 if (object & ICO_WINDOW_MGR_ACTIVE_POINTER) {
1110 _ico_win_mgr->active_pointer_usurf = NULL;
1112 if (object & ICO_WINDOW_MGR_ACTIVE_KEYBOARD) {
1113 _ico_win_mgr->active_keyboard_usurf = NULL;
1117 wl_list_for_each(seat, &_ico_win_mgr->compositor->seat_list, link) {
1118 if ((object & ICO_WINDOW_MGR_ACTIVE_POINTER) && (seat->pointer)) {
1120 if (seat->pointer->focus != surface) {
1121 uifw_trace("win_mgr_set_active: pointer change surface(%08x=>%08x)",
1122 (int)seat->pointer->focus, (int)surface);
1123 weston_surface_from_global_fixed(surface,
1127 weston_pointer_set_focus(seat->pointer, surface, sx, sy);
1130 uifw_trace("win_mgr_set_active: pointer nochange surface(%08x)",
1135 uifw_trace("win_mgr_set_active: pointer reset surface(%08x)",
1136 (int)seat->pointer->focus);
1137 weston_pointer_set_focus(seat->pointer, NULL,
1138 wl_fixed_from_int(0), wl_fixed_from_int(0));
1141 if ((object & ICO_WINDOW_MGR_ACTIVE_KEYBOARD) && (seat->keyboard)) {
1143 if (seat->keyboard->focus != surface) {
1144 weston_keyboard_set_focus(seat->keyboard, surface);
1145 uifw_trace("win_mgr_set_active: keyboard change surface(%08x=>%08x)",
1146 (int)seat->keyboard->focus, (int)surface);
1149 uifw_trace("win_mgr_set_active: keyboard nochange surface(%08x)",
1154 uifw_trace("win_mgr_set_active: keyboard reset surface(%08x)",
1155 (int)seat->keyboard);
1156 weston_keyboard_set_focus(seat->keyboard, NULL);
1160 uifw_trace("win_mgr_set_active: Leave(%08x)", (int)usurf);
1163 /*--------------------------------------------------------------------------*/
1165 * @brief uifw_declare_manager: declare manager(ex.SystemController) client
1167 * @param[in] client Weyland client
1168 * @param[in] resource resource of request
1169 * @param[in] manager manager(1=manager, 0=not manager)
1172 /*--------------------------------------------------------------------------*/
1174 uifw_declare_manager(struct wl_client *client, struct wl_resource *resource, int manager)
1176 struct uifw_manager* mgr;
1177 struct uifw_win_surface *usurf;
1178 struct uifw_client *uclient;
1179 struct uifw_win_layer *el;
1181 uifw_trace("uifw_declare_manager: Enter client=%08x manager=%d",
1182 (int)client, manager);
1184 uclient = find_client_from_client(client);
1186 uclient->manager = manager;
1189 /* client set to manager */
1190 _ico_win_mgr->num_manager = 0;
1191 wl_list_for_each (mgr, &_ico_win_mgr->manager_list, link) {
1192 if (mgr->resource == resource) {
1193 if (mgr->manager != manager) {
1194 uifw_trace("uifw_declare_manager: Event Client.%08x Callback %d=>%d",
1195 (int)client, mgr->manager, manager);
1196 mgr->manager = manager;
1199 wl_list_for_each (el, &_ico_win_mgr->ivi_layer_list, link) {
1200 wl_list_for_each (usurf, &el->surface_list, ivi_layer) {
1201 /* send window create event to manager */
1202 if (usurf->created != 0) {
1203 uifw_trace("uifw_declare_manager: Send manager(%08x) "
1204 "WINDOW_CREATED(surf=%08x,pid=%d,appid=%s)",
1205 (int)resource, usurf->surfaceid,
1206 usurf->uclient->pid, usurf->uclient->appid);
1207 ico_window_mgr_send_window_created(resource,
1210 usurf->uclient->pid,
1211 usurf->uclient->appid);
1219 _ico_win_mgr->num_manager++;
1222 uifw_trace("uifw_declare_manager: Leave(managers=%d)", _ico_win_mgr->num_manager);
1225 /*--------------------------------------------------------------------------*/
1227 * @brief uifw_create_layer: create layer Id and set attribute
1229 * @param[in] client Weyland client
1230 * @param[in] resource resource of request
1231 * @param[in] layer layer id
1232 * @param[in] attribute layer attribute
1235 /*--------------------------------------------------------------------------*/
1237 uifw_create_layer(struct wl_client *client, struct wl_resource *resource,
1238 uint32_t layer, int32_t attribute)
1240 uifw_trace("uifw_create_layer: Enter(layer=%x,attr=%x)", layer, attribute);
1241 uifw_trace("uifw_create_layer: Leave");
1244 /*--------------------------------------------------------------------------*/
1246 * @brief uifw_set_window_layer: set layer id to surface
1248 * @param[in] client Weyland client
1249 * @param[in] resource resource of request
1250 * @param[in] surfaceid UIFW surface id
1251 * @param[in] layer layer id
1254 /*--------------------------------------------------------------------------*/
1256 uifw_set_window_layer(struct wl_client *client, struct wl_resource *resource,
1257 uint32_t surfaceid, uint32_t layer)
1259 uifw_trace("uifw_set_window_layer: Enter res=%08x surfaceid=%08x layer=%d",
1260 (int)resource, surfaceid, layer);
1262 struct uifw_win_surface *usurf = find_uifw_win_surface_by_id(surfaceid);
1265 uifw_trace("uifw_set_window_layer: Leave(No Surface(id=%08x))", surfaceid);
1268 if (usurf->win_layer->layer != layer) {
1269 win_mgr_set_layer(usurf, layer);
1271 win_mgr_change_surface(usurf->surface, 1, 1);
1273 uifw_trace("uifw_set_window_layer: Leave");
1276 /*--------------------------------------------------------------------------*/
1278 * @brief win_mgr_set_weston_surface: set weston surface from UIFW surface
1280 * @param[in] usurf UIFW surface
1283 /*--------------------------------------------------------------------------*/
1285 win_mgr_set_weston_surface(struct uifw_win_surface *usurf)
1287 struct weston_surface *es = usurf->surface;
1288 int buf_width, buf_height;
1295 uifw_trace("win_mgr_set_weston_surface: usurf(%08x) has no surface", (int)usurf);
1299 if (es->buffer_ref.buffer != NULL) {
1300 buf_width = weston_surface_buffer_width(es);
1301 buf_height = weston_surface_buffer_height(es);
1302 width = usurf->width;
1303 height = usurf->height;
1306 if ((width <= 0) || (height <= 0)) {
1308 usurf->width = buf_width;
1309 height = buf_height;
1310 usurf->height = buf_height;
1312 if (usurf->width > buf_width) {
1314 x += (usurf->width - buf_width)/2;
1316 if (usurf->height > buf_height) {
1317 height = buf_height;
1318 y += (usurf->height - buf_height)/2;
1320 if (usurf->visible) {
1321 x += usurf->node_tbl->disp_x;
1322 y += usurf->node_tbl->disp_y;
1325 x = ICO_IVI_MAX_COORDINATE+1;
1326 y = ICO_IVI_MAX_COORDINATE+1;
1328 if ((es->geometry.x != x) || (es->geometry.y != y) ||
1329 (es->geometry.width != width) || (es->geometry.height != height)) {
1330 weston_surface_damage_below(es);
1331 weston_surface_configure(es, x, y, width, height);
1333 weston_surface_damage(es);
1334 weston_compositor_schedule_repaint(_ico_win_mgr->compositor);
1338 /*--------------------------------------------------------------------------*/
1340 * @brief uifw_set_positionsize: set surface position and size
1342 * @param[in] client Weyland client
1343 * @param[in] resource resource of request
1344 * @param[in] surfaceid UIFW surface id
1345 * @param[in] node surface node id
1346 * @param[in] x X coordinate on screen(if bigger than 16383, no change)
1347 * @param[in] y Y coordinate on screen(if bigger than 16383, no change)
1348 * @param[in] width surface width(if bigger than 16383, no change)
1349 * @param[in] height surface height(if bigger than 16383, no change)
1350 * @param[in] animation with/without animation
1353 /*--------------------------------------------------------------------------*/
1355 uifw_set_positionsize(struct wl_client *client, struct wl_resource *resource,
1356 uint32_t surfaceid, uint32_t node, int32_t x, int32_t y,
1357 int32_t width, int32_t height, int32_t animation)
1359 struct uifw_client *uclient;
1360 struct weston_surface *es;
1361 int cx, cy, cwidth, cheight;
1363 uifw_trace("uifw_set_positionsize: Enter surf=%08x node=%x x/y/w/h=%d/%d/%d/%d anim=%d",
1364 surfaceid, node, x, y, width, height, animation);
1366 if (((int)node) >= _ico_num_nodes) {
1367 uifw_trace("uifw_set_positionsize: node=%d dose not exist(max=%d)",
1368 node, _ico_num_nodes);
1371 struct uifw_win_surface* usurf = find_uifw_win_surface_by_id(surfaceid);
1373 if (usurf && (usurf->surface)) {
1374 /* weston surface exist */
1375 usurf->node_tbl = &_ico_node_table[node];
1376 es = usurf->surface;
1378 /* if x,y,width,height bigger then ICO_IVI_MAX_COORDINATE, no change */
1381 cwidth = usurf->width;
1382 cheight = usurf->height;
1383 if (x > ICO_IVI_MAX_COORDINATE) x = cx;
1384 if (y > ICO_IVI_MAX_COORDINATE) y = cy;
1385 if (width > ICO_IVI_MAX_COORDINATE) width = cwidth;
1386 if (height > ICO_IVI_MAX_COORDINATE) height = cheight;
1388 /* check animation */
1389 if ((usurf->animation.restrain_configure != 0) &&
1390 (x == usurf->x) && (y == usurf->y) &&
1391 (width == usurf->width) && (height == usurf->height)) {
1392 uifw_trace("uifw_set_positionsize: Leave(same position size at animation)");
1396 uclient = find_client_from_client(client);
1398 if (! uclient->manager) uclient = NULL;
1401 if ((usurf->width > 0) && (usurf->height > 0)) {
1402 win_mgr_surface_change_mgr(es, x, y, width, height);
1403 uifw_trace("uifw_set_positionsize: Leave(Request from App)");
1407 uifw_trace("uifw_set_positionsize: Initial Position/Size visible=%d",
1409 /* Initiale position is (0,0) */
1410 weston_surface_set_position(es, (float)(usurf->node_tbl->disp_x),
1411 (float)(usurf->node_tbl->disp_y));
1414 uifw_trace("uifw_set_positionsize: Old geometry x/y=%d/%d,w/h=%d/%d",
1415 (int)es->geometry.x, (int)es->geometry.y,
1416 (int)es->geometry.width, (int)es->geometry.height);
1420 usurf->width = width;
1421 usurf->height = height;
1422 if (_ico_win_mgr->num_manager <= 0) {
1423 /* no manager(HomeScreen), set geometory */
1424 weston_surface_set_position(es, (float)(usurf->node_tbl->disp_x + x),
1425 (float)(usurf->node_tbl->disp_y + y));
1427 if ((es->output) && (es->buffer_ref.buffer) &&
1428 (es->geometry.width > 0) && (es->geometry.height > 0)) {
1429 uifw_trace("uifw_set_positionsize: Fixed Geometry, Change(Vis=%d)",
1431 if (usurf->visible) {
1432 win_mgr_set_weston_surface(usurf);
1435 win_mgr_change_surface(es, 0, 1);
1437 uifw_trace("uifw_set_positionsize: Leave(OK,output=%08x)", (int)es->output);
1440 uifw_trace("uifw_set_positionsize: Leave(surf=%08x NOT Found)", surfaceid);
1444 /*--------------------------------------------------------------------------*/
1446 * @brief uifw_set_visible: surface visible/raise control
1448 * @param[in] client Weyland client
1449 * @param[in] resource resource of request
1450 * @param[in] surfaceid UIFW surface id
1451 * @param[in] visible visible(1=show/0=hide/other=no change)
1452 * @param[in] raise raise(1=raise/0=lower/other=no change)
1453 * @param[in] animation with/without animation
1456 /*--------------------------------------------------------------------------*/
1458 uifw_set_visible(struct wl_client *client, struct wl_resource *resource,
1459 uint32_t surfaceid, int32_t visible, int32_t raise, int32_t animation)
1461 struct uifw_win_surface* usurf;
1462 struct uifw_client *uclient;
1466 uifw_trace("uifw_set_visible: Enter(surf=%08x,%d,%d,%d)",
1467 surfaceid, visible, raise, animation);
1469 uclient = find_client_from_client(client);
1471 if (! uclient->manager) {
1472 uifw_trace("uifw_set_visible: Request from App(%s), not Manager",
1477 uifw_trace("uifw_set_visible: Request from Manager(%s)", uclient->appid);
1481 uifw_trace("uifw_set_visible: Request from Unknown App, not Manager");
1484 usurf = find_uifw_win_surface_by_id(surfaceid);
1486 if ((! usurf) || (! usurf->surface)) {
1487 uifw_trace("uifw_set_visible: Leave(Surface Not Exist)");
1492 if (visible == ICO_WINDOW_MGR_VISIBLE_SHOW) {
1494 if (! usurf->visible) {
1496 uifw_trace("uifw_set_visible: Change to Visible");
1498 ico_ivi_shell_set_toplevel(usurf->shsurf);
1500 /* Weston surface configure */
1501 uifw_trace("uifw_set_visible: Visible to Weston WSurf=%08x,%d.%d/%d/%d/%d",
1502 (int)usurf->surface, usurf->node_tbl->node, usurf->x, usurf->y,
1503 usurf->width, usurf->height);
1504 ico_ivi_shell_set_surface_type(usurf->shsurf);
1505 win_mgr_set_weston_surface(usurf);
1507 restack = 1; /* need damage */
1509 if ((animation == ICO_WINDOW_MGR_ANIMATION_ANIMATION) &&
1510 (usurf->animation.show_name != ICO_WINDOW_MGR_ANIMATION_NONE) &&
1511 (win_mgr_hook_animation != NULL)) {
1512 retanim = (*win_mgr_hook_animation)(ICO_WINDOW_MGR_ANIMATION_OPSHOW,
1514 uifw_trace("uifw_set_visible: ret call animation = %d", retanim);
1517 else if ((raise != ICO_WINDOW_MGR_RAISE_LOWER) &&
1518 (raise != ICO_WINDOW_MGR_RAISE_RAISE)) {
1519 uifw_trace("uifw_set_visible: Leave(No Change)");
1523 else if (visible == ICO_WINDOW_MGR_VISIBLE_HIDE) {
1525 if (usurf->visible) {
1527 /* Weston surface configure */
1528 weston_surface_damage_below(usurf->surface);
1529 win_mgr_set_weston_surface(usurf);
1531 retanim = ICO_WINDOW_MGR_ANIMATION_RET_ANIMA;
1532 if ((animation == ICO_WINDOW_MGR_ANIMATION_ANIMATION) &&
1533 (usurf->animation.hide_name != ICO_WINDOW_MGR_ANIMATION_NONE) &&
1534 (win_mgr_hook_animation != NULL)) {
1535 retanim = (*win_mgr_hook_animation)(ICO_WINDOW_MGR_ANIMATION_OPHIDE,
1538 if (retanim != ICO_WINDOW_MGR_ANIMATION_RET_ANIMASHOW) {
1540 uifw_trace("uifw_set_visible: Change to UnVisible");
1541 /* change visible to unvisible, restack surface list */
1543 /* Weston surface configure */
1544 win_mgr_set_weston_surface(usurf);
1547 uifw_trace("uifw_set_visible: UnVisible but animation");
1550 else if ((raise != ICO_WINDOW_MGR_RAISE_LOWER) &&
1551 (raise != ICO_WINDOW_MGR_RAISE_RAISE)) {
1552 uifw_trace("uifw_set_visible: Leave(No Change)");
1556 else if ((raise != ICO_WINDOW_MGR_RAISE_LOWER) &&
1557 (raise != ICO_WINDOW_MGR_RAISE_RAISE)) {
1558 uifw_trace("uifw_set_visible: Leave(No Change)");
1563 if ((raise == ICO_WINDOW_MGR_RAISE_LOWER) || (raise == ICO_WINDOW_MGR_RAISE_RAISE)) {
1564 win_mgr_set_raise(usurf, raise);
1565 if (usurf->visible == 0) {
1570 raise = ICO_WINDOW_MGR_V_NOCHANGE;
1573 if ((restack == 1) && (usurf->surface) &&
1574 (usurf->surface->buffer_ref.buffer) && (usurf->surface->output)) {
1575 weston_surface_damage(usurf->surface);
1577 else if(restack & 2) {
1578 win_mgr_restack_ivi_layer(usurf);
1581 /* send event(VISIBLE) to manager */
1583 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_VISIBLE,
1585 (visible == ICO_WINDOW_MGR_VISIBLE_SHOW) ? 1 :
1586 ((visible == ICO_WINDOW_MGR_VISIBLE_HIDE) ? 0 :
1587 ICO_WINDOW_MGR_V_NOCHANGE),
1588 raise, uclient ? 0 : 1, 0,0);
1590 uifw_trace("uifw_set_visible: Leave(OK)");
1593 /*--------------------------------------------------------------------------*/
1595 * @brief uifw_set_animation: set animation of surface visible/unvisible
1597 * @param[in] client Weyland client
1598 * @param[in] resource resource of request
1599 * @param[in] surfaceid UIFW surface id
1600 * @param[in] type how to change surface
1601 * @param[in] anmation animation name
1602 * @param[in] time animation time(ms), if 0, default time
1605 /*--------------------------------------------------------------------------*/
1607 uifw_set_animation(struct wl_client *client, struct wl_resource *resource,
1608 uint32_t surfaceid, int32_t type, const char *animation, int32_t time)
1611 struct uifw_win_surface* usurf = find_uifw_win_surface_by_id(surfaceid);
1613 uifw_trace("uifw_set_transition: Enter(surf=%08x,type=%x,anim=%s,time=%d)",
1614 surfaceid, type, animation, time);
1617 if ((*animation != 0) && (*animation != ' ')) {
1618 animaid = ico_get_animation_name(animation);
1619 uifw_trace("uifw_set_animation: Leave(OK) type=%d", animaid);
1620 if (type & ICO_WINDOW_MGR_ANIMATION_TYPE_HIDE) {
1621 if (usurf->animation.type == ICO_WINDOW_MGR_ANIMATION_OPHIDE) {
1622 usurf->animation.next_name = animaid;
1625 usurf->animation.hide_name = animaid;
1628 if (type & ICO_WINDOW_MGR_ANIMATION_TYPE_SHOW) {
1629 if (usurf->animation.type == ICO_WINDOW_MGR_ANIMATION_OPSHOW) {
1630 usurf->animation.next_name = animaid;
1633 usurf->animation.show_name = animaid;
1636 if (type & ICO_WINDOW_MGR_ANIMATION_TYPE_MOVE) {
1637 if (usurf->animation.type == ICO_WINDOW_MGR_ANIMATION_OPMOVE) {
1638 usurf->animation.next_name = animaid;
1641 usurf->animation.move_name = animaid;
1644 if (type & ICO_WINDOW_MGR_ANIMATION_TYPE_RESIZE) {
1645 if (usurf->animation.type == ICO_WINDOW_MGR_ANIMATION_OPRESIZE) {
1646 usurf->animation.next_name = animaid;
1649 usurf->animation.resize_name = animaid;
1653 if ((time > 0) && (time != ICO_WINDOW_MGR_V_NOCHANGE)) {
1654 if (type & ICO_WINDOW_MGR_ANIMATION_TYPE_HIDE) {
1655 usurf->animation.hide_time = time;
1657 if (type & ICO_WINDOW_MGR_ANIMATION_TYPE_SHOW) {
1658 usurf->animation.show_time = time;
1660 if (type & ICO_WINDOW_MGR_ANIMATION_TYPE_MOVE) {
1661 usurf->animation.move_time = time;
1663 if (type & ICO_WINDOW_MGR_ANIMATION_TYPE_RESIZE) {
1664 usurf->animation.resize_time = time;
1669 uifw_trace("uifw_set_animation: Leave(Surface(%08x) Not exist)", surfaceid);
1673 /*--------------------------------------------------------------------------*/
1675 * @brief uifw_set_active: set active surface
1677 * @param[in] client Weyland client
1678 * @param[in] resource resource of request
1679 * @param[in] surfaceid UIFW surface id
1680 * @param[in] active target device
1683 /*--------------------------------------------------------------------------*/
1685 uifw_set_active(struct wl_client *client, struct wl_resource *resource,
1686 uint32_t surfaceid, int32_t active)
1688 struct uifw_win_surface* usurf;
1690 uifw_trace("uifw_set_active: Enter(surf=%08x,active=%x)", surfaceid, active);
1692 if ((surfaceid > 0) &&
1693 ((active & (ICO_WINDOW_MGR_ACTIVE_POINTER|ICO_WINDOW_MGR_ACTIVE_KEYBOARD)) != 0)) {
1694 usurf = find_uifw_win_surface_by_id(surfaceid);
1700 switch (active & (ICO_WINDOW_MGR_ACTIVE_POINTER|ICO_WINDOW_MGR_ACTIVE_KEYBOARD)) {
1701 case ICO_WINDOW_MGR_ACTIVE_POINTER:
1702 if (usurf != _ico_win_mgr->active_pointer_usurf) {
1703 if (_ico_win_mgr->active_pointer_usurf) {
1704 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
1705 _ico_win_mgr->active_pointer_usurf,
1706 (_ico_win_mgr->active_keyboard_usurf ==
1707 _ico_win_mgr->active_pointer_usurf) ?
1708 ICO_WINDOW_MGR_ACTIVE_KEYBOARD :
1709 ICO_WINDOW_MGR_ACTIVE_NONE,
1712 _ico_win_mgr->active_pointer_usurf = usurf;
1713 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
1715 ICO_WINDOW_MGR_ACTIVE_POINTER |
1716 (_ico_win_mgr->active_keyboard_usurf == usurf) ?
1717 ICO_WINDOW_MGR_ACTIVE_KEYBOARD : 0,
1719 win_mgr_set_active(usurf, ICO_WINDOW_MGR_ACTIVE_POINTER);
1722 case ICO_WINDOW_MGR_ACTIVE_KEYBOARD:
1723 if (usurf != _ico_win_mgr->active_keyboard_usurf) {
1724 if (_ico_win_mgr->active_keyboard_usurf) {
1725 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
1726 _ico_win_mgr->active_keyboard_usurf,
1727 (_ico_win_mgr->active_keyboard_usurf ==
1728 _ico_win_mgr->active_pointer_usurf) ?
1729 ICO_WINDOW_MGR_ACTIVE_POINTER :
1730 ICO_WINDOW_MGR_ACTIVE_NONE,
1733 _ico_win_mgr->active_keyboard_usurf = usurf;
1734 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
1736 ICO_WINDOW_MGR_ACTIVE_KEYBOARD |
1737 (_ico_win_mgr->active_pointer_usurf == usurf) ?
1738 ICO_WINDOW_MGR_ACTIVE_POINTER : 0,
1740 win_mgr_set_active(usurf, ICO_WINDOW_MGR_ACTIVE_KEYBOARD);
1744 if ((usurf != _ico_win_mgr->active_pointer_usurf) ||
1745 (usurf != _ico_win_mgr->active_keyboard_usurf)) {
1746 if (_ico_win_mgr->active_pointer_usurf) {
1747 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
1748 _ico_win_mgr->active_pointer_usurf,
1749 ICO_WINDOW_MGR_ACTIVE_NONE,
1751 if (_ico_win_mgr->active_keyboard_usurf ==
1752 _ico_win_mgr->active_pointer_usurf) {
1753 _ico_win_mgr->active_keyboard_usurf = NULL;
1756 if (_ico_win_mgr->active_keyboard_usurf) {
1757 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
1758 _ico_win_mgr->active_keyboard_usurf,
1759 ICO_WINDOW_MGR_ACTIVE_NONE,
1762 _ico_win_mgr->active_pointer_usurf = usurf;
1763 _ico_win_mgr->active_keyboard_usurf = usurf;
1764 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
1766 ICO_WINDOW_MGR_ACTIVE_POINTER |
1767 ICO_WINDOW_MGR_ACTIVE_KEYBOARD,
1769 win_mgr_set_active(usurf, ICO_WINDOW_MGR_ACTIVE_POINTER |
1770 ICO_WINDOW_MGR_ACTIVE_KEYBOARD);
1774 uifw_trace("uifw_set_active: Leave(Change Active)");
1777 win_mgr_set_active(NULL, active);
1778 uifw_trace("uifw_set_active: Leave(Reset active surface)");
1782 /*--------------------------------------------------------------------------*/
1784 * @brief uifw_set_layer_visible: layer visible control
1786 * @param[in] client Weyland client
1787 * @param[in] resource resource of request
1788 * @param[in] layer layer id
1789 * @param[in] visible visible(1=show/0=hide)
1792 /*--------------------------------------------------------------------------*/
1794 uifw_set_layer_visible(struct wl_client *client, struct wl_resource *resource,
1795 uint32_t layer, int32_t visible)
1797 struct uifw_win_layer *el;
1798 struct uifw_win_layer *new_el;
1799 struct uifw_win_surface *usurf;
1801 uifw_trace("uifw_set_layer_visible: Enter(layer=%d, visilbe=%d)", layer, visible);
1804 wl_list_for_each (el, &_ico_win_mgr->ivi_layer_list, link) {
1805 if (el->layer == layer) break;
1808 if (&el->link == &_ico_win_mgr->ivi_layer_list) {
1809 /* layer not exist, create new layer */
1810 uifw_trace("uifw_set_layer_visible: New Layer %d", layer);
1811 new_el = win_mgr_create_layer(NULL, layer);
1813 uifw_trace("uifw_set_layer_visible: Leave(No Memory)");
1816 new_el->visible = (visible != 0) ? TRUE : FALSE;
1817 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_LAYER_VISIBLE, NULL,
1818 layer, new_el->visible, 0,0,0);
1819 uifw_trace("uifw_set_layer_visible: Leave(new layer)");
1823 /* control all surface in layer */
1824 if ((el->visible != FALSE) && (visible == 0)) {
1825 /* layer change to NOT visible */
1826 uifw_trace("uifw_set_layer_visible: change to not visible");
1827 el->visible = FALSE;
1829 else if ((el->visible == FALSE) && (visible != 0)) {
1830 /* layer change to visible */
1831 uifw_trace("uifw_set_layer_visible: change to visible");
1836 uifw_trace("uifw_set_layer_visible: Leave(no Change %d=>%d)",
1837 el->visible, visible);
1841 /* set damege area */
1842 wl_list_for_each (usurf, &el->surface_list, ivi_layer) {
1843 if ((usurf->visible != FALSE) && (usurf->surface != NULL) &&
1844 (usurf->surface->output != NULL)) {
1845 /* Damage(redraw) target surface */
1846 weston_surface_damage_below(usurf->surface);
1850 /* rebild compositor surface list */
1851 win_mgr_restack_ivi_layer(NULL);
1853 /* send layer visible event to manager */
1854 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_LAYER_VISIBLE, NULL,
1855 layer, el->visible, 0,0,0);
1857 uifw_trace("uifw_set_layer_visible: Leave");
1860 /*--------------------------------------------------------------------------*/
1862 * @brief uifw_get_surfaces: get application surfaces
1864 * @param[in] client Weyland client
1865 * @param[in] resource resource of request
1866 * @param[in] appid application id
1869 /*--------------------------------------------------------------------------*/
1871 uifw_get_surfaces(struct wl_client *client, struct wl_resource *resource, const char *appid)
1873 uifw_trace("uifw_get_surfaces: Enter(appid=%s)", appid);
1874 uifw_trace("uifw_get_surfaces: Leave");
1877 /*--------------------------------------------------------------------------*/
1879 * @brief uifw_map_surface: map surface buffer to shared memory
1881 * @param[in] client Weyland client
1882 * @param[in] resource resource of request
1883 * @param[in] surfaceid surface id
1884 * @param[in] mapname shared memory map name
1885 * @param[in] framerate frame rate of shared memory update(frame/sec)
1888 /*--------------------------------------------------------------------------*/
1890 uifw_map_surface(struct wl_client *client, struct wl_resource *resource,
1891 uint32_t surfaceid, const char *mapname, int32_t framerate)
1893 uifw_trace("uifw_map_surface: Enter(surface=%08x,map=%s,fps=%d)",
1894 surfaceid, mapname, framerate);
1895 uifw_trace("uifw_map_surface: Leave");
1898 /*--------------------------------------------------------------------------*/
1900 * @brief uifw_unmap_surface: unmap surface buffer to shared memory
1902 * @param[in] client Weyland client
1903 * @param[in] resource resource of request
1904 * @param[in] surfaceid surface id
1907 /*--------------------------------------------------------------------------*/
1909 uifw_unmap_surface(struct wl_client *client, struct wl_resource *resource,
1912 uifw_trace("uifw_map_surface: Enter(surface=%08x)", surfaceid);
1913 uifw_trace("uifw_map_surface: Leave");
1916 /*--------------------------------------------------------------------------*/
1918 * @brief win_mgr_surface_change_mgr: surface chagen from manager(HomeScreen)
1920 * @param[in] surface Weston surface
1921 * @param[in] x X coordinate on screen
1922 * @param[in] y Y coordinate on screen
1923 * @param[in] width surface width
1924 * @param[in] height surface height
1925 * @return number of managers
1926 * @retval > 0 number of managers
1927 * @retval 0 manager not exist
1929 /*--------------------------------------------------------------------------*/
1931 win_mgr_surface_change_mgr(struct weston_surface *surface,
1932 const int x, const int y, const int width, const int height)
1935 struct uifw_win_surface *usurf;
1937 uifw_trace("win_mgr_surface_change_mgr: Enter(%08x,x/y=%d/%d,w/h=%d/%d)",
1938 (int)surface, x, y, width, height);
1940 usurf = find_uifw_win_surface_by_ws(surface);
1942 uifw_trace("win_mgr_surface_change_mgr: Leave(Not Exist)");
1946 num_mgr = ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_CONFIGURE,
1947 usurf, x, y, width, height, 1);
1949 uifw_trace("win_mgr_surface_change_mgr: Leave(%d)", num_mgr);
1953 /*--------------------------------------------------------------------------*/
1955 * @brief win_mgr_change_surface: surface change
1957 * @param[in] surface Weston surface
1958 * @param[in] to destination(0=Client&Manager,1=Client,-1=Manager)
1959 * @param[in] manager request from manager(0=Client,1=Manager)
1962 /*--------------------------------------------------------------------------*/
1964 win_mgr_change_surface(struct weston_surface *surface, const int to, const int manager)
1966 struct uifw_win_surface *usurf;
1970 uifw_trace("win_mgr_change_surface: Enter(%08x,%d,%d)", (int)surface, to, manager);
1973 usurf = find_uifw_win_surface_by_ws(surface);
1975 uifw_trace("win_mgr_change_surface: Leave(Not Exist)");
1979 /* if not configure surface, set surface size */
1980 if (((usurf->width <= 0) || (usurf->height <= 0)) && (usurf->surface)) {
1981 uifw_trace("win_mgr_change_surface: set surface x/y=%d/%d=>%d/%d w/h=%d/%d=>%d/%d",
1982 (int)usurf->surface->geometry.x, (int)usurf->surface->geometry.y,
1983 usurf->x, usurf->y, usurf->width, usurf->height,
1984 usurf->surface->geometry.width, usurf->surface->geometry.height);
1985 usurf->width = usurf->surface->geometry.width;
1986 usurf->height = usurf->surface->geometry.height;
1987 if (usurf->visible) {
1988 weston_surface_set_position(usurf->surface,
1989 (float)(usurf->node_tbl->disp_x + usurf->x),
1990 (float)(usurf->node_tbl->disp_y + usurf->y));
1991 win_mgr_restack_ivi_layer(usurf);
1994 weston_surface_set_position(usurf->surface, (float)(ICO_IVI_MAX_COORDINATE+1),
1995 (float)(ICO_IVI_MAX_COORDINATE+1));
1999 /* send wayland event to client */
2000 if ((to >= 0) && (usurf->shsurf != NULL) && (manager !=0) &&
2001 (usurf->width > 0) && (usurf->height > 0)) {
2002 uifw_trace("win_mgr_change_surface: SHELL_SURFACE_CONFIGURE %08x(%08x),w/h=%d/%d ",
2003 usurf->surfaceid, (int)usurf->surface, usurf->width, usurf->height);
2004 ico_ivi_shell_send_configure(usurf->surface,
2005 WL_SHELL_SURFACE_RESIZE_BOTTOM_RIGHT,
2006 usurf->width, usurf->height);
2009 if (usurf->visible) {
2010 x = usurf->node_tbl->disp_x + usurf->x;
2011 y = usurf->node_tbl->disp_y + usurf->y;
2014 x = ICO_IVI_MAX_COORDINATE+1;
2015 y = ICO_IVI_MAX_COORDINATE+1;
2017 /* change geometry if request from manager */
2019 if ((usurf->width != usurf->surface->geometry.width) ||
2020 (usurf->height != usurf->surface->geometry.height) ||
2021 (usurf->surface->geometry.x != (float)x) ||
2022 (usurf->surface->geometry.y != (float)y)) {
2023 weston_surface_configure(usurf->surface, (float)x, (float)y,
2024 usurf->width, usurf->height);
2025 weston_compositor_schedule_repaint(_ico_win_mgr->compositor);
2029 /* send manager event to HomeScreen */
2032 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_CONFIGURE,
2033 usurf, usurf->x, usurf->y,
2034 usurf->width, usurf->height, 0);
2037 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_CONFIGURE,
2038 usurf, (int)usurf->surface->geometry.x,
2039 (int)usurf->surface->geometry.y,
2040 usurf->surface->geometry.width,
2041 usurf->surface->geometry.height, 1);
2045 /* change geometry if request from client */
2047 if ((usurf->width != usurf->surface->geometry.width) ||
2048 (usurf->height != usurf->surface->geometry.height) ||
2049 (usurf->surface->geometry.x != (float)x) ||
2050 (usurf->surface->geometry.y != (float)y)) {
2051 weston_surface_configure(usurf->surface, (float)x, (float)y,
2052 usurf->width, usurf->height);
2053 weston_compositor_schedule_repaint(_ico_win_mgr->compositor);
2056 uifw_trace("win_mgr_change_surface: Leave(OK)");
2059 /*--------------------------------------------------------------------------*/
2061 * @brief win_mgr_select_surface: select surface by Bottun/Touch
2063 * @param[in] surface Weston surface
2066 /*--------------------------------------------------------------------------*/
2068 win_mgr_select_surface(struct weston_surface *surface)
2070 struct uifw_win_surface *usurf;
2072 uifw_trace("win_mgr_select_surface: Enter(%08x)", (int)surface);
2075 usurf = find_uifw_win_surface_by_ws(surface);
2077 uifw_trace("win_mgr_select_surface: Leave(Not Exist)");
2080 if (usurf != _ico_win_mgr->active_pointer_usurf) {
2082 /* send active event to manager */
2083 if (ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
2084 usurf, ICO_WINDOW_MGR_ACTIVE_SELECTED, 0,0,0,0) <= 0) {
2085 uifw_trace("win_mgr_select_surface: not found manager, set active");
2086 win_mgr_set_active(usurf, ICO_WINDOW_MGR_ACTIVE_POINTER |
2087 ICO_WINDOW_MGR_ACTIVE_KEYBOARD);
2090 uifw_trace("win_mgr_select_surface: Leave(OK)");
2093 /*--------------------------------------------------------------------------*/
2095 * @brief win_mgr_set_title: set tile name to surface
2097 * @param[in] surface weston surface
2098 * @param[in] title title name
2101 /*--------------------------------------------------------------------------*/
2103 win_mgr_set_title(struct weston_surface *surface, const char *title)
2105 struct uifw_win_surface *usurf;
2107 uifw_trace("win_mgr_set_title: Enter(%08x) name=%s", (int)surface, title);
2109 usurf = find_uifw_win_surface_by_ws(surface);
2111 uifw_trace("win_mgr_set_title: Leave(Not Exist)");
2114 if (((usurf->width > 0) && (usurf->height > 0)) &&
2115 ((usurf->created == 0) ||
2116 (strncmp(title, usurf->winname, ICO_IVI_WINNAME_LENGTH-1) != 0))) {
2117 strncpy(usurf->winname, title, ICO_IVI_WINNAME_LENGTH-1);
2118 usurf->winname[ICO_IVI_WINNAME_LENGTH-1] = 0;
2119 if (usurf->created == 0) {
2120 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_CREATED, usurf, 0,0,0,0,0);
2124 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_NAME, usurf, 0,0,0,0,0);
2128 strncpy(usurf->winname, title, ICO_IVI_WINNAME_LENGTH-1);
2129 usurf->winname[ICO_IVI_WINNAME_LENGTH-1] = 0;
2131 uifw_trace("win_mgr_set_title: Leave");
2134 /*--------------------------------------------------------------------------*/
2136 * @brief win_mgr_surface_move: set tile name to surface
2138 * @param[in] surface weston surface
2139 * @param[in] title title name
2142 /*--------------------------------------------------------------------------*/
2144 win_mgr_surface_move(struct weston_surface *surface, int *dx, int *dy)
2146 struct uifw_win_surface *usurf;
2148 uifw_trace("win_mgr_surface_move: Enter(%08x) x/y=%d,%d", (int)surface, *dx, *dy);
2150 usurf = find_uifw_win_surface_by_ws(surface);
2152 uifw_trace("win_mgr_surface_move: Leave(Not Exist)");
2155 if (usurf->visible) {
2156 *dx = usurf->node_tbl->disp_x + usurf->x;
2157 *dy = usurf->node_tbl->disp_y + usurf->y;
2160 *dx = ICO_IVI_MAX_COORDINATE+1;
2161 *dy = ICO_IVI_MAX_COORDINATE+1;
2163 uifw_trace("win_mgr_surface_move: Leave(change to x/y=%d/%d)", *dx, *dy);
2166 /*--------------------------------------------------------------------------*/
2168 * @brief ico_window_mgr_set_visible: change surface visibility
2170 * @param[in] usurf UIFW surface
2171 * @param[in] visible visible(=1)/unvisible(0)
2174 /*--------------------------------------------------------------------------*/
2176 ico_window_mgr_set_visible(struct uifw_win_surface *usurf, const int visible)
2179 if (usurf->visible == 0) {
2180 uifw_trace("ico_window_mgr_set_visible: Chagne to Visible(%08x)", (int)usurf);
2182 /* change unvisible to visible, restack surface list */
2183 win_mgr_restack_ivi_layer(usurf);
2187 if (usurf->visible != 0) {
2188 uifw_trace("ico_window_mgr_set_visible: Chagne to Unvisible(%08x)", (int)usurf);
2190 /* change visible to unvisible, restack surface list */
2191 win_mgr_restack_ivi_layer(usurf);
2194 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_VISIBLE,
2195 usurf, usurf->visible, usurf->raise, 0, 0,0);
2198 /*--------------------------------------------------------------------------*/
2200 * @brief win_mgr_set_raise: change surface raise/lower
2202 * @param[in] usurf UIFW surface
2203 * @param[in] raise raise(=1)/lower(0)
2206 /*--------------------------------------------------------------------------*/
2208 win_mgr_set_raise(struct uifw_win_surface *usurf, const int raise)
2210 uifw_trace("win_mgr_set_raise: Enter(%08x,%d) layer=%x",
2211 (int)usurf, raise, (int)usurf->win_layer->layer);
2213 wl_list_remove(&usurf->ivi_layer);
2215 /* raise ... surface stack to top of layer */
2216 wl_list_insert(&usurf->win_layer->surface_list, &usurf->ivi_layer);
2218 uifw_trace("win_mgr_set_raise: Raise Link to Top");
2221 /* Lower ... surface stack to bottom of layer */
2222 wl_list_insert(usurf->win_layer->surface_list.prev, &usurf->ivi_layer);
2224 uifw_trace("win_mgr_set_raise: Lower Link to Bottom");
2227 /* rebild compositor surface list */
2228 if (usurf->visible) {
2229 win_mgr_restack_ivi_layer(usurf);
2231 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_VISIBLE,
2232 usurf, usurf->visible, usurf->raise, 0, 0,0);
2234 uifw_trace("win_mgr_set_raise: Leave");
2237 /*--------------------------------------------------------------------------*/
2239 * @brief win_mgr_destroy_surface: surface destroy
2241 * @param[in] surface Weston surface
2244 /*--------------------------------------------------------------------------*/
2246 win_mgr_destroy_surface(struct weston_surface *surface)
2248 struct uifw_win_surface *usurf;
2249 struct uifw_win_surface *phash;
2250 struct uifw_win_surface *bhash;
2253 usurf = find_uifw_win_surface_by_ws(surface);
2255 uifw_trace("win_mgr_destroy_surface: UIFW surface Not Exist");
2258 uifw_trace("win_mgr_destroy_surface: Enter(%08x) %08x", (int)surface, usurf->surfaceid);
2260 /* destroy active surface */
2261 if (usurf == _ico_win_mgr->active_pointer_usurf) {
2262 _ico_win_mgr->active_pointer_usurf = NULL;
2264 if (usurf == _ico_win_mgr->active_keyboard_usurf) {
2265 _ico_win_mgr->active_keyboard_usurf = NULL;
2268 /* destory animation extenson */
2269 if (win_mgr_hook_animation) {
2270 (*win_mgr_hook_animation)(ICO_WINDOW_MGR_ANIMATION_DESTROY, (void *)usurf);
2273 /* delete from layer list */
2274 wl_list_remove(&usurf->ivi_layer);
2275 win_mgr_restack_ivi_layer(NULL);
2277 /* delete from hash table */
2278 hash = MAKE_IDHASH(usurf->surfaceid);
2279 phash = _ico_win_mgr->idhash[hash];
2281 while ((phash) && (phash != usurf)) {
2283 phash = phash->next_idhash;
2286 bhash->next_idhash = usurf->next_idhash;
2289 _ico_win_mgr->idhash[hash] = usurf->next_idhash;
2292 hash = MAKE_WSHASH(usurf->surface);
2293 phash = _ico_win_mgr->wshash[hash];
2295 while ((phash) && (phash != usurf)) {
2297 phash = phash->next_wshash;
2300 bhash->next_wshash = usurf->next_wshash;
2303 _ico_win_mgr->wshash[hash] = usurf->next_wshash;
2306 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_DESTROYED,
2309 hash = usurf->surfaceid & SURCAFE_ID_MASK;
2310 _ico_win_mgr->surfaceid_map[(hash - 1)/16] &= ~(1 << ((hash - 1) % 16));
2313 uifw_trace("win_mgr_destroy_surface: Leave(OK)");
2316 /*--------------------------------------------------------------------------*/
2318 * @brief bind_ico_win_mgr: bind Multi Window Manager from client
2320 * @param[in] client client
2321 * @param[in] data user data(unused)
2322 * @param[in] version protocol version(unused)
2323 * @param[in] id client object id
2326 /*--------------------------------------------------------------------------*/
2328 bind_ico_win_mgr(struct wl_client *client,
2329 void *data, uint32_t version, uint32_t id)
2331 struct wl_resource *add_resource;
2332 struct uifw_manager *nm;
2333 struct uifw_client *uclient;
2335 uifw_trace("bind_ico_win_mgr: Enter(client=%08x, id=%x)", (int)client, (int)id);
2337 add_resource = wl_resource_create(client, &ico_window_mgr_interface, 1, id);
2339 wl_resource_set_implementation(add_resource, &ico_window_mgr_implementation,
2340 _ico_win_mgr, unbind_ico_win_mgr);
2343 /* Create client management tabel */
2344 uclient = find_client_from_client(client);
2346 win_mgr_bind_client(client, NULL);
2350 nm = (struct uifw_manager *)malloc(sizeof(struct uifw_manager));
2351 memset(nm, 0, sizeof(struct uifw_manager));
2352 nm->resource = add_resource;
2353 wl_list_insert(&_ico_win_mgr->manager_list, &nm->link);
2355 uifw_trace("bind_ico_win_mgr: Leave");
2358 /*--------------------------------------------------------------------------*/
2360 * @brief unbind_ico_win_mgr: unbind Multi Window Manager from client
2362 * @param[in] resource client resource
2365 /*--------------------------------------------------------------------------*/
2367 unbind_ico_win_mgr(struct wl_resource *resource)
2369 struct uifw_manager *mgr, *itmp;
2371 uifw_trace("unbind_ico_win_mgr: Enter");
2373 /* Remove manager from manager list */
2374 _ico_win_mgr->num_manager = 0;
2375 wl_list_for_each_safe (mgr, itmp, &_ico_win_mgr->manager_list, link) {
2376 if (mgr->resource == resource) {
2377 wl_list_remove(&mgr->link);
2382 _ico_win_mgr->num_manager++;
2386 uifw_trace("unbind_ico_win_mgr: Leave");
2389 /*--------------------------------------------------------------------------*/
2391 * @brief ico_win_mgr_send_to_mgr: send event to manager(HomeScreen)
2393 * @param[in] event event code(if -1, not send event)
2394 * @param[in] usurf UIFW surface table
2395 * @param[in] param1 parameter 1
2397 * @param[in] param5 parameter 5
2398 * @return number of managers
2399 * @retval > 0 number of managers
2400 * @retval 0 manager not exist
2402 /*--------------------------------------------------------------------------*/
2404 ico_win_mgr_send_to_mgr(const int event, struct uifw_win_surface *usurf,
2405 const int param1, const int param2, const int param3,
2406 const int param4, const int param5)
2409 struct uifw_manager* mgr;
2411 /* send created if not send created event */
2412 if ((usurf != NULL) && (usurf->created == 0) &&
2413 (((usurf->width > 0) && (usurf->height > 0)) ||
2414 ((event != ICO_WINDOW_MGR_WINDOW_CREATED) &&
2415 (event != ICO_WINDOW_MGR_WINDOW_NAME)))) {
2416 wl_list_for_each (mgr, &_ico_win_mgr->manager_list, link) {
2418 uifw_trace("ico_win_mgr_send_to_mgr: Send Manager(%08x) WINDOW_CREATED"
2419 "(surf=%08x,name=%s,pid=%d,appid=%s)", (int)mgr->resource,
2420 usurf->surfaceid, usurf->winname, usurf->uclient->pid,
2421 usurf->uclient->appid);
2422 ico_window_mgr_send_window_created(mgr->resource, usurf->surfaceid,
2423 usurf->winname, usurf->uclient->pid,
2424 usurf->uclient->appid);
2430 wl_list_for_each (mgr, &_ico_win_mgr->manager_list, link) {
2435 case ICO_WINDOW_MGR_WINDOW_CREATED:
2436 /* Do nothing anymore because sended window create event */
2439 case ICO_WINDOW_MGR_WINDOW_NAME:
2440 uifw_trace("ico_win_mgr_send_to_mgr: Send Manager(%08x) WINDOW_NAME"
2441 "(surf=%08x,name=%s)", (int)mgr->resource,
2442 usurf->surfaceid, usurf->winname);
2443 ico_window_mgr_send_window_name(mgr->resource, usurf->surfaceid,
2447 case ICO_WINDOW_MGR_WINDOW_DESTROYED:
2448 uifw_trace("ico_win_mgr_send_to_mgr: Send Manager(%08x) DESTROYED"
2449 "(surf=%08x)", (int)mgr->resource, usurf->surfaceid);
2450 ico_window_mgr_send_window_destroyed(mgr->resource, usurf->surfaceid);
2453 case ICO_WINDOW_MGR_WINDOW_VISIBLE:
2454 uifw_trace("ico_win_mgr_send_to_mgr: Send Manager(%08x) VISIBLE"
2455 "(surf=%08x,vis=%d,raise=%d,hint=%d)",
2456 (int)mgr->resource, usurf->surfaceid, param1, param2, param3);
2457 ico_window_mgr_send_window_visible(mgr->resource,
2458 usurf->surfaceid, param1, param2, param3);
2461 case ICO_WINDOW_MGR_WINDOW_CONFIGURE:
2462 uifw_trace("ico_win_mgr_send_to_mgr: Send Manager(%08x) CONFIGURE"
2463 "(surf=%08x,app=%s,node=%x,layer=%x,x/y=%d/%d,w/h=%d/%d,hint=%d)",
2464 (int)mgr->resource, usurf->surfaceid, usurf->uclient->appid,
2465 usurf->node_tbl->node, usurf->win_layer->layer,
2466 param1, param2, param3, param4, param5);
2467 ico_window_mgr_send_window_configure(mgr->resource, usurf->surfaceid,
2468 usurf->node_tbl->node,
2469 usurf->win_layer->layer,
2470 param1, param2, param3, param4, param5);
2473 case ICO_WINDOW_MGR_WINDOW_ACTIVE:
2474 uifw_trace("ico_win_mgr_send_to_mgr: Send Manager(%08x) ACTIVE"
2475 "(surf=%08x,active=%d)", (int)mgr->resource, usurf->surfaceid,
2477 ico_window_mgr_send_window_active(mgr->resource, usurf->surfaceid,
2481 case ICO_WINDOW_MGR_LAYER_VISIBLE:
2482 uifw_trace("ico_win_mgr_send_to_mgr: Send Manager(%08x) LAYER_VISIBLE"
2483 "(layer=%x,visivle=%d)", (int)mgr->resource, param1, param2);
2484 ico_window_mgr_send_layer_visible(mgr->resource, (uint32_t)param1, param2);
2487 case ICO_WINDOW_MGR_MAP_SURFACE:
2488 uifw_trace("ico_win_mgr_send_to_mgr: Send Manager(%08x) MAP SURFACE"
2489 "(%08x,ev=%x,w/h/s/f=%d/%d/%d/%x)", (int)mgr->resource,
2491 param1, param2, param3, param4, param5);
2492 ico_window_mgr_send_map_surface(mgr->resource, param1, usurf->surfaceid,
2493 param2, param3, param4, param5);
2497 uifw_error("ico_win_mgr_send_to_mgr: Illegal event(%08x)", event);
2505 /*--------------------------------------------------------------------------*/
2507 * @brief ico_window_mgr_set_hook_animation: set animation hook routine
2509 * @param[in] hook_animation hook routine
2512 /*--------------------------------------------------------------------------*/
2514 ico_window_mgr_set_hook_animation(int (*hook_animation)(const int op, void *data))
2516 win_mgr_hook_animation = hook_animation;
2519 /*--------------------------------------------------------------------------*/
2521 * @brief module_init: initialize ico_window_mgr
2522 * this function called from ico_pluign_loader
2524 * @param[in] es weston compositor
2525 * @param[in] argc number of arguments(unused)
2526 * @param[in] argv argument list(unused)
2531 /*--------------------------------------------------------------------------*/
2533 module_init(struct weston_compositor *ec, int *argc, char *argv[])
2538 struct weston_output *output;
2539 struct weston_config_section *section;
2540 char *displayno = NULL;
2543 uifw_info("ico_window_mgr: Enter(module_init)");
2545 /* get ivi debug level */
2546 section = weston_config_get_section(ec->config, "ivi-debug", NULL, NULL);
2548 weston_config_section_get_int(section, "flag", &_ico_ivi_debug_flag, 0);
2549 weston_config_section_get_int(section, "log", &_ico_ivi_debug_level, 3);
2552 /* get animation default */
2553 section = weston_config_get_section(ec->config, "ivi-animation", NULL, NULL);
2555 weston_config_section_get_string(section, "default", &_ico_ivi_animation_name, NULL);
2556 weston_config_section_get_int(section, "time", &_ico_ivi_animation_time, 500);
2557 weston_config_section_get_int(section, "fps", &_ico_ivi_animation_fps, 15);
2560 /* get display number list */
2561 section = weston_config_get_section(ec->config, "ivi-display", NULL, NULL);
2563 weston_config_section_get_string(section, "displayno", &displayno, NULL);
2566 /* create ico_window_mgr management table */
2567 _ico_win_mgr = (struct ico_win_mgr *)malloc(sizeof(struct ico_win_mgr));
2568 if (_ico_win_mgr == NULL) {
2569 uifw_error("ico_window_mgr: malloc failed");
2573 memset(_ico_win_mgr, 0, sizeof(struct ico_win_mgr));
2574 _ico_win_mgr->surfaceid_map = (uint16_t *) malloc(INIT_SURFACE_IDS/8);
2575 if (! _ico_win_mgr->surfaceid_map) {
2576 uifw_error("ico_window_mgr: malloc failed");
2579 uifw_trace("ico_window_mgr: table=%08x", (int)_ico_win_mgr);
2580 memset(_ico_win_mgr->surfaceid_map, 0, INIT_SURFACE_IDS/8);
2582 _ico_win_mgr->compositor = ec;
2584 _ico_win_mgr->surfaceid_max = INIT_SURFACE_IDS;
2585 _ico_win_mgr->surfaceid_count = INIT_SURFACE_IDS;
2587 uifw_trace("ico_window_mgr: wl_global_create(bind_ico_win_mgr)");
2588 if (wl_global_create(ec->wl_display, &ico_window_mgr_interface, 1,
2589 _ico_win_mgr, bind_ico_win_mgr) == NULL) {
2590 uifw_error("ico_window_mgr: Error(wl_global_create)");
2594 wl_list_init(&_ico_win_mgr->client_list);
2595 wl_list_init(&_ico_win_mgr->manager_list);
2596 wl_list_init(&_ico_win_mgr->ivi_layer_list);
2598 /* create display list */
2599 if (displayno != NULL) {
2606 wl_list_for_each(output, &ec->output_list, link) {
2608 if (_ico_num_nodes >= ICO_IVI_MAX_DISPLAY) break;
2610 memset(&_ico_node_table[0], 0, sizeof(_ico_node_table));
2612 wl_list_for_each(output, &ec->output_list, link) {
2615 idx = strtol(p, (char **)0, 0);
2616 uifw_trace("ico_window_mgr: config Display.%d is %d", i, idx);
2618 if ((idx < 0) || (idx >= _ico_num_nodes)) {
2625 if (_ico_node_table[idx].node) {
2626 for (idx = 0; idx < _ico_num_nodes; idx++) {
2627 if (_ico_node_table[idx].node == 0) break;
2629 if (idx >= _ico_num_nodes) {
2630 uifw_error("ico_window_mgr: number of display overflow");
2634 _ico_node_table[idx].node = idx + 0x100;
2635 _ico_node_table[idx].displayno = i;
2636 _ico_node_table[idx].disp_x = output->x;
2637 _ico_node_table[idx].disp_y = output->y;
2638 _ico_node_table[idx].disp_width = output->width;
2639 _ico_node_table[idx].disp_height = output->height;
2641 if (i >= _ico_num_nodes) break;
2644 for (i = 0; i < _ico_num_nodes; i++) {
2645 _ico_node_table[i].node &= 0x0ff;
2646 uifw_trace("ico_window_mgr: Display.%d no=%d x/y=%d/%d w/h=%d/%d",
2647 i, _ico_node_table[i].displayno,
2648 _ico_node_table[i].disp_x, _ico_node_table[i].disp_y,
2649 _ico_node_table[i].disp_width, _ico_node_table[i].disp_height);
2651 if (displayno) free(displayno);
2653 /* my node Id ... this version fixed 0 */
2654 nodeId = ico_ivi_get_mynode();
2656 _ico_win_mgr->surface_head = ICO_IVI_SURFACEID_BASE(nodeId);
2657 uifw_trace("ico_window_mgr: NoedId=%04x SurfaceIdBase=%08x",
2658 nodeId, _ico_win_mgr->surface_head);
2660 /* Hook to IVI-Shell */
2661 ico_ivi_shell_hook_bind(win_mgr_bind_client);
2662 ico_ivi_shell_hook_unbind(win_mgr_unbind_client);
2663 ico_ivi_shell_hook_create(win_mgr_register_surface);
2664 ico_ivi_shell_hook_destroy(win_mgr_destroy_surface);
2665 ico_ivi_shell_hook_map(win_mgr_map_surface);
2666 ico_ivi_shell_hook_change(win_mgr_change_surface);
2667 ico_ivi_shell_hook_select(win_mgr_select_surface);
2668 ico_ivi_shell_hook_title(win_mgr_set_title);
2669 ico_ivi_shell_hook_move(win_mgr_surface_move);
2671 uifw_info("ico_window_mgr: Leave(module_init)");