3 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an AS IS BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
21 #include <appcore-efl.h>
26 #include "tickernoti-syspopup.h"
28 #define HAVE_ELEMENTARY_X 1
29 #define SYSPOPUP_PARAM_LEN 3
30 syspopup_handler handler = {
32 .def_timeout_fn = NULL
35 static void __win_del(void *data, Evas_Object * obj, void *event)
40 static Evas_Object *__create_win(const char *name)
42 if(!name) return NULL;
47 eo = elm_win_add(NULL, name, ELM_WIN_DIALOG_BASIC);
49 elm_win_title_set(eo, name);
50 elm_win_borderless_set(eo, EINA_TRUE);
51 elm_win_alpha_set(eo, EINA_TRUE);
53 evas_object_smart_callback_add(eo, "delete,request",
55 ecore_x_window_size_get(ecore_x_window_root_first_get(),
57 evas_object_resize(eo, w, h);
64 static int __app_create(void *data)
67 struct appdata *ad = data;
72 /* init internationalization */
73 r = appcore_set_i18n(PACKAGE, LOCALEDIR);
82 static void unload_popup(void *data)
85 struct appdata *ad = data;
87 if (ad->rotation_event_handler)
89 ecore_event_handler_del(ad->rotation_event_handler);
94 evas_object_del(ad->layout);
99 static int __app_terminate(void *data)
103 struct appdata *ad = data;
110 evas_object_del(ad->win);
115 ret = bundle_free(ad->b);
125 static int __app_pause(void *data)
130 static int __app_resume(void *data)
135 static void __prt_recvd_bundle(const char *key, const char *value, void *d)
139 static Eina_Bool timeout_cb(void *data)
144 return ECORE_CALLBACK_CANCEL;
147 #ifdef HAVE_ELEMENTARY_X
149 _update_window_hints(Evas_Object *obj)
152 Ecore_X_Atom _notification_level_atom;
154 // elm_win_xwindow_get() must call after elm_win_alpha_set()
155 xwin = elm_win_xwindow_get(obj);
157 ecore_x_icccm_hints_set(xwin, 0, ECORE_X_WINDOW_STATE_HINT_NONE, 0, 0, 0, 0, 0);
158 ecore_x_netwm_window_type_set(xwin, ECORE_X_WINDOW_TYPE_NOTIFICATION);
159 ecore_x_netwm_opacity_set(xwin, 0);
160 // Create atom for notification level
161 _notification_level_atom = ecore_x_atom_get("_E_ILLUME_NOTIFICATION_LEVEL");
163 // HIGH:150, NORMAL:100, LOW:50
166 // Set notification level of the window
167 ecore_x_window_prop_property_set(xwin, _notification_level_atom, ECORE_X_ATOM_CARDINAL, 32, &level, 1);
172 *_create_window(Evas_Object *parent, const char *name)
176 win = elm_win_add(parent, name, ELM_WIN_BASIC);
177 elm_win_title_set(win, name);
178 elm_win_borderless_set(win, EINA_TRUE);
179 elm_win_autodel_set(win, EINA_TRUE);
180 elm_win_alpha_set(win, EINA_TRUE);
181 evas_object_size_hint_weight_set(win, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
182 evas_object_size_hint_align_set(win, EVAS_HINT_FILL, EVAS_HINT_FILL);
184 #ifdef HAVE_ELEMENTARY_X
186 _update_window_hints(win);
192 _update_geometry_on_rotation(void *data, int *x, int *y, int *w)
197 struct appdata *ad = data;
200 #ifdef HAVE_ELEMENTARY_X
201 Evas_Coord root_w, root_h;
204 * manually calculate win_tickernoti_indi window position & size
205 * - win_indi is not full size window
207 ecore_x_window_size_get(ecore_x_window_root_first_get(), &root_w, &root_h);
213 if (ad->orient == _ELM_TICKERNOTI_ORIENT_BOTTOM)
214 *x = root_w - ad->noti_height;
218 if (!(ad->orient == _ELM_TICKERNOTI_ORIENT_BOTTOM))
219 *x = root_w - ad->noti_height;
223 if (!ad->orient == _ELM_TICKERNOTI_ORIENT_BOTTOM)
224 *y = root_h - ad->noti_height;
229 if (ad->orient == _ELM_TICKERNOTI_ORIENT_BOTTOM)
230 *y = root_h - ad->noti_height;
237 _win_rotated(void *data)
239 struct appdata *ad = data;
240 int x = 0, y = 0, w = 0, angle = 0;
243 angle = elm_win_rotation_get(ad->win);
244 if (angle % 90) return;
246 if (angle < 0) angle += 360;
248 _update_geometry_on_rotation(ad, &x, &y, &w);
249 evas_object_move(ad->win, x, y);
250 evas_object_resize(ad->win, w, ad->noti_height);
251 #ifdef HAVE_ELEMENTARY_X
252 _update_window_hints(ad->win);
257 _prop_change(void *data, int type, void *event)
259 #ifdef HAVE_ELEMENTARY_X
260 Ecore_X_Event_Window_Property *ev;
261 struct appdata *ad = data;
263 if (!ad) return ECORE_CALLBACK_PASS_ON;
265 if (ev->atom == ECORE_X_ATOM_E_ILLUME_ROTATE_WINDOW_ANGLE)
267 if (ev->win == elm_win_xwindow_get(ad->win))
272 return ECORE_CALLBACK_PASS_ON;
275 static void _hide_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
277 struct appdata *ad = data;
280 evas_object_hide(ad->win);
284 _create_tickernoti(void *data)
287 char *data_win_height = NULL;
290 struct appdata *ad = data;
292 evas_object_move(ad->win, 0, 0);
294 ad->layout = elm_layout_add(ad->win);
295 elm_layout_file_set(ad->layout, TICKERNOTI_EDJ, ad->style);
297 elm_win_resize_object_add(ad->win, ad->layout);
298 evas_object_size_hint_weight_set(ad->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
300 // tickernoti height setting
301 if ((ad->style) && (!strcmp(ad->style, "info")))
302 data_win_height = TICKERNOTI_INFO_BG_MIN_HEIGHT;
304 data_win_height = TICKERNOTI_DEFAULT_BG_MIN_HEIGHT;
306 if (data_win_height != NULL && elm_config_scale_get() > 0.0)
307 ad->noti_height = (int)(elm_config_scale_get() * atoi(data_win_height));
309 ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, NULL);
310 evas_object_size_hint_min_set(ad->layout, w, ad->noti_height);
311 evas_object_resize(ad->win, w, ad->noti_height);
313 ad->rotation_event_handler = ecore_event_handler_add(
314 ECORE_X_EVENT_WINDOW_PROPERTY, _prop_change, ad);
316 edje_object_signal_callback_add(elm_layout_edje_get(ad->layout), "request,hide", "", _hide_cb, ad);
317 evas_object_show(ad->layout);
321 _show_tickernoti(void *data)
324 struct appdata *ad = data;
326 _update_window_hints(ad->win);
327 evas_object_show(ad->win);
328 edje_object_signal_emit(elm_layout_edje_get(ad->layout), "effect,show", "elm");
329 edje_object_message_signal_process(elm_layout_edje_get(ad->layout));
333 _hide(void *data, Evas *e, Evas_Object *obj, void *event_info)
336 struct appdata *ad = data;
337 evas_object_hide(ad->win);
341 _elm_tickernoti_add(void *data)
345 if(!data) return NULL;
346 struct appdata *ad = data;
348 ad->win = _create_window(NULL, "noti-window");
350 _create_tickernoti(ad);
352 evas_object_event_callback_add(ad->layout, EVAS_CALLBACK_HIDE, _hide, ad);
357 _sizing_eval(void *data)
360 struct appdata *ad = data;
361 Evas_Coord minw = -1, minh = -1;
363 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
364 edje_object_size_min_restricted_calc(elm_layout_edje_get(ad->layout), &minw, &minh, minw, minh);
368 _elm_tickernoti_label_set(void *data)
371 struct appdata *ad = data;
372 edje_object_part_text_set(elm_layout_edje_get(ad->layout), "elm.text", ad->text);
377 _elm_tickernoti_orient_set(void *data, _Elm_Tickernoti_Orient orient)
379 Evas_Coord root_w, root_h;
381 struct appdata *ad = data;
383 if (orient >= _ELM_TICKERNOTI_ORIENT_LAST) return;
385 ecore_x_window_size_get(ecore_x_window_root_first_get(), &root_w, &root_h);
388 case _ELM_TICKERNOTI_ORIENT_BOTTOM:
389 evas_object_move(ad->win, 0, root_h - ad->noti_height);
390 ad->orient = _ELM_TICKERNOTI_ORIENT_BOTTOM;
392 case _ELM_TICKERNOTI_ORIENT_TOP:
394 evas_object_move(ad->win, 0, 0);
395 ad->orient = _ELM_TICKERNOTI_ORIENT_TOP;
398 _update_window_hints(ad->win);
401 static void load_small_popup(void *data)
404 struct appdata *ad = data;
409 evas_object_del(ad->win);
413 _elm_tickernoti_add(ad);
415 ret = syspopup_create(ad->b, &handler, ad->win, ad);
418 _elm_tickernoti_label_set(ad);
419 _elm_tickernoti_orient_set(ad, ad->orient);
420 evas_object_show(ad->layout);
421 _show_tickernoti(ad);
423 if (ad->timeout <= 0) return;
424 ad->e_timer = ecore_timer_add(ad->timeout, timeout_cb, NULL);
427 static int __app_reset(bundle *b, void *data)
431 struct appdata *ad = data;
432 char key[SYSPOPUP_PARAM_LEN];
435 ad->b = bundle_dup(b);
437 /* When syspopup is already loaded, remove the popup and load new popup */
438 if (syspopup_has_popup(b))
442 ecore_timer_del(ad->e_timer);
447 evas_object_del(ad->layout);
452 evas_object_del(ad->win);
455 /* Resetting all proporties of syspopup */
460 snprintf(key, SYSPOPUP_PARAM_LEN, "%d", SYSPOPUP_TEXT);
461 ad->text = bundle_get_val(b, (const char *)key);
467 /* get tickernoti style */
468 snprintf(key, SYSPOPUP_PARAM_LEN, "%d", SYSPOPUP_STYLE);
469 ad->style = bundle_get_val(b, (const char *)key);
470 if (!ad->style) ad->style = "default";
473 snprintf(key, SYSPOPUP_PARAM_LEN, "%d", SYSPOPUP_ORIENT);
474 const char *orient = bundle_get_val(b, (const char *)key);
478 ad->orient = _ELM_TICKERNOTI_ORIENT_TOP;
482 ad->orient = atoi(orient);
486 snprintf(key, SYSPOPUP_PARAM_LEN, "%d", SYSPOPUP_TIMEOUT);
487 const char *timeout = bundle_get_val(b, (const char *)key);
490 /* default timeout */
495 ad->timeout = atoi(timeout);
498 load_small_popup(ad);
503 int main(int argc, char *argv[])
507 struct appcore_ops ops = {
508 .create = __app_create,
509 .terminate = __app_terminate,
510 .pause = __app_pause,
511 .resume = __app_resume,
512 .reset = __app_reset,
515 memset(&ad, 0x0, sizeof(struct appdata));
518 return appcore_efl_main(PACKAGE, &argc, &argv, &ops);