2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 /* Set to run in wayland only */
21 #include <Elementary.h>
36 #include "menu_screen.h"
39 #include "page_scroller.h"
42 #define STR_ENV_ENGINE "ELM_ENGINE"
43 #define STR_ENV_FPS "LAUNCHER_FPS"
45 #define LAYOUT_EDJE_PORTRAIT EDJEDIR"/layout_portrait.edj"
46 #define LAYOUT_GROUP_NAME "layout"
50 // Define prototype of the "hidden API of AUL"
51 extern int aul_listen_app_dead_signal(int (*func)(int signal, void *data), void *data);
62 } menu_screen_info = {
63 .state = APP_STATE_PAUSE,
70 static void _set_scale(void);
72 Evas *menu_screen_get_evas(void)
74 return menu_screen_info.evas;
79 int menu_screen_get_root_width(void)
81 return menu_screen_info.root_width;
86 int menu_screen_get_root_height(void)
88 return menu_screen_info.root_height;
93 double menu_screen_get_yscale(void)
95 return menu_screen_info.yscale;
100 Evas_Object *menu_screen_get_win(void)
102 return menu_screen_info.win;
107 bool menu_screen_get_done(void)
109 return menu_screen_info.is_done;
114 void menu_screen_set_done(bool is_done)
116 menu_screen_info.is_done = is_done;
121 static menu_screen_error_e _create_canvas(char *name, char *title)
123 Ecore_X_Atom ATOM_WM_WINDOW_ROLE;
125 menu_screen_info.win = elm_win_add(NULL, name, ELM_WIN_BASIC);
126 retv_if(NULL == menu_screen_info.win, MENU_SCREEN_ERROR_FAIL);
129 elm_win_title_set(menu_screen_info.win, title);
131 elm_win_borderless_set(menu_screen_info.win, EINA_TRUE);
135 ecore_x_icccm_name_class_set(elm_win_xwindow_get(menu_screen_info.win), "MENU_SCREEN", "MENU_SCREEN");
136 ATOM_WM_WINDOW_ROLE = ecore_x_atom_get("WM_WINDOW_ROLE");
137 if (ATOM_WM_WINDOW_ROLE) {
138 ecore_x_window_prop_string_set(elm_win_xwindow_get(menu_screen_info.win), ATOM_WM_WINDOW_ROLE, "MENU_SCREEN");
140 _D("Failed to set the window role as MENU_SCREEN");
144 /* have to call this after elm_win_add() in wayland */
147 menu_screen_info.evas = evas_object_evas_get(menu_screen_info.win);
148 if (!menu_screen_info.evas) {
149 _E("[%s] Failed to get the evas object", __func__);
152 menu_screen_info.ee = ecore_evas_ecore_evas_get(menu_screen_info.evas);
153 if (!menu_screen_info.ee) {
154 _E("[%s] Failed to get ecore_evas object", __func__);
157 evas_object_move(menu_screen_info.win, 0, 0);
158 evas_object_resize(menu_screen_info.win, menu_screen_info.root_width, menu_screen_info.root_height);
159 evas_object_show(menu_screen_info.win);
161 return MENU_SCREEN_ERROR_OK;
166 static void _destroy_canvas(void)
168 evas_object_del(menu_screen_info.win);
173 static int _dead_cb(int pid, void *data)
177 utilx_hide_fake_effect(
178 ecore_x_display_get(),
179 ecore_x_window_root_get(ecore_evas_window_get(menu_screen_info.ee))
188 static void _set_scale(void)
191 Ecore_X_Window focus_win;
192 Ecore_X_Window root_win;
194 focus_win = ecore_x_window_focus_get();
195 root_win = ecore_x_window_root_get(focus_win);
196 ecore_x_window_size_get(root_win, &menu_screen_info.root_width, &menu_screen_info.root_height);
198 menu_screen_info.xscale = (double) menu_screen_info.root_width / (double) BASE_WIDTH;
199 menu_screen_info.yscale = (double) menu_screen_info.root_height / (double) BASE_HEIGHT;
200 scale = menu_screen_info.xscale < menu_screen_info.yscale ? menu_screen_info.xscale : menu_screen_info.yscale;
201 _D("width:%d, height:%d, scale:%f", menu_screen_info.root_width, menu_screen_info.root_height, scale);
202 elm_config_scale_set(scale);
207 static void _create_bg(void)
214 static int trigger = 0;
219 buf = vconf_get_str(VCONFKEY_BGSET);
222 width = menu_screen_get_root_width();
223 height = menu_screen_get_root_height();
225 bg = evas_object_data_get(menu_screen_get_win(), "bg");
229 rect = evas_object_rectangle_add(menu_screen_get_evas());
230 ret_if(NULL == rect);
231 evas_object_data_set(menu_screen_get_win(), "rect", rect);
232 evas_object_color_set(rect, 0, 0, 0, 255);
233 evas_object_size_hint_min_set(rect, width, height);
234 evas_object_size_hint_max_set(rect, width, height);
235 evas_object_resize(rect, width, height);
236 evas_object_show(rect);
238 bg = evas_object_image_add(menu_screen_get_evas());
243 evas_object_data_set(menu_screen_get_win(), "bg", bg);
254 evas_object_image_file_set(bg, buf, key);
255 evas_object_image_size_get(bg, &w, &h);
256 evas_object_image_filled_set(bg, 1);
258 wf = (double) width / (double) w;
259 hf = (double) height / (double) h;
261 f = wf > hf ? hf : wf;
263 w = (int) ((double) f * (double) w);
264 h = (int) ((double) f * (double) h);
266 evas_object_image_load_size_set(bg, w, h);
267 evas_object_image_fill_set(bg, 0, 0, w, h);
268 evas_object_move(bg, (width - w) / 2, (height - h) / 2);
269 evas_object_resize(bg, w, h);
270 evas_object_show(bg);
278 static void _destroy_bg()
283 rect = evas_object_data_del(menu_screen_get_win(), "rect");
284 evas_object_del(rect);
286 bg = evas_object_data_del(menu_screen_get_win(), "bg");
292 static void _change_bg_cb(keynode_t *node, void *data)
294 _D("Background image is changed.");
300 static bool _create_cb(void *data)
305 /* Move this call to be executed after window is created */
309 retv_if(MENU_SCREEN_ERROR_FAIL == _create_canvas(PACKAGE, PACKAGE), EXIT_FAILURE);
310 elm_win_indicator_mode_set(menu_screen_info.win, ELM_WIN_INDICATOR_SHOW);
312 if (vconf_notify_key_changed(VCONFKEY_BGSET, _change_bg_cb, NULL) < 0) {
313 _E("Failed to register a vconf cb for %s\n", VCONFKEY_BGSET);
317 layout = layout_create(menu_screen_info.win, LAYOUT_EDJE_PORTRAIT,
318 LAYOUT_GROUP_NAME, MENU_SCREEN_ROTATE_PORTRAIT);
319 if (NULL == layout) {
320 _E("Faield to load an edje object");
321 evas_object_del(menu_screen_info.win);
324 evas_object_data_set(menu_screen_info.win, "layout", layout);
325 evas_object_show(layout);
328 aul_listen_app_dead_signal(_dead_cb, NULL);
335 static void _terminate_cb(void *data)
339 if (vconf_ignore_key_changed(VCONFKEY_BGSET, _change_bg_cb) < 0) {
340 _E("Failed to remove bgset %s\n", VCONFKEY_BGSET);
343 evas_object_hide(menu_screen_info.win);
347 layout = evas_object_data_del(menu_screen_info.win, "layout");
348 layout_destroy(layout);
352 evas_object_del(menu_screen_info.win);
357 static void _pause_cb(void *data)
361 if (vconf_set_int(VCONFKEY_IDLE_SCREEN_TOP, VCONFKEY_IDLE_SCREEN_TOP_FALSE) < 0) {
362 _E("Failed to set memory/idle/top to 0");
365 menu_screen_info.state = APP_STATE_PAUSE;
370 static void _resume_cb(void *data)
374 if (vconf_set_int(VCONFKEY_IDLE_SCREEN_TOP, VCONFKEY_IDLE_SCREEN_TOP_TRUE) < 0) {
375 _E("Failed to set memory/idle/top to 1");
380 utilx_hide_fake_effect(
381 ecore_x_display_get(),
382 ecore_x_window_root_get(ecore_evas_window_get(menu_screen_info.ee))
386 menu_screen_info.state = APP_STATE_RESUME;
391 static void _service_cb(service_h service, void *data)
393 _D("START RESET : %d", menu_screen_info.state);
395 if (vconf_set_int(VCONFKEY_IDLE_SCREEN_TOP, VCONFKEY_IDLE_SCREEN_TOP_TRUE) < 0) {
396 _E("Failed to set memory/idle/top to 1");
401 utilx_hide_fake_effect(
402 ecore_x_display_get(),
403 ecore_x_window_root_get(ecore_evas_window_get(menu_screen_info.ee))
410 static void _language_changed_cb(void *data)
412 register unsigned int i;
413 register unsigned int j;
416 Evas_Object *all_apps;
417 Evas_Object *scroller;
420 unsigned int page_max_app;
422 _D("Language is changed");
424 if (false == menu_screen_info.is_done) {
428 layout = evas_object_data_get(menu_screen_info.win, "layout");
429 ret_if(NULL == layout);
430 all_apps = evas_object_data_get(layout, "all_apps");
431 ret_if(NULL == all_apps);
432 scroller = elm_object_part_content_get(all_apps, "content");
433 ret_if(NULL == scroller);
435 count = page_scroller_count_page(scroller);
436 page_max_app = (unsigned int) evas_object_data_get(scroller, "page_max_app");
437 for (i = 0; i < count; i ++) {
438 page = page_scroller_get_page_at(scroller, i);
440 if (mapbuf_is_enabled(page)) {
441 mapbuf_disable(page, 1);
444 for (j = 0; j < page_max_app; j ++) {
448 item = page_get_item_at(page, j);
451 if (ail_package_get_appinfo(item_get_package(item), &ai) < 0) continue;
452 if (ail_appinfo_get_str(ai, AIL_PROP_NAME_STR, &name) < 0) {
453 ail_package_destroy_appinfo(ai);
458 _D("Faield to get name for %s", item_get_package(item));
459 ail_package_destroy_appinfo(ai);
463 item_set_name(item, name, 0);
464 ail_package_destroy_appinfo(ai);
467 mapbuf_enable(page, 1);
473 static void _init(app_event_callback_s *event_callback)
475 event_callback->create = _create_cb;
476 event_callback->terminate = _terminate_cb;
477 event_callback->pause = _pause_cb;
478 event_callback->resume = _resume_cb;
479 event_callback->service = _service_cb;
480 event_callback->low_memory = NULL;
481 event_callback->low_battery = NULL;
482 event_callback->device_orientation = NULL;
483 event_callback->language_changed = _language_changed_cb;
484 event_callback->region_format_changed = NULL;
489 static void _fini(void)
495 int main(int argc, char *argv[])
498 app_event_callback_s event_callback;
500 env = getenv(STR_ENV_ENGINE);
502 _D("ELM_ENGINE is set as [%s]", env);
503 setenv("ELM_ENGINE", env, 1);
505 _D("ELM_ENGINE is set as [%s]", "gl");
506 setenv("ELM_ENGINE", "gl", 1);
509 env = getenv(STR_ENV_FPS);
511 _D("ELM_FPS is set as [%s]", env);
512 setenv("ELM_FPS", env, 1);
514 _D("ELM_FPS is set as [%s]", "6000");
515 setenv("ELM_FPS", "6000", 1);
518 _init(&event_callback);
519 app_efl_main(&argc, &argv, &event_callback, NULL);