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 "ico_ivi_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 eventcb; /* Event send flag */
78 struct wl_list link; /* link to next manager */
81 /* Multi Windiw Manager */
83 struct weston_compositor *compositor; /* Weston compositor */
84 int32_t surface_head; /* (HostID << 24) | (DisplayNo << 16) */
86 struct wl_list client_list; /* Clients */
87 struct wl_list manager_list; /* Manager(ex.HomeScreen) list */
88 int num_manager; /* Number of managers */
89 struct wl_list surface_list; /* Surface list */
90 struct wl_list client_attr_list; /* Client attribute list */
91 struct uifw_win_surface *active_pointer_surface; /* Active Pointer Surface */
92 struct uifw_win_surface *active_keyboard_surface; /* 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 */
102 /* Internal macros */
104 #define MAKE_IDHASH(v) (((uint32_t)v) & (UIFW_HASH-1))
106 #define MAKE_WSHASH(v) ((((uint32_t)v) >> 5) & (UIFW_HASH-1))
108 /* function prototype */
109 /* weston compositor interface */
110 int module_init(struct weston_compositor *ec);
111 /* get surface table from surfece id */
112 static struct uifw_win_surface* find_uifw_win_surface_by_id(uint32_t surfaceid);
113 /* get surface table from weston surface*/
114 static struct uifw_win_surface* find_uifw_win_surface_by_ws(
115 struct weston_surface *wsurf);
116 /* get client table from weston client */
117 static struct uifw_client* find_client_from_client(struct wl_client* client);
118 /* assign new surface id */
119 static uint32_t generate_id(void);
120 /* bind shell client */
121 static void bind_shell_client(struct wl_client *client);
122 /* unind shell client */
123 static void unbind_shell_client(struct wl_client *client);
124 /* create new surface */
125 static void client_register_surface(
126 struct wl_client *client, struct wl_resource *resource,
127 struct weston_surface *surface, struct shell_surface *shsurf);
128 /* map new surface */
129 static void win_mgr_map_surface(struct weston_surface *surface, int32_t *width,
130 int32_t *height, int32_t *sx, int32_t *sy);
131 /* set applicationId for RemoteUI */
132 static void uifw_set_user(struct wl_client *client, struct wl_resource *resource,
133 int pid, const char *appid);
134 /* set/reset event flag */
135 static void uifw_set_eventcb(struct wl_client *client, struct wl_resource *resource,
137 /* set window layer */
138 static void uifw_set_window_layer(struct wl_client *client,
139 struct wl_resource *resource,
140 uint32_t surfaceid, int layer);
141 /* set surface size and position */
142 static void uifw_set_positionsize(struct wl_client *client,
143 struct wl_resource *resource, uint32_t surfaceid,
144 int32_t x, int32_t y, int32_t width, int32_t height);
145 /* show/hide and raise/lower surface */
146 static void uifw_set_visible(struct wl_client *client, struct wl_resource *resource,
147 uint32_t surfaceid, int32_t visible, int32_t raise);
148 /* set surface animation */
149 static void uifw_set_animation(struct wl_client *client, struct wl_resource *resource,
150 uint32_t surfaceid, int32_t change, const char *animation);
151 /* set active surface (form HomeScreen) */
152 static void uifw_set_active(struct wl_client *client, struct wl_resource *resource,
153 uint32_t surfaceid, uint32_t target);
154 /* layer visibility control */
155 static void uifw_set_layer_visible(struct wl_client *client, struct wl_resource *resource,
156 int32_t layer, int32_t visible);
157 /* send surface change event to manager */
158 static void uifw_set_client_attr(struct wl_client *client, struct wl_resource *resource,
159 const char *appid, int32_t attr, int32_t value);
160 /* set client application attribute */
161 static void win_mgr_surface_change(struct weston_surface *surface,
162 const int to, const int manager);
163 /* surface change from manager */
164 static int win_mgr_surface_change_mgr(struct weston_surface *surface, const int x,
165 const int y, const int width, const int height);
166 /* surface destory */
167 static void win_mgr_surface_destroy(struct weston_surface *surface);
169 static void bind_ico_win_mgr(struct wl_client *client,
170 void *data, uint32_t version, uint32_t id);
172 static void unbind_ico_win_mgr(struct wl_resource *resource);
173 /* convert surfaceId to nodeId */
174 static int ico_winmgr_usurf_2_node(const int surfaceid);
175 /* send event to manager */
176 static int ico_win_mgr_send_to_mgr(const int event, const int surfaceid,
177 const char *appid, const int param1,
178 const int param2, const int param3, const int param4,
179 const int param5, const int param6);
180 /* convert animation name to type value */
181 static int ico_get_animation_type(const char *animation);
182 /* hook for set user */
183 static void (*win_mgr_hook_set_user)
184 (struct wl_client *client, const char *appid) = NULL;
185 /* hook for surface create */
186 static void (*win_mgr_hook_create)
187 (struct wl_client *client, struct weston_surface *surface,
188 int surfaceId, const char *appid) = NULL;
189 /* hook for surface destory */
190 static void (*win_mgr_hook_destroy)(struct weston_surface *surface) = NULL;
191 /* hook for animation */
192 static int (*win_mgr_hook_animation)(const int op, void *data) = NULL;
195 /* Multi Window Manager interface */
196 static const struct ico_window_mgr_interface ico_window_mgr_implementation = {
199 uifw_set_window_layer,
200 uifw_set_positionsize,
204 uifw_set_layer_visible,
208 /* static management table */
209 static struct ico_win_mgr *_ico_win_mgr = NULL;
212 /*--------------------------------------------------------------------------*/
214 * @brief find_uifw_win_surface_by_id: find UIFW surface by surface id
216 * @param[in] surfaceid UIFW surface id
217 * @return UIFW surface table address
218 * @retval !=NULL success(surface table address)
219 * @retval NULL error(surface id dose not exist)
221 /*--------------------------------------------------------------------------*/
222 static struct uifw_win_surface*
223 find_uifw_win_surface_by_id(uint32_t surfaceid)
225 struct uifw_win_surface* usurf;
227 usurf = _ico_win_mgr->idhash[MAKE_IDHASH(surfaceid)];
230 if (usurf->id == surfaceid) {
233 usurf = usurf->next_idhash;
235 uifw_trace("find_uifw_win_surface_by_id: NULL");
240 /*--------------------------------------------------------------------------*/
242 * @brief find_uifw_win_surface_by_ws: find UIFW srurace by weston surface
244 * @param[in] wsurf Weston surface
245 * @return UIFW surface table address
246 * @retval !=NULL success(surface table address)
247 * @retval NULL error(surface dose not exist)
249 /*--------------------------------------------------------------------------*/
250 static struct uifw_win_surface*
251 find_uifw_win_surface_by_ws(struct weston_surface *wsurf)
253 struct uifw_win_surface* usurf;
255 usurf = _ico_win_mgr->wshash[MAKE_WSHASH(wsurf)];
258 if (usurf->surface == wsurf) {
261 usurf = usurf->next_wshash;
263 uifw_trace("find_uifw_win_surface_by_ws: NULL");
267 /*--------------------------------------------------------------------------*/
269 * @brief find_client_from_client: find UIFW client by wayland client
271 * @param[in] client Wayland client
272 * @return UIFW client table address
273 * @retval !=NULL success(client table address)
274 * @retval NULL error(client dose not exist)
276 /*--------------------------------------------------------------------------*/
277 static struct uifw_client*
278 find_client_from_client(struct wl_client* client)
280 struct uifw_client *uclient;
282 wl_list_for_each (uclient, &_ico_win_mgr->client_list, link) {
283 if (uclient->client == client) {
287 uifw_trace("find_client_from_client: NULL");
291 /*--------------------------------------------------------------------------*/
293 * @brief ico_window_mgr_appid: find application id by wayland client
295 * @param[in] client Wayland client
296 * @return application id
297 * @retval !=NULL success(application id)
298 * @retval NULL error(client dose not exist)
300 /*--------------------------------------------------------------------------*/
302 ico_window_mgr_appid(struct wl_client* client)
304 struct uifw_client *uclient;
306 uclient = find_client_from_client(client);
311 return uclient->appid;
314 /*--------------------------------------------------------------------------*/
316 * @brief generate_id: generate uniq id for UIFW surface id
319 * @return uniq id for UIFW surface id
321 /*--------------------------------------------------------------------------*/
332 _ico_win_mgr->surfaceid_count ++;
334 /* serach free id from bitmap */
335 for (rep = 0; rep < (int)(_ico_win_mgr->surfaceid_max/16); rep++) {
336 if (_ico_win_mgr->surfaceid_count >= _ico_win_mgr->surfaceid_max) {
337 _ico_win_mgr->surfaceid_count = 0;
339 if (_ico_win_mgr->surfaceid_map[_ico_win_mgr->surfaceid_count/16] != 0xffff) {
340 /* find free id from bitmap */
341 map = 1 << (_ico_win_mgr->surfaceid_count % 16);
342 for (i = (_ico_win_mgr->surfaceid_count % 16); i < 16; i++) {
343 if ((_ico_win_mgr->surfaceid_map[_ico_win_mgr->surfaceid_count/16] & map)
345 _ico_win_mgr->surfaceid_map[_ico_win_mgr->surfaceid_count/16] |= map;
346 _ico_win_mgr->surfaceid_count
347 = (_ico_win_mgr->surfaceid_count/16)*16 + i;
349 surfaceId = (_ico_win_mgr->surfaceid_count + 1)
350 | _ico_win_mgr->surface_head;
351 uifw_trace("generate_id: SurfaceId=%08x", surfaceId);
357 _ico_win_mgr->surfaceid_count += 16;
360 /* no free id in bitmap, extend bitmap */
361 if ((_ico_win_mgr->surfaceid_max + ADD_SURFACE_IDS) > SURCAFE_ID_MASK) {
362 /* too many surfaces, system error */
363 uifw_trace("generate_id: SurffaceId Overflow(%d, Max=%d), Abort",
364 _ico_win_mgr->surfaceid_max + ADD_SURFACE_IDS, SURCAFE_ID_MASK);
365 fprintf(stderr, "generate_id: SurffaceId Overflow(%d, Max=%d), Abort\n",
366 _ico_win_mgr->surfaceid_max + ADD_SURFACE_IDS, SURCAFE_ID_MASK);
370 new_map = (uint16_t *) malloc((_ico_win_mgr->surfaceid_max + ADD_SURFACE_IDS) / 8);
371 memcpy(new_map, _ico_win_mgr->surfaceid_map, _ico_win_mgr->surfaceid_max/8);
372 memset(&new_map[_ico_win_mgr->surfaceid_max/16], 0, ADD_SURFACE_IDS/8);
373 _ico_win_mgr->surfaceid_count = _ico_win_mgr->surfaceid_max;
374 new_map[_ico_win_mgr->surfaceid_count/16] |= 1;
375 _ico_win_mgr->surfaceid_max += ADD_SURFACE_IDS;
376 free(_ico_win_mgr->surfaceid_map);
377 _ico_win_mgr->surfaceid_map = new_map;
379 uifw_trace("generate_id: Extent SurfaceId=%d(Max.%d)",
380 _ico_win_mgr->surfaceid_count+1, _ico_win_mgr->surfaceid_max);
381 surfaceId = (_ico_win_mgr->surfaceid_count + 1) | _ico_win_mgr->surface_head;
383 uifw_trace("generate_id: SurfaceId=%08x", surfaceId);
387 /*--------------------------------------------------------------------------*/
389 * @brief bind_shell_client: ico_ivi_shell from client
391 * @param[in] client Wayland client
394 /*--------------------------------------------------------------------------*/
396 bind_shell_client(struct wl_client *client)
398 struct uifw_client *uclient;
399 struct uifw_client_attr *lattr;
409 uifw_trace("bind_shell_client: Enter(client=%08x)", (int)client);
412 uclient = find_client_from_client(client);
414 /* client not exist, create client management table */
415 uifw_trace("bind_shell_client: Create Client");
416 uclient = (struct uifw_client *)malloc(sizeof(struct uifw_client));
418 uifw_error("bind_shell_client: Error, No Memory");
421 memset(uclient, 0, sizeof(struct uifw_client));
422 uclient->client = client;
423 wl_list_insert(&_ico_win_mgr->client_list, &uclient->link);
425 wl_client_get_credentials(client, &pid, &uid, &gid);
426 uifw_trace("bind_shell_client: client=%08x pid=%d uid=%d gid=%d",
427 (int)client, (int)pid, (int)uid, (int)gid);
429 uclient->pid = (int)pid;
430 /* get applicationId from AppCore(AUL) */
431 if (aul_app_get_appid_bypid(uclient->pid, uclient->appid, ICO_IVI_APPID_LENGTH)
433 uifw_trace("bind_shell_client: client=%08x pid=%d appid=<%s>",
434 (int)client, uclient->pid, uclient->appid);
437 /* client dose not exist in AppCore, search Linux process table */
438 uifw_trace("bind_shell_client: pid=%d dose not exist in AppCore(AUL)",
441 memset(uclient->appid, 0, ICO_IVI_APPID_LENGTH);
442 snprintf(procpath, sizeof(procpath)-1, "/proc/%d/cmdline", uclient->pid);
443 fd = open(procpath, O_RDONLY);
445 size = read(fd, procpath, sizeof(procpath));
446 for (; size > 0; size--) {
447 if (procpath[size-1]) break;
450 /* get program base name */
452 for (j = 0; j < size; j++) {
453 if (procpath[j] == 0) break;
454 if (procpath[j] == '/') i = j + 1;
457 for (; i < size; i++) {
458 uclient->appid[j] = procpath[i];
459 if ((uclient->appid[j] == 0) ||
460 (j >= (ICO_IVI_APPID_LENGTH-1))) break;
463 /* search application number in apprication start option */
464 if ((uclient->appid[j] == 0) && (j < (ICO_IVI_APPID_LENGTH-2))) {
465 for (; i < size; i++) {
466 if ((procpath[i] == 0) &&
467 (procpath[i+1] == '@')) {
468 strncpy(&uclient->appid[j], &procpath[i+1],
469 ICO_IVI_APPID_LENGTH - j - 2);
476 if (uclient->appid[0]) {
477 uifw_trace("bind_shell_client: client=%08x pid=%d appid=<%s> from "
478 "Process table", (int)client, uclient->pid, uclient->appid);
481 uifw_trace("bind_shell_client: pid=%d dose not exist in Process table",
483 sprintf(uclient->appid, "?%d?", uclient->pid);
487 wl_list_for_each (lattr, &_ico_win_mgr->client_attr_list, link) {
488 if (strcmp(lattr->appid, uclient->appid) == 0) {
489 for (i = 0; i < MAX_CLIENT_ATTR; i++) {
490 switch (lattr->attrs[i].attr) {
491 case ICO_WINDOW_MGR_CLIENT_ATTR_NOCONFIGURE:
492 uclient->noconfigure = lattr->attrs[i].value;
493 ivi_shell_set_client_attr(uclient->client,
494 ICO_CLEINT_ATTR_NOCONFIGURE,
495 lattr->attrs[i].value);
496 uifw_trace("bind_shell_client: set to ivi-shell");
507 uifw_trace("bind_shell_client: client=%08x pid dose not exist", (int)client);
509 uifw_trace("bind_shell_client: Leave");
512 /*--------------------------------------------------------------------------*/
514 * @brief unbind_shell_client: unbind ico_ivi_shell from client
516 * @param[in] client Wayland client
519 /*--------------------------------------------------------------------------*/
521 unbind_shell_client(struct wl_client *client)
523 struct uifw_client *uclient;
525 uifw_trace("unbind_shell_client: Enter(client=%08x)", (int)client);
527 uclient = find_client_from_client(client);
529 /* Client exist, Destory client management table */
530 wl_list_remove(&uclient->link);
533 uifw_trace("unbind_shell_client: Leave");
536 /*--------------------------------------------------------------------------*/
538 * @brief ico_get_animation_type: convert animation name to type value
540 * @param[in] animation animation name
541 * @return animation type value
543 /*--------------------------------------------------------------------------*/
545 ico_get_animation_type(const char *animation)
547 int anima = ICO_WINDOW_MGR_ANIMATION_NONE;
549 if (strcasecmp(animation, "none") == 0) {
550 return ICO_WINDOW_MGR_ANIMATION_NONE;
553 if (win_mgr_hook_animation) {
554 anima = (*win_mgr_hook_animation)(ICO_WINDOW_MGR_ANIMATION_TYPE, (void *)animation);
557 anima = ICO_WINDOW_MGR_ANIMATION_NONE;
562 /*--------------------------------------------------------------------------*/
564 * @brief client_register_surface: create UIFW surface
566 * @param[in] client Wayland client
567 * @param[in] resource client resource
568 * @param[in] surface Weston surface
569 * @param[in] shsurf shell surface
572 /*--------------------------------------------------------------------------*/
574 client_register_surface(struct wl_client *client, struct wl_resource *resource,
575 struct weston_surface *surface, struct shell_surface *shsurf)
577 struct uifw_win_surface *us;
578 struct uifw_win_surface *phash;
579 struct uifw_win_surface *bhash;
580 struct uifw_client_attr *lattr;
584 uifw_trace("client_register_surface: Enter(surf=%08x,client=%08x,res=%08x)",
585 (int)surface, (int)client, (int)resource);
587 /* check new surface */
588 if (find_uifw_win_surface_by_ws(surface)) {
589 /* surface exist, NOP */
590 uifw_trace("client_register_surface: Leave(Already Exist)");
594 /* create UIFW surface management table */
595 us = malloc(sizeof(struct uifw_win_surface));
597 uifw_error("client_register_surface: No Memory");
601 memset(us, 0, sizeof(struct uifw_win_surface));
603 us->id = generate_id();
604 us->surface = surface;
606 wl_list_init(&us->animation.animation.link);
607 us->animation.type = ico_get_animation_type(ivi_shell_default_animation(NULL, NULL));
608 us->animation.type_next = us->animation.type;
610 if (_ico_win_mgr->num_manager <= 0) {
611 uifw_trace("client_register_surface: No Manager, Force visible");
612 ivi_shell_set_visible(shsurf, 1); /* NOT exist HomeScreen */
615 uifw_trace("client_register_surface: Manager exist, Not visible");
616 ivi_shell_set_visible(shsurf, -1); /* Exist HomeScreen */
620 us->uclient = find_client_from_client(client);
622 /* client not exist, create client management table */
623 uifw_trace("client_register_surface: Create Client");
624 bind_shell_client(client);
625 us->uclient = find_client_from_client(client);
627 uifw_error("client_register_surface: No Memory");
631 wl_list_insert(&_ico_win_mgr->surface_list, &us->link);
633 /* make surface id hash table */
634 hash = MAKE_IDHASH(us->id);
635 phash = _ico_win_mgr->idhash[hash];
639 phash = phash->next_idhash;
642 bhash->next_idhash = us;
645 _ico_win_mgr->idhash[hash] = us;
648 /* make weston surface hash table */
649 hash = MAKE_WSHASH(us->surface);
650 phash = _ico_win_mgr->wshash[hash];
654 phash = phash->next_wshash;
657 bhash->next_wshash = us;
660 _ico_win_mgr->wshash[hash] = us;
662 /* set default layer id */
663 ivi_shell_set_layer(shsurf, 0);
665 /* set client attribute */
666 wl_list_for_each (lattr, &_ico_win_mgr->client_attr_list, link) {
667 if (strcmp(lattr->appid, us->uclient->appid) == 0) {
668 for (i = 0; i < MAX_CLIENT_ATTR; i++) {
669 switch (lattr->attrs[i].attr) {
670 case ICO_WINDOW_MGR_CLIENT_ATTR_NOCONFIGURE:
671 us->uclient->noconfigure = lattr->attrs[i].value;
672 ivi_shell_set_client_attr(us->uclient->client,
673 ICO_CLEINT_ATTR_NOCONFIGURE,
674 lattr->attrs[i].value);
675 uifw_trace("client_register_surface: set attr(%d=%d) to %08x",
676 lattr->attrs[i].attr, lattr->attrs[i].value, us->id);
686 /* send event to manager */
687 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_CREATED,
688 us->id, us->uclient->appid, us->uclient->pid, 0,0,0,0,0);
690 if (win_mgr_hook_create) {
691 /* call surface create hook for other plugin */
692 (void) (*win_mgr_hook_create)(client, surface, us->id, us->uclient->appid);
694 uifw_trace("client_register_surface: Leave(surfaceId=%08x)", us->id);
697 /*--------------------------------------------------------------------------*/
699 * @brief win_mgr_map_surface: map surface
701 * @param[in] surface Weston surface
702 * @param[in] width surface width
703 * @param[in] height surface height
704 * @param[in] sx X coordinate on screen
705 * @param[in] sy Y coordinate on screen
708 /*--------------------------------------------------------------------------*/
710 win_mgr_map_surface(struct weston_surface *surface, int32_t *width, int32_t *height,
711 int32_t *sx, int32_t *sy)
713 struct uifw_win_surface *usurf;
715 uifw_trace("win_mgr_map_surface: Enter(%08x, x/y=%d/%d w/h=%d/%d)",
716 (int)surface, *sx, *sy, *width, *height);
718 usurf = find_uifw_win_surface_by_ws(surface);
721 uifw_trace("win_mgr_map_surface: surf=%08x w/h=%d/%d vis=%d",
722 usurf->id, usurf->width, usurf->height,
723 ivi_shell_is_visible(usurf->shsurf));
725 if ((usurf->width > 0) && (usurf->height > 0)) {
726 uifw_trace("win_mgr_map_surface: HomeScreen registed, PositionSize"
727 "(surf=%08x x/y=%d/%d w/h=%d/%d vis=%d",
728 usurf->id, usurf->x, usurf->y, usurf->width, usurf->height,
729 ivi_shell_is_visible(usurf->shsurf));
730 *width = usurf->width;
731 *height = usurf->height;
732 surface->geometry.x = usurf->x;
733 surface->geometry.y = usurf->y;
736 uifw_trace("win_mgr_map_surface: HomeScreen not regist Surface, "
737 "Change PositionSize(surf=%08x x/y=%d/%d w/h=%d/%d)",
738 usurf->id, *sx, *sy, *width, *height);
739 usurf->width = *width;
740 usurf->height = *height;
743 if (usurf->x < 0) usurf->x = 0;
744 if (usurf->y < 0) usurf->y = 0;
746 if (_ico_win_mgr->num_manager > 0) {
747 /* HomeScreen exist, coodinate set by HomeScreen */
748 surface->geometry.x = 0;
749 surface->geometry.y = 0;
751 /* change surface size, because HomeScreen change surface size */
754 uifw_trace("win_mgr_map_surface: Change size and position");
757 uifw_trace("win_mgr_map_surface: Np HomeScreen, chaneg to Visible");
758 ivi_shell_set_visible(usurf->shsurf, 1);
761 ivi_shell_set_positionsize(usurf->shsurf,
762 usurf->x, usurf->y, usurf->width, usurf->height);
763 uifw_trace("win_mgr_map_surface: Leave");
766 uifw_trace("win_mgr_map_surface: Leave(No Window Manager Surface)");
770 /*--------------------------------------------------------------------------*/
772 * @briefdwi uifw_set_user: set user id (for RemoteUI)
774 * @param[in] client Weyland client
775 * @param[in] resource resource of request
776 * @param[in] pid client process id
777 * @param[in] appid application id
780 /*--------------------------------------------------------------------------*/
782 uifw_set_user(struct wl_client *client, struct wl_resource *resource,
783 int pid, const char *appid)
785 struct uifw_client *uclient;
787 uifw_trace("uifw_set_user: Enter(client=%08x pid=%d appid=%s)",
788 (int)client, pid, appid);
790 uclient = find_client_from_client(client);
793 memset(uclient->appid, 0, ICO_IVI_APPID_LENGTH);
794 strncpy(uclient->appid, appid, ICO_IVI_APPID_LENGTH-1);
795 uclient->resource = resource;
796 uifw_trace("uifw_set_user: Leave(Client Exist, change PID/AppId)");
800 uclient = (struct uifw_client *)malloc(sizeof(struct uifw_client));
802 uifw_trace("uifw_set_user: Leave(Error, No Memory)");
806 memset(uclient, 0, sizeof(struct uifw_client));
807 uclient->client = client;
809 memset(uclient->appid, 0, ICO_IVI_APPID_LENGTH);
810 strncpy(uclient->appid, appid, ICO_IVI_APPID_LENGTH-1);
811 uclient->resource = resource;
813 wl_list_insert(&_ico_win_mgr->client_list, &uclient->link);
815 if (win_mgr_hook_set_user) {
816 (void) (*win_mgr_hook_set_user) (client, uclient->appid);
818 uifw_trace("uifw_set_user: Leave");
821 /*--------------------------------------------------------------------------*/
823 * @brief uifw_set_eventcb: set event callback flag for HomeScreen
825 * @param[in] client Weyland client
826 * @param[in] resource resource of request
827 * @param[in] eventcb event callback flag(1=callback, 0=no callback)
830 /*--------------------------------------------------------------------------*/
832 uifw_set_eventcb(struct wl_client *client, struct wl_resource *resource, int eventcb)
834 struct uifw_manager* mgr;
835 struct uifw_win_surface *usurf;
836 struct uifw_client *uclient;
838 uifw_trace("uifw_set_eventcb: Enter client=%08x eventcb=%d",
839 (int)client, eventcb);
841 uclient = find_client_from_client(client);
843 uclient->manager = eventcb;
846 /* client set to manager */
847 _ico_win_mgr->num_manager = 0;
848 wl_list_for_each (mgr, &_ico_win_mgr->manager_list, link) {
849 if (mgr->resource == resource) {
850 if (mgr->eventcb != eventcb) {
851 uifw_trace("uifw_set_eventcb: Event Callback %d=>%d",
852 mgr->eventcb, eventcb);
853 mgr->eventcb = eventcb;
856 wl_list_for_each (usurf, &_ico_win_mgr->surface_list, link) {
857 /* send window create event to manager */
858 uifw_trace("uifw_set_eventcb: Send manager(%08x) WINDOW_CREATED"
859 "(surf=%08x,pid=%d,appid=%s)", (int)resource, usurf->id,
860 usurf->uclient->pid, usurf->uclient->appid);
861 ico_window_mgr_send_window_created(resource,
862 usurf->id, usurf->uclient->pid, usurf->uclient->appid);
868 _ico_win_mgr->num_manager++;
871 uifw_trace("uifw_set_eventcb: Leave(managers=%d)", _ico_win_mgr->num_manager);
874 /*--------------------------------------------------------------------------*/
876 * @brief uifw_set_window_layer: set layer id to surface
878 * @param[in] client Weyland client
879 * @param[in] resource resource of request
880 * @param[in] surfaceid UIFW surface id
881 * @param[in] layer layer id
884 /*--------------------------------------------------------------------------*/
886 uifw_set_window_layer(struct wl_client *client, struct wl_resource *resource,
887 uint32_t surfaceid, int32_t layer)
889 uifw_trace("uifw_set_window_layer: Enter res=%08x surfaceid=%08x layer=%d",
890 (int)resource, surfaceid, layer);
892 struct uifw_win_surface *usurf = find_uifw_win_surface_by_id(surfaceid);
895 uifw_trace("uifw_set_window_layer: Leave(No Surface(id=%08x)", surfaceid);
898 else if (usurf->layer != layer) {
899 usurf->layer = layer;
900 uifw_trace("uifw_set_window_layer: Set Layer(%d) to Shell Surface", layer);
901 ivi_shell_set_layer(usurf->shsurf, layer);
903 win_mgr_surface_change(usurf->surface, 1, 1);
905 uifw_trace("uifw_set_window_layer: Leave");
908 /*--------------------------------------------------------------------------*/
910 * @brief uifw_set_weston_surface: set weston surface from UIFW surface
912 * @param[in] usurf UIFW surface
915 /*--------------------------------------------------------------------------*/
917 uifw_set_weston_surface(struct uifw_win_surface *usurf)
919 struct weston_surface *es = usurf->surface;
920 int width = usurf->width;
921 int height = usurf->height;
925 if ((es != NULL) && (es->buffer != NULL)) {
926 if (usurf->width > es->buffer->width) {
927 width = es->buffer->width;
928 x += (usurf->width - es->buffer->width)/2;
930 if (usurf->height > es->buffer->height) {
931 height = es->buffer->height;
932 y += (usurf->height - es->buffer->height)/2;
935 ivi_shell_set_positionsize(usurf->shsurf,
936 usurf->x, usurf->y, usurf->width, usurf->height);
937 uifw_trace("uifw_set_weston_surface: w/h=%d/%d->%d/%d x/y=%d/%d->%d/%d",
938 usurf->width, usurf->height, width, height, usurf->x, usurf->y, x, y);
939 ivi_shell_surface_configure(usurf->shsurf, x, y, width, height);
942 /*--------------------------------------------------------------------------*/
944 * @brief uifw_set_positionsize: set surface position and size
946 * @param[in] client Weyland client
947 * @param[in] resource resource of request
948 * @param[in] surfaceid UIFW surface id
949 * @param[in] x X coordinate on screen(if bigger than 16383, no change)
950 * @param[in] y Y coordinate on screen(if bigger than 16383, no change)
951 * @param[in] width surface width(if bigger than 16383, no change)
952 * @param[in] height surface height(if bigger than 16383, no change)
955 /*--------------------------------------------------------------------------*/
957 uifw_set_positionsize(struct wl_client *client, struct wl_resource *resource,
959 int32_t x, int32_t y, int32_t width, int32_t height)
961 struct uifw_client *uclient;
963 uifw_trace("uifw_set_positionsize: Enter res=%08x surf=%08x x/y/w/h=%d/%d/%d/%d",
964 (int)resource, surfaceid, x, y, width, height);
966 struct uifw_win_surface* usurf = find_uifw_win_surface_by_id(surfaceid);
968 if (usurf && (usurf->surface)) {
969 /* weston surface exist */
970 struct weston_surface *es = usurf->surface;
972 /* if x,y,width,height bigger then ICO_IVI_MAX_COORDINATE, no change */
973 if (x > ICO_IVI_MAX_COORDINATE) x = usurf->x;
974 if (y > ICO_IVI_MAX_COORDINATE) y = usurf->y;
975 if (width > ICO_IVI_MAX_COORDINATE) width = usurf->width;
976 if (height > ICO_IVI_MAX_COORDINATE) height = usurf->height;
978 /* check animation */
979 if ((usurf->animation.type != ICO_WINDOW_MGR_ANIMATION_NONE) &&
980 (usurf->animation.state != ICO_WINDOW_MGR_ANIMATION_STATE_NONE) &&
981 (win_mgr_hook_animation != NULL) &&
982 (x == usurf->x) && (y == usurf->y) &&
983 (width == usurf->width) && (height == usurf->height)) {
984 uifw_trace("uifw_set_positionsize: Leave(same position size at animation)");
988 uclient = find_client_from_client(client);
990 if (! uclient->manager) uclient = NULL;
993 if ((usurf->width > 0) && (usurf->height > 0)) {
994 win_mgr_surface_change_mgr(es, x, y, width, height);
995 uifw_trace("uifw_set_positionsize: Leave(Request from App)");
999 uifw_trace("uifw_set_positionsize: Initial Position/Size visible=%d",
1000 ivi_shell_is_visible(usurf->shsurf));
1001 /* Initiale position is (0,0) */
1006 uifw_trace("uifw_set_positionsize: Old geometry x/y=%d/%d,w/h=%d/%d",
1007 (int)es->geometry.x, (int)es->geometry.y,
1008 (int)es->geometry.width, (int)es->geometry.height);
1012 usurf->width = width;
1013 usurf->height = height;
1014 ivi_shell_set_positionsize(usurf->shsurf, x, y, width, height);
1015 if (_ico_win_mgr->num_manager <= 0) {
1016 /* no manager(HomeScreen), set geometory */
1020 if ((es->output) && (es->buffer) &&
1021 (es->geometry.width > 0) && (es->geometry.height > 0)) {
1022 uifw_trace("uifw_set_positionsize: Fixed Geometry, Change(Vis=%d)",
1023 ivi_shell_is_visible(usurf->shsurf));
1024 uifw_set_weston_surface(usurf);
1025 weston_surface_damage_below(es);
1026 weston_surface_damage(es);
1027 weston_compositor_schedule_repaint(_ico_win_mgr->compositor);
1029 win_mgr_surface_change(es, 0, 1);
1031 uifw_trace("uifw_set_positionsize: Leave(OK,output=%x)", (int)es->output);
1034 uifw_trace("uifw_set_positionsize: Leave(surf=%08x NOT Found)", surfaceid);
1038 /*--------------------------------------------------------------------------*/
1040 * @brief uifw_set_visible: surface visible/raise control
1042 * @param[in] client Weyland client
1043 * @param[in] resource resource of request
1044 * @param[in] surfaceid UIFW surface id
1045 * @param[in] visible visible(1=show/0=hide/other=no change)
1046 * @param[in] raise raise(1=raise/0=lower/other=no change)
1049 /*--------------------------------------------------------------------------*/
1051 uifw_set_visible(struct wl_client *client, struct wl_resource *resource,
1052 uint32_t surfaceid, int32_t visible, int32_t raise)
1054 struct uifw_win_surface* usurf;
1055 struct uifw_client *uclient;
1058 uifw_trace("uifw_set_visible: Enter(surf=%08x,%d,%d)", surfaceid, visible, raise);
1060 uclient = find_client_from_client(client);
1062 if (! uclient->manager) {
1063 uifw_trace("uifw_set_visible: Request from App(%s), not Manager",
1068 uifw_trace("uifw_set_visible: Request from Manager(%s)", uclient->appid);
1072 uifw_trace("uifw_set_visible: Request from Unknown App, not Manager");
1075 usurf = find_uifw_win_surface_by_id(surfaceid);
1077 if ((! usurf) || (! usurf->surface)) {
1078 uifw_trace("uifw_set_visible: Leave(Surface Not Exist)");
1082 if ((visible == ICO_WINDOW_MGR_VISIBLE_SHOW) ||
1083 (visible == ICO_WINDOW_MGR_VISIBLE_SHOW_WO_ANIMATION)) {
1084 if ((usurf->width <= 0) || (usurf->height <= 0)) {
1085 /* not declare surface geometry, initialize */
1086 usurf->width = usurf->surface->geometry.width;
1087 usurf->height = usurf->surface->geometry.height;
1088 uifw_trace("uifw_set_visible: Set w/h=%d/%d", usurf->width, usurf->height);
1090 if (! ivi_shell_is_visible(usurf->shsurf)) {
1092 /* manager exist, change to visible */
1093 ivi_shell_set_visible(usurf->shsurf, 1);
1095 uifw_trace("uifw_set_visible: Change to Visible");
1097 ivi_shell_set_toplevel(usurf->shsurf);
1099 /* Weston surface configure */
1100 uifw_trace("uifw_set_visible: Visible to Weston WSurf=%08x,%d/%d/%d/%d",
1101 (int)usurf->surface, usurf->x, usurf->y,
1102 usurf->width, usurf->height);
1103 uifw_set_weston_surface(usurf);
1104 ivi_shell_set_surface_type(usurf->shsurf);
1106 if ((visible == ICO_WINDOW_MGR_VISIBLE_SHOW) &&
1107 (usurf->animation.type != ICO_WINDOW_MGR_ANIMATION_NONE) &&
1108 (win_mgr_hook_animation != NULL)) {
1109 animation = (*win_mgr_hook_animation)(ICO_WINDOW_MGR_ANIMATION_OPIN,
1113 else if ((raise != ICO_WINDOW_MGR_RAISE_LOWER) &&
1114 (raise != ICO_WINDOW_MGR_RAISE_RAISE)) {
1115 uifw_trace("uifw_set_visible: Leave(No Change)");
1119 else if ((visible == ICO_WINDOW_MGR_VISIBLE_HIDE) ||
1120 (visible == ICO_WINDOW_MGR_VISIBLE_HIDE_WO_ANIMATION)) {
1122 if (ivi_shell_is_visible(usurf->shsurf)) {
1124 /* Weston surface configure */
1125 uifw_set_weston_surface(usurf);
1127 animation = ICO_WINDOW_MGR_ANIMATION_RET_ANIMA;
1128 if ((visible == ICO_WINDOW_MGR_VISIBLE_HIDE) &&
1129 (usurf->animation.type > 0) &&
1130 (win_mgr_hook_animation != NULL)) {
1131 animation = (*win_mgr_hook_animation)(ICO_WINDOW_MGR_ANIMATION_OPOUT,
1134 if (animation != ICO_WINDOW_MGR_ANIMATION_RET_ANIMASHOW) {
1135 ivi_shell_set_visible(usurf->shsurf, 0);
1136 uifw_trace("uifw_set_visible: Change to UnVisible");
1139 uifw_trace("uifw_set_visible: UnVisible but animation");
1142 else if ((raise != ICO_WINDOW_MGR_RAISE_LOWER) &&
1143 (raise != ICO_WINDOW_MGR_RAISE_RAISE)) {
1144 uifw_trace("uifw_set_visible: Leave(No Change)");
1148 else if ((raise != ICO_WINDOW_MGR_RAISE_LOWER) &&
1149 (raise != ICO_WINDOW_MGR_RAISE_RAISE)) {
1150 uifw_trace("uifw_set_visible: Leave(No Change)");
1155 if ((raise == ICO_WINDOW_MGR_RAISE_LOWER) || (raise != ICO_WINDOW_MGR_RAISE_RAISE)) {
1156 ivi_shell_set_raise(usurf->shsurf, raise);
1159 if ((usurf->surface) && (usurf->surface->buffer) && (usurf->surface->output)) {
1160 weston_surface_damage_below(usurf->surface);
1161 weston_surface_damage(usurf->surface);
1162 weston_compositor_schedule_repaint(_ico_win_mgr->compositor);
1164 /* send event(VISIBLE) to manager */
1165 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_VISIBLE,
1167 (visible == ICO_WINDOW_MGR_VISIBLE_SHOW) ||
1168 (visible == ICO_WINDOW_MGR_VISIBLE_SHOW_WO_ANIMATION) ? 1 :
1169 ((visible == ICO_WINDOW_MGR_VISIBLE_HIDE) ||
1170 (visible == ICO_WINDOW_MGR_VISIBLE_HIDE_WO_ANIMATION) ? 0 :
1171 ICO_WINDOW_MGR_VISIBLE_NOCHANGE),
1172 raise, uclient ? 0 : 1, 0,0,0);
1174 uifw_trace("uifw_set_visible: Leave(OK)");
1177 /*--------------------------------------------------------------------------*/
1179 * @brief uifw_set_animation: set animation of surface visible/unvisible
1181 * @param[in] client Weyland client
1182 * @param[in] resource resource of request
1183 * @param[in] surfaceid UIFW surface id
1184 * @param[in] change change type(show/hide,reeize,move)
1185 * @param[in] anmation animation name
1188 /*--------------------------------------------------------------------------*/
1190 uifw_set_animation(struct wl_client *client, struct wl_resource *resource,
1191 uint32_t surfaceid, int32_t change, const char *animation)
1193 struct uifw_win_surface* usurf = find_uifw_win_surface_by_id(surfaceid);
1195 uifw_trace("uifw_set_transition: Enter(surf=%08x, change=%d, animation=%s)",
1196 surfaceid, change, animation);
1199 if (change != ICO_WINDOW_MGR_ANIMATION_CHANGE_VISIBLE) {
1200 uifw_trace("uifw_set_animation: Leave(change type(%d9 not support)", change);
1203 usurf->animation.type_next = ico_get_animation_type(animation);
1204 uifw_trace("uifw_set_animation: Leave(OK) type=%d", usurf->animation.type_next);
1205 if (usurf->animation.state == ICO_WINDOW_MGR_ANIMATION_STATE_NONE) {
1206 usurf->animation.type = usurf->animation.type_next;
1211 uifw_trace("uifw_set_animation: Leave(Surface(%08x) Not exist)", surfaceid);
1215 /*--------------------------------------------------------------------------*/
1217 * @brief uifw_set_active: set active surface
1219 * @param[in] client Weyland client
1220 * @param[in] resource resource of request
1221 * @param[in] surfaceid UIFW surface id
1222 * @param[in] target target device
1225 /*--------------------------------------------------------------------------*/
1227 uifw_set_active(struct wl_client *client, struct wl_resource *resource,
1228 uint32_t surfaceid, uint32_t target)
1230 struct uifw_win_surface* usurf;
1232 uifw_trace("uifw_set_active: Enter(surf=%08x,target=%x)", surfaceid, target);
1234 if ((surfaceid > 0) &&
1235 ((target & (ICO_IVI_SHELL_ACTIVE_POINTER|ICO_IVI_SHELL_ACTIVE_KEYBOARD)) != 0)) {
1236 usurf = find_uifw_win_surface_by_id(surfaceid);
1242 switch (target & (ICO_IVI_SHELL_ACTIVE_POINTER|ICO_IVI_SHELL_ACTIVE_KEYBOARD)) {
1243 case ICO_IVI_SHELL_ACTIVE_POINTER:
1244 if (usurf != _ico_win_mgr->active_pointer_surface) {
1245 if (_ico_win_mgr->active_pointer_surface) {
1246 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
1247 _ico_win_mgr->active_pointer_surface->id, NULL,
1248 (_ico_win_mgr->active_keyboard_surface ==
1249 _ico_win_mgr->active_pointer_surface) ?
1250 ICO_IVI_SHELL_ACTIVE_KEYBOARD :
1251 ICO_IVI_SHELL_ACTIVE_NONE,
1254 _ico_win_mgr->active_pointer_surface = usurf;
1255 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
1257 ICO_IVI_SHELL_ACTIVE_POINTER |
1258 (_ico_win_mgr->active_keyboard_surface == usurf) ?
1259 ICO_IVI_SHELL_ACTIVE_KEYBOARD : 0,
1261 ivi_shell_set_active(usurf->shsurf, ICO_IVI_SHELL_ACTIVE_POINTER);
1264 case ICO_IVI_SHELL_ACTIVE_KEYBOARD:
1265 if (usurf != _ico_win_mgr->active_keyboard_surface) {
1266 if (_ico_win_mgr->active_keyboard_surface) {
1267 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
1268 _ico_win_mgr->active_keyboard_surface->id, NULL,
1269 (_ico_win_mgr->active_keyboard_surface ==
1270 _ico_win_mgr->active_pointer_surface) ?
1271 ICO_IVI_SHELL_ACTIVE_POINTER :
1272 ICO_IVI_SHELL_ACTIVE_NONE,
1275 _ico_win_mgr->active_keyboard_surface = usurf;
1276 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
1278 ICO_IVI_SHELL_ACTIVE_KEYBOARD |
1279 (_ico_win_mgr->active_pointer_surface == usurf) ?
1280 ICO_IVI_SHELL_ACTIVE_POINTER : 0,
1282 ivi_shell_set_active(usurf->shsurf, ICO_IVI_SHELL_ACTIVE_KEYBOARD);
1286 if ((usurf != _ico_win_mgr->active_pointer_surface) ||
1287 (usurf != _ico_win_mgr->active_keyboard_surface)) {
1288 if (_ico_win_mgr->active_pointer_surface) {
1289 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
1290 _ico_win_mgr->active_pointer_surface->id,
1291 NULL, ICO_IVI_SHELL_ACTIVE_NONE,
1293 if (_ico_win_mgr->active_keyboard_surface ==
1294 _ico_win_mgr->active_pointer_surface) {
1295 _ico_win_mgr->active_keyboard_surface = NULL;
1298 if (_ico_win_mgr->active_keyboard_surface) {
1299 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
1300 _ico_win_mgr->active_keyboard_surface->id,
1301 NULL, ICO_IVI_SHELL_ACTIVE_NONE,
1304 _ico_win_mgr->active_pointer_surface = usurf;
1305 _ico_win_mgr->active_keyboard_surface = usurf;
1306 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
1308 ICO_IVI_SHELL_ACTIVE_POINTER |
1309 ICO_IVI_SHELL_ACTIVE_KEYBOARD,
1311 ivi_shell_set_active(usurf->shsurf,
1312 ICO_IVI_SHELL_ACTIVE_POINTER |
1313 ICO_IVI_SHELL_ACTIVE_KEYBOARD);
1317 uifw_trace("uifw_set_active: Leave(Change Active)");
1320 ivi_shell_set_active(NULL, target);
1321 uifw_trace("uifw_set_active: Leave(Reset active surface)");
1325 /*--------------------------------------------------------------------------*/
1327 * @brief uifw_set_layer_visible: layer visible control
1329 * @param[in] client Weyland client
1330 * @param[in] resource resource of request
1331 * @param[in] layer layer id
1332 * @param[in] visible visible(1=show/0=hide)
1335 /*--------------------------------------------------------------------------*/
1337 uifw_set_layer_visible(struct wl_client *client, struct wl_resource *resource,
1338 int32_t layer, int32_t visible)
1340 uifw_trace("uifw_set_layer_visible: Enter(layer=%d, visilbe=%d)", layer, visible);
1342 ivi_shell_set_layer_visible(layer, visible);
1344 uifw_trace("uifw_set_layer_visible: Leave");
1347 /*--------------------------------------------------------------------------*/
1349 * @brief uifw_set_client_attr: set client application attribute
1351 * @param[in] client Weyland client
1352 * @param[in] resource resource of request
1353 * @param[in] appid client application name
1354 * @param[in] attr attribute
1355 * @param[in] value attribute value
1358 /*--------------------------------------------------------------------------*/
1360 uifw_set_client_attr(struct wl_client *client, struct wl_resource *resource,
1361 const char *appid, int32_t attr, int32_t value)
1363 struct uifw_client_attr *lattr;
1364 struct uifw_client *uclient;
1367 uifw_trace("uifw_set_client_attr: Enter(appid=%s, attr=%d, value=%d)",
1368 appid, attr, value);
1371 wl_list_for_each (lattr, &_ico_win_mgr->client_attr_list, link) {
1372 if (strcmp(lattr->appid, appid) == 0) {
1373 for (idx = 0; idx < MAX_CLIENT_ATTR; idx++) {
1374 if (lattr->attrs[idx].attr == attr) {
1375 lattr->attrs[idx].value = value;
1379 if ((freeidx < 0) && (lattr->attrs[idx].attr < 0)) {
1383 if ((idx >= MAX_CLIENT_ATTR) && (freeidx >= 0)) {
1384 lattr->attrs[freeidx].attr = attr;
1385 lattr->attrs[freeidx].value = value;
1394 lattr = malloc(sizeof(struct uifw_client_attr));
1396 memset(lattr, 0, sizeof(struct uifw_client_attr));
1397 strncpy(lattr->appid, appid, ICO_IVI_APPID_LENGTH-1);
1398 for (idx = 1; idx < MAX_CLIENT_ATTR; idx++) {
1399 lattr->attrs[idx].attr = -1;
1401 lattr->attrs[0].attr = attr;
1402 lattr->attrs[0].value = value;
1403 wl_list_insert(&_ico_win_mgr->client_attr_list, &lattr->link);
1407 wl_list_for_each (uclient, &_ico_win_mgr->client_list, link) {
1408 if (strcmp(uclient->appid, appid) == 0) {
1410 case ICO_WINDOW_MGR_CLIENT_ATTR_NOCONFIGURE:
1411 uclient->noconfigure = value;
1412 ivi_shell_set_client_attr(uclient->client,
1413 ICO_CLEINT_ATTR_NOCONFIGURE, value);
1414 uifw_trace("uifw_set_client_attr: set to ivi-shell");
1417 uifw_trace("uifw_set_client_attr: Unknown attr(%d)", attr);
1423 uifw_trace("uifw_set_client_attr: Leave");
1426 /*--------------------------------------------------------------------------*/
1428 * @brief win_mgr_surface_change_mgr: surface chagen from manager(HomeScreen)
1430 * @param[in] surface Weston surface
1431 * @param[in] x X coordinate on screen
1432 * @param[in] y Y coordinate on screen
1433 * @param[in] width surface width
1434 * @param[in] height surface height
1435 * @return number of managers
1436 * @retval > 0 number of managers
1437 * @retval 0 manager not exist
1439 /*--------------------------------------------------------------------------*/
1441 win_mgr_surface_change_mgr(struct weston_surface *surface,
1442 const int x, const int y, const int width, const int height)
1445 struct uifw_win_surface *usurf;
1447 uifw_trace("win_mgr_surface_change_mgr: Enter(%08x,x/y=%d/%d,w/h=%d/%d)",
1448 (int)surface, x, y, width, height);
1450 usurf = find_uifw_win_surface_by_ws(surface);
1452 uifw_trace("win_mgr_surface_change_mgr: Leave(Not Exist)");
1456 num_mgr = ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_CONFIGURE,
1457 usurf->id, usurf->uclient->appid, usurf->layer,
1458 x, y, width, height, 1);
1460 uifw_trace("win_mgr_surface_change_mgr: Leave(%d)", num_mgr);
1464 /*--------------------------------------------------------------------------*/
1466 * @brief win_mgr_surface_change: surface change
1468 * @param[in] surface Weston surface
1469 * @param[in] to destination(0=Client&Manager,1=Client,-1=Manager)
1470 * @param[in] manager request from manager(0=Client,1=Manager)
1473 /*--------------------------------------------------------------------------*/
1475 win_mgr_surface_change(struct weston_surface *surface, const int to, const int manager)
1477 struct uifw_win_surface *usurf;
1479 uifw_trace("win_mgr_surface_change: Enter(%08x,%d,%d)", (int)surface, to, manager);
1482 usurf = find_uifw_win_surface_by_ws(surface);
1484 uifw_trace("win_mgr_surface_change: Leave(Not Exist)");
1488 /* send wayland event to client */
1489 if ((to >= 0) && (usurf->shsurf != NULL) && (manager !=0)) {
1490 uifw_trace("win_mgr_surface_change: Send SHELL_SURFACE_CONFIGURE(%08x,w/h=%d/%d)",
1491 usurf->id, usurf->width, usurf->height);
1492 ivi_shell_send_configure(usurf->shsurf, usurf->id,
1493 (WL_SHELL_SURFACE_RESIZE_RIGHT |
1494 WL_SHELL_SURFACE_RESIZE_BOTTOM),
1495 usurf->width, usurf->height);
1498 /* send manager event to HomeScreen */
1500 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_CONFIGURE,
1501 usurf->id, usurf->uclient->appid, usurf->layer,
1502 usurf->x, usurf->y, usurf->width, usurf->height,
1503 (manager != 0) ? 0 : 1);
1505 uifw_trace("win_mgr_surface_change: Leave(OK)");
1508 /*--------------------------------------------------------------------------*/
1510 * @brief win_mgr_surface_select: select surface by Bottun/Touch
1512 * @param[in] surface Weston surface
1515 /*--------------------------------------------------------------------------*/
1517 win_mgr_surface_select(struct weston_surface *surface)
1519 struct uifw_win_surface *usurf;
1521 uifw_trace("win_mgr_surface_select: Enter(%08x)", (int)surface);
1524 usurf = find_uifw_win_surface_by_ws(surface);
1526 uifw_trace("win_mgr_surface_select: Leave(Not Exist)");
1530 /* send active event to manager */
1531 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_ACTIVE,
1532 usurf->id, NULL, ICO_IVI_SHELL_ACTIVE_SELECTED, 0,0,0,0,0);
1534 uifw_trace("win_mgr_surface_select: Leave(OK)");
1537 /*--------------------------------------------------------------------------*/
1539 * @brief win_mgr_surface_destroy: surface destroy
1541 * @param[in] surface Weston surface
1544 /*--------------------------------------------------------------------------*/
1546 win_mgr_surface_destroy(struct weston_surface *surface)
1548 struct uifw_win_surface *usurf;
1549 struct uifw_win_surface *phash;
1550 struct uifw_win_surface *bhash;
1553 uifw_trace("win_mgr_surface_destroy: Enter(%08x)", (int)surface);
1555 usurf = find_uifw_win_surface_by_ws(surface);
1557 uifw_trace("win_mgr_surface_destroy: Leave(Not Exist)");
1561 /* destory animation extenson */
1562 if (win_mgr_hook_animation) {
1563 (*win_mgr_hook_animation)(ICO_WINDOW_MGR_ANIMATION_DESTROY, (void *)usurf);
1565 hash = MAKE_IDHASH(usurf->id);
1566 phash = _ico_win_mgr->idhash[hash];
1568 while ((phash) && (phash != usurf)) {
1570 phash = phash->next_idhash;
1573 bhash->next_idhash = usurf->next_idhash;
1576 _ico_win_mgr->idhash[hash] = usurf->next_idhash;
1579 hash = MAKE_WSHASH(usurf->surface);
1580 phash = _ico_win_mgr->wshash[hash];
1582 while ((phash) && (phash != usurf)) {
1584 phash = phash->next_wshash;
1587 bhash->next_wshash = usurf->next_wshash;
1590 _ico_win_mgr->wshash[hash] = usurf->next_wshash;
1593 wl_list_remove(&usurf->link);
1594 wl_list_init(&usurf->link);
1596 ico_win_mgr_send_to_mgr(ICO_WINDOW_MGR_WINDOW_DESTROYED,
1597 usurf->id, NULL, 0,0,0,0,0,0);
1599 hash = usurf->id & SURCAFE_ID_MASK;
1600 _ico_win_mgr->surfaceid_map[(hash - 1)/16] &= ~(1 << ((hash - 1) % 16));
1604 if (win_mgr_hook_destroy) {
1605 (void) (*win_mgr_hook_destroy) (surface);
1607 uifw_trace("win_mgr_surface_destroy: Leave(OK)");
1610 /*--------------------------------------------------------------------------*/
1612 * @brief bind_ico_win_mgr: bind Multi Window Manager from client
1614 * @param[in] client client
1615 * @param[in] data user data(unused)
1616 * @param[in] version protocol version(unused)
1617 * @param[in] id client object id
1620 /*--------------------------------------------------------------------------*/
1622 bind_ico_win_mgr(struct wl_client *client,
1623 void *data, uint32_t version, uint32_t id)
1625 struct wl_resource *add_resource;
1626 struct uifw_manager *nm;
1628 uifw_trace("bind_ico_win_mgr: Enter(client=%08x, id=%x)", (int)client, (int)id);
1630 add_resource = wl_client_add_object(client, &ico_window_mgr_interface,
1631 &ico_window_mgr_implementation, id, _ico_win_mgr);
1632 add_resource->destroy = unbind_ico_win_mgr;
1635 nm = (struct uifw_manager *)malloc(sizeof(struct uifw_manager));
1636 memset(nm, 0, sizeof(struct uifw_manager));
1637 nm->resource = add_resource;
1638 wl_list_insert(&_ico_win_mgr->manager_list, &nm->link);
1640 uifw_trace("bind_ico_win_mgr: Leave");
1643 /*--------------------------------------------------------------------------*/
1645 * @brief unbind_ico_win_mgr: unbind Multi Window Manager from client
1647 * @param[in] resource client resource
1650 /*--------------------------------------------------------------------------*/
1652 unbind_ico_win_mgr(struct wl_resource *resource)
1654 struct uifw_manager *mgr, *itmp;
1656 uifw_trace("unbind_ico_win_mgr: Enter");
1658 /* Remove manager from manager list */
1659 _ico_win_mgr->num_manager = 0;
1660 wl_list_for_each_safe (mgr, itmp, &_ico_win_mgr->manager_list, link) {
1661 if (mgr->resource == resource) {
1662 wl_list_remove(&mgr->link);
1667 _ico_win_mgr->num_manager++;
1673 uifw_trace("unbind_ico_win_mgr: Leave");
1676 /*--------------------------------------------------------------------------*/
1678 * @brief ico_winmgr_usurf_2_node: get surface nodeId
1680 * @param[in] surfaceid UIFW surface id
1682 * @retval >= 0 success(surface node id)
1683 * @retval < 0 error(surface id dose not exist)
1685 /*--------------------------------------------------------------------------*/
1687 ico_winmgr_usurf_2_node(const int surfaceid)
1689 /* currently support single ECU system */
1690 return(ICO_IVI_SURFACEID_2_NODEID(surfaceid));
1693 /*--------------------------------------------------------------------------*/
1695 * @brief ico_win_mgr_send_to_mgr: send event to manager(HomeScreen)
1697 * @param[in] event event code(if -1, not send event)
1698 * @param[in] surfaceid UIFW surface id
1699 * @param[in] appid applicationId
1700 * @param[in] param1 parameter 1
1702 * @param[in] param6 parameter 6
1703 * @return number of managers
1704 * @retval > 0 number of managers
1705 * @retval 0 manager not exist
1707 /*--------------------------------------------------------------------------*/
1709 ico_win_mgr_send_to_mgr(const int event, const int surfaceid, const char *appid,
1710 const int param1, const int param2, const int param3,
1711 const int param4, const int param5, const int param6)
1714 struct uifw_manager* mgr;
1716 wl_list_for_each (mgr, &_ico_win_mgr->manager_list, link) {
1720 case ICO_WINDOW_MGR_WINDOW_CREATED:
1721 uifw_trace("ico_win_mgr_send_to_mgr: Send Manager(%08x) WINDOW_CREATED"
1722 "(surf=%08x,pid=%d,appid=%s)",
1723 (int)mgr->resource, surfaceid, param1, appid);
1724 ico_window_mgr_send_window_created(mgr->resource, surfaceid, param1, appid);
1727 case ICO_WINDOW_MGR_WINDOW_VISIBLE:
1728 uifw_trace("ico_win_mgr_send_to_mgr: Send Manager(%08x) VISIBLE"
1729 "(surf=%08x,vis=%d,raise=%d,hint=%d)",
1730 (int)mgr->resource, surfaceid, param1, param2, param3);
1731 ico_window_mgr_send_window_visible(mgr->resource,
1732 surfaceid, param1, param2, param3);
1735 case ICO_WINDOW_MGR_WINDOW_CONFIGURE:
1736 uifw_trace("ico_win_mgr_send_to_mgr: Send Manager(%08x) CONFIGURE"
1737 "(surf=%08x,app=%s,layer=%d,x/y=%d/%d,w/h=%d/%d,hint=%d)",
1738 (int)mgr->resource, surfaceid, appid,
1739 param1, param2, param3, param4, param5, param6);
1740 ico_window_mgr_send_window_configure(mgr->resource, surfaceid, appid,
1741 param1, param2, param3, param4,
1745 case ICO_WINDOW_MGR_WINDOW_DESTROYED:
1746 uifw_trace("ico_win_mgr_send_to_mgr: Send Manager(%08x) DESTROYED "
1747 "surf=%08x", (int)mgr->resource, surfaceid);
1748 ico_window_mgr_send_window_destroyed(mgr->resource, surfaceid);
1751 case ICO_WINDOW_MGR_WINDOW_ACTIVE:
1752 uifw_trace("ico_win_mgr_send_to_mgr: Send Manager(%08x) ACTIVE surf=%08x "
1753 "active=%d", (int)mgr->resource, surfaceid, param1);
1754 ico_window_mgr_send_window_active(mgr->resource, surfaceid,
1766 /*--------------------------------------------------------------------------*/
1768 * @brief ico_win_mgr_hook_set_user: set hook function for set user
1770 * @param[in] hook_set_user hook function
1773 /*--------------------------------------------------------------------------*/
1775 ico_win_mgr_hook_set_user(void (*hook_set_user)(struct wl_client *client,
1778 uifw_trace("ico_win_mgr_hook_set_user: Hook %08x", (int)hook_set_user);
1779 win_mgr_hook_set_user = hook_set_user;
1782 /*--------------------------------------------------------------------------*/
1784 * @brief ico_win_mgr_hook_create: set hook function for create surface
1786 * @param[in] hook_create hook function
1789 /*--------------------------------------------------------------------------*/
1791 ico_win_mgr_hook_create(void (*hook_create)(struct wl_client *client,
1792 struct weston_surface *surface,
1793 int surfaceId, const char *appid))
1795 uifw_trace("ico_win_mgr_hook_create: Hook %08x", (int)hook_create);
1796 win_mgr_hook_create = hook_create;
1799 /*--------------------------------------------------------------------------*/
1801 * @brief ico_win_mgr_hook_destroy: set hook function for destroy surface
1803 * @param[in] hook_destroy hook function
1806 /*--------------------------------------------------------------------------*/
1808 ico_win_mgr_hook_destroy(void (*hook_destroy)(struct weston_surface *surface))
1810 uifw_trace("ico_win_mgr_hook_destroy: Hook %08x", (int)hook_destroy);
1811 win_mgr_hook_destroy = hook_destroy;
1814 /*--------------------------------------------------------------------------*/
1816 * @brief ico_window_mgr_set_animation: set animation hook routine
1818 * @param[in] hook_animation hook routine
1821 /*--------------------------------------------------------------------------*/
1823 ico_window_mgr_set_animation(int (*hook_animation)(const int op, void *data))
1825 win_mgr_hook_animation = hook_animation;
1828 /*--------------------------------------------------------------------------*/
1830 * @brief module_init: initialize ico_window_mgr
1831 * this function called from ico_pluign_loader
1833 * @param[in] es weston compositor
1838 /*--------------------------------------------------------------------------*/
1840 module_init(struct weston_compositor *ec)
1844 uifw_info("ico_window_mgr: Enter(module_init)");
1846 _ico_win_mgr = (struct ico_win_mgr *)malloc(sizeof(struct ico_win_mgr));
1847 if (_ico_win_mgr == NULL) {
1848 uifw_error("ico_window_mgr: malloc failed");
1852 memset(_ico_win_mgr, 0, sizeof(struct ico_win_mgr));
1853 _ico_win_mgr->surfaceid_map = (uint16_t *) malloc(INIT_SURFACE_IDS/8);
1854 if (! _ico_win_mgr->surfaceid_map) {
1855 uifw_error("ico_window_mgr: malloc failed");
1858 uifw_trace("ico_window_mgr: sh=%08x", (int)_ico_win_mgr);
1859 memset(_ico_win_mgr->surfaceid_map, 0, INIT_SURFACE_IDS/8);
1861 _ico_win_mgr->compositor = ec;
1863 _ico_win_mgr->surfaceid_max = INIT_SURFACE_IDS;
1864 _ico_win_mgr->surfaceid_count = INIT_SURFACE_IDS;
1866 uifw_trace("ico_window_mgr: wl_display_add_global(bind_ico_win_mgr)");
1867 if (wl_display_add_global(ec->wl_display, &ico_window_mgr_interface,
1868 _ico_win_mgr, bind_ico_win_mgr) == NULL) {
1869 uifw_error("ico_window_mgr: Error(wl_display_add_global)");
1873 wl_list_init(&_ico_win_mgr->surface_list);
1874 wl_list_init(&_ico_win_mgr->client_list);
1875 wl_list_init(&_ico_win_mgr->manager_list);
1876 wl_list_init(&_ico_win_mgr->client_attr_list);
1878 nodeId = ico_ivi_get_mynode();
1879 _ico_win_mgr->surface_head = ICO_IVI_SURFACEID_BASE(nodeId);
1880 uifw_trace("ico_window_mgr: NoedId=%08x SurfaceIdBase=%08x",
1881 nodeId, _ico_win_mgr->surface_head);
1883 /* Regist usurf_2_node to ivi_common plugin */
1884 ico_ivi_set_usurf_2_node(ico_winmgr_usurf_2_node);
1886 /* Regist send_to_mgr to ivi_common plugin */
1887 ico_ivi_set_send_to_mgr(ico_win_mgr_send_to_mgr);
1888 ico_ivi_set_send_surface_change(win_mgr_surface_change_mgr);
1890 /* Hook to IVI-Shell */
1891 ivi_shell_hook_bind(bind_shell_client);
1892 ivi_shell_hook_unbind(unbind_shell_client);
1893 ivi_shell_hook_create(client_register_surface);
1894 ivi_shell_hook_destroy(win_mgr_surface_destroy);
1895 ivi_shell_hook_map(win_mgr_map_surface);
1896 ivi_shell_hook_change(win_mgr_surface_change);
1897 ivi_shell_hook_select(win_mgr_surface_select);
1899 uifw_info("ico_window_mgr: Leave(module_init)");