2 # include "elementary_config.h"
9 #include <Elementary.h>
13 Elm_Config *_elm_config = NULL;
14 char *_elm_profile = NULL;
15 static Eet_Data_Descriptor *_config_edd = NULL;
16 static Eet_Data_Descriptor *_config_font_overlay_edd = NULL;
18 static Ecore_Poller *_elm_cache_flush_poller = NULL;
20 const char *_elm_engines[] = {
29 "software_16_wince_gdi",
36 /* whenever you want to add a new text class support into Elementary,
37 declare it both here and in the (default) theme */
38 static const Elm_Text_Class _elm_text_classes[] = {
39 {"button", "Button Labels"},
40 {"label", "Text Labels"},
41 {"entry", "Text Entries"},
42 {"title_bar", "Title Bar"},
43 {"list_item", "List Items"},
44 {"grid_item", "Grid Items"},
45 {"toolbar_item", "Toolbar Items"},
46 {"menu_item", "Menu Items"},
50 static void _desc_init(void);
51 static void _desc_shutdown(void);
52 static void _profile_fetch_from_conf(void);
53 static void _config_free(void);
54 static void _config_apply(void);
55 static Elm_Config *_config_user_load(void);
56 static Elm_Config *_config_system_load(void);
57 static void _config_load(void);
58 static void _config_update(void);
59 static void _env_get(void);
60 static size_t _elm_data_dir_snprintf(char *dst,
64 static size_t _elm_user_dir_snprintf(char *dst,
69 #define ELM_CONFIG_VAL(edd, type, member, dtype) \
70 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, type, #member, member, dtype)
71 #define ELM_CONFIG_LIST(edd, type, member, eddtype) \
72 EET_DATA_DESCRIPTOR_ADD_LIST(edd, type, #member, member, eddtype)
74 #ifdef HAVE_ELEMENTARY_X
75 static Ecore_Event_Handler *_prop_change_handler = NULL;
76 static Ecore_X_Window _root_1st = 0;
78 static Ecore_X_Atom _atom[ATOM_COUNT];
79 static Ecore_X_Atom _atom_config = 0;
80 static const char *_atom_names[ATOM_COUNT] =
82 "ENLIGHTENMENT_SCALE",
83 "ENLIGHTENMENT_FINGER_SIZE",
84 "ENLIGHTENMENT_THEME",
85 "ENLIGHTENMENT_PROFILE",
86 "ENLIGHTENMENT_FONT_OVERLAY",
87 "ENLIGHTENMENT_CACHE_FLUSH_INTERVAL",
88 "ENLIGHTENMENT_CACHE_FLUSH_ENABLE",
89 "ENLIGHTENMENT_FONT_CACHE",
90 "ENLIGHTENMENT_IMAGE_CACHE",
91 "ENLIGHTENMENT_EDJE_FILE_CACHE",
92 "ENLIGHTENMENT_EDJE_COLLECTION_CACHE",
93 "ENLIGHTENMENT_THUMBSCROLL_BOUNCE_ENABLE",
94 "ENLIGHTENMENT_THUMBSCROLL_BOUNCE_FRICTION",
95 "ENLIGHTENMENT_THUMBSCROLL_ENABLE",
96 "ENLIGHTENMENT_THUMBSCROLL_THRESHOLD",
97 "ENLIGHTENMENT_THUMBSCROLL_MOMENTUM_THRESHOLD",
98 "ENLIGHTENMENT_THUMBSCROLL_FRICTION",
99 "ENLIGHTENMENT_THUMBSCROLL_BORDER_FRICTION",
100 "ENLIGHTENMENT_THUMBSCROLL_PAGE_SCROLL_FRICTION",
101 "ENLIGHTENMENT_THUMBSCROLL_BRING_IN_SCROLL_FRICTION",
102 "ENLIGHTENMENT_THUMBSCROLL_ZOOM_FRICTION",
103 "ENLIGHTENMENT_CONFIG"
105 #define ATOM_E_SCALE 0
106 #define ATOM_E_FINGER_SIZE 1
107 #define ATOM_E_THEME 2
108 #define ATOM_E_PROFILE 3
109 #define ATOM_E_FONT_OVERLAY 4
110 #define ATOM_E_CACHE_FLUSH_INTERVAL 5
111 #define ATOM_E_CACHE_FLUSH_ENABLE 6
112 #define ATOM_E_FONT_CACHE 7
113 #define ATOM_E_IMAGE_CACHE 8
114 #define ATOM_E_EDJE_FILE_CACHE 9
115 #define ATOM_E_EDJE_COLLECTION_CACHE 10
116 #define ATOM_E_THUMBSCROLL_BOUNCE_ENABLE 11
117 #define ATOM_E_THUMBSCROLL_BOUNCE_FRICTION 12
118 #define ATOM_E_THUMBSCROLL_ENABLE 13
119 #define ATOM_E_THUMBSCROLL_THRESHOLD 14
120 #define ATOM_E_THUMBSCROLL_MOMENTUM_THRESHOLD 15
121 #define ATOM_E_THUMBSCROLL_FRICTION 16
122 #define ATOM_E_THUMBSCROLL_BORDER_FRICTION 17
123 #define ATOM_E_THUMBSCROLL_PAGE_SCROLL_FRICTION 18
124 #define ATOM_E_THUMBSCROLL_BRING_IN_SCROLL_FRICTION 19
125 #define ATOM_E_THUMBSCROLL_ZOOM_FRICTION 20
126 #define ATOM_E_CONFIG 21
128 static Eina_Bool _prop_config_get(void);
129 static Eina_Bool _prop_change(void *data __UNUSED__,
130 int ev_type __UNUSED__,
134 _prop_config_get(void)
139 unsigned char *data = NULL;
140 Elm_Config *config_data;
142 snprintf(buf, sizeof(buf), "ENLIGHTENMENT_CONFIG_%s", _elm_profile);
143 atom = ecore_x_atom_get(buf);
145 if (!ecore_x_window_prop_property_get(_root_1st,
146 atom, _atom[ATOM_E_CONFIG],
149 if (!ecore_x_window_prop_property_get(_root_1st,
150 _atom[ATOM_E_CONFIG],
151 _atom[ATOM_E_CONFIG],
155 _atom_config = _atom[ATOM_E_CONFIG];
164 config_data = eet_data_descriptor_decode(_config_edd, data, size);
166 if (!config_data) return EINA_FALSE;
168 /* What do we do on version mismatch when someone changes the
169 * config in the rootwindow? */
170 /* Most obvious case, new version and we are still linked to
171 * whatever was there before, we just ignore until user restarts us */
172 if (config_data->config_version > ELM_CONFIG_VERSION)
174 /* What in the case the version is older? Do we even support those
175 * cases or we only check for equality above? */
178 _elm_config = config_data;
180 _elm_config_font_overlay_apply();
187 _prop_change(void *data __UNUSED__,
188 int ev_type __UNUSED__,
191 Ecore_X_Event_Window_Property *event = ev;
193 if (event->win == _root_1st)
195 if (event->atom == _atom[ATOM_E_SCALE])
197 unsigned int val = 1000;
199 if (ecore_x_window_prop_card32_get(event->win,
205 pscale = _elm_config->scale;
206 if (val > 0) _elm_config->scale = (double)val / 1000.0;
207 if (pscale != _elm_config->scale)
214 else if (event->atom == _atom[ATOM_E_FINGER_SIZE])
216 unsigned int val = 1000;
218 if (ecore_x_window_prop_card32_get(event->win,
224 pfinger_size = _elm_config->finger_size;
225 _elm_config->finger_size = val;
226 if (pfinger_size != _elm_config->finger_size)
233 else if (event->atom == _atom[ATOM_E_THEME])
237 val = ecore_x_window_prop_string_get(event->win,
239 eina_stringshare_replace(&_elm_config->theme, val);
242 _elm_theme_parse(NULL, val);
248 else if (event->atom == _atom[ATOM_E_PROFILE])
252 val = ecore_x_window_prop_string_get(event->win,
260 if (strcmp(_elm_profile, val)) changed = 1;
266 if (!_prop_config_get())
271 _elm_config_font_overlay_apply();
277 else if (event->atom == _atom[ATOM_E_FONT_OVERLAY])
279 unsigned int val = 1000;
281 if (ecore_x_window_prop_card32_get(event->win,
288 _elm_config_font_overlay_apply();
292 else if (event->atom == _atom[ATOM_E_CACHE_FLUSH_INTERVAL])
294 unsigned int val = 1000;
296 if (ecore_x_window_prop_card32_get(event->win,
300 int cache_flush_interval;
302 cache_flush_interval = _elm_config->cache_flush_poll_interval;
303 _elm_config->cache_flush_poll_interval = val;
304 if (cache_flush_interval !=
305 _elm_config->cache_flush_poll_interval)
309 else if (event->atom == _atom[ATOM_E_CACHE_FLUSH_ENABLE])
311 unsigned int val = 1000;
313 if (ecore_x_window_prop_card32_get(event->win,
317 _elm_config->cache_flush_enable = !!val;
321 else if (event->atom == _atom[ATOM_E_FONT_CACHE])
323 unsigned int val = 1000;
325 if (ecore_x_window_prop_card32_get(event->win,
331 font_cache = _elm_config->font_cache;
332 _elm_config->font_cache = val;
333 if (font_cache != _elm_config->font_cache)
337 else if (event->atom == _atom[ATOM_E_IMAGE_CACHE])
339 unsigned int val = 1000;
341 if (ecore_x_window_prop_card32_get(event->win,
347 image_cache = _elm_config->image_cache;
348 _elm_config->image_cache = val;
349 if (image_cache != _elm_config->image_cache)
353 else if (event->atom == _atom[ATOM_E_EDJE_FILE_CACHE])
355 unsigned int val = 1000;
357 if (ecore_x_window_prop_card32_get(event->win,
363 edje_file_cache = _elm_config->edje_cache;
364 _elm_config->edje_cache = val;
365 if (edje_file_cache != _elm_config->edje_cache)
369 else if (event->atom == _atom[ATOM_E_EDJE_COLLECTION_CACHE])
371 unsigned int val = 1000;
373 if (ecore_x_window_prop_card32_get(event->win,
377 int edje_collection_cache;
379 edje_collection_cache = _elm_config->edje_collection_cache;
380 _elm_config->edje_collection_cache = val;
381 if (edje_collection_cache !=
382 _elm_config->edje_collection_cache)
386 else if (event->atom == _atom[ATOM_E_THUMBSCROLL_BOUNCE_ENABLE])
388 unsigned int val = 1000;
390 if (ecore_x_window_prop_card32_get(event->win,
394 _elm_config->thumbscroll_bounce_enable = !!val;
397 else if (event->atom == _atom[ATOM_E_THUMBSCROLL_BOUNCE_FRICTION])
399 unsigned int val = 1000;
401 if (ecore_x_window_prop_card32_get(event->win,
406 _elm_config->thumbscroll_bounce_friction =
407 (double)val / 1000.0;
410 else if (event->atom == _atom[ATOM_E_THUMBSCROLL_ENABLE])
412 unsigned int val = 1000;
414 if (ecore_x_window_prop_card32_get(event->win,
418 _elm_config->thumbscroll_enable = !!val;
421 else if (event->atom == _atom[ATOM_E_THUMBSCROLL_THRESHOLD])
423 unsigned int val = 1000;
425 if (ecore_x_window_prop_card32_get(event->win,
429 if (val > 0) _elm_config->thumbscroll_threshold = val;
432 else if (event->atom == _atom[ATOM_E_THUMBSCROLL_MOMENTUM_THRESHOLD])
434 unsigned int val = 1000;
436 if (ecore_x_window_prop_card32_get(event->win,
441 _elm_config->thumbscroll_momentum_threshold =
442 (double)val / 1000.0;
445 else if (event->atom == _atom[ATOM_E_THUMBSCROLL_FRICTION])
447 unsigned int val = 1000;
449 if (ecore_x_window_prop_card32_get(event->win,
454 _elm_config->thumbscroll_friction = (double)val / 1000.0;
457 else if (event->atom == _atom[ATOM_E_THUMBSCROLL_BORDER_FRICTION])
459 unsigned int val = 1000;
461 if (ecore_x_window_prop_card32_get(event->win,
466 _elm_config->thumbscroll_border_friction =
467 (double)val / 1000.0;
470 else if (event->atom == _atom[ATOM_E_THUMBSCROLL_PAGE_SCROLL_FRICTION])
472 unsigned int val = 1000;
474 if (ecore_x_window_prop_card32_get(event->win,
479 _elm_config->page_scroll_friction =
480 (double)val / 1000.0;
483 else if (event->atom ==
484 _atom[ATOM_E_THUMBSCROLL_BRING_IN_SCROLL_FRICTION])
486 unsigned int val = 1000;
488 if (ecore_x_window_prop_card32_get(event->win,
493 _elm_config->bring_in_scroll_friction =
494 (double)val / 1000.0;
497 else if (event->atom ==
498 _atom[ATOM_E_THUMBSCROLL_ZOOM_FRICTION])
500 unsigned int val = 1000;
502 if (ecore_x_window_prop_card32_get(event->win,
507 _elm_config->zoom_friction = (double)val / 1000.0;
510 else if (((_atom_config > 0) && (event->atom == _atom_config)) ||
511 (event->atom == _atom[ATOM_E_CONFIG]))
516 return ECORE_CALLBACK_PASS_ON;
524 Eet_Data_Descriptor_Class eddc;
526 EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Elm_Config);
527 eddc.func.str_direct_alloc = NULL;
528 eddc.func.str_direct_free = NULL;
530 _config_edd = eet_data_descriptor_file_new(&eddc);
533 printf("EEEK! eet_data_descriptor_file_new() failed\n");
537 memset(&eddc, 0, sizeof(eddc)); /* just in case... */
538 EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Elm_Font_Overlay);
539 eddc.func.str_direct_alloc = NULL;
540 eddc.func.str_direct_free = NULL;
542 _config_font_overlay_edd = eet_data_descriptor_stream_new(&eddc);
543 if (!_config_font_overlay_edd)
545 printf("EEEK! eet_data_descriptor_stream_new() failed\n");
546 eet_data_descriptor_free(_config_edd);
549 #define T_INT EET_T_INT
550 #define T_DOUBLE EET_T_DOUBLE
551 #define T_STRING EET_T_STRING
552 #define T_UCHAR EET_T_UCHAR
554 #define T Elm_Font_Overlay
555 #define D _config_font_overlay_edd
556 ELM_CONFIG_VAL(D, T, text_class, EET_T_STRING);
557 ELM_CONFIG_VAL(D, T, font, EET_T_STRING);
558 ELM_CONFIG_VAL(D, T, size, EET_T_INT);
563 #define D _config_edd
564 ELM_CONFIG_VAL(D, T, config_version, T_INT);
565 ELM_CONFIG_VAL(D, T, engine, T_STRING);
566 ELM_CONFIG_VAL(D, T, vsync, T_UCHAR);
567 ELM_CONFIG_VAL(D, T, thumbscroll_enable, T_UCHAR);
568 ELM_CONFIG_VAL(D, T, thumbscroll_threshold, T_INT);
569 ELM_CONFIG_VAL(D, T, thumbscroll_momentum_threshold, T_DOUBLE);
570 ELM_CONFIG_VAL(D, T, thumbscroll_friction, T_DOUBLE);
571 ELM_CONFIG_VAL(D, T, thumbscroll_bounce_friction, T_DOUBLE);
572 ELM_CONFIG_VAL(D, T, thumbscroll_border_friction, T_DOUBLE);
573 ELM_CONFIG_VAL(D, T, page_scroll_friction, T_DOUBLE);
574 ELM_CONFIG_VAL(D, T, bring_in_scroll_friction, T_DOUBLE);
575 ELM_CONFIG_VAL(D, T, zoom_friction, T_DOUBLE);
576 ELM_CONFIG_VAL(D, T, thumbscroll_bounce_enable, T_UCHAR);
577 ELM_CONFIG_VAL(D, T, scale, T_DOUBLE);
578 ELM_CONFIG_VAL(D, T, bgpixmap, T_INT);
579 ELM_CONFIG_VAL(D, T, compositing, T_INT);
580 /* EET_DATA_DESCRIPTOR_ADD_LIST(D, T, "font_dirs", font_dirs, sub_edd); */
581 ELM_CONFIG_LIST(D, T, font_overlays, _config_font_overlay_edd);
582 ELM_CONFIG_VAL(D, T, font_hinting, T_INT);
583 ELM_CONFIG_VAL(D, T, cache_flush_poll_interval, T_INT);
584 ELM_CONFIG_VAL(D, T, cache_flush_enable, T_UCHAR);
585 ELM_CONFIG_VAL(D, T, image_cache, T_INT);
586 ELM_CONFIG_VAL(D, T, font_cache, T_INT);
587 ELM_CONFIG_VAL(D, T, edje_cache, T_INT);
588 ELM_CONFIG_VAL(D, T, edje_collection_cache, T_INT);
589 ELM_CONFIG_VAL(D, T, finger_size, T_INT);
590 ELM_CONFIG_VAL(D, T, fps, T_DOUBLE);
591 ELM_CONFIG_VAL(D, T, theme, T_STRING);
592 ELM_CONFIG_VAL(D, T, modules, T_STRING);
593 ELM_CONFIG_VAL(D, T, tooltip_delay, T_DOUBLE);
594 ELM_CONFIG_VAL(D, T, cursor_engine_only, T_UCHAR);
595 ELM_CONFIG_VAL(D, T, focus_highlight_enable, T_UCHAR);
596 ELM_CONFIG_VAL(D, T, focus_highlight_animate, T_UCHAR);
597 ELM_CONFIG_VAL(D, T, toolbar_shrink_mode, T_INT);
598 ELM_CONFIG_VAL(D, T, fileselector_expand_enable, T_UCHAR);
599 ELM_CONFIG_VAL(D, T, inwin_dialogs_enable, T_UCHAR);
600 ELM_CONFIG_VAL(D, T, icon_size, T_INT);
601 ELM_CONFIG_VAL(D, T, longpress_timeout, T_DOUBLE);
602 ELM_CONFIG_VAL(D, T, effect_enable, T_UCHAR);
603 ELM_CONFIG_VAL(D, T, desktop_entry, T_UCHAR);
617 eet_data_descriptor_free(_config_edd);
621 if (_config_font_overlay_edd)
623 eet_data_descriptor_free(_config_font_overlay_edd);
624 _config_font_overlay_edd = NULL;
629 _sort_files_cb(const void *f1,
632 return strcmp(f1, f2);
636 _elm_config_current_profile_get(void)
642 _elm_data_dir_snprintf(char *dst,
647 size_t data_dir_len, off;
650 data_dir_len = eina_strlcpy(dst, _elm_data_dir, size);
652 off = data_dir_len + 1;
657 dst[data_dir_len] = '/';
659 off = off + vsnprintf(dst + off, size - off, fmt, ap);
667 _elm_user_dir_snprintf(char *dst,
673 size_t user_dir_len, off;
677 home = evil_homedir_get();
679 home = getenv("HOME");
684 user_dir_len = eina_str_join_len(dst, size, '/', home, strlen(home),
685 ".elementary", sizeof(".elementary") - 1);
687 off = user_dir_len + 1;
692 dst[user_dir_len] = '/';
694 off = off + vsnprintf(dst + off, size - off, fmt, ap);
702 _elm_config_profile_dir_get(const char *prof,
710 _elm_user_dir_snprintf(buf, sizeof(buf), "config/%s", prof);
712 if (ecore_file_is_dir(buf))
718 snprintf(buf, sizeof(buf), "%s/config/%s", _elm_data_dir, prof);
720 if (ecore_file_is_dir(buf))
727 _elm_config_font_overlays_list(void)
729 return _elm_config->font_overlays;
733 _elm_config_font_overlay_set(const char *text_class,
737 Elm_Font_Overlay *efd;
740 EINA_LIST_FOREACH(_elm_config->font_overlays, l, efd)
742 if (strcmp(efd->text_class, text_class))
745 if (efd->font) eina_stringshare_del(efd->font);
746 efd->font = eina_stringshare_add(font);
748 _elm_config->font_overlays =
749 eina_list_promote_list(_elm_config->font_overlays, l);
753 /* the text class doesn't exist */
754 efd = calloc(1, sizeof(Elm_Font_Overlay));
755 efd->text_class = eina_stringshare_add(text_class);
756 efd->font = eina_stringshare_add(font);
759 _elm_config->font_overlays = eina_list_prepend(_elm_config->font_overlays,
764 _elm_config_font_overlay_remove(const char *text_class)
766 Elm_Font_Overlay *efd;
769 EINA_LIST_FOREACH(_elm_config->font_overlays, l, efd)
771 if (strcmp(efd->text_class, text_class))
774 _elm_config->font_overlays =
775 eina_list_remove_list(_elm_config->font_overlays, l);
776 if (efd->text_class) eina_stringshare_del(efd->text_class);
777 if (efd->font) eina_stringshare_del(efd->font);
785 _elm_config_font_overlay_apply(void)
787 Elm_Font_Overlay *efd;
791 for (i = 0; _elm_text_classes[i].desc; i++)
792 edje_text_class_del(_elm_text_classes[i].name);
794 EINA_LIST_FOREACH(_elm_config->font_overlays, l, efd)
795 edje_text_class_set(efd->text_class, efd->font, efd->size);
799 _elm_config_text_classes_get(void)
801 Eina_List *ret = NULL;
804 for (i = 0; _elm_text_classes[i].desc; i++)
807 tc = malloc(sizeof(*tc));
809 *tc = _elm_text_classes[i];
811 ret = eina_list_append(ret, tc);
818 _elm_config_text_classes_free(Eina_List *l)
822 EINA_LIST_FREE(l, tc)
827 _elm_config_profiles_list(void)
829 const Eina_File_Direct_Info *info;
830 Eina_List *flist = NULL;
831 Eina_Iterator *file_it;
836 len = _elm_user_dir_snprintf(buf, sizeof(buf), "config");
838 file_it = eina_file_direct_ls(buf);
845 len = sizeof(buf) - len;
847 EINA_ITERATOR_FOREACH(file_it, info)
849 if (info->name_length >= len)
852 if (info->type == EINA_FILE_DIR)
855 eina_list_sorted_insert(flist, _sort_files_cb,
856 eina_stringshare_add(info->path +
861 eina_iterator_free(file_it);
864 len = eina_str_join_len(buf, sizeof(buf), '/', _elm_data_dir,
865 strlen(_elm_data_dir), "config",
866 sizeof("config") - 1);
868 file_it = eina_file_direct_ls(buf);
875 len = sizeof(buf) - len;
876 EINA_ITERATOR_FOREACH(file_it, info)
878 if (info->name_length >= len)
888 EINA_LIST_FOREACH(flist, l, tmp)
889 if (!strcmp(info->path + info->name_start, tmp))
894 eina_list_sorted_insert(flist, _sort_files_cb,
895 eina_stringshare_add(info->path +
906 eina_iterator_free(file_it);
909 EINA_LIST_FREE(flist, dir)
910 eina_stringshare_del(dir);
916 _profile_fetch_from_conf(void)
918 char buf[PATH_MAX], *p, *s;
922 _elm_profile = strdup("default");
924 // if env var - use profile without question
925 s = getenv("ELM_PROFILE");
929 _elm_profile = strdup(s);
934 _elm_user_dir_snprintf(buf, sizeof(buf), "config/profile.cfg");
935 ef = eet_open(buf, EET_FILE_MODE_READ);
938 p = eet_read(ef, "config", &len);
942 _elm_profile = malloc(len + 1);
943 memcpy(_elm_profile, p, len);
944 _elm_profile[len] = 0;
953 _elm_data_dir_snprintf(buf, sizeof(buf), "config/profile.cfg");
954 ef = eet_open(buf, EET_FILE_MODE_READ);
957 p = eet_read(ef, "config", &len);
961 _elm_profile = malloc(len + 1);
962 memcpy(_elm_profile, p, len);
963 _elm_profile[len] = 0;
973 Elm_Font_Overlay *fo;
976 if (!_elm_config) return;
977 EINA_LIST_FREE(_elm_config->font_dirs, fontdir)
979 eina_stringshare_del(fontdir);
981 if (_elm_config->engine) eina_stringshare_del(_elm_config->engine);
982 EINA_LIST_FREE(_elm_config->font_overlays, fo)
984 if (fo->text_class) eina_stringshare_del(fo->text_class);
985 if (fo->font) eina_stringshare_del(fo->font);
988 if (_elm_config->theme) eina_stringshare_del(_elm_config->theme);
989 if (_elm_config->modules) eina_stringshare_del(_elm_config->modules);
997 _elm_theme_parse(NULL, _elm_config->theme);
998 ecore_animator_frametime_set(1.0 / _elm_config->fps);
1002 _config_sub_apply(void)
1004 edje_frametime_set(1.0 / _elm_config->fps);
1005 edje_scale_set(_elm_config->scale);
1006 if (_elm_config->modules) _elm_module_parse(_elm_config->modules);
1010 _elm_cache_flush_cb(void *data __UNUSED__)
1013 return ECORE_CALLBACK_RENEW;
1016 /* kind of abusing this call right now -- shared between all of those
1017 * properties -- but they are not meant to be called that periodically
1027 EINA_LIST_FOREACH(_elm_win_list, l, win)
1029 Evas *e = evas_object_evas_get(win);
1030 evas_image_cache_set(e, _elm_config->image_cache * 1024);
1031 evas_font_cache_set(e, _elm_config->font_cache * 1024);
1033 edje_file_cache_set(_elm_config->edje_cache);
1034 edje_collection_cache_set(_elm_config->edje_collection_cache);
1036 if (_elm_cache_flush_poller)
1038 ecore_poller_del(_elm_cache_flush_poller);
1039 _elm_cache_flush_poller = NULL;
1041 if (_elm_config->cache_flush_enable)
1043 if (_elm_config->cache_flush_poll_interval > 0)
1045 _elm_cache_flush_poller =
1046 ecore_poller_add(ECORE_POLLER_CORE,
1047 _elm_config->cache_flush_poll_interval,
1048 _elm_cache_flush_cb, NULL);
1054 _config_user_load(void)
1056 Elm_Config *cfg = NULL;
1060 _elm_user_dir_snprintf(buf, sizeof(buf), "config/%s/base.cfg",
1063 ef = eet_open(buf, EET_FILE_MODE_READ);
1066 cfg = eet_data_read(ef, _config_edd, "config");
1073 _config_system_load(void)
1075 Elm_Config *cfg = NULL;
1079 _elm_data_dir_snprintf(buf, sizeof(buf), "config/%s/base.cfg",
1082 ef = eet_open(buf, EET_FILE_MODE_READ);
1085 cfg = eet_data_read(ef, _config_edd, "config");
1094 _elm_config = _config_user_load();
1097 if (_elm_config->config_version < ELM_CONFIG_VERSION)
1102 /* no user config, fallback for system. No need to check version for
1103 * this one, if it's not the right one, someone screwed up at the time
1104 * of installing it */
1105 _elm_config = _config_system_load();
1106 if (_elm_config) return;
1107 /* FIXME: config load could have failed because of a non-existent
1108 * profile. Fallback to default before moving on */
1110 // config load fail - defaults
1111 /* XXX: do these make sense? Only if it's valid to install the lib
1112 * without the config, but do we want that? */
1113 _elm_config = ELM_NEW(Elm_Config);
1114 _elm_config->config_version = ELM_CONFIG_VERSION;
1115 _elm_config->engine = eina_stringshare_add("software_x11");
1116 _elm_config->vsync = 0;
1117 _elm_config->thumbscroll_enable = EINA_TRUE;
1118 _elm_config->thumbscroll_threshold = 24;
1119 _elm_config->thumbscroll_momentum_threshold = 100.0;
1120 _elm_config->thumbscroll_friction = 1.0;
1121 _elm_config->thumbscroll_bounce_friction = 0.5;
1122 _elm_config->thumbscroll_bounce_enable = EINA_TRUE;
1123 _elm_config->page_scroll_friction = 0.5;
1124 _elm_config->bring_in_scroll_friction = 0.5;
1125 _elm_config->zoom_friction = 0.5;
1126 _elm_config->thumbscroll_border_friction = 0.5;
1127 _elm_config->scale = 1.0;
1128 _elm_config->bgpixmap = 0;
1129 _elm_config->compositing = 1;
1130 _elm_config->font_hinting = 2;
1131 _elm_config->cache_flush_poll_interval = 512;
1132 _elm_config->cache_flush_enable = EINA_TRUE;
1133 _elm_config->font_dirs = NULL;
1134 _elm_config->image_cache = 4096;
1135 _elm_config->font_cache = 512;
1136 _elm_config->edje_cache = 32;
1137 _elm_config->edje_collection_cache = 64;
1138 _elm_config->finger_size = 40;
1139 _elm_config->fps = 60.0;
1140 _elm_config->theme = eina_stringshare_add("default");
1141 _elm_config->modules = NULL;
1142 _elm_config->tooltip_delay = 1.0;
1143 _elm_config->cursor_engine_only = EINA_TRUE;
1144 _elm_config->focus_highlight_enable = EINA_FALSE;
1145 _elm_config->focus_highlight_animate = EINA_TRUE;
1146 _elm_config->toolbar_shrink_mode = 2;
1147 _elm_config->fileselector_expand_enable = EINA_FALSE;
1148 _elm_config->inwin_dialogs_enable = EINA_FALSE;
1149 _elm_config->icon_size = 32;
1150 _elm_config->longpress_timeout = 1.0;
1151 _elm_config->effect_enable = EINA_TRUE;
1152 _elm_config->desktop_entry = EINA_FALSE;
1154 _elm_config->is_mirrored = EINA_FALSE; /* Read sys value in env_get() */
1158 _elm_config_eet_close_error_get(Eet_File *ef,
1162 const char *erstr = NULL;
1164 err = eet_close(ef);
1167 case EET_ERROR_WRITE_ERROR:
1168 erstr = "An error occurred while saving Elementary's "
1169 "settings to disk. The error could not be "
1170 "deterimined. The file where the error occurred was: "
1171 "%s. This file has been deleted to avoid corrupt data.";
1174 case EET_ERROR_WRITE_ERROR_FILE_TOO_BIG:
1175 erstr = "Elementary's settings files are too big "
1176 "for the file system they are being saved to. "
1177 "This error is very strange as the files should "
1178 "be extremely small. Please check the settings "
1179 "for your home directory. "
1180 "The file where the error occurred was: %s ."
1181 "This file has been deleted to avoid corrupt data.";
1184 case EET_ERROR_WRITE_ERROR_IO_ERROR:
1185 erstr = "An output error occurred when writing the settings "
1186 "files for Elementary. Your disk is having troubles "
1187 "and possibly needs replacement. "
1188 "The file where the error occurred was: %s ."
1189 "This file has been deleted to avoid corrupt data.";
1192 case EET_ERROR_WRITE_ERROR_OUT_OF_SPACE:
1193 erstr = "Elementary cannot write its settings file "
1194 "because it ran out of space to write the file. "
1195 "You have either run out of disk space or have "
1196 "gone over your quota limit. "
1197 "The file where the error occurred was: %s ."
1198 "This file has been deleted to avoid corrupt data.";
1201 case EET_ERROR_WRITE_ERROR_FILE_CLOSED:
1202 erstr = "Elementary unexpectedly had the settings file "
1203 "it was writing closed on it. This is very unusual. "
1204 "The file where the error occurred was: %s "
1205 "This file has been deleted to avoid corrupt data.";
1213 /* delete any partially-written file */
1214 ecore_file_unlink(file);
1215 return strdup(erstr);
1222 _elm_config_profile_save(void)
1224 char buf[4096], buf2[4096];
1230 len = _elm_user_dir_snprintf(buf, sizeof(buf), "config/profile.cfg");
1231 if (len + 1 >= sizeof(buf))
1234 len = _elm_user_dir_snprintf(buf2, sizeof(buf2), "config/profile.cfg.tmp");
1235 if (len + 1 >= sizeof(buf2))
1238 ef = eet_open(buf2, EET_FILE_MODE_WRITE);
1242 ok = eet_write(ef, "config", _elm_profile, strlen(_elm_profile), 0);
1246 err = _elm_config_eet_close_error_get(ef, buf2);
1254 ret = ecore_file_mv(buf2, buf);
1257 ERR("Error saving Elementary's configuration file");
1261 ecore_file_unlink(buf2);
1265 ecore_file_unlink(buf2);
1270 _elm_config_save(void)
1272 char buf[4096], buf2[4096];
1278 len = _elm_user_dir_snprintf(buf, sizeof(buf), "config/%s", _elm_profile);
1279 if (len + 1 >= sizeof(buf))
1282 ok = ecore_file_mkpath(buf);
1285 ERR("Problem acessing Elementary's user configuration directory: %s",
1290 if (!_elm_config_profile_save())
1296 if (len + sizeof("base.cfg") >= sizeof(buf) - len)
1299 memcpy(buf + len, "base.cfg", sizeof("base.cfg"));
1300 len += sizeof("base.cfg") - 1;
1302 if (len + sizeof(".tmp") >= sizeof(buf))
1305 memcpy(buf2, buf, len);
1306 memcpy(buf2 + len, ".tmp", sizeof(".tmp"));
1308 ef = eet_open(buf2, EET_FILE_MODE_WRITE);
1312 ok = eet_data_write(ef, _config_edd, "config", _elm_config, 1);
1316 err = _elm_config_eet_close_error_get(ef, buf2);
1324 ret = ecore_file_mv(buf2, buf);
1327 ERR("Error saving Elementary's configuration file");
1331 ecore_file_unlink(buf2);
1335 ecore_file_unlink(buf2);
1340 _config_update(void)
1344 tcfg = _config_system_load();
1347 /* weird profile or something? We should probably fill
1348 * with hardcoded defaults, or get from default previx */
1351 #define IFCFG(v) if ((_elm_config->config_version & 0xffff) < (v)) {
1352 #define IFCFGELSE } else {
1354 #define COPYVAL(x) do {_elm_config->x = tcfg->x; } while(0)
1355 #define COPYPTR(x) do {_elm_config->x = tcfg->x; tcfg->x = NULL; } while(0)
1356 #define COPYSTR(x) COPYPTR(x)
1358 /* we also need to update for property changes in the root window
1359 * if needed, but that will be dependent on new properties added
1360 * with each version */
1363 COPYVAL(longpress_timeout);
1373 /* after updating user config, we must save */
1382 s = getenv("ELM_ENGINE");
1385 if ((!strcasecmp(s, "x11")) ||
1386 (!strcasecmp(s, "x")) ||
1387 (!strcasecmp(s, "software-x11")) ||
1388 (!strcasecmp(s, "software_x11")))
1389 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_X11);
1390 else if ((!strcasecmp(s, "opengl")) ||
1391 (!strcasecmp(s, "gl")) ||
1392 (!strcasecmp(s, "opengl-x11")) ||
1393 (!strcasecmp(s, "opengl_x11")))
1394 eina_stringshare_replace(&_elm_config->engine, ELM_OPENGL_X11);
1395 else if ((!strcasecmp(s, "x11-8")) ||
1396 (!strcasecmp(s, "x8")) ||
1397 (!strcasecmp(s, "software-8-x11")) ||
1398 (!strcasecmp(s, "software_8_x11")))
1399 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_8_X11);
1400 else if ((!strcasecmp(s, "x11-16")) ||
1401 (!strcasecmp(s, "x16")) ||
1402 (!strcasecmp(s, "software-16-x11")) ||
1403 (!strcasecmp(s, "software_16_x11")))
1404 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_16_X11);
1406 else if ((!strcasecmp(s, "xrender")) ||
1407 (!strcasecmp(s, "xr")) ||
1408 (!strcasecmp(s, "xrender-x11")) ||
1409 (!strcasecmp(s, "xrender_x11")))
1410 eina_stringshare_replace(&_elm_config->engine, ELM_XRENDER_X11);
1412 else if ((!strcasecmp(s, "fb")) ||
1413 (!strcasecmp(s, "software-fb")) ||
1414 (!strcasecmp(s, "software_fb")))
1415 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_FB);
1416 else if ((!strcasecmp(s, "directfb")) ||
1417 (!strcasecmp(s, "dfb")))
1418 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_DIRECTFB);
1419 else if ((!strcasecmp(s, "sdl")) ||
1420 (!strcasecmp(s, "software-sdl")) ||
1421 (!strcasecmp(s, "software_sdl")))
1422 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_SDL);
1423 else if ((!strcasecmp(s, "sdl-16")) ||
1424 (!strcasecmp(s, "software-16-sdl")) ||
1425 (!strcasecmp(s, "software_16_sdl")))
1426 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_16_SDL);
1427 else if ((!strcasecmp(s, "opengl-sdl")) ||
1428 (!strcasecmp(s, "opengl_sdl")) ||
1429 (!strcasecmp(s, "gl-sdl")) ||
1430 (!strcasecmp(s, "gl_sdl")))
1431 eina_stringshare_replace(&_elm_config->engine, ELM_OPENGL_SDL);
1432 else if ((!strcasecmp(s, "gdi")) ||
1433 (!strcasecmp(s, "software-gdi")) ||
1434 (!strcasecmp(s, "software_gdi")))
1435 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_WIN32);
1436 else if ((!strcasecmp(s, "wince-gdi")) ||
1437 (!strcasecmp(s, "software-16-wince-gdi")) ||
1438 (!strcasecmp(s, "software_16_wince_gdi")))
1439 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_16_WINCE);
1440 else if ((!strncmp(s, "shot:", 5)))
1441 eina_stringshare_replace(&_elm_config->engine, s);
1444 s = getenv("ELM_VSYNC");
1445 if (s) _elm_config->vsync = !!atoi(s);
1447 s = getenv("ELM_THUMBSCROLL_ENABLE");
1448 if (s) _elm_config->thumbscroll_enable = !!atoi(s);
1449 s = getenv("ELM_THUMBSCROLL_THRESHOLD");
1450 if (s) _elm_config->thumbscroll_threshold = atoi(s);
1451 // FIXME: floatformat locale issues here 1.0 vs 1,0 - should just be 1.0
1452 s = getenv("ELM_THUMBSCROLL_MOMENTUM_THRESHOLD");
1453 if (s) _elm_config->thumbscroll_momentum_threshold = atof(s);
1454 s = getenv("ELM_THUMBSCROLL_FRICTION");
1455 if (s) _elm_config->thumbscroll_friction = atof(s);
1456 s = getenv("ELM_THUMBSCROLL_BOUNCE_ENABLE");
1457 if (s) _elm_config->thumbscroll_bounce_enable = !!atoi(s);
1458 s = getenv("ELM_THUMBSCROLL_BOUNCE_FRICTION");
1459 if (s) _elm_config->thumbscroll_bounce_friction = atof(s);
1460 s = getenv("ELM_PAGE_SCROLL_FRICTION");
1461 if (s) _elm_config->page_scroll_friction = atof(s);
1462 s = getenv("ELM_BRING_IN_SCROLL_FRICTION");
1463 if (s) _elm_config->bring_in_scroll_friction = atof(s);
1464 s = getenv("ELM_ZOOM_FRICTION");
1465 if (s) _elm_config->zoom_friction = atof(s);
1466 s = getenv("ELM_THUMBSCROLL_BORDER_FRICTION");
1476 _elm_config->thumbscroll_border_friction = friction;
1478 s = getenv("ELM_THEME");
1479 if (s) eina_stringshare_replace(&_elm_config->theme, s);
1481 s = getenv("ELM_FONT_HINTING");
1484 if (!strcasecmp(s, "none")) _elm_config->font_hinting = 0;
1485 else if (!strcasecmp(s, "auto"))
1486 _elm_config->font_hinting = 1;
1487 else if (!strcasecmp(s, "bytecode"))
1488 _elm_config->font_hinting = 2;
1491 s = getenv("ELM_FONT_PATH");
1497 EINA_LIST_FREE(_elm_config->font_dirs, p)
1499 eina_stringshare_del(p);
1502 buf2 = alloca(strlen(s) + 1);
1507 if ((*p == ':') || (*p == 0))
1512 strncpy(buf2, pp, len);
1514 _elm_config->font_dirs =
1515 eina_list_append(_elm_config->font_dirs,
1516 eina_stringshare_add(buf2));
1529 s = getenv("ELM_IMAGE_CACHE");
1530 if (s) _elm_config->image_cache = atoi(s);
1532 s = getenv("ELM_FONT_CACHE");
1533 if (s) _elm_config->font_cache = atoi(s);
1535 s = getenv("ELM_SCALE");
1536 if (s) _elm_config->scale = atof(s);
1538 _elm_config->finger_size =
1539 (double)_elm_config->finger_size * _elm_config->scale;
1540 s = getenv("ELM_FINGER_SIZE");
1541 if (s) _elm_config->finger_size = atoi(s);
1543 s = getenv("ELM_FPS");
1544 if (s) _elm_config->fps = atof(s);
1545 if (_elm_config->fps < 1.0) _elm_config->fps = 1.0;
1547 s = getenv("ELM_MODULES");
1548 if (s) eina_stringshare_replace(&_elm_config->modules, s);
1550 /* Get RTL orientation from system */
1551 setlocale(LC_ALL, "");
1552 bindtextdomain(PACKAGE, LOCALE_DIR);
1553 _elm_config->is_mirrored = !strcmp(E_("default:LTR"), "default:RTL");
1555 s = getenv("ELM_TOOLTIP_DELAY");
1558 double delay = atof(s);
1560 _elm_config->tooltip_delay = delay;
1563 s = getenv("ELM_CURSOR_ENGINE_ONLY");
1564 if (s) _elm_config->cursor_engine_only = !!atoi(s);
1566 s = getenv("ELM_FOCUS_HIGHLIGHT_ENABLE");
1567 if (s) _elm_config->focus_highlight_enable = !!atoi(s);
1569 s = getenv("ELM_FOCUS_HIGHLIGHT_ANIMATE");
1570 if (s) _elm_config->focus_highlight_animate = !!atoi(s);
1572 s = getenv("ELM_TOOLBAR_SHRINK_MODE");
1573 if (s) _elm_config->toolbar_shrink_mode = atoi(s);
1575 s = getenv("ELM_FILESELECTOR_EXPAND_ENABLE");
1576 if (s) _elm_config->fileselector_expand_enable = !!atoi(s);
1578 s = getenv("ELM_INWIN_DIALOGS_ENABLE");
1579 if (s) _elm_config->inwin_dialogs_enable = !!atoi(s);
1581 s = getenv("ELM_ICON_SIZE");
1582 if (s) _elm_config->icon_size = atoi(s);
1584 s = getenv("ELM_LONGPRESS_TIMEOUT");
1585 if (s) _elm_config->longpress_timeout = atof(s);
1586 if (_elm_config->longpress_timeout < 0.0)
1587 _elm_config->longpress_timeout = 0.0;
1589 s = getenv("ELM_EFFECT_ENABLE");
1590 if (s) _elm_config->effect_enable = !!atoi(s);
1592 s = getenv("ELM_DESKTOP_ENTRY");
1593 if (s) _elm_config->desktop_entry = !!atoi(s);
1597 * Get the system mirrored mode. This determines the default mirrored mode
1600 * @return EINA_TRUE if mirrored is set, EINA_FALSE otherwise
1603 elm_mirrored_get(void)
1605 return _elm_config->is_mirrored;
1609 * Set the system mirrored mode. This determines the default mirrored mode
1612 * @param mirrored EINA_TRUE to set mirrored mode, EINA_FALSE to unset it.
1615 elm_mirrored_set(Eina_Bool mirrored)
1617 _elm_config->is_mirrored = mirrored;
1622 _elm_config_init(void)
1625 _profile_fetch_from_conf();
1629 _elm_config_font_overlay_apply();
1634 _elm_config_sub_init(void)
1636 #define ENGINE_COMPARE(name) (!strcmp(_elm_config->engine, name))
1637 if (ENGINE_COMPARE(ELM_SOFTWARE_X11) ||
1638 ENGINE_COMPARE(ELM_SOFTWARE_16_X11) ||
1639 ENGINE_COMPARE(ELM_XRENDER_X11) ||
1640 ENGINE_COMPARE(ELM_OPENGL_X11))
1641 #undef ENGINE_COMPARE
1643 #ifdef HAVE_ELEMENTARY_X
1644 unsigned int val = 1000;
1646 if (!ecore_x_init(NULL))
1648 ERR("Cannot connect to X11 display. check $DISPLAY variable");
1651 _root_1st = ecore_x_window_root_first_get();
1653 if (!ecore_x_screen_is_composited(0))
1654 _elm_config->compositing = 0;
1656 ecore_x_atoms_get(_atom_names, ATOM_COUNT, _atom);
1657 ecore_x_event_mask_set(_root_1st,
1658 ECORE_X_EVENT_MASK_WINDOW_PROPERTY);
1659 _prop_change_handler = ecore_event_handler_add
1660 (ECORE_X_EVENT_WINDOW_PROPERTY, _prop_change, NULL);
1661 if (!getenv("ELM_SCALE"))
1663 if (ecore_x_window_prop_card32_get(_root_1st,
1664 _atom[ATOM_E_SCALE],
1669 _elm_config->scale = (double)val / 1000.0;
1670 // FIXME: hack until e export finger size too
1671 if (!getenv("ELM_FINGER_SIZE"))
1673 _elm_config->finger_size = 40.0 * _elm_config->scale;
1675 edje_scale_set(_elm_config->scale);
1679 if (!getenv("ELM_FINGER_SIZE"))
1681 if (ecore_x_window_prop_card32_get(_root_1st,
1682 _atom[ATOM_E_FINGER_SIZE],
1687 _elm_config->finger_size = val;
1691 if (!getenv("ELM_THEME"))
1695 s = ecore_x_window_prop_string_get(_root_1st,
1696 _atom[ATOM_E_THEME]);
1699 eina_stringshare_replace(&_elm_config->theme, s);
1700 _elm_theme_parse(NULL, s);
1704 if (!getenv("ELM_PROFILE"))
1708 s = ecore_x_window_prop_string_get(_root_1st,
1709 _atom[ATOM_E_PROFILE]);
1716 if (strcmp(_elm_profile, s)) changed = 1;
1720 if (changed) _prop_config_get();
1725 _config_sub_apply();
1729 _elm_config_reload(void)
1734 _elm_config_font_overlay_apply();
1740 _elm_config_engine_set(const char *engine)
1742 if (_elm_config->engine && strcmp(_elm_config->engine, engine))
1743 eina_stringshare_del(_elm_config->engine);
1745 _elm_config->engine = eina_stringshare_add(engine);
1749 _elm_config_profile_set(const char *profile)
1751 Eina_Bool changed = EINA_FALSE;
1755 if (strcmp(_elm_profile, profile))
1760 _elm_profile = strdup(profile);
1767 _elm_config_font_overlay_apply();
1774 _elm_config_shutdown(void)
1776 #define ENGINE_COMPARE(name) (!strcmp(_elm_config->engine, name))
1777 if (ENGINE_COMPARE(ELM_SOFTWARE_X11) ||
1778 ENGINE_COMPARE(ELM_SOFTWARE_16_X11) ||
1779 ENGINE_COMPARE(ELM_XRENDER_X11) ||
1780 ENGINE_COMPARE(ELM_OPENGL_X11))
1781 #undef ENGINE_COMPARE
1783 #ifdef HAVE_ELEMENTARY_X
1784 ecore_event_handler_del(_prop_change_handler);
1785 _prop_change_handler = NULL;
1792 _elm_profile = NULL;