2 # include "elementary_config.h"
9 #include <Elementary.h>
12 #define _(string) gettext(string)
14 Elm_Config *_elm_config = NULL;
15 char *_elm_profile = NULL;
16 static Eet_Data_Descriptor *_config_edd = NULL;
17 static Eet_Data_Descriptor *_config_font_overlay_edd = NULL;
19 static Ecore_Poller *_elm_cache_flush_poller = NULL;
21 const char *_elm_engines[] = {
30 "software_16_wince_gdi",
37 /* whenever you want to add a new text class support into Elementary,
38 declare it both here and in the (default) theme */
39 static const Elm_Text_Class _elm_text_classes[] = {
40 {"button", "Button Labels"},
41 {"label", "Text Labels"},
42 {"entry", "Text Entries"},
43 {"title_bar", "Title Bar"},
44 {"list_item", "List Items"},
45 {"grid_item", "Grid Items"},
46 {"toolbar_item", "Toolbar Items"},
47 {"menu_item", "Menu Items"},
51 static void _desc_init(void);
52 static void _desc_shutdown(void);
53 static void _profile_fetch_from_conf(void);
54 static void _config_free(void);
55 static void _config_apply(void);
56 static Elm_Config *_config_user_load(void);
57 static Elm_Config *_config_system_load(void);
58 static void _config_load(void);
59 static void _config_update(void);
60 static void _env_get(void);
61 static size_t _elm_data_dir_snprintf(char *dst,
65 static size_t _elm_user_dir_snprintf(char *dst,
70 #define ELM_CONFIG_VAL(edd, type, member, dtype) \
71 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, type, #member, member, dtype)
72 #define ELM_CONFIG_LIST(edd, type, member, eddtype) \
73 EET_DATA_DESCRIPTOR_ADD_LIST(edd, type, #member, member, eddtype)
75 #ifdef HAVE_ELEMENTARY_X
76 static Ecore_Event_Handler *_prop_change_handler = NULL;
77 static Ecore_X_Window _root_1st = 0;
79 static Ecore_X_Atom _atom[ATOM_COUNT];
80 static Ecore_X_Atom _atom_config = 0;
81 static const char *_atom_names[ATOM_COUNT] =
83 "ENLIGHTENMENT_SCALE",
84 "ENLIGHTENMENT_FINGER_SIZE",
85 "ENLIGHTENMENT_THEME",
86 "ENLIGHTENMENT_PROFILE",
87 "ENLIGHTENMENT_FONT_OVERLAY",
88 "ENLIGHTENMENT_CACHE_FLUSH_INTERVAL",
89 "ENLIGHTENMENT_CACHE_FLUSH_ENABLE",
90 "ENLIGHTENMENT_FONT_CACHE",
91 "ENLIGHTENMENT_IMAGE_CACHE",
92 "ENLIGHTENMENT_EDJE_FILE_CACHE",
93 "ENLIGHTENMENT_EDJE_COLLECTION_CACHE",
94 "ENLIGHTENMENT_THUMBSCROLL_BOUNCE_ENABLE",
95 "ENLIGHTENMENT_THUMBSCROLL_BOUNCE_FRICTION",
96 "ENLIGHTENMENT_THUMBSCROLL_ENABLE",
97 "ENLIGHTENMENT_THUMBSCROLL_THRESHOLD",
98 "ENLIGHTENMENT_THUMBSCROLL_MOMENTUM_THRESHOLD",
99 "ENLIGHTENMENT_THUMBSCROLL_FRICTION",
100 "ENLIGHTENMENT_THUMBSCROLL_BORDER_FRICTION",
101 "ENLIGHTENMENT_THUMBSCROLL_PAGE_SCROLL_FRICTION",
102 "ENLIGHTENMENT_THUMBSCROLL_BRING_IN_SCROLL_FRICTION",
103 "ENLIGHTENMENT_THUMBSCROLL_ZOOM_FRICTION",
104 "ENLIGHTENMENT_CONFIG"
106 #define ATOM_E_SCALE 0
107 #define ATOM_E_FINGER_SIZE 1
108 #define ATOM_E_THEME 2
109 #define ATOM_E_PROFILE 3
110 #define ATOM_E_FONT_OVERLAY 4
111 #define ATOM_E_CACHE_FLUSH_INTERVAL 5
112 #define ATOM_E_CACHE_FLUSH_ENABLE 6
113 #define ATOM_E_FONT_CACHE 7
114 #define ATOM_E_IMAGE_CACHE 8
115 #define ATOM_E_EDJE_FILE_CACHE 9
116 #define ATOM_E_EDJE_COLLECTION_CACHE 10
117 #define ATOM_E_THUMBSCROLL_BOUNCE_ENABLE 11
118 #define ATOM_E_THUMBSCROLL_BOUNCE_FRICTION 12
119 #define ATOM_E_THUMBSCROLL_ENABLE 13
120 #define ATOM_E_THUMBSCROLL_THRESHOLD 14
121 #define ATOM_E_THUMBSCROLL_MOMENTUM_THRESHOLD 15
122 #define ATOM_E_THUMBSCROLL_FRICTION 16
123 #define ATOM_E_THUMBSCROLL_BORDER_FRICTION 17
124 #define ATOM_E_THUMBSCROLL_PAGE_SCROLL_FRICTION 18
125 #define ATOM_E_THUMBSCROLL_BRING_IN_SCROLL_FRICTION 19
126 #define ATOM_E_THUMBSCROLL_ZOOM_FRICTION 20
127 #define ATOM_E_CONFIG 21
129 static Eina_Bool _prop_config_get(void);
130 static Eina_Bool _prop_change(void *data __UNUSED__,
131 int ev_type __UNUSED__,
135 _prop_config_get(void)
140 unsigned char *data = NULL;
141 Elm_Config *config_data;
143 snprintf(buf, sizeof(buf), "ENLIGHTENMENT_CONFIG_%s", _elm_profile);
144 atom = ecore_x_atom_get(buf);
146 if (!ecore_x_window_prop_property_get(_root_1st,
147 atom, _atom[ATOM_E_CONFIG],
150 if (!ecore_x_window_prop_property_get(_root_1st,
151 _atom[ATOM_E_CONFIG],
152 _atom[ATOM_E_CONFIG],
156 _atom_config = _atom[ATOM_E_CONFIG];
165 config_data = eet_data_descriptor_decode(_config_edd, data, size);
167 if (!config_data) return EINA_FALSE;
169 /* What do we do on version mismatch when someone changes the
170 * config in the rootwindow? */
171 /* Most obvious case, new version and we are still linked to
172 * whatever was there before, we just ignore until user restarts us */
173 if (config_data->config_version > ELM_CONFIG_VERSION)
175 /* What in the case the version is older? Do we even support those
176 * cases or we only check for equality above? */
179 _elm_config = config_data;
181 _elm_config_font_overlay_apply();
188 _prop_change(void *data __UNUSED__,
189 int ev_type __UNUSED__,
192 Ecore_X_Event_Window_Property *event = ev;
194 if (event->win == _root_1st)
196 if (event->atom == _atom[ATOM_E_SCALE])
198 unsigned int val = 1000;
200 if (ecore_x_window_prop_card32_get(event->win,
206 pscale = _elm_config->scale;
207 if (val > 0) _elm_config->scale = (double)val / 1000.0;
208 if (pscale != _elm_config->scale)
215 else if (event->atom == _atom[ATOM_E_FINGER_SIZE])
217 unsigned int val = 1000;
219 if (ecore_x_window_prop_card32_get(event->win,
225 pfinger_size = _elm_config->finger_size;
226 _elm_config->finger_size = val;
227 if (pfinger_size != _elm_config->finger_size)
234 else if (event->atom == _atom[ATOM_E_THEME])
238 val = ecore_x_window_prop_string_get(event->win,
240 eina_stringshare_replace(&_elm_config->theme, val);
243 _elm_theme_parse(NULL, val);
249 else if (event->atom == _atom[ATOM_E_PROFILE])
253 val = ecore_x_window_prop_string_get(event->win,
261 if (strcmp(_elm_profile, val)) changed = 1;
267 if (!_prop_config_get())
272 _elm_config_font_overlay_apply();
278 else if (event->atom == _atom[ATOM_E_FONT_OVERLAY])
280 unsigned int val = 1000;
282 if (ecore_x_window_prop_card32_get(event->win,
289 _elm_config_font_overlay_apply();
293 else if (event->atom == _atom[ATOM_E_CACHE_FLUSH_INTERVAL])
295 unsigned int val = 1000;
297 if (ecore_x_window_prop_card32_get(event->win,
301 int cache_flush_interval;
303 cache_flush_interval = _elm_config->cache_flush_poll_interval;
304 _elm_config->cache_flush_poll_interval = val;
305 if (cache_flush_interval !=
306 _elm_config->cache_flush_poll_interval)
310 else if (event->atom == _atom[ATOM_E_CACHE_FLUSH_ENABLE])
312 unsigned int val = 1000;
314 if (ecore_x_window_prop_card32_get(event->win,
318 _elm_config->cache_flush_enable = !!val;
322 else if (event->atom == _atom[ATOM_E_FONT_CACHE])
324 unsigned int val = 1000;
326 if (ecore_x_window_prop_card32_get(event->win,
332 font_cache = _elm_config->font_cache;
333 _elm_config->font_cache = val;
334 if (font_cache != _elm_config->font_cache)
338 else if (event->atom == _atom[ATOM_E_IMAGE_CACHE])
340 unsigned int val = 1000;
342 if (ecore_x_window_prop_card32_get(event->win,
348 image_cache = _elm_config->image_cache;
349 _elm_config->image_cache = val;
350 if (image_cache != _elm_config->image_cache)
354 else if (event->atom == _atom[ATOM_E_EDJE_FILE_CACHE])
356 unsigned int val = 1000;
358 if (ecore_x_window_prop_card32_get(event->win,
364 edje_file_cache = _elm_config->edje_cache;
365 _elm_config->edje_cache = val;
366 if (edje_file_cache != _elm_config->edje_cache)
370 else if (event->atom == _atom[ATOM_E_EDJE_COLLECTION_CACHE])
372 unsigned int val = 1000;
374 if (ecore_x_window_prop_card32_get(event->win,
378 int edje_collection_cache;
380 edje_collection_cache = _elm_config->edje_collection_cache;
381 _elm_config->edje_collection_cache = val;
382 if (edje_collection_cache !=
383 _elm_config->edje_collection_cache)
387 else if (event->atom == _atom[ATOM_E_THUMBSCROLL_BOUNCE_ENABLE])
389 unsigned int val = 1000;
391 if (ecore_x_window_prop_card32_get(event->win,
395 _elm_config->thumbscroll_bounce_enable = !!val;
398 else if (event->atom == _atom[ATOM_E_THUMBSCROLL_BOUNCE_FRICTION])
400 unsigned int val = 1000;
402 if (ecore_x_window_prop_card32_get(event->win,
407 _elm_config->thumbscroll_bounce_friction =
408 (double)val / 1000.0;
411 else if (event->atom == _atom[ATOM_E_THUMBSCROLL_ENABLE])
413 unsigned int val = 1000;
415 if (ecore_x_window_prop_card32_get(event->win,
419 _elm_config->thumbscroll_enable = !!val;
422 else if (event->atom == _atom[ATOM_E_THUMBSCROLL_THRESHOLD])
424 unsigned int val = 1000;
426 if (ecore_x_window_prop_card32_get(event->win,
430 if (val > 0) _elm_config->thumbscroll_threshold = val;
433 else if (event->atom == _atom[ATOM_E_THUMBSCROLL_MOMENTUM_THRESHOLD])
435 unsigned int val = 1000;
437 if (ecore_x_window_prop_card32_get(event->win,
442 _elm_config->thumbscroll_momentum_threshold =
443 (double)val / 1000.0;
446 else if (event->atom == _atom[ATOM_E_THUMBSCROLL_FRICTION])
448 unsigned int val = 1000;
450 if (ecore_x_window_prop_card32_get(event->win,
455 _elm_config->thumbscroll_friction = (double)val / 1000.0;
458 else if (event->atom == _atom[ATOM_E_THUMBSCROLL_BORDER_FRICTION])
460 unsigned int val = 1000;
462 if (ecore_x_window_prop_card32_get(event->win,
467 _elm_config->thumbscroll_border_friction =
468 (double)val / 1000.0;
471 else if (event->atom == _atom[ATOM_E_THUMBSCROLL_PAGE_SCROLL_FRICTION])
473 unsigned int val = 1000;
475 if (ecore_x_window_prop_card32_get(event->win,
480 _elm_config->page_scroll_friction =
481 (double)val / 1000.0;
484 else if (event->atom ==
485 _atom[ATOM_E_THUMBSCROLL_BRING_IN_SCROLL_FRICTION])
487 unsigned int val = 1000;
489 if (ecore_x_window_prop_card32_get(event->win,
494 _elm_config->bring_in_scroll_friction =
495 (double)val / 1000.0;
498 else if (event->atom ==
499 _atom[ATOM_E_THUMBSCROLL_ZOOM_FRICTION])
501 unsigned int val = 1000;
503 if (ecore_x_window_prop_card32_get(event->win,
508 _elm_config->zoom_friction = (double)val / 1000.0;
511 else if (((_atom_config > 0) && (event->atom == _atom_config)) ||
512 (event->atom == _atom[ATOM_E_CONFIG]))
517 return ECORE_CALLBACK_PASS_ON;
525 Eet_Data_Descriptor_Class eddc;
527 EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Elm_Config);
528 eddc.func.str_direct_alloc = NULL;
529 eddc.func.str_direct_free = NULL;
531 _config_edd = eet_data_descriptor_file_new(&eddc);
534 printf("EEEK! eet_data_descriptor_file_new() failed\n");
538 memset(&eddc, 0, sizeof(eddc)); /* just in case... */
539 EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Elm_Font_Overlay);
540 eddc.func.str_direct_alloc = NULL;
541 eddc.func.str_direct_free = NULL;
543 _config_font_overlay_edd = eet_data_descriptor_stream_new(&eddc);
544 if (!_config_font_overlay_edd)
546 printf("EEEK! eet_data_descriptor_stream_new() failed\n");
547 eet_data_descriptor_free(_config_edd);
550 #define T_INT EET_T_INT
551 #define T_DOUBLE EET_T_DOUBLE
552 #define T_STRING EET_T_STRING
553 #define T_UCHAR EET_T_UCHAR
555 #define T Elm_Font_Overlay
556 #define D _config_font_overlay_edd
557 ELM_CONFIG_VAL(D, T, text_class, EET_T_STRING);
558 ELM_CONFIG_VAL(D, T, font, EET_T_STRING);
559 ELM_CONFIG_VAL(D, T, size, EET_T_INT);
564 #define D _config_edd
565 ELM_CONFIG_VAL(D, T, config_version, T_INT);
566 ELM_CONFIG_VAL(D, T, engine, T_STRING);
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);
616 eet_data_descriptor_free(_config_edd);
620 if (_config_font_overlay_edd)
622 eet_data_descriptor_free(_config_font_overlay_edd);
623 _config_font_overlay_edd = NULL;
628 _sort_files_cb(const void *f1,
631 return strcmp(f1, f2);
635 _elm_config_current_profile_get(void)
641 _elm_data_dir_snprintf(char *dst,
646 size_t data_dir_len, off;
649 data_dir_len = eina_strlcpy(dst, _elm_data_dir, size);
651 off = data_dir_len + 1;
656 dst[data_dir_len] = '/';
658 off = off + vsnprintf(dst + off, size - off, fmt, ap);
666 _elm_user_dir_snprintf(char *dst,
672 size_t user_dir_len, off;
675 home = getenv("HOME");
679 user_dir_len = eina_str_join_len(dst, size, '/', home, strlen(home),
680 ".elementary", sizeof(".elementary") - 1);
682 off = user_dir_len + 1;
687 dst[user_dir_len] = '/';
689 off = off + vsnprintf(dst + off, size - off, fmt, ap);
697 _elm_config_profile_dir_get(const char *prof,
705 _elm_user_dir_snprintf(buf, sizeof(buf), "config/%s", prof);
707 if (ecore_file_is_dir(buf))
713 snprintf(buf, sizeof(buf), "%s/config/%s", _elm_data_dir, prof);
715 if (ecore_file_is_dir(buf))
722 _elm_config_font_overlays_list(void)
724 return _elm_config->font_overlays;
728 _elm_config_font_overlay_set(const char *text_class,
732 Elm_Font_Overlay *efd;
735 EINA_LIST_FOREACH(_elm_config->font_overlays, l, efd)
737 if (strcmp(efd->text_class, text_class))
740 if (efd->font) eina_stringshare_del(efd->font);
741 efd->font = eina_stringshare_add(font);
743 _elm_config->font_overlays =
744 eina_list_promote_list(_elm_config->font_overlays, l);
748 /* the text class doesn't exist */
749 efd = calloc(1, sizeof(Elm_Font_Overlay));
750 efd->text_class = eina_stringshare_add(text_class);
751 efd->font = eina_stringshare_add(font);
754 _elm_config->font_overlays = eina_list_prepend(_elm_config->font_overlays,
759 _elm_config_font_overlay_remove(const char *text_class)
761 Elm_Font_Overlay *efd;
764 EINA_LIST_FOREACH(_elm_config->font_overlays, l, efd)
766 if (strcmp(efd->text_class, text_class))
769 _elm_config->font_overlays =
770 eina_list_remove_list(_elm_config->font_overlays, l);
771 if (efd->text_class) eina_stringshare_del(efd->text_class);
772 if (efd->font) eina_stringshare_del(efd->font);
780 _elm_config_font_overlay_apply(void)
782 Elm_Font_Overlay *efd;
786 for (i = 0; _elm_text_classes[i].desc; i++)
787 edje_text_class_del(_elm_text_classes[i].name);
789 EINA_LIST_FOREACH(_elm_config->font_overlays, l, efd)
790 edje_text_class_set(efd->text_class, efd->font, efd->size);
794 _elm_config_text_classes_get(void)
796 Eina_List *ret = NULL;
799 for (i = 0; _elm_text_classes[i].desc; i++)
802 tc = malloc(sizeof(*tc));
804 *tc = _elm_text_classes[i];
806 ret = eina_list_append(ret, tc);
813 _elm_config_text_classes_free(Eina_List *l)
817 EINA_LIST_FREE(l, tc)
822 _elm_config_profiles_list(void)
824 const Eina_File_Direct_Info *info;
825 Eina_List *flist = NULL;
826 Eina_Iterator *file_it;
831 len = _elm_user_dir_snprintf(buf, sizeof(buf), "config");
833 file_it = eina_file_direct_ls(buf);
840 len = sizeof(buf) - len;
842 EINA_ITERATOR_FOREACH(file_it, info)
844 if (info->name_length >= len)
847 if (info->type == EINA_FILE_DIR)
850 eina_list_sorted_insert(flist, _sort_files_cb,
851 eina_stringshare_add(info->path +
856 eina_iterator_free(file_it);
859 len = eina_str_join_len(buf, sizeof(buf), '/', _elm_data_dir,
860 strlen(_elm_data_dir), "config",
861 sizeof("config") - 1);
863 file_it = eina_file_direct_ls(buf);
870 len = sizeof(buf) - len;
871 EINA_ITERATOR_FOREACH(file_it, info)
873 if (info->name_length >= len)
883 EINA_LIST_FOREACH(flist, l, tmp)
884 if (!strcmp(info->path + info->name_start, tmp))
889 eina_list_sorted_insert(flist, _sort_files_cb,
890 eina_stringshare_add(info->path +
901 eina_iterator_free(file_it);
904 EINA_LIST_FREE(flist, dir)
905 eina_stringshare_del(dir);
911 _profile_fetch_from_conf(void)
913 char buf[PATH_MAX], *p, *s;
917 _elm_profile = strdup("default");
919 // if env var - use profile without question
920 s = getenv("ELM_PROFILE");
924 _elm_profile = strdup(s);
929 _elm_user_dir_snprintf(buf, sizeof(buf), "config/profile.cfg");
930 ef = eet_open(buf, EET_FILE_MODE_READ);
933 p = eet_read(ef, "config", &len);
937 _elm_profile = malloc(len + 1);
938 memcpy(_elm_profile, p, len);
939 _elm_profile[len] = 0;
948 _elm_data_dir_snprintf(buf, sizeof(buf), "config/profile.cfg");
949 ef = eet_open(buf, EET_FILE_MODE_READ);
952 p = eet_read(ef, "config", &len);
956 _elm_profile = malloc(len + 1);
957 memcpy(_elm_profile, p, len);
958 _elm_profile[len] = 0;
968 Elm_Font_Overlay *fo;
971 if (!_elm_config) return;
972 EINA_LIST_FREE(_elm_config->font_dirs, fontdir)
974 eina_stringshare_del(fontdir);
976 if (_elm_config->engine) eina_stringshare_del(_elm_config->engine);
977 EINA_LIST_FREE(_elm_config->font_overlays, fo)
979 if (fo->text_class) eina_stringshare_del(fo->text_class);
980 if (fo->font) eina_stringshare_del(fo->font);
983 if (_elm_config->theme) eina_stringshare_del(_elm_config->theme);
984 if (_elm_config->modules) eina_stringshare_del(_elm_config->modules);
992 _elm_theme_parse(NULL, _elm_config->theme);
993 ecore_animator_frametime_set(1.0 / _elm_config->fps);
997 _config_sub_apply(void)
999 edje_frametime_set(1.0 / _elm_config->fps);
1000 edje_scale_set(_elm_config->scale);
1001 if (_elm_config->modules) _elm_module_parse(_elm_config->modules);
1005 _elm_cache_flush_cb(void *data __UNUSED__)
1008 return ECORE_CALLBACK_RENEW;
1011 /* kind of abusing this call right now -- shared between all of those
1012 * properties -- but they are not meant to be called that periodically
1022 EINA_LIST_FOREACH(_elm_win_list, l, win)
1024 Evas *e = evas_object_evas_get(win);
1025 evas_image_cache_set(e, _elm_config->image_cache * 1024);
1026 evas_font_cache_set(e, _elm_config->font_cache * 1024);
1028 edje_file_cache_set(_elm_config->edje_cache);
1029 edje_collection_cache_set(_elm_config->edje_collection_cache);
1031 if (_elm_cache_flush_poller)
1033 ecore_poller_del(_elm_cache_flush_poller);
1034 _elm_cache_flush_poller = NULL;
1036 if (_elm_config->cache_flush_enable)
1038 if (_elm_config->cache_flush_poll_interval > 0)
1040 _elm_cache_flush_poller =
1041 ecore_poller_add(ECORE_POLLER_CORE,
1042 _elm_config->cache_flush_poll_interval,
1043 _elm_cache_flush_cb, NULL);
1049 _config_user_load(void)
1051 Elm_Config *cfg = NULL;
1055 _elm_user_dir_snprintf(buf, sizeof(buf), "config/%s/base.cfg",
1058 ef = eet_open(buf, EET_FILE_MODE_READ);
1061 cfg = eet_data_read(ef, _config_edd, "config");
1068 _config_system_load(void)
1070 Elm_Config *cfg = NULL;
1074 _elm_data_dir_snprintf(buf, sizeof(buf), "config/%s/base.cfg",
1077 ef = eet_open(buf, EET_FILE_MODE_READ);
1080 cfg = eet_data_read(ef, _config_edd, "config");
1089 _elm_config = _config_user_load();
1092 if (_elm_config->config_version < ELM_CONFIG_VERSION)
1097 /* no user config, fallback for system. No need to check version for
1098 * this one, if it's not the right one, someone screwed up at the time
1099 * of installing it */
1100 _elm_config = _config_system_load();
1101 if (_elm_config) return;
1102 /* FIXME: config load could have failed because of a non-existent
1103 * profile. Fallback to default before moving on */
1105 // config load fail - defaults
1106 /* XXX: do these make sense? Only if it's valid to install the lib
1107 * without the config, but do we want that? */
1108 _elm_config = ELM_NEW(Elm_Config);
1109 _elm_config->config_version = ELM_CONFIG_VERSION;
1110 _elm_config->engine = eina_stringshare_add("software_x11");
1111 _elm_config->thumbscroll_enable = EINA_TRUE;
1112 _elm_config->thumbscroll_threshold = 24;
1113 _elm_config->thumbscroll_momentum_threshold = 100.0;
1114 _elm_config->thumbscroll_friction = 1.0;
1115 _elm_config->thumbscroll_bounce_friction = 0.5;
1116 _elm_config->thumbscroll_bounce_enable = EINA_TRUE;
1117 _elm_config->page_scroll_friction = 0.5;
1118 _elm_config->bring_in_scroll_friction = 0.5;
1119 _elm_config->zoom_friction = 0.5;
1120 _elm_config->thumbscroll_border_friction = 0.5;
1121 _elm_config->scale = 1.0;
1122 _elm_config->bgpixmap = 0;
1123 _elm_config->compositing = 1;
1124 _elm_config->font_hinting = 2;
1125 _elm_config->cache_flush_poll_interval = 512;
1126 _elm_config->cache_flush_enable = EINA_TRUE;
1127 _elm_config->font_dirs = NULL;
1128 _elm_config->image_cache = 4096;
1129 _elm_config->font_cache = 512;
1130 _elm_config->edje_cache = 32;
1131 _elm_config->edje_collection_cache = 64;
1132 _elm_config->finger_size = 40;
1133 _elm_config->fps = 60.0;
1134 _elm_config->theme = eina_stringshare_add("default");
1135 _elm_config->modules = NULL;
1136 _elm_config->is_mirrored = EINA_FALSE; /* Read sys value in env_get() */
1137 _elm_config->tooltip_delay = 1.0;
1138 _elm_config->cursor_engine_only = EINA_TRUE;
1139 _elm_config->focus_highlight_enable = EINA_FALSE;
1140 _elm_config->focus_highlight_animate = EINA_TRUE;
1141 _elm_config->toolbar_shrink_mode = 2;
1142 _elm_config->fileselector_expand_enable = EINA_FALSE;
1143 _elm_config->inwin_dialogs_enable = EINA_FALSE;
1144 _elm_config->icon_size = 32;
1145 _elm_config->longpress_timeout = 1.0;
1146 _elm_config->effect_enable = EINA_TRUE;
1150 _elm_config_eet_close_error_get(Eet_File *ef,
1154 const char *erstr = NULL;
1156 err = eet_close(ef);
1159 case EET_ERROR_WRITE_ERROR:
1160 erstr = "An error occurred while saving Elementary's "
1161 "settings to disk. The error could not be "
1162 "deterimined. The file where the error occurred was: "
1163 "%s. This file has been deleted to avoid corrupt data.";
1166 case EET_ERROR_WRITE_ERROR_FILE_TOO_BIG:
1167 erstr = "Elementary's settings files are too big "
1168 "for the file system they are being saved to. "
1169 "This error is very strange as the files should "
1170 "be extremely small. Please check the settings "
1171 "for your home directory. "
1172 "The file where the error occurred was: %s ."
1173 "This file has been deleted to avoid corrupt data.";
1176 case EET_ERROR_WRITE_ERROR_IO_ERROR:
1177 erstr = "An output error occurred when writing the settings "
1178 "files for Elementary. Your disk is having troubles "
1179 "and possibly needs replacement. "
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_OUT_OF_SPACE:
1185 erstr = "Elementary cannot write its settings file "
1186 "because it ran out of space to write the file. "
1187 "You have either run out of disk space or have "
1188 "gone over your quota limit. "
1189 "The file where the error occurred was: %s ."
1190 "This file has been deleted to avoid corrupt data.";
1193 case EET_ERROR_WRITE_ERROR_FILE_CLOSED:
1194 erstr = "Elementary unexpectedly had the settings file "
1195 "it was writing closed on it. This is very unusual. "
1196 "The file where the error occurred was: %s "
1197 "This file has been deleted to avoid corrupt data.";
1205 /* delete any partially-written file */
1206 ecore_file_unlink(file);
1207 return strdup(erstr);
1214 _elm_config_profile_save(void)
1216 char buf[4096], buf2[4096];
1222 len = _elm_user_dir_snprintf(buf, sizeof(buf), "config/profile.cfg");
1223 if (len + 1 >= sizeof(buf))
1226 len = _elm_user_dir_snprintf(buf2, sizeof(buf2), "config/profile.cfg.tmp");
1227 if (len + 1 >= sizeof(buf2))
1230 ef = eet_open(buf2, EET_FILE_MODE_WRITE);
1234 ok = eet_write(ef, "config", _elm_profile, strlen(_elm_profile), 0);
1238 err = _elm_config_eet_close_error_get(ef, buf2);
1246 ret = ecore_file_mv(buf2, buf);
1249 ERR("Error saving Elementary's configuration file");
1253 ecore_file_unlink(buf2);
1257 ecore_file_unlink(buf2);
1262 _elm_config_save(void)
1264 char buf[4096], buf2[4096];
1270 len = _elm_user_dir_snprintf(buf, sizeof(buf), "config/%s", _elm_profile);
1271 if (len + 1 >= sizeof(buf))
1274 ok = ecore_file_mkpath(buf);
1277 ERR("Problem acessing Elementary's user configuration directory: %s",
1282 if (!_elm_config_profile_save())
1288 if (len + sizeof("base.cfg") >= sizeof(buf) - len)
1291 memcpy(buf + len, "base.cfg", sizeof("base.cfg"));
1292 len += sizeof("base.cfg") - 1;
1294 if (len + sizeof(".tmp") >= sizeof(buf))
1297 memcpy(buf2, buf, len);
1298 memcpy(buf2 + len, ".tmp", sizeof(".tmp"));
1300 ef = eet_open(buf2, EET_FILE_MODE_WRITE);
1304 ok = eet_data_write(ef, _config_edd, "config", _elm_config, 1);
1308 err = _elm_config_eet_close_error_get(ef, buf2);
1316 ret = ecore_file_mv(buf2, buf);
1319 ERR("Error saving Elementary's configuration file");
1323 ecore_file_unlink(buf2);
1327 ecore_file_unlink(buf2);
1332 _config_update(void)
1336 tcfg = _config_system_load();
1339 /* weird profile or something? We should probably fill
1340 * with hardcoded defaults, or get from default previx */
1343 #define IFCFG(v) if ((_elm_config->config_version & 0xffff) < (v)) {
1344 #define IFCFGELSE } else {
1346 #define COPYVAL(x) do {_elm_config->x = tcfg->x; } while(0)
1347 #define COPYPTR(x) do {_elm_config->x = tcfg->x; tcfg->x = NULL; } while(0)
1348 #define COPYSTR(x) COPYPTR(x)
1350 /* we also need to update for property changes in the root window
1351 * if needed, but that will be dependent on new properties added
1352 * with each version */
1355 COPYVAL(longpress_timeout);
1365 /* after updating user config, we must save */
1374 s = getenv("ELM_ENGINE");
1377 if ((!strcasecmp(s, "x11")) ||
1378 (!strcasecmp(s, "x")) ||
1379 (!strcasecmp(s, "software-x11")) ||
1380 (!strcasecmp(s, "software_x11")))
1381 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_X11);
1382 else if ((!strcasecmp(s, "opengl")) ||
1383 (!strcasecmp(s, "gl")) ||
1384 (!strcasecmp(s, "opengl-x11")) ||
1385 (!strcasecmp(s, "opengl_x11")))
1386 eina_stringshare_replace(&_elm_config->engine, ELM_OPENGL_X11);
1387 else if ((!strcasecmp(s, "x11-8")) ||
1388 (!strcasecmp(s, "x18")) ||
1389 (!strcasecmp(s, "software-8-x11")) ||
1390 (!strcasecmp(s, "software_8_x11")))
1391 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_8_X11);
1392 else if ((!strcasecmp(s, "x11-16")) ||
1393 (!strcasecmp(s, "x16")) ||
1394 (!strcasecmp(s, "software-16-x11")) ||
1395 (!strcasecmp(s, "software_16_x11")))
1396 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_16_X11);
1397 else if ((!strcasecmp(s, "xrender")) ||
1398 (!strcasecmp(s, "xr")) ||
1399 (!strcasecmp(s, "xrender-x11")) ||
1400 (!strcasecmp(s, "xrender_x11")))
1401 eina_stringshare_replace(&_elm_config->engine, ELM_XRENDER_X11);
1402 else if ((!strcasecmp(s, "fb")) ||
1403 (!strcasecmp(s, "software-fb")) ||
1404 (!strcasecmp(s, "software_fb")))
1405 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_FB);
1406 else if ((!strcasecmp(s, "directfb")) ||
1407 (!strcasecmp(s, "dfb")))
1408 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_DIRECTFB);
1409 else if ((!strcasecmp(s, "sdl")) ||
1410 (!strcasecmp(s, "software-sdl")) ||
1411 (!strcasecmp(s, "software_sdl")))
1412 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_SDL);
1413 else if ((!strcasecmp(s, "sdl-16")) ||
1414 (!strcasecmp(s, "software-16-sdl")) ||
1415 (!strcasecmp(s, "software_16_sdl")))
1416 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_16_SDL);
1417 else if ((!strcasecmp(s, "opengl-sdl")) ||
1418 (!strcasecmp(s, "opengl_sdl")) ||
1419 (!strcasecmp(s, "gl-sdl")) ||
1420 (!strcasecmp(s, "gl_sdl")))
1421 eina_stringshare_replace(&_elm_config->engine, ELM_OPENGL_SDL);
1422 else if ((!strcasecmp(s, "gdi")) ||
1423 (!strcasecmp(s, "software-gdi")) ||
1424 (!strcasecmp(s, "software_gdi")))
1425 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_WIN32);
1426 else if ((!strcasecmp(s, "wince-gdi")) ||
1427 (!strcasecmp(s, "software-16-wince-gdi")) ||
1428 (!strcasecmp(s, "software_16_wince_gdi")))
1429 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_16_WINCE);
1432 s = getenv("ELM_THUMBSCROLL_ENABLE");
1433 if (s) _elm_config->thumbscroll_enable = !!atoi(s);
1434 s = getenv("ELM_THUMBSCROLL_THRESHOLD");
1435 if (s) _elm_config->thumbscroll_threshold = atoi(s);
1436 // FIXME: floatformat locale issues here 1.0 vs 1,0 - should just be 1.0
1437 s = getenv("ELM_THUMBSCROLL_MOMENTUM_THRESHOLD");
1438 if (s) _elm_config->thumbscroll_momentum_threshold = atof(s);
1439 s = getenv("ELM_THUMBSCROLL_FRICTION");
1440 if (s) _elm_config->thumbscroll_friction = atof(s);
1441 s = getenv("ELM_THUMBSCROLL_BOUNCE_ENABLE");
1442 if (s) _elm_config->thumbscroll_bounce_enable = !!atoi(s);
1443 s = getenv("ELM_THUMBSCROLL_BOUNCE_FRICTION");
1444 if (s) _elm_config->thumbscroll_bounce_friction = atof(s);
1445 s = getenv("ELM_PAGE_SCROLL_FRICTION");
1446 if (s) _elm_config->page_scroll_friction = atof(s);
1447 s = getenv("ELM_BRING_IN_SCROLL_FRICTION");
1448 if (s) _elm_config->bring_in_scroll_friction = atof(s);
1449 s = getenv("ELM_ZOOM_FRICTION");
1450 if (s) _elm_config->zoom_friction = atof(s);
1451 s = getenv("ELM_THUMBSCROLL_BORDER_FRICTION");
1461 _elm_config->thumbscroll_border_friction = friction;
1463 s = getenv("ELM_THEME");
1464 if (s) eina_stringshare_replace(&_elm_config->theme, s);
1466 s = getenv("ELM_FONT_HINTING");
1469 if (!strcasecmp(s, "none")) _elm_config->font_hinting = 0;
1470 else if (!strcasecmp(s, "auto"))
1471 _elm_config->font_hinting = 1;
1472 else if (!strcasecmp(s, "bytecode"))
1473 _elm_config->font_hinting = 2;
1476 s = getenv("ELM_FONT_PATH");
1482 EINA_LIST_FREE(_elm_config->font_dirs, p)
1484 eina_stringshare_del(p);
1487 buf2 = alloca(strlen(s) + 1);
1492 if ((*p == ':') || (*p == 0))
1497 strncpy(buf2, pp, len);
1499 _elm_config->font_dirs =
1500 eina_list_append(_elm_config->font_dirs,
1501 eina_stringshare_add(buf2));
1514 s = getenv("ELM_IMAGE_CACHE");
1515 if (s) _elm_config->image_cache = atoi(s);
1517 s = getenv("ELM_FONT_CACHE");
1518 if (s) _elm_config->font_cache = atoi(s);
1520 s = getenv("ELM_SCALE");
1521 if (s) _elm_config->scale = atof(s);
1523 _elm_config->finger_size =
1524 (double)_elm_config->finger_size * _elm_config->scale;
1525 s = getenv("ELM_FINGER_SIZE");
1526 if (s) _elm_config->finger_size = atoi(s);
1528 s = getenv("ELM_FPS");
1529 if (s) _elm_config->fps = atof(s);
1530 if (_elm_config->fps < 1.0) _elm_config->fps = 1.0;
1532 s = getenv("ELM_MODULES");
1533 if (s) eina_stringshare_replace(&_elm_config->modules, s);
1535 /* Get RTL orientation from system */
1536 setlocale(LC_ALL, "");
1537 bindtextdomain("elementary", LOCALE_DIR);
1538 textdomain("elementary");
1539 _elm_config->is_mirrored = !strcmp(_("default:LTR"), "default:RTL");
1541 s = getenv("ELM_TOOLTIP_DELAY");
1544 double delay = atof(s);
1546 _elm_config->tooltip_delay = delay;
1549 s = getenv("ELM_CURSOR_ENGINE_ONLY");
1550 if (s) _elm_config->cursor_engine_only = !!atoi(s);
1552 s = getenv("ELM_FOCUS_HIGHLIGHT_ENABLE");
1553 if (s) _elm_config->focus_highlight_enable = !!atoi(s);
1555 s = getenv("ELM_FOCUS_HIGHLIGHT_ANIMATE");
1556 if (s) _elm_config->focus_highlight_animate = !!atoi(s);
1558 s = getenv("ELM_TOOLBAR_SHRINK_MODE");
1559 if (s) _elm_config->toolbar_shrink_mode = atoi(s);
1561 s = getenv("ELM_FILESELECTOR_EXPAND_ENABLE");
1562 if (s) _elm_config->fileselector_expand_enable = !!atoi(s);
1564 s = getenv("ELM_INWIN_DIALOGS_ENABLE");
1565 if (s) _elm_config->inwin_dialogs_enable = !!atoi(s);
1567 s = getenv("ELM_ICON_SIZE");
1568 if (s) _elm_config->icon_size = atoi(s);
1570 s = getenv("ELM_LONGPRESS_TIMEOUT");
1571 if (s) _elm_config->longpress_timeout = atof(s);
1572 if (_elm_config->longpress_timeout < 0.0)
1573 _elm_config->longpress_timeout = 0.0;
1575 s = getenv("ELM_EFFECT_ENABLE");
1576 if (s) _elm_config->effect_enable = !!atoi(s);
1580 * Get the system mirrored mode. This determines the default mirrored mode
1583 * @return EINA_TRUE if mirrored is set, EINA_FALSE otherwise
1586 elm_mirrored_get(void)
1588 return _elm_config->is_mirrored;
1592 * Set the system mirrored mode. This determines the default mirrored mode
1595 * @param mirrored EINA_TRUE to set mirrored mode, EINA_FALSE to unset it.
1598 elm_mirrored_set(Eina_Bool mirrored)
1600 _elm_config->is_mirrored = mirrored;
1605 _elm_config_init(void)
1608 _profile_fetch_from_conf();
1612 _elm_config_font_overlay_apply();
1617 _elm_config_sub_init(void)
1619 #define ENGINE_COMPARE(name) (!strcmp(_elm_config->engine, name))
1620 if (ENGINE_COMPARE(ELM_SOFTWARE_X11) ||
1621 ENGINE_COMPARE(ELM_SOFTWARE_16_X11) ||
1622 ENGINE_COMPARE(ELM_XRENDER_X11) ||
1623 ENGINE_COMPARE(ELM_OPENGL_X11))
1624 #undef ENGINE_COMPARE
1626 #ifdef HAVE_ELEMENTARY_X
1627 unsigned int val = 1000;
1629 if (!ecore_x_init(NULL))
1631 ERR("Cannot connect to X11 display. check $DISPLAY variable");
1634 _root_1st = ecore_x_window_root_first_get();
1636 if (!ecore_x_screen_is_composited(0))
1637 _elm_config->compositing = 0;
1639 ecore_x_atoms_get(_atom_names, ATOM_COUNT, _atom);
1640 ecore_x_event_mask_set(_root_1st,
1641 ECORE_X_EVENT_MASK_WINDOW_PROPERTY);
1642 _prop_change_handler = ecore_event_handler_add
1643 (ECORE_X_EVENT_WINDOW_PROPERTY, _prop_change, NULL);
1644 if (!getenv("ELM_SCALE"))
1646 if (ecore_x_window_prop_card32_get(_root_1st,
1647 _atom[ATOM_E_SCALE],
1652 _elm_config->scale = (double)val / 1000.0;
1653 // FIXME: hack until e export finger size too
1654 if (!getenv("ELM_FINGER_SIZE"))
1656 _elm_config->finger_size = 40.0 * _elm_config->scale;
1658 edje_scale_set(_elm_config->scale);
1662 if (!getenv("ELM_FINGER_SIZE"))
1664 if (ecore_x_window_prop_card32_get(_root_1st,
1665 _atom[ATOM_E_FINGER_SIZE],
1670 _elm_config->finger_size = val;
1674 if (!getenv("ELM_THEME"))
1678 s = ecore_x_window_prop_string_get(_root_1st,
1679 _atom[ATOM_E_THEME]);
1682 eina_stringshare_replace(&_elm_config->theme, s);
1683 _elm_theme_parse(NULL, s);
1687 if (!getenv("ELM_PROFILE"))
1691 s = ecore_x_window_prop_string_get(_root_1st,
1692 _atom[ATOM_E_PROFILE]);
1699 if (strcmp(_elm_profile, s)) changed = 1;
1703 if (changed) _prop_config_get();
1708 _config_sub_apply();
1712 _elm_config_reload(void)
1717 _elm_config_font_overlay_apply();
1723 _elm_config_engine_set(const char *engine)
1725 if (_elm_config->engine && strcmp(_elm_config->engine, engine))
1726 eina_stringshare_del(_elm_config->engine);
1728 _elm_config->engine = eina_stringshare_add(engine);
1732 _elm_config_profile_set(const char *profile)
1734 Eina_Bool changed = EINA_FALSE;
1738 if (strcmp(_elm_profile, profile))
1743 _elm_profile = strdup(profile);
1750 _elm_config_font_overlay_apply();
1757 _elm_config_shutdown(void)
1759 #define ENGINE_COMPARE(name) (!strcmp(_elm_config->engine, name))
1760 if (ENGINE_COMPARE(ELM_SOFTWARE_X11) ||
1761 ENGINE_COMPARE(ELM_SOFTWARE_16_X11) ||
1762 ENGINE_COMPARE(ELM_XRENDER_X11) ||
1763 ENGINE_COMPARE(ELM_OPENGL_X11))
1764 #undef ENGINE_COMPARE
1766 #ifdef HAVE_ELEMENTARY_X
1767 ecore_event_handler_del(_prop_change_handler);
1768 _prop_change_handler = NULL;
1775 _elm_profile = NULL;