2 #include <Elementary.h>
5 //for 'tizen_policy_set_transient_for'
6 //#ifndef EFL_BETA_API_SUPPORT
7 //#define EFL_BETA_API_SUPPORT
10 #include <tizen-extension-client-protocol.h>
11 #include <wayland-util.h>
13 #include "SDL_tizenindicator.h"
16 Eina_Array *mEcoreEventHandler;
19 _tizen_set_transient_for (appdata_s *ad, uint32_t child_id, uint32_t parent_id)
22 child_id : indicator resource id
23 parent_id : SDL window resource id,
25 Eina_Iterator *globals;
26 Ecore_Wl2_Global *global;
27 struct wl_registry *registry;
28 if (!ad->tizen_policy)
30 Ecore_Wl2_Display *wl2_display = ecore_wl2_connected_display_get(NULL);
32 registry = ecore_wl2_display_registry_get(wl2_display);
33 globals = ecore_wl2_display_globals_get(wl2_display);
35 if (!registry || !globals)
39 eina_iterator_free(globals);
43 EINA_ITERATOR_FOREACH(globals, global)
45 if (!strcmp(global->interface, "tizen_policy"))
46 ad->tizen_policy = wl_registry_bind(registry, global->id, &tizen_policy_interface, 7);
48 eina_iterator_free(globals);
49 if (!ad->tizen_policy)
53 _INFO("[SDL] handle_server_data major : %d, minor : %d\n", child_id, parent_id);
54 tizen_policy_set_transient_for (ad->tizen_policy, child_id, parent_id);
60 handler_server_add(void *data, int ev_type EINA_UNUSED, void *ev)
62 appdata_s *ad = (appdata_s *)data;
65 _INFO("[SDL] handler_server_add\n");
67 ecore_ipc_server_send(ad->IpcServer, OP_INDICATOR_INIT, ad->indicator_h, 0, 0, 0, NULL, 0);
72 handler_server_del(void *data, int ev_type EINA_UNUSED, void *ev)
74 appdata_s *ad = (appdata_s *)data;
76 _INFO("[SDL] handler_server_del\n");
80 void resetTimer(appdata_s *ad)
82 if(ad->timer_hide_effect)
84 ecore_timer_freeze(ad->timer_hide_effect);
85 ecore_timer_reset(ad->timer_hide_effect);
86 ecore_timer_del(ad->timer_hide_effect);
89 if(ad->timer_hide_window)
91 ecore_timer_freeze(ad->timer_hide_window);
92 ecore_timer_reset(ad->timer_hide_window);
93 ecore_timer_del(ad->timer_hide_window);
96 ad->timer_hide_effect = NULL;
97 ad->timer_hide_window = NULL;
100 Eina_Bool ecore_timer_cb_hide_effect(void *data) {
101 appdata_s *ad = (appdata_s *)data;
103 elm_object_signal_emit(ad->conform, "indicator,hide,effect", "elm");
104 ecore_ipc_server_send(ad->IpcServer, OP_INDICATOR_HIDE, 1, 0, 0, 0, NULL, 0);
106 return ECORE_CALLBACK_PASS_ON;
109 Eina_Bool ecore_timer_cb_hide_window(void *data) {
110 appdata_s *ad = (appdata_s *)data;
111 ecore_ipc_server_send(ad->IpcServer, OP_INDICATOR_HIDE, 2, 0, 0, 0, NULL, 0);
113 elm_win_iconified_set(ad->win, EINA_TRUE);
114 elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_HIDE);
116 return ECORE_CALLBACK_PASS_ON;
119 void start_hide_timer(appdata_s *ad)
122 ad->timer_hide_effect = ecore_timer_add(2.4, ecore_timer_cb_hide_effect, ad);
123 ad->timer_hide_window = ecore_timer_add(2.5, ecore_timer_cb_hide_window, ad);
126 void setIndicatorGeometry(appdata_s *ad)
128 int idx = ad->rotation / 90;
129 elm_win_rotation_set(ad->win, ad->rotation);
130 evas_object_resize(ad->win, info_size[idx][0], info_size[idx][1]);
131 evas_object_move(ad->win, info_position[idx][0], info_position[idx][1]);
133 _INFO("[SDL] setIndicator - rotation:%d, x:%d, y:%d, w:%d, h:%d\n", ad->rotation,
134 info_position[idx][0], info_position[idx][1], info_size[idx][0], info_size[idx][1]);
138 void setIndicatorOpacity(appdata_s *ad, int style)
143 elm_win_indicator_opacity_set(ad->win, SDL_INDICATOR_OPAQUE);
146 elm_win_indicator_opacity_set(ad->win, SDL_INDICATOR_TRANSLUCENT);
149 elm_win_indicator_opacity_set(ad->win, SDL_INDICATOR_TRANSPARENT);
152 elm_win_indicator_opacity_set(ad->win, SDL_INDICATOR_OPAQUE);
153 elm_object_signal_emit(ad->conform, "elm,state,indicator,overlap", "elm");
158 void showIndicator(appdata_s *ad)
160 elm_win_iconified_set(ad->win, EINA_FALSE);
161 setIndicatorGeometry(ad);
162 elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW);
163 elm_object_signal_emit(ad->conform, "indicator,show,effect", "elm");
165 if(ad->indicator_type == SDL_INDICATOR_TRANSPARENT || ad->rotation % 180)
166 start_hide_timer(ad);
169 Eina_Bool handler_server_data(void *data, int ev_type EINA_UNUSED, void *ev)
171 appdata_s *ad = (appdata_s *)data;
173 Ecore_Ipc_Event_Server_Data* epcEvent = (Ecore_Ipc_Event_Server_Data*)ev;
175 switch(epcEvent->major)
177 case OP_INDICATOR_SHOW:
181 _INFO("[SDL] 1. call event OP_INDICATOR_SHOW");
185 ad->rotation = epcEvent->minor;
186 ad->parent_res_id = epcEvent->ref;
188 if(epcEvent->ref_to!=0)
190 ad->indicator_type = epcEvent->ref_to;
191 setIndicatorOpacity(ad, ad->indicator_type);
196 _tizen_set_transient_for(ad, ad->indicator_res_id, ad->parent_res_id);
197 ecore_ipc_server_send(ad->IpcServer, OP_INDICATOR_SHOW, 0, 0, 0, 0, NULL, 0);
203 ad->timer_hide_window = ecore_timer_add(0.5, ecore_timer_cb_hide_window, ad);
214 ecore_ipc_server_send(ad->IpcServer, OP_TERMINATE, 0, 0, 0, 0, NULL, 0);
223 void create_ipcServer(appdata_s *ad)
226 Ecore_Event_Handler *h;
227 if((ad->IpcServer = ecore_ipc_server_connect(ECORE_IPC_LOCAL_USER, ECORE_IPC_INDICATOR, 0, NULL)))
229 h = ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_ADD, handler_server_add, ad);
230 eina_array_push(mEcoreEventHandler, h);
231 h = ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_DEL, handler_server_del, NULL);
232 eina_array_push(mEcoreEventHandler, h);
233 h = ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_DATA, handler_server_data, ad);
234 eina_array_push(mEcoreEventHandler, h);
238 _INFO("[SDL] Failed IPC Server\n");
244 elm_win_create(const char *name)
246 Evas_Object *win = elm_win_add(NULL, name, ELM_WIN_UTILITY);
248 elm_win_autodel_set(win, EINA_TRUE);
249 elm_win_alpha_set(win, EINA_TRUE);
250 elm_win_conformant_set(win, EINA_TRUE);
252 if (elm_win_wm_rotation_supported_get(win)) {
253 int rots[4] = { 0, 90, 180, 270 };
254 elm_win_wm_rotation_available_rotations_set(win, (const int *)(&rots), 4);
257 evas_object_show(win);
258 elm_win_prop_focus_skip_set(win, EINA_TRUE);
263 elm_conformand_create(Evas_Object *parent)
265 Evas_Object* conform = elm_conformant_add(parent);
266 evas_object_size_hint_align_set(conform, EVAS_HINT_FILL, EVAS_HINT_FILL);
267 evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
268 elm_win_resize_object_add(parent, conform);
269 elm_win_indicator_mode_set(parent, ELM_WIN_INDICATOR_SHOW);
270 elm_win_indicator_opacity_set(parent, ELM_WIN_INDICATOR_TRANSPARENT);
271 evas_object_show(conform);
276 win_delete_request_cb(void *data, Evas_Object *obj, void *event_info)
281 static Eina_Bool _window_show_cb(void *data, int type, void *event)
283 appdata_s *ad = data;
284 Ecore_Wl2_Event_Window_Show *e;
286 uint32_t g_res_id = -1;
290 g_res_id = e->data[0];
292 dlog_print(DLOG_INFO, LOG_TAG, "[SDL]Window resource Id : %d", g_res_id);
295 ad->indicator_res_id = g_res_id;
297 return ECORE_CALLBACK_PASS_ON;
300 void init_info(appdata_s *ad)
304 elm_win_screen_size_get(ad->win, 0, 0, &width, &height);
307 edje_object_part_geometry_get(elm_layout_edje_get(ad->conform), "indicator_base", NULL, NULL, NULL, &(h));
309 evas_object_resize(ad->win, width, ad->indicator_h);
311 dlog_print(DLOG_INFO, LOG_TAG, "[SDL]indicator size : %d", ad->indicator_h);
312 for(int i=0; i<4; i++)
313 info_position[i][0] = info_position[i][1] = 0;
314 info_position[2][1] = height - ad->indicator_h;
315 info_position[3][0] = width - ad->indicator_h;
317 for(int i=0; i<4; i++)
321 info_size[i][0] = height;
322 info_size[i][1] = ad->indicator_h;
326 info_size[i][0] = width;
327 info_size[i][1] = ad->indicator_h;
333 create_base_gui(appdata_s *ad)
335 Ecore_Event_Handler *h;
336 h = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_SHOW, _window_show_cb, ad);
337 eina_array_push(mEcoreEventHandler, h);
339 ad->win = (Evas_Object *)elm_win_create("SDL_Indicator");
340 evas_object_smart_callback_add(ad->win, "delete,request", win_delete_request_cb, NULL);
341 ad->conform = (Evas_Object *)elm_conformand_create(ad->win);
346 app_create(void *data)
348 /* Hook to take necessary actions before main event loop starts
349 Initialize UI resources and application's data
350 If this function returns true, the main loop of application starts
351 If this function returns false, the application is terminated */
352 appdata_s *ad = data;
355 create_ipcServer(ad);
361 app_control(app_control_h app_control, void *data)
363 /* Handle the launch request. */
367 app_pause(void *data)
369 /* Take necessary actions when application becomes invisible. */
373 app_resume(void *data)
375 /* Take necessary actions when application becomes visible. */
379 app_terminate(void *data)
381 /* Release all resources. */
385 ui_app_lang_changed(app_event_info_h event_info, void *user_data)
387 /*APP_EVENT_LANGUAGE_CHANGED*/
392 ret = app_event_get_language(event_info, &language);
393 if (ret != APP_ERROR_NONE) {
394 dlog_print(DLOG_ERROR, LOG_TAG, "app_event_get_language() failed. Err = %d.", ret);
398 if (language != NULL) {
399 elm_language_set(language);
405 ui_app_orient_changed(app_event_info_h event_info, void *user_data)
407 /*APP_EVENT_DEVICE_ORIENTATION_CHANGED*/
412 ui_app_region_changed(app_event_info_h event_info, void *user_data)
414 /*APP_EVENT_REGION_FORMAT_CHANGED*/
418 ui_app_low_battery(app_event_info_h event_info, void *user_data)
420 /*APP_EVENT_LOW_BATTERY*/
424 ui_app_low_memory(app_event_info_h event_info, void *user_data)
426 /*APP_EVENT_LOW_MEMORY*/
430 main(int argc, char *argv[])
432 mEcoreEventHandler = eina_array_new(2);
434 ad.indicator_type = SDL_INDICATOR_TRANSPARENT;
437 ui_app_lifecycle_callback_s event_callback = {0,};
438 app_event_handler_h handlers[5] = {NULL, };
440 event_callback.create = app_create;
441 event_callback.terminate = app_terminate;
442 event_callback.pause = app_pause;
443 event_callback.resume = app_resume;
444 event_callback.app_control = app_control;
447 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, ui_app_low_battery, &ad);
448 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, ui_app_low_memory, &ad);
449 ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, ui_app_orient_changed, &ad);
450 ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, &ad);
451 ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, ui_app_region_changed, &ad);
453 ret = ui_app_main(argc, argv, &event_callback, &ad);
454 if (ret != APP_ERROR_NONE) {
455 dlog_print(DLOG_ERROR, LOG_TAG, "app_main() is failed. err = %d", ret);
458 if (mEcoreEventHandler)
460 while (eina_array_count(mEcoreEventHandler))
461 ecore_event_handler_del(eina_array_pop(mEcoreEventHandler));
462 eina_array_free(mEcoreEventHandler);