3 EAPI E_Path *path_data = NULL;
4 EAPI E_Path *path_images = NULL;
5 EAPI E_Path *path_fonts = NULL;
6 EAPI E_Path *path_themes = NULL;
7 EAPI E_Path *path_icons = NULL;
8 EAPI E_Path *path_modules = NULL;
9 EAPI E_Path *path_backgrounds = NULL;
10 EAPI E_Path *path_messages = NULL;
12 typedef struct _E_Util_Fake_Mouse_Up_Info E_Util_Fake_Mouse_Up_Info;
14 struct _E_Util_Fake_Mouse_Up_Info
20 /* local subsystem functions */
21 static Eina_Bool _e_util_cb_delayed_del(void *data);
22 static Eina_Bool _e_util_wakeup_cb(void *data);
24 static Evas_Object *_e_util_icon_add(const char *path, Evas *evas, int size);
26 static void _e_util_cb_delayed_cancel(void *data, void *obj);
28 /* local subsystem globals */
29 static Ecore_Timer *_e_util_dummy_timer = NULL;
31 /* externally accessible functions */
35 if (_e_util_dummy_timer) return;
36 _e_util_dummy_timer = ecore_timer_add(0.0, _e_util_wakeup_cb, NULL);
40 e_util_env_set(const char *var, const char *val)
49 snprintf(buf, sizeof(buf), "%s=%s", var, val);
61 if (getenv(var)) putenv(var);
67 e_util_zone_current_get(E_Manager *man)
71 E_OBJECT_CHECK_RETURN(man, NULL);
72 E_OBJECT_TYPE_CHECK_RETURN(man, E_MANAGER_TYPE, NULL);
73 con = e_container_current_get(man);
78 zone = e_zone_current_get(con);
85 e_util_glob_match(const char *str, const char *pattern)
87 if ((!str) || (!pattern)) return 0;
90 if (str[0] == 0) return 1;
93 if (!strcmp(pattern, "*")) return 1;
94 if (!fnmatch(pattern, str, 0)) return 1;
99 e_util_glob_case_match(const char *str, const char *pattern)
102 char *tstr, *tglob, *tp;
106 if (str[0] == 0) return 1;
109 if (!strcmp(pattern, "*")) return 1;
110 tstr = alloca(strlen(str) + 1);
111 for (tp = tstr, p = str; *p != 0; p++, tp++)
114 tglob = alloca(strlen(pattern) + 1);
115 for (tp = tglob, p = pattern; *p != 0; p++, tp++)
118 if (!fnmatch(tglob, tstr, 0)) return 1;
123 e_util_container_number_get(int num)
128 EINA_LIST_FOREACH(e_manager_list(), l, man)
132 con = e_container_number_get(man, num);
139 e_util_container_zone_number_get(int con_num, int zone_num)
143 con = e_util_container_number_get(con_num);
144 if (!con) return NULL;
145 return e_container_zone_number_get(con, zone_num);
149 e_util_container_zone_id_get(int con_num, int id)
153 con = e_util_container_number_get(con_num);
154 if (!con) return NULL;
155 return e_container_zone_id_get(con, id);
159 e_util_head_exec(int head, const char *cmd)
163 char buf[4096], buf2[32];
167 penv_display = getenv("DISPLAY");
168 if (!penv_display) return 0;
169 penv_display = strdup(penv_display);
171 p1 = strrchr(penv_display, ':');
172 p2 = strrchr(penv_display, '.');
173 if ((p1) && (p2) && (p2 > p1)) /* "blah:x.y" */
175 /* yes it could overflow... but who will overflow DISPLAY eh? why? to
176 * "exploit" your own applications running as you?
178 strcpy(buf, penv_display);
179 buf[p2 - penv_display + 1] = 0;
180 snprintf(buf2, sizeof(buf2), "%i", head);
183 else if (p1) /* "blah:x */
185 strcpy(buf, penv_display);
186 snprintf(buf2, sizeof(buf2), ".%i", head);
190 strcpy(buf, penv_display);
193 e_util_library_path_strip();
194 exe = ecore_exe_run(cmd, NULL);
195 e_util_library_path_restore();
198 e_util_dialog_show(_("Run Error"),
199 _("Enlightenment was unable to fork a child process:<br>"
209 e_util_env_set("DISPLAY", penv_display);
216 e_util_strcmp(const char *s1, const char *s2)
219 return strcmp(s1, s2);
224 e_util_strcasecmp(const char *s1, const char *s2)
226 if ((!s1) && (!s2)) return 0;
229 return strcasecmp(s1, s2);
233 e_util_both_str_empty(const char *s1, const char *s2)
237 if ((!s1) && (!s2)) return 1;
238 if ((!s1) || ((s1) && (s1[0] == 0))) empty++;
239 if ((!s2) || ((s2) && (s2[0] == 0))) empty++;
240 if (empty == 2) return 1;
245 e_util_immortal_check(void)
249 wins = e_border_immortal_windows_get();
252 e_util_dialog_show(_("Cannot exit - immortal windows."),
253 _("Some windows are left still around with the Lifespan lock enabled. This means<br>"
254 "that Enlightenment will not allow itself to exit until these windows have<br>"
255 "been closed or have the lifespan lock removed.<br>"));
256 /* FIXME: should really display a list of these lifespan locked */
257 /* windows in a dialog and let the user disable their locks in */
259 eina_list_free(wins);
266 e_util_edje_icon_list_check(const char *list)
272 if ((!list) || (!list[0])) return 0;
273 buf = alloca(strlen(list) + 1);
280 strncpy(buf, p, c - p);
282 if (e_util_edje_icon_check(buf)) return 1;
289 if (e_util_edje_icon_check(buf)) return 1;
297 e_util_edje_icon_list_set(Evas_Object *obj, const char *list)
303 if ((!list) || (!list[0])) return 0;
304 buf = alloca(strlen(list) + 1);
311 strncpy(buf, p, c - p);
313 if (e_util_edje_icon_set(obj, buf)) return 1;
320 if (e_util_edje_icon_set(obj, buf)) return 1;
328 e_util_menu_item_edje_icon_list_set(E_Menu_Item *mi, const char *list)
334 if ((!list) || (!list[0])) return 0;
335 buf = alloca(strlen(list) + 1);
342 strncpy(buf, p, c - p);
344 if (e_util_menu_item_theme_icon_set(mi, buf)) return 1;
351 if (e_util_menu_item_theme_icon_set(mi, buf)) return 1;
359 e_util_edje_icon_check(const char *name)
364 if ((!name) || (!name[0])) return 0;
365 snprintf(buf, sizeof(buf), "e/icons/%s", name);
366 file = e_theme_edje_file_get("base/theme/icons", buf);
367 if (file[0]) return 1;
371 /* WARNING This function is deprecated,. must be made static.
372 * You should use e_util_icon_theme_set instead
375 e_util_edje_icon_set(Evas_Object *obj, const char *name)
380 if ((!name) || (!name[0])) return 0;
381 snprintf(buf, sizeof(buf), "e/icons/%s", name);
382 file = e_theme_edje_file_get("base/theme/icons", buf);
385 edje_object_file_set(obj, file, buf);
392 _e_util_icon_theme_set(Evas_Object *obj, const char *icon, Eina_Bool fallback)
397 if ((!icon) || (!icon[0])) return 0;
398 snprintf(buf, sizeof(buf), "e/icons/%s", icon);
401 file = e_theme_edje_icon_fallback_file_get(buf);
403 file = e_theme_edje_file_get("base/theme/icons", buf);
407 e_icon_file_edje_set(obj, file, buf);
415 _e_util_icon_fdo_set(Evas_Object *obj, const char *icon)
417 const char *path = NULL;
420 if ((!icon) || (!icon[0])) return 0;
421 size = e_icon_scale_size_get(obj);
422 if (size < 16) size = 16;
423 size = e_util_icon_size_normalize(size * e_scale);
425 path = efreet_icon_path_find(e_config->icon_theme, icon, size);
428 e_icon_file_set(obj, path);
432 /* use e_icon_size_scale_set(obj, size) to set the preferred icon size */
434 e_util_icon_theme_set(Evas_Object *obj, const char *icon)
436 if (e_config->icon_theme_overrides)
438 if (_e_util_icon_fdo_set(obj, icon))
440 if (_e_util_icon_theme_set(obj, icon, EINA_FALSE))
442 return _e_util_icon_theme_set(obj, icon, EINA_TRUE);
446 if (_e_util_icon_theme_set(obj, icon, EINA_FALSE))
448 if (_e_util_icon_fdo_set(obj, icon))
450 return _e_util_icon_theme_set(obj, icon, EINA_TRUE);
455 _e_util_menu_item_edje_icon_set(E_Menu_Item *mi, const char *name, Eina_Bool fallback)
460 if ((!name) || (!name[0])) return 0;
462 if ((!fallback) && (name[0] == '/') && ecore_file_exists(name))
464 e_menu_item_icon_edje_set(mi, name, "icon");
467 snprintf(buf, sizeof(buf), "e/icons/%s", name);
470 file = e_theme_edje_icon_fallback_file_get(buf);
472 file = e_theme_edje_file_get("base/theme/icons", buf);
476 e_menu_item_icon_edje_set(mi, file, buf);
483 e_util_icon_size_normalize(unsigned int desired)
485 const unsigned int *itr, known_sizes[] =
487 16, 22, 24, 32, 36, 48, 64, 72, 96, 128, 192, 256, 0
490 for (itr = known_sizes; *itr > 0; itr++)
494 return 256; /* largest know size? */
498 _e_util_menu_item_fdo_icon_set(E_Menu_Item *mi, const char *icon)
500 const char *path = NULL;
503 if ((!icon) || (!icon[0])) return 0;
504 size = e_util_icon_size_normalize(24 * e_scale);
505 path = efreet_icon_path_find(e_config->icon_theme, icon, size);
507 e_menu_item_icon_file_set(mi, path);
512 e_util_menu_item_theme_icon_set(E_Menu_Item *mi, const char *icon)
514 if (e_config->icon_theme_overrides)
516 if (_e_util_menu_item_fdo_icon_set(mi, icon))
518 if (_e_util_menu_item_edje_icon_set(mi, icon, EINA_FALSE))
520 return _e_util_menu_item_edje_icon_set(mi, icon, EINA_TRUE);
524 if (_e_util_menu_item_edje_icon_set(mi, icon, EINA_FALSE))
526 if (_e_util_menu_item_fdo_icon_set(mi, icon))
528 return _e_util_menu_item_edje_icon_set(mi, icon, EINA_TRUE);
533 e_util_mime_icon_get(const char *mime, unsigned int size)
536 const char *file = NULL;
538 if (e_config->icon_theme_overrides)
539 file = efreet_mime_type_icon_get(mime, e_config->icon_theme, e_util_icon_size_normalize(size));
540 if (file) return file;
542 if (snprintf(buf, sizeof(buf), "e/icons/fileman/mime/%s", mime) >= (int)sizeof(buf))
545 file = e_theme_edje_file_get("base/theme/icons", buf);
546 if (file && file[0]) return file;
547 return efreet_mime_type_icon_get(mime, e_config->icon_theme, e_util_icon_size_normalize(size));
551 e_util_container_window_find(Ecore_X_Window win)
557 EINA_LIST_FOREACH(e_manager_list(), l, man)
559 EINA_LIST_FOREACH(man->containers, ll, con)
561 if ((con->win == win) || (con->bg_win == win) ||
562 (con->event_win == win))
570 e_util_zone_window_find(Ecore_X_Window win)
572 Eina_List *l, *ll, *lll;
577 EINA_LIST_FOREACH(e_manager_list(), l, man)
578 EINA_LIST_FOREACH(man->containers, ll, con)
579 EINA_LIST_FOREACH(con->zones, lll, zone)
580 if (zone->black_win == win) return zone;
586 _e_util_layer_map(int layer)
590 if (layer < 0) layer = 0;
591 pos = 1 + (layer / 50);
592 if (pos > 10) pos = 10;
597 e_util_desk_border_above(E_Border *bd)
599 E_Border *bd2, *above = NULL;
603 E_OBJECT_CHECK_RETURN(bd, NULL);
604 E_OBJECT_TYPE_CHECK_RETURN(bd, E_BORDER_TYPE, NULL);
606 pos = _e_util_layer_map(bd->layer);
608 EINA_LIST_FOREACH(eina_list_data_find_list(bd->zone->container->layers[pos].clients, bd), l, bd2)
610 if (!eina_list_next(l) || above) break;
611 above = eina_list_data_get(eina_list_next(l));
612 if ((above->desk != bd->desk) && (!above->sticky))
617 /* Need to check the layers above */
618 for (i = pos + 1; (i < 7) && (!above); i++)
620 EINA_LIST_FOREACH(bd->zone->container->layers[i].clients, l, bd2)
624 if ((above->desk != bd->desk) && (!above->sticky))
633 e_util_desk_border_below(E_Border *bd)
635 E_Border *below = NULL, *bd2;
639 E_OBJECT_CHECK_RETURN(bd, NULL);
640 E_OBJECT_TYPE_CHECK_RETURN(bd, E_BORDER_TYPE, NULL);
642 pos = _e_util_layer_map(bd->layer);
644 for (l = eina_list_data_find_list(bd->zone->container->layers[pos].clients, bd); l; l = l->prev)
646 if (!eina_list_prev(l) || below) break;
647 below = eina_list_data_get(eina_list_prev(l));
648 if ((below->desk != bd->desk) && (!below->sticky))
653 /* Need to check the layers below */
654 for (i = pos - 1; (i >= 0) && (!below); i--)
656 if (bd->zone->container->layers[i].clients)
658 l = eina_list_data_find_list(bd->zone->container->layers[pos].clients, bd);
659 for (; l && !below; l = l->prev)
663 if ((below->desk != bd->desk) && (!below->sticky))
674 e_util_edje_collection_exists(const char *file, const char *coll)
676 Eina_List *clist, *l;
679 clist = edje_file_collection_list(file);
680 EINA_LIST_FOREACH(clist, l, str)
682 if (!strcmp(coll, str))
684 edje_file_collection_list_free(clist);
688 edje_file_collection_list_free(clist);
693 e_util_dialog_internal(const char *title, const char *txt)
697 dia = e_dialog_new(e_container_current_get(e_manager_current_get()), "E", "_error_dialog");
698 if (!dia) return NULL;
699 e_dialog_title_set(dia, title);
700 e_dialog_text_set(dia, txt);
701 e_dialog_icon_set(dia, "dialog-error", 64);
702 e_dialog_button_add(dia, _("OK"), NULL, NULL, NULL);
703 e_dialog_button_focus_num(dia, 0);
704 e_win_centered_set(dia->win, 1);
710 e_util_filename_escape(const char *filename)
714 static char buf[PATH_MAX];
716 if (!filename) return NULL;
721 if ((q - buf) > 4090) return NULL;
723 (*p == ' ') || (*p == '\t') || (*p == '\n') ||
724 (*p == '\\') || (*p == '\'') || (*p == '\"') ||
725 (*p == ';') || (*p == '!') || (*p == '#') ||
726 (*p == '$') || (*p == '%') || (*p == '&') ||
727 (*p == '*') || (*p == '(') || (*p == ')') ||
728 (*p == '[') || (*p == ']') || (*p == '{') ||
729 (*p == '}') || (*p == '|') || (*p == '<') ||
730 (*p == '>') || (*p == '?')
745 e_util_icon_save(Ecore_X_Icon *icon, const char *filename)
752 ee = ecore_evas_buffer_new(icon->width, icon->height);
754 evas = ecore_evas_get(ee);
755 evas_image_cache_set(evas, 0);
756 evas_font_cache_set(evas, 0);
758 im = evas_object_image_add(evas);
764 evas_object_move(im, 0, 0);
765 evas_object_resize(im, icon->width, icon->height);
766 evas_object_image_size_set(im, icon->width, icon->height);
767 evas_object_image_data_copy_set(im, icon->data);
768 evas_object_image_alpha_set(im, 1);
769 evas_object_show(im);
770 ret = evas_object_image_save(im, filename, NULL, NULL);
777 e_util_shell_env_path_eval(const char *path)
779 /* evaluate things like:
780 * $HOME/bling -> /home/user/bling
781 * $HOME/bin/$HOSTNAME/blah -> /home/user/bin/localhost/blah
784 const char *p, *v2, *v1 = NULL;
785 char buf[PATH_MAX], *pd, *s, *vp;
787 int esc = 0, invar = 0;
789 for (p = path, pd = buf; (pd < (buf + sizeof(buf) - 1)); p++)
793 if (!((isalnum(*p)) || (*p == '_')))
800 strncpy(s, v1 + 1, v2 - v1 - 1);
802 if (strncmp(s, "XDG", 3))
806 if (!strcmp(s, "XDG_CONFIG_HOME"))
807 v = (char *)efreet_config_home_get();
808 else if (!strcmp(s, "XDG_CACHE_HOME"))
809 v = (char *)efreet_cache_home_get();
810 else if (!strcmp(s, "XDG_DATA_HOME"))
811 v = (char *)efreet_data_home_get();
817 while ((*vp) && (pd < (buf + sizeof(buf) - 1)))
825 if (pd < (buf + sizeof(buf) - 1))
841 if (*p == '\\') esc = 1;
861 e_util_size_string_get(off_t size)
866 dsize = (double)size;
867 if (dsize < 1024.0) snprintf(buf, sizeof(buf), _("%'.0f bytes"), dsize);
871 if (dsize < 1024) snprintf(buf, sizeof(buf), _("%'.0f KiB"), dsize);
875 if (dsize < 1024) snprintf(buf, sizeof(buf), _("%'.1f MiB"), dsize);
879 if (dsize < 1024) snprintf(buf, sizeof(buf), _("%'.1f GiB"), dsize);
883 snprintf(buf, sizeof(buf), _("%'.1f TiB"), dsize);
892 e_util_file_time_get(time_t ftime)
894 time_t diff, ltime, test;
899 diff = ltime - ftime;
902 snprintf(buf, sizeof(buf), _("In the future"));
906 snprintf(buf, sizeof(buf), _("In the last minute"));
907 else if (diff >= 31526000)
909 test = diff / 31526000;
911 snprintf(buf, sizeof(buf), _("Last year"));
913 snprintf(buf, sizeof(buf), _("%li Years ago"), test);
915 else if (diff >= 2592000)
917 test = diff / 2592000;
919 snprintf(buf, sizeof(buf), _("Last month"));
921 snprintf(buf, sizeof(buf), _("%li Months ago"), test);
923 else if (diff >= 604800)
925 test = diff / 604800;
927 snprintf(buf, sizeof(buf), _("Last week"));
929 snprintf(buf, sizeof(buf), _("%li Weeks ago"), test);
931 else if (diff >= 86400)
935 snprintf(buf, sizeof(buf), _("Yesterday"));
937 snprintf(buf, sizeof(buf), _("%li Days ago"), test);
939 else if (diff >= 3600)
943 snprintf(buf, sizeof(buf), _("An hour ago"));
945 snprintf(buf, sizeof(buf), _("%li Hours ago"), test);
951 snprintf(buf, sizeof(buf), _("A minute ago"));
953 snprintf(buf, sizeof(buf), _("%li Minutes ago"), test);
960 s = strdup(_("Unknown"));
964 //static char *prev_ld_library_path = NULL;
965 //static char *prev_path = NULL;
968 e_util_library_path_strip(void)
970 /* disabled as i think we dont need/want this anymore - leftover from a bygone era
973 p = getenv("LD_LIBRARY_PATH");
974 E_FREE(prev_ld_library_path);
977 prev_ld_library_path = strdup(p);
980 e_util_env_set("LD_LIBRARY_PATH", p2);
986 prev_path = strdup(p);
989 e_util_env_set("PATH", p2);
995 e_util_library_path_restore(void)
997 /* disabled as i think we dont need/want this anymore - leftover from a bygone era
998 if (prev_ld_library_path)
1000 e_util_env_set("LD_LIBRARY_PATH", prev_ld_library_path);
1001 E_FREE(prev_ld_library_path);
1005 e_util_env_set("PATH", prev_path);
1012 e_util_icon_add(const char *path, Evas *evas)
1014 return _e_util_icon_add(path, evas, 64);
1018 e_util_desktop_icon_add(Efreet_Desktop *desktop, unsigned int size, Evas *evas)
1020 if ((!desktop) || (!desktop->icon)) return NULL;
1021 return e_util_icon_theme_icon_add(desktop->icon, size, evas);
1025 e_util_icon_theme_icon_add(const char *icon_name, unsigned int size, Evas *evas)
1027 if (!icon_name) return NULL;
1028 if (icon_name[0] == '/') return _e_util_icon_add(icon_name, evas, size);
1034 path = efreet_icon_path_find(e_config->icon_theme, icon_name, size);
1037 obj = _e_util_icon_add(path, evas, size);
1045 e_util_desktop_menu_item_icon_add(Efreet_Desktop *desktop, unsigned int size, E_Menu_Item *mi)
1047 const char *path = NULL;
1049 if ((!desktop) || (!desktop->icon)) return;
1051 if (desktop->icon[0] == '/') path = desktop->icon;
1052 else path = efreet_icon_path_find(e_config->icon_theme, desktop->icon, size);
1058 ext = strrchr(path, '.');
1061 if (strcmp(ext, ".edj") == 0)
1062 e_menu_item_icon_edje_set(mi, path, "icon");
1064 e_menu_item_icon_file_set(mi, path);
1067 e_menu_item_icon_file_set(mi, path);
1072 e_util_dir_check(const char *dir)
1074 if (!ecore_file_exists(dir))
1076 if (!ecore_file_mkpath(dir))
1078 e_util_dialog_show("Error creating directory", "Failed to create directory: %s .<br>Check that you have correct permissions set.", dir);
1084 if (!ecore_file_is_dir(dir))
1086 e_util_dialog_show("Error creating directory", "Failed to create directory: %s .<br>A file of that name already exists.", dir);
1094 e_util_defer_object_del(E_Object *obj)
1100 Ecore_Idle_Enterer *idler;
1102 idler = ecore_idle_enterer_before_add(_e_util_cb_delayed_del, obj);
1103 if (idler) e_object_delfn_add(obj, _e_util_cb_delayed_cancel, idler);
1108 e_util_winid_str_get(Ecore_X_Window win)
1110 const char *vals = "qWeRtYuIoP5-$&<~";
1114 val = (unsigned int)win;
1115 id[0] = vals[(val >> 28) & 0xf];
1116 id[1] = vals[(val >> 24) & 0xf];
1117 id[2] = vals[(val >> 20) & 0xf];
1118 id[3] = vals[(val >> 16) & 0xf];
1119 id[4] = vals[(val >> 12) & 0xf];
1120 id[5] = vals[(val >> 8) & 0xf];
1121 id[6] = vals[(val >> 4) & 0xf];
1122 id[7] = vals[(val) & 0xf];
1128 _win_auto_size_calc(int max, int min)
1130 const float *itr, scales[] = {0.25, 0.3, 0.5, 0.75, 0.8, 0.9, 0.95, -1};
1132 for (itr = scales; *itr > 0; itr++)
1134 int value = *itr * max;
1135 if (value > min) /* not >=, try a bit larger */
1143 e_util_win_auto_resize_fill(E_Win *win)
1145 E_Zone *zone = NULL;
1148 zone = win->border->zone;
1149 if ((!zone) && (win->container))
1150 zone = e_util_zone_current_get(win->container->manager);
1156 e_zone_useful_geometry_get(zone, NULL, NULL, &w, &h);
1158 w = _win_auto_size_calc(w, win->min_w);
1159 h = _win_auto_size_calc(h, win->min_h);
1160 e_win_resize(win, w, h);
1165 e_util_container_desk_count_get(E_Container *con)
1171 E_OBJECT_CHECK_RETURN(con, 0);
1172 E_OBJECT_TYPE_CHECK_RETURN(con, E_CONTAINER_TYPE, 0);
1173 EINA_LIST_FOREACH(con->zones, zl, zone)
1178 e_zone_desk_count_get(zone, &cx, &cy);
1179 for (x = 0; x < cx; x++)
1181 for (y = 0; y < cy; y++)
1188 /* local subsystem functions */
1190 static Evas_Object *
1191 _e_util_icon_add(const char *path, Evas *evas, int size)
1193 Evas_Object *o = NULL;
1196 if (!path) return NULL;
1197 if (!ecore_file_exists(path)) return NULL;
1199 o = e_icon_add(evas);
1200 e_icon_scale_size_set(o, size);
1201 e_icon_preload_set(o, 1);
1202 ext = strrchr(path, '.');
1205 if (!strcmp(ext, ".edj"))
1206 e_icon_file_edje_set(o, path, "icon");
1208 e_icon_file_set(o, path);
1211 e_icon_file_set(o, path);
1212 e_icon_fill_inside_set(o, 1);
1218 _e_util_cb_delayed_del(void *data)
1220 e_object_del(E_OBJECT(data));
1221 return ECORE_CALLBACK_CANCEL;
1225 _e_util_cb_delayed_cancel(void *data, void *obj __UNUSED__)
1227 Ecore_Idle_Enterer *idler = data;
1229 ecore_idle_enterer_del(idler);
1233 _e_util_wakeup_cb(void *data __UNUSED__)
1235 _e_util_dummy_timer = NULL;
1236 return ECORE_CALLBACK_CANCEL;
1240 _e_util_conf_timer_old(void *data)
1242 char *module_name = data;
1244 char *msg = _("Configuration data needed upgrading. Your old configuration<br>"
1245 "has been wiped and a new set of defaults initialized. This<br>"
1246 "will happen regularly during development, so don't report a<br>"
1247 "bug. This means the module needs new configuration<br>"
1248 "data by default for usable functionality that your old<br>"
1249 "configuration lacked. This new set of defaults will fix<br>"
1250 "that by adding it in. You can re-configure things now to your<br>"
1251 "liking. Sorry for the hiccup in your configuration.<br>");
1253 snprintf(buf, sizeof(buf), N_("%s Configuration Updated"), module_name);
1254 e_util_dialog_internal(buf, msg);
1255 E_FREE(module_name);
1257 return ECORE_CALLBACK_CANCEL;
1261 _e_util_conf_timer_new(void *data)
1263 char *module_name = data;
1266 _("Your module configuration is NEWER "
1267 "than the module version. This is "
1268 "very<br>strange. This should not happen unless"
1269 " you downgraded<br>the module or "
1270 "copied the configuration from a place where"
1271 "<br>a newer version of the module "
1272 "was running. This is bad and<br>as a "
1273 "precaution your configuration has been now "
1274 "restored to<br>defaults. Sorry for the "
1275 "inconvenience.<br>");
1277 snprintf(buf, sizeof(buf), N_("%s Configuration Updated"), module_name);
1278 e_util_dialog_internal(buf, msg);
1279 E_FREE(module_name);
1281 return ECORE_CALLBACK_CANCEL;
1285 e_util_module_config_check(const char *module_name, int loaded, int current)
1287 if ((loaded >> 16) < (current >> 16))
1289 ecore_timer_add(1.0, _e_util_conf_timer_old, strdup(module_name));
1292 else if (loaded > current)
1294 ecore_timer_add(1.0, _e_util_conf_timer_new, strdup(module_name));
1302 * Checks whenever the current manager/container/zone have fullscreen windows.
1305 e_util_fullscreen_curreny_any(void)
1307 E_Manager *man = e_manager_current_get();
1308 E_Container *con = e_container_current_get(man);
1309 E_Zone *zone = e_zone_current_get(con);
1312 if ((zone) && (zone->fullscreen > 0)) return EINA_TRUE;
1313 desk = e_desk_current_get(zone);
1314 if ((desk) && (desk->fullscreen_borders > 0)) return EINA_TRUE;
1319 * Checks whenever any manager/container/zone have fullscreen windows.
1322 e_util_fullscreen_any(void)
1325 Eina_List *lm, *lc, *lz;
1331 EINA_LIST_FOREACH(e_manager_list(), lm, man)
1333 EINA_LIST_FOREACH(man->containers, lc, con)
1335 EINA_LIST_FOREACH(con->zones, lz, zone)
1337 if (zone->fullscreen > 0) return EINA_TRUE;
1339 for (x = 0; x < zone->desk_x_count; x++)
1340 for (y = 0; y < zone->desk_y_count; y++)
1342 desk = e_desk_at_xy_get(zone, x, y);
1343 if ((desk) && (desk->fullscreen_borders > 0))
1353 e_util_time_str_get(long int seconds)
1355 static char buf[1024];
1359 snprintf(buf, sizeof(buf), _("Never"));
1363 snprintf(buf, sizeof(buf), _("%li Seconds"), seconds);
1364 else if (seconds >= 31526000)
1366 test = seconds / 31526000;
1368 snprintf(buf, sizeof(buf), _("One year"));
1370 snprintf(buf, sizeof(buf), _("%li Years"), test);
1372 else if (seconds >= 2592000)
1374 test = seconds / 2592000;
1376 snprintf(buf, sizeof(buf), _("One month"));
1378 snprintf(buf, sizeof(buf), _("%li Months"), test);
1380 else if (seconds >= 604800)
1382 test = seconds / 604800;
1384 snprintf(buf, sizeof(buf), _("One week"));
1386 snprintf(buf, sizeof(buf), _("%li Weeks"), test);
1388 else if (seconds >= 86400)
1390 test = seconds / 86400;
1392 snprintf(buf, sizeof(buf), _("One day"));
1394 snprintf(buf, sizeof(buf), _("%li Days"), test);
1396 else if (seconds >= 3600)
1398 test = seconds / 3600;
1400 snprintf(buf, sizeof(buf), _("An hour"));
1402 snprintf(buf, sizeof(buf), _("%li Hours"), test);
1404 else if (seconds > 60)
1406 test = seconds / 60;
1408 snprintf(buf, sizeof(buf), _("A minute"));
1410 snprintf(buf, sizeof(buf), _("%li Minutes"), test);
1417 _e_util_size_debug(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1421 evas_object_geometry_get(obj, &x, &y, &w, &h);
1422 fprintf(stderr, "OBJ[%p]: (%d,%d) - %dx%d\n", obj, x, y, w, h);
1426 e_util_size_debug_set(Evas_Object *obj, Eina_Bool enable)
1430 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE,
1431 _e_util_size_debug, NULL);
1432 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE,
1433 _e_util_size_debug, NULL);
1437 evas_object_event_callback_del_full(obj, EVAS_CALLBACK_MOVE,
1438 _e_util_size_debug, NULL);
1439 evas_object_event_callback_del_full(obj, EVAS_CALLBACK_RESIZE,
1440 _e_util_size_debug, NULL);
1444 static Efreet_Desktop *
1445 _e_util_default_terminal_get(const char *defaults_list)
1447 Efreet_Desktop *tdesktop = NULL;
1451 ini = efreet_ini_new(defaults_list);
1452 if ((ini) && (ini->data) &&
1453 (efreet_ini_section_set(ini, "Default Applications")) &&
1456 s = efreet_ini_string_get(ini, "x-scheme-handler/terminal");
1457 if (s) tdesktop = efreet_util_desktop_file_id_find(s);
1459 if (ini) efreet_ini_free(ini);
1463 EAPI Efreet_Desktop *
1464 e_util_terminal_desktop_get(void)
1466 const char *terms[] =
1468 "terminology.desktop",
1471 "gnome-terminal.desktop",
1477 Efreet_Desktop *tdesktop = NULL, *td;
1481 s = efreet_data_home_get();
1484 snprintf(buf, sizeof(buf), "%s/applications/defaults.list", s);
1485 tdesktop = _e_util_default_terminal_get(buf);
1487 if (tdesktop) return tdesktop;
1488 EINA_LIST_FOREACH(efreet_data_dirs_get(), l, s)
1490 snprintf(buf, sizeof(buf), "%s/applications/defaults.list", s);
1491 tdesktop = _e_util_default_terminal_get(buf);
1492 if (tdesktop) return tdesktop;
1495 for (i = 0; terms[i]; i++)
1497 tdesktop = efreet_util_desktop_file_id_find(terms[i]);
1498 if (tdesktop) return tdesktop;
1502 l = efreet_util_desktop_category_list("TerminalEmulator");
1505 // just take first one since above list doesn't work.
1507 EINA_LIST_FREE(l, td)
1509 // free/unref the desktosp we are not going to use
1510 if (td != tdesktop) efreet_desktop_free(td);
1518 EAPI E_Config_Binding_Key *
1519 e_util_binding_match(const Eina_List *bindlist, Ecore_Event_Key *ev, unsigned int *num, const E_Config_Binding_Key *skip)
1521 E_Config_Binding_Key *bi;
1523 unsigned int mod = E_BINDING_MODIFIER_NONE;
1527 if (ev->modifiers & ECORE_EVENT_MODIFIER_SHIFT)
1528 mod |= E_BINDING_MODIFIER_SHIFT;
1529 if (ev->modifiers & ECORE_EVENT_MODIFIER_CTRL)
1530 mod |= E_BINDING_MODIFIER_CTRL;
1531 if (ev->modifiers & ECORE_EVENT_MODIFIER_ALT)
1532 mod |= E_BINDING_MODIFIER_ALT;
1533 if (ev->modifiers & ECORE_EVENT_MODIFIER_WIN)
1534 mod |= E_BINDING_MODIFIER_WIN;
1535 /* see comment in e_bindings on numlock
1536 if (ev->modifiers & ECORE_X_LOCK_NUM)
1537 mod |= ECORE_X_LOCK_NUM;
1539 EINA_LIST_FOREACH(bindlist ?: e_config->key_bindings, l, bi)
1543 if ((bi->modifiers == mod) && (!strcmp(bi->key, ev->keyname)))
1553 e_util_gadcon_orient_icon_set(E_Gadcon_Orient orient, Evas_Object *obj)
1557 case E_GADCON_ORIENT_LEFT:
1558 e_util_icon_theme_set(obj, "preferences-position-left");
1561 case E_GADCON_ORIENT_RIGHT:
1562 e_util_icon_theme_set(obj, "preferences-position-right");
1565 case E_GADCON_ORIENT_TOP:
1566 e_util_icon_theme_set(obj, "preferences-position-top");
1569 case E_GADCON_ORIENT_BOTTOM:
1570 e_util_icon_theme_set(obj, "preferences-position-bottom");
1573 case E_GADCON_ORIENT_CORNER_TL:
1574 e_util_icon_theme_set(obj, "preferences-position-top-left");
1577 case E_GADCON_ORIENT_CORNER_TR:
1578 e_util_icon_theme_set(obj, "preferences-position-top-right");
1581 case E_GADCON_ORIENT_CORNER_BL:
1582 e_util_icon_theme_set(obj, "preferences-position-bottom-left");
1585 case E_GADCON_ORIENT_CORNER_BR:
1586 e_util_icon_theme_set(obj, "preferences-position-bottom-right");
1589 case E_GADCON_ORIENT_CORNER_LT:
1590 e_util_icon_theme_set(obj, "preferences-position-left-top");
1593 case E_GADCON_ORIENT_CORNER_RT:
1594 e_util_icon_theme_set(obj, "preferences-position-right-top");
1597 case E_GADCON_ORIENT_CORNER_LB:
1598 e_util_icon_theme_set(obj, "preferences-position-left-bottom");
1601 case E_GADCON_ORIENT_CORNER_RB:
1602 e_util_icon_theme_set(obj, "preferences-position-right-bottom");
1606 e_util_icon_theme_set(obj, "enlightenment");
1612 e_util_gadcon_orient_menu_item_icon_set(E_Gadcon_Orient orient, E_Menu_Item *mi)
1616 case E_GADCON_ORIENT_LEFT:
1617 e_util_menu_item_theme_icon_set(mi, "preferences-position-left");
1620 case E_GADCON_ORIENT_RIGHT:
1621 e_util_menu_item_theme_icon_set(mi, "preferences-position-right");
1624 case E_GADCON_ORIENT_TOP:
1625 e_util_menu_item_theme_icon_set(mi, "preferences-position-top");
1628 case E_GADCON_ORIENT_BOTTOM:
1629 e_util_menu_item_theme_icon_set(mi, "preferences-position-bottom");
1632 case E_GADCON_ORIENT_CORNER_TL:
1633 e_util_menu_item_theme_icon_set(mi, "preferences-position-top-left");
1636 case E_GADCON_ORIENT_CORNER_TR:
1637 e_util_menu_item_theme_icon_set(mi, "preferences-position-top-right");
1640 case E_GADCON_ORIENT_CORNER_BL:
1641 e_util_menu_item_theme_icon_set(mi, "preferences-position-bottom-left");
1644 case E_GADCON_ORIENT_CORNER_BR:
1645 e_util_menu_item_theme_icon_set(mi, "preferences-position-bottom-right");
1648 case E_GADCON_ORIENT_CORNER_LT:
1649 e_util_menu_item_theme_icon_set(mi, "preferences-position-left-top");
1652 case E_GADCON_ORIENT_CORNER_RT:
1653 e_util_menu_item_theme_icon_set(mi, "preferences-position-right-top");
1656 case E_GADCON_ORIENT_CORNER_LB:
1657 e_util_menu_item_theme_icon_set(mi, "preferences-position-left-bottom");
1660 case E_GADCON_ORIENT_CORNER_RB:
1661 e_util_menu_item_theme_icon_set(mi, "preferences-position-right-bottom");
1665 e_util_menu_item_theme_icon_set(mi, "enlightenment");
1670 #if _F_USE_EXTN_DIALOG_
1672 * Using external elementary dialog util instead of e_dialog to display error or warning
1673 * messages. It is a temporary solution for supporting consistent UX theme. The external
1674 * dialog is a simple EFL application which is based on elementary. Thus window manager
1675 * can display message using elementary UX theme, along with other system popup.
1678 e_util_extn_dialog_show(const char *title,
1684 /* external_dialog_name, icccm_name, icccm_class, popup_title, popup_contents */
1685 snprintf(cmd, sizeof(cmd), "/usr/bin/extndialog E _extn_dialog \'%s\' \'%s\'", title, txt);
1686 exe = ecore_exe_run(cmd, NULL);
1687 if (exe) ecore_exe_free(exe);