2 * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved
4 * This file is part of the UI Gadget
5 * Written by Jayoun Lee <airjany@samsung.com>, Jinwoo Nam <jwoo.nam@samsung.com>
7 * PROPRIETARY/CONFIDENTIAL
9 * This software is the confidential and proprietary information of
10 * SAMSUNG ELECTRONICS (Confidential Information).
11 * You shall not disclose such Confidential Information and shall
12 * use it only in accordance with the terms of the license agreement
13 * you entered into with SAMSUNG ELECTRONICS. SAMSUNG make no
14 * representations or warranties about the suitability
15 * of the software, either express or implied, including but not
16 * limited to the implied warranties of merchantability, fitness for a particular purpose, or non-
17 * infringement. SAMSUNG shall not be liable for any damages suffered by licensee as
18 * a result of using, modifying or distributing this software or its derivatives.
30 #include "ug-manager.h"
31 #include "ug-engine.h"
35 struct ui_gadget *root;
36 struct ui_gadget *fv_top;
43 enum ug_option base_opt;
44 enum ug_event last_rotate_evt;
52 struct ug_engine *engine;
55 static struct ug_manager ug_man;
57 static inline void job_start(void);
58 static inline void job_end(void);
60 static int ug_relation_add(struct ui_gadget *p, struct ui_gadget *c)
63 /* prepend element to avoid the inefficiency,
64 which is to traverse the entire list to find the end*/
65 p->children = g_slist_prepend(p->children, c);
70 static int ug_relation_del(struct ui_gadget *ug)
76 _ERR("ug_relation_del failed: no parent\n");
79 p->children = g_slist_remove(p->children, ug);
81 g_slist_free(ug->children);
87 static int ug_fvlist_add(struct ui_gadget *c)
89 ug_man.fv_list = g_slist_prepend(ug_man.fv_list, c);
95 static int ug_fvlist_del(struct ui_gadget *c)
99 ug_man.fv_list = g_slist_remove(ug_man.fv_list, c);
101 /* update fullview top ug*/
102 t = g_slist_nth_data(ug_man.fv_list, 0);
108 static void ugman_tree_dump(struct ui_gadget *ug)
120 if (ug == ug_man.root) {
122 _DBG("\n============== TREE_DUMP =============\n");
123 _DBG("ROOT: Manager\n");
127 child = ug->children;
136 _DBG("[%d] %s [%c] (%p) (PARENT: %s)\n",
138 c && c->name ? c->name : "NO CHILD INFO FIXIT!!!",
139 c && c->mode == UG_MODE_FULLVIEW ? 'F' : 'f', c, name);
141 child = g_slist_next(child);
145 static int ugman_ug_find(struct ui_gadget *p, struct ui_gadget *ug)
147 GSList *child = NULL;
154 if (child->data == ug)
156 if (ugman_ug_find(child->data, ug))
158 child = g_slist_next(child);
164 static int ugman_ug_start(void *data)
166 struct ui_gadget *ug = data;
167 struct ug_module_ops *ops = NULL;
169 if (!ug || ug->state != UG_STATE_CREATED
170 || ug->state == UG_STATE_RUNNING)
173 ug->state = UG_STATE_RUNNING;
176 ops = &ug->module->ops;
178 if (ops && ops->start)
179 ops->start(ug, ug->data, ops->priv);
184 static int ugman_ug_pause(void *data)
186 struct ui_gadget *ug = data;
187 struct ug_module_ops *ops = NULL;
188 GSList *child = NULL;
192 if (!ug || ug->state != UG_STATE_RUNNING)
195 ug->state = UG_STATE_STOPPED;
198 child = ug->children;
200 ugman_ug_pause(child->data);
201 child = g_slist_next(child);
206 ops = &ug->module->ops;
208 if (ops && ops->pause)
209 ops->pause(ug, ug->data, ops->priv);
216 static int ugman_ug_resume(void *data)
218 struct ui_gadget *ug = data;
219 struct ug_module_ops *ops = NULL;
220 GSList *child = NULL;
228 case UG_STATE_CREATED:
231 case UG_STATE_STOPPED:
237 ug->state = UG_STATE_RUNNING;
240 child = ug->children;
242 ugman_ug_resume(child->data);
243 child = g_slist_next(child);
248 ops = &ug->module->ops;
250 if (ops && ops->resume)
251 ops->resume(ug, ug->data, ops->priv);
258 static int ugman_indicator_update(enum ug_option opt, enum ug_event event)
264 _ERR("ugman_indicator_update failed: no window\n");
268 switch (UG_OPT_INDICATOR(opt)) {
269 case UG_OPT_INDICATOR_ENABLE:
270 if (event == UG_EVENT_NONE)
273 cur_state = utilx_get_indicator_state(ug_man.disp, ug_man.win_id);
274 enable = cur_state ? 1 : 0;
277 case UG_OPT_INDICATOR_PORTRAIT_ONLY:
278 enable = ug_man.is_landscape ? 0 : 1;
280 case UG_OPT_INDICATOR_LANDSCAPE_ONLY:
281 enable = ug_man.is_landscape ? 1 : 0;
283 case UG_OPT_INDICATOR_DISABLE:
287 _ERR("ugman_indicator_update failed: Invalid opt\n");
291 utilx_enable_indicator(ug_man.disp, ug_man.win_id, enable);
296 static int ugman_ug_getopt(struct ui_gadget *ug)
300 /* Indicator Option */
301 if (ug->mode == UG_MODE_FULLVIEW)
302 ugman_indicator_update(UG_OPT_INDICATOR(ug->opt), UG_EVENT_NONE);
307 static int ugman_ug_event(struct ui_gadget *ug, enum ug_event event)
309 struct ug_module_ops *ops = NULL;
310 GSList *child = NULL;
316 child = ug->children;
318 ugman_ug_event(child->data, event);
319 child = g_slist_next(child);
324 ops = &ug->module->ops;
326 if (ops && ops->event)
327 ops->event(ug, event, ug->data, ops->priv);
332 static int ugman_ug_destroy(void *data)
334 struct ui_gadget *ug = data;
335 struct ug_module_ops *ops = NULL;
336 GSList *child, *trail;
344 case UG_STATE_CREATED:
345 case UG_STATE_RUNNING:
346 case UG_STATE_STOPPED:
347 case UG_STATE_DESTROYING:
353 ug->state = UG_STATE_DESTROYED;
356 ops = &ug->module->ops;
359 child = ug->children;
361 trail = g_slist_next(child);
362 ugman_ug_destroy(child->data);
367 if (ops && ops->destroy)
368 ops->destroy(ug, ug->data, ops->priv);
372 if (ug->mode == UG_MODE_FULLVIEW) {
373 if (ug_man.fv_top == ug) {
375 ugman_ug_getopt(ug_man.fv_top);
383 if (ug_man.root == ug)
386 ugman_tree_dump(ug_man.root);
393 static void ug_hide_end_cb(struct ui_gadget *ug)
395 g_idle_add(ugman_ug_destroy, ug);
398 static int ugman_ug_create(void *data)
400 struct ui_gadget *ug = data;
401 struct ug_module_ops *ops = NULL;
403 struct ug_engine_ops *eng_ops = NULL;
405 if (!ug || ug->state != UG_STATE_READY)
408 ug->state = UG_STATE_CREATED;
411 ops = &ug->module->ops;
414 eng_ops = &ug_man.engine->ops;
416 if (ops && ops->create) {
417 ug->layout = ops->create(ug, ug->mode, ug->data, ops->priv);
423 if (ug->mode == (UG_MODE_FULLVIEW)) {
424 if (eng_ops && eng_ops->create)
425 ug->effect_layout = eng_ops->create(ug_man.win, ug, ug_hide_end_cb);
429 if (cbs && cbs->layout_cb)
430 cbs->layout_cb(ug, ug->mode, cbs->priv);
435 ugman_ug_event(ug, ug_man.last_rotate_evt);
437 ugman_tree_dump(ug_man.root);
442 int ugman_ug_add(struct ui_gadget *parent, struct ui_gadget *ug)
444 if (!ug_man.is_initted) {
445 _ERR("ugman_ug_add failed: manager is not initted\n");
451 _ERR("ugman_ug_add failed: parent has to be NULL w/o root\n");
456 ug_man.root = ug_root_create();
459 ug_man.root->opt = ug_man.base_opt;
460 ug_man.root->layout = ug_man.win;
461 ug_fvlist_add(ug_man.root);
465 parent = ug_man.root;
467 if (ug_relation_add(parent, ug))
470 if (ugman_ug_create(ug) == -1)
473 if (ug->mode == UG_MODE_FULLVIEW)
479 struct ui_gadget *ugman_ug_load(struct ui_gadget *parent,
482 bundle *data, struct ug_cbs *cbs)
485 struct ui_gadget *ug;
487 ug = calloc(1, sizeof(struct ui_gadget));
489 _ERR("ug_create() failed: Memory allocation failed\n");
493 ug->module = ug_module_load(name);
495 _ERR("ug_create() failed: Module loading failed\n");
499 ug->name = strdup(name);
502 ug->data = bundle_dup(data);
503 ug->opt = ug->module->ops.opt;
504 ug->state = UG_STATE_READY;
508 memcpy(&ug->cbs, cbs, sizeof(struct ug_cbs));
510 r = ugman_ug_add(parent, ug);
512 _ERR("ug_create() failed: Tree update failed\n");
523 int ugman_ug_destroying(struct ui_gadget *ug)
525 struct ug_module_ops *ops = NULL;
526 GSList *child, *trail;
529 ug->state = UG_STATE_DESTROYING;
532 ops = &ug->module->ops;
535 child = ug->children;
537 trail = g_slist_next(child);
538 ugman_ug_destroying(child->data);
543 if (ops && ops->destroying)
544 ops->destroying(ug, ug->data, ops->priv);
549 int ugman_ug_del(struct ui_gadget *ug)
551 struct ug_engine_ops *eng_ops = NULL;
553 if (!ug || !ugman_ug_exist(ug) || ug->state == UG_STATE_DESTROYED) {
554 _ERR("ugman_ug_del failed: Invalid ug\n");
559 if (ug->destroy_me) {
560 _ERR("ugman_ug_del failed: ug is alreay on destroying\n");
564 if (!ug_man.is_initted) {
565 _ERR("ugman_ug_del failed: manager is not initted\n");
570 _ERR("ugman_ug_del failed: no root\n");
574 ugman_ug_destroying(ug);
576 if (ug->mode == UG_MODE_FULLVIEW) {
578 eng_ops = &ug_man.engine->ops;
580 if (eng_ops && eng_ops->destroy) {
581 eng_ops->destroy(ug, ug_man.fv_top);
584 g_idle_add(ugman_ug_destroy, ug);
588 g_idle_add(ugman_ug_destroy, ug);
594 int ugman_ug_del_all(void)
597 if (!ug_man.is_initted) {
598 _ERR("ugman_ug_del_all failed: manager is not initted\n");
603 _ERR("ugman_ug_del_all failed: no root\n");
607 if (ug_man.walking > 0)
608 ug_man.destroy_all = 1;
610 ugman_ug_destroy(ug_man.root);
615 int ugman_init(Display *disp, Window xid, void *win, enum ug_option opt)
617 ug_man.is_initted = 1;
621 ug_man.base_opt = opt;
622 ug_man.last_rotate_evt = UG_EVENT_ROTATE_PORTRAIT;
623 ug_man.engine = ug_engine_load();
628 int ugman_resume(void)
631 if (!ug_man.is_initted) {
632 _ERR("ugman_resume failed: manager is not initted\n");
637 _ERR("ugman_resume failed: no root\n");
641 g_idle_add(ugman_ug_resume, ug_man.root);
646 int ugman_pause(void)
648 /* PAUSE (Background) */
649 if (!ug_man.is_initted) {
650 _ERR("ugman_pause failed: manager is not initted\n");
655 _ERR("ugman_pause failed: no root\n");
659 g_idle_add(ugman_ug_pause, ug_man.root);
664 static int ugman_send_event_pre(void *data)
668 ugman_ug_event(ug_man.root, (enum ug_event)data);
675 int ugman_send_event(enum ug_event event)
679 /* Propagate event */
680 if (!ug_man.is_initted) {
681 _ERR("ugman_send_event failed: manager is not initted\n");
685 /* In case of rotation, indicator state has to be updated */
687 case UG_EVENT_ROTATE_PORTRAIT:
688 case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
689 ug_man.last_rotate_evt = event;
690 ug_man.is_landscape = 0;
692 case UG_EVENT_ROTATE_LANDSCAPE:
693 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
694 ug_man.last_rotate_evt = event;
695 ug_man.is_landscape = 1;
702 _ERR("ugman_send_event failed: no root\n");
706 g_idle_add(ugman_send_event_pre, (void *)event);
708 if (is_rotation && ug_man.fv_top)
709 ugman_indicator_update(UG_OPT_INDICATOR(ug_man.fv_top->opt), event);
714 static int ugman_send_key_event_to_ug(struct ui_gadget *ug,
715 enum ug_key_event event)
717 struct ug_module_ops *ops = NULL;
723 ops = &ug->module->ops;
728 if (ops && ops->key_event) {
729 ops->key_event(ug, event, ug->data, ops->priv);
737 int ugman_send_key_event(enum ug_key_event event)
739 if (!ug_man.is_initted) {
740 _ERR("ugman_send_key_event failed: manager is not initted\n");
744 if (!ug_man.fv_top || !ugman_ug_exist(ug_man.fv_top)
745 || ug_man.fv_top->state == UG_STATE_DESTROYED) {
746 _ERR("ugman_send_key_event failed: full view top UG is invalid\n");
750 return ugman_send_key_event_to_ug(ug_man.fv_top, event);
753 int ugman_send_message(struct ui_gadget *ug, bundle *msg)
755 struct ug_module_ops *ops = NULL;
756 if (!ug || !ugman_ug_exist(ug) || ug->state == UG_STATE_DESTROYED) {
757 _ERR("ugman_send_message failed: Invalid ug\n");
763 _ERR("ugman_send_message failed: Invalid msg\n");
769 ops = &ug->module->ops;
771 if (ops && ops->message)
772 ops->message(ug, msg, ug->data, ops->priv);
777 void *ugman_get_window(void)
782 static inline void job_start(void)
787 static inline void job_end(void)
791 if (!ug_man.walking && ug_man.destroy_all) {
792 ug_man.destroy_all = 0;
794 ugman_ug_destroy(ug_man.root);
797 if (ug_man.walking < 0)
801 int ugman_ug_exist(struct ui_gadget *ug)
803 return ugman_ug_find(ug_man.root, ug);