2 #include <Elementary.h>
5 //for 'tizen_policy_set_transient_for'
6 #include <Ecore_Wayland.h>
7 #include <tizen-extension-client-protocol.h>
8 #include <wayland-util.h>
10 #include "SDL_tizenindicator.h"
14 _tizen_set_transient_for (appdata_s *ad, uint32_t child_id, uint32_t parent_id)
17 child_id : indicator resource id
18 parent_id : SDL window resource id,
21 Ecore_Wl_Global *global;
22 struct wl_registry *registry;
23 if (!ad->tizen_policy)
25 registry = ecore_wl_registry_get();
26 globals = ecore_wl_globals_get();
28 if (!registry || !globals)
30 EINA_INLIST_FOREACH(globals, global)
32 if (!strcmp(global->interface, "tizen_policy"))
33 ad->tizen_policy = wl_registry_bind(registry, global->id, &tizen_policy_interface, 7);
35 if (!ad->tizen_policy)
39 _INFO("[SDL] handle_server_data major : %d, minor : %d\n", child_id, parent_id);
40 tizen_policy_set_transient_for (ad->tizen_policy, child_id, parent_id);
46 handler_server_add(void *data, int ev_type EINA_UNUSED, void *ev)
48 appdata_s *ad = (appdata_s *)data;
51 _INFO("[SDL] handler_server_add\n");
53 ecore_ipc_server_send(ad->IpcServer, OP_INDICATOR_INIT, ad->indicator_h, 0, 0, 0, NULL, 0);
58 handler_server_del(void *data, int ev_type EINA_UNUSED, void *ev)
60 appdata_s *ad = (appdata_s *)data;
62 _INFO("[SDL] handler_server_del\n");
66 void resetTimer(appdata_s *ad)
68 if(ad->timer_hide_effect)
70 ecore_timer_freeze(ad->timer_hide_effect);
71 ecore_timer_reset(ad->timer_hide_effect);
72 ecore_timer_del(ad->timer_hide_effect);
75 if(ad->timer_hide_window)
77 ecore_timer_freeze(ad->timer_hide_window);
78 ecore_timer_reset(ad->timer_hide_window);
79 ecore_timer_del(ad->timer_hide_window);
82 ad->timer_hide_effect = NULL;
83 ad->timer_hide_window = NULL;
86 Eina_Bool ecore_timer_cb_hide_effect(void *data) {
87 appdata_s *ad = (appdata_s *)data;
89 elm_object_signal_emit(ad->conform, "indicator,hide,effect", "elm");
90 ecore_ipc_server_send(ad->IpcServer, OP_INDICATOR_HIDE, 1, 0, 0, 0, NULL, 0);
92 return ECORE_CALLBACK_CANCEL;
95 Eina_Bool ecore_timer_cb_hide_window(void *data) {
96 appdata_s *ad = (appdata_s *)data;
97 ecore_ipc_server_send(ad->IpcServer, OP_INDICATOR_HIDE, 2, 0, 0, 0, NULL, 0);
99 elm_win_iconified_set(ad->win, EINA_TRUE);
100 elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_HIDE);
102 return ECORE_CALLBACK_CANCEL;
105 void start_hide_timer(appdata_s *ad)
108 ad->timer_hide_effect = ecore_timer_add(2.4, ecore_timer_cb_hide_effect, ad);
109 ad->timer_hide_window = ecore_timer_add(2.5, ecore_timer_cb_hide_window, ad);
112 void setIndicatorGeometry(appdata_s *ad)
114 int idx = ad->rotation / 90;
115 elm_win_rotation_set(ad->win, ad->rotation);
116 evas_object_resize(ad->win, info_size[idx][0], info_size[idx][1]);
117 evas_object_move(ad->win, info_position[idx][0], info_position[idx][1]);
119 _INFO("[SDL] setIndicator - rotation:%d, x:%d, y:%d, w:%d, h:%d\n", ad->rotation,
120 info_position[idx][0], info_position[idx][1], info_size[idx][0], info_size[idx][1]);
124 void setIndicatorOpacity(appdata_s *ad, int style)
129 elm_win_indicator_opacity_set(ad->win, SDL_INDICATOR_OPAQUE);
132 elm_win_indicator_opacity_set(ad->win, SDL_INDICATOR_TRANSLUCENT);
135 elm_win_indicator_opacity_set(ad->win, SDL_INDICATOR_TRANSPARENT);
138 elm_win_indicator_opacity_set(ad->win, SDL_INDICATOR_OPAQUE);
139 elm_object_signal_emit(ad->conform, "elm,state,indicator,overlap", "elm");
144 void showIndicator(appdata_s *ad)
146 elm_win_iconified_set(ad->win, EINA_FALSE);
147 setIndicatorGeometry(ad);
148 elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW);
149 elm_object_signal_emit(ad->conform, "indicator,show,effect", "elm");
151 if(ad->indicator_type == SDL_INDICATOR_TRANSPARENT || ad->rotation % 180)
152 start_hide_timer(ad);
155 Eina_Bool handler_server_data(void *data, int ev_type EINA_UNUSED, void *ev)
157 appdata_s *ad = (appdata_s *)data;
159 Ecore_Ipc_Event_Server_Data* epcEvent = (Ecore_Ipc_Event_Server_Data*)ev;
161 switch(epcEvent->major)
163 case OP_INDICATOR_SHOW:
167 _INFO("[SDL] 1. call event OP_INDICATOR_SHOW");
171 ad->rotation = epcEvent->minor;
172 ad->parent_res_id = epcEvent->ref;
174 if(epcEvent->ref_to!=0)
176 ad->indicator_type = epcEvent->ref_to;
177 setIndicatorOpacity(ad, ad->indicator_type);
182 _tizen_set_transient_for(ad, ad->indicator_res_id, ad->parent_res_id);
183 ecore_ipc_server_send(ad->IpcServer, OP_INDICATOR_SHOW, 0, 0, 0, 0, NULL, 0);
189 ad->timer_hide_window = ecore_timer_add(0.5, ecore_timer_cb_hide_window, ad);
200 ecore_ipc_server_send(ad->IpcServer, OP_TERMINATE, 0, 0, 0, 0, NULL, 0);
209 void create_ipcServer(appdata_s *ad)
212 if((ad->IpcServer = ecore_ipc_server_connect(ECORE_IPC_LOCAL_USER, ECORE_IPC_INDICATOR, 0, NULL)))
214 ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_ADD, handler_server_add, ad);
215 ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_DEL, handler_server_del, NULL);
216 ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_DATA, handler_server_data, ad);
220 _INFO("[SDL] Failed IPC Server\n");
226 elm_win_create(const char *name)
228 Evas_Object *win = elm_win_add(NULL, name, ELM_WIN_UTILITY);
230 elm_win_autodel_set(win, EINA_TRUE);
231 elm_win_alpha_set(win, EINA_TRUE);
232 elm_win_conformant_set(win, EINA_TRUE);
234 if (elm_win_wm_rotation_supported_get(win)) {
235 int rots[4] = { 0, 90, 180, 270 };
236 elm_win_wm_rotation_available_rotations_set(win, (const int *)(&rots), 4);
239 evas_object_show(win);
240 elm_win_prop_focus_skip_set(win, EINA_TRUE);
245 elm_conformand_create(Evas_Object *parent)
247 Evas_Object* conform = elm_conformant_add(parent);
248 evas_object_size_hint_align_set(conform, EVAS_HINT_FILL, EVAS_HINT_FILL);
249 evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
250 elm_win_resize_object_add(parent, conform);
251 elm_win_indicator_mode_set(parent, ELM_WIN_INDICATOR_SHOW);
252 elm_win_indicator_opacity_set(parent, ELM_WIN_INDICATOR_TRANSPARENT);
253 evas_object_show(conform);
258 win_delete_request_cb(void *data, Evas_Object *obj, void *event_info)
263 static Eina_Bool _window_show_cb(void *data, int type, void *event)
265 appdata_s *ad = data;
266 Ecore_Wl_Event_Window_Show *e;
268 uint32_t g_res_id = -1;
272 g_res_id = e->data[0];
274 dlog_print(DLOG_INFO, LOG_TAG, "[SDL]Window resource Id : %d", g_res_id);
277 ad->indicator_res_id = g_res_id;
279 return ECORE_CALLBACK_PASS_ON;
282 void init_info(appdata_s *ad)
286 elm_win_screen_size_get(ad->win, 0, 0, &width, &height);
289 edje_object_part_geometry_get(elm_layout_edje_get(ad->conform), "indicator_base", NULL, NULL, NULL, &(h));
291 evas_object_resize(ad->win, width, ad->indicator_h);
293 dlog_print(DLOG_INFO, LOG_TAG, "[SDL]indicator size : %d", ad->indicator_h);
294 for(int i=0; i<4; i++)
295 info_position[i][0] = info_position[i][1] = 0;
296 info_position[2][1] = height - ad->indicator_h;
297 info_position[3][0] = width - ad->indicator_h;
299 for(int i=0; i<4; i++)
303 info_size[i][0] = height;
304 info_size[i][1] = ad->indicator_h;
308 info_size[i][0] = width;
309 info_size[i][1] = ad->indicator_h;
315 create_base_gui(appdata_s *ad)
317 ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_SHOW, _window_show_cb, ad);
319 ad->win = (Evas_Object *)elm_win_create("SDL_Indicator");
320 evas_object_smart_callback_add(ad->win, "delete,request", win_delete_request_cb, NULL);
321 ad->conform = (Evas_Object *)elm_conformand_create(ad->win);
326 app_create(void *data)
328 /* Hook to take necessary actions before main event loop starts
329 Initialize UI resources and application's data
330 If this function returns true, the main loop of application starts
331 If this function returns false, the application is terminated */
332 appdata_s *ad = data;
335 create_ipcServer(ad);
341 app_control(app_control_h app_control, void *data)
343 /* Handle the launch request. */
347 app_pause(void *data)
349 /* Take necessary actions when application becomes invisible. */
353 app_resume(void *data)
355 /* Take necessary actions when application becomes visible. */
359 app_terminate(void *data)
361 /* Release all resources. */
365 ui_app_lang_changed(app_event_info_h event_info, void *user_data)
367 /*APP_EVENT_LANGUAGE_CHANGED*/
372 ret = app_event_get_language(event_info, &language);
373 if (ret != APP_ERROR_NONE) {
374 dlog_print(DLOG_ERROR, LOG_TAG, "app_event_get_language() failed. Err = %d.", ret);
378 if (language != NULL) {
379 elm_language_set(language);
385 ui_app_orient_changed(app_event_info_h event_info, void *user_data)
387 /*APP_EVENT_DEVICE_ORIENTATION_CHANGED*/
392 ui_app_region_changed(app_event_info_h event_info, void *user_data)
394 /*APP_EVENT_REGION_FORMAT_CHANGED*/
398 ui_app_low_battery(app_event_info_h event_info, void *user_data)
400 /*APP_EVENT_LOW_BATTERY*/
404 ui_app_low_memory(app_event_info_h event_info, void *user_data)
406 /*APP_EVENT_LOW_MEMORY*/
410 main(int argc, char *argv[])
413 ad.indicator_type = SDL_INDICATOR_TRANSPARENT;
416 ui_app_lifecycle_callback_s event_callback = {0,};
417 app_event_handler_h handlers[5] = {NULL, };
419 event_callback.create = app_create;
420 event_callback.terminate = app_terminate;
421 event_callback.pause = app_pause;
422 event_callback.resume = app_resume;
423 event_callback.app_control = app_control;
426 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, ui_app_low_battery, &ad);
427 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, ui_app_low_memory, &ad);
428 ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, ui_app_orient_changed, &ad);
429 ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, &ad);
430 ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, ui_app_region_changed, &ad);
432 ret = ui_app_main(argc, argv, &event_callback, &ad);
433 if (ret != APP_ERROR_NONE) {
434 dlog_print(DLOG_ERROR, LOG_TAG, "app_main() is failed. err = %d", ret);