2 # include "elementary_config.h"
9 #include <Elementary.h>
12 Elm_Config *_elm_config = NULL;
13 char *_elm_profile = NULL;
14 static Eet_Data_Descriptor *_config_edd = NULL;
15 static Eet_Data_Descriptor *_config_font_overlay_edd = NULL;
17 static Ecore_Poller *_elm_cache_flush_poller = NULL;
19 const char *_elm_engines[] = {
28 "software_16_wince_gdi",
35 /* whenever you want to add a new text class support into Elementary,
36 declare it both here and in the (default) theme */
37 static const Elm_Text_Class _elm_text_classes[] = {
38 {"button", "Button Labels"},
39 {"label", "Text Labels"},
40 {"entry", "Text Entries"},
41 {"title_bar", "Title Bar"},
42 {"list_item", "List Items"},
43 {"grid_item", "Grid Items"},
44 {"toolbar_item", "Toolbar Items"},
45 {"menu_item", "Menu Items"},
49 static void _desc_init(void);
50 static void _desc_shutdown(void);
51 static void _profile_fetch_from_conf(void);
52 static void _config_free(void);
53 static void _config_apply(void);
54 static Elm_Config *_config_user_load(void);
55 static Elm_Config *_config_system_load(void);
56 static void _config_load(void);
57 static void _config_update(void);
58 static void _env_get(void);
59 static size_t _elm_data_dir_snprintf(char *dst,
63 static size_t _elm_user_dir_snprintf(char *dst,
68 #define ELM_CONFIG_VAL(edd, type, member, dtype) \
69 EET_DATA_DESCRIPTOR_ADD_BASIC(edd, type, #member, member, dtype)
70 #define ELM_CONFIG_LIST(edd, type, member, eddtype) \
71 EET_DATA_DESCRIPTOR_ADD_LIST(edd, type, #member, member, eddtype)
73 #ifdef HAVE_ELEMENTARY_X
74 static Ecore_Event_Handler *_prop_change_handler = NULL;
75 static Ecore_X_Window _root_1st = 0;
77 static Ecore_X_Atom _atom[ATOM_COUNT];
78 static Ecore_X_Atom _atom_config = 0;
79 static const char *_atom_names[ATOM_COUNT] =
81 "ENLIGHTENMENT_SCALE",
82 "ENLIGHTENMENT_FINGER_SIZE",
83 "ENLIGHTENMENT_THEME",
84 "ENLIGHTENMENT_PROFILE",
85 "ENLIGHTENMENT_FONT_OVERLAY",
86 "ENLIGHTENMENT_CACHE_FLUSH_INTERVAL",
87 "ENLIGHTENMENT_CACHE_FLUSH_ENABLE",
88 "ENLIGHTENMENT_FONT_CACHE",
89 "ENLIGHTENMENT_IMAGE_CACHE",
90 "ENLIGHTENMENT_EDJE_FILE_CACHE",
91 "ENLIGHTENMENT_EDJE_COLLECTION_CACHE",
92 "ENLIGHTENMENT_THUMBSCROLL_BOUNCE_ENABLE",
93 "ENLIGHTENMENT_THUMBSCROLL_BOUNCE_FRICTION",
94 "ENLIGHTENMENT_THUMBSCROLL_ENABLE",
95 "ENLIGHTENMENT_THUMBSCROLL_THRESHOLD",
96 "ENLIGHTENMENT_THUMBSCROLL_MOMENTUM_THRESHOLD",
97 "ENLIGHTENMENT_THUMBSCROLL_FRICTION",
98 "ENLIGHTENMENT_THUMBSCROLL_BORDER_FRICTION",
99 "ENLIGHTENMENT_THUMBSCROLL_PAGE_SCROLL_FRICTION",
100 "ENLIGHTENMENT_THUMBSCROLL_BRING_IN_SCROLL_FRICTION",
101 "ENLIGHTENMENT_THUMBSCROLL_ZOOM_FRICTION",
102 "ENLIGHTENMENT_CONFIG"
104 #define ATOM_E_SCALE 0
105 #define ATOM_E_FINGER_SIZE 1
106 #define ATOM_E_THEME 2
107 #define ATOM_E_PROFILE 3
108 #define ATOM_E_FONT_OVERLAY 4
109 #define ATOM_E_CACHE_FLUSH_INTERVAL 5
110 #define ATOM_E_CACHE_FLUSH_ENABLE 6
111 #define ATOM_E_FONT_CACHE 7
112 #define ATOM_E_IMAGE_CACHE 8
113 #define ATOM_E_EDJE_FILE_CACHE 9
114 #define ATOM_E_EDJE_COLLECTION_CACHE 10
115 #define ATOM_E_THUMBSCROLL_BOUNCE_ENABLE 11
116 #define ATOM_E_THUMBSCROLL_BOUNCE_FRICTION 12
117 #define ATOM_E_THUMBSCROLL_ENABLE 13
118 #define ATOM_E_THUMBSCROLL_THRESHOLD 14
119 #define ATOM_E_THUMBSCROLL_MOMENTUM_THRESHOLD 15
120 #define ATOM_E_THUMBSCROLL_FRICTION 16
121 #define ATOM_E_THUMBSCROLL_BORDER_FRICTION 17
122 #define ATOM_E_THUMBSCROLL_PAGE_SCROLL_FRICTION 18
123 #define ATOM_E_THUMBSCROLL_BRING_IN_SCROLL_FRICTION 19
124 #define ATOM_E_THUMBSCROLL_ZOOM_FRICTION 20
125 #define ATOM_E_CONFIG 21
127 static Eina_Bool _prop_config_get(void);
128 static Eina_Bool _prop_change(void *data __UNUSED__,
129 int ev_type __UNUSED__,
133 _prop_config_get(void)
138 unsigned char *data = NULL;
139 Elm_Config *config_data;
141 snprintf(buf, sizeof(buf), "ENLIGHTENMENT_CONFIG_%s", _elm_profile);
142 atom = ecore_x_atom_get(buf);
144 if (!ecore_x_window_prop_property_get(_root_1st,
145 atom, _atom[ATOM_E_CONFIG],
148 if (!ecore_x_window_prop_property_get(_root_1st,
149 _atom[ATOM_E_CONFIG],
150 _atom[ATOM_E_CONFIG],
154 _atom_config = _atom[ATOM_E_CONFIG];
163 config_data = eet_data_descriptor_decode(_config_edd, data, size);
165 if (!config_data) return EINA_FALSE;
167 /* What do we do on version mismatch when someone changes the
168 * config in the rootwindow? */
169 /* Most obvious case, new version and we are still linked to
170 * whatever was there before, we just ignore until user restarts us */
171 if (config_data->config_version > ELM_CONFIG_VERSION)
173 /* What in the case the version is older? Do we even support those
174 * cases or we only check for equality above? */
177 _elm_config = config_data;
179 _elm_config_font_overlay_apply();
186 _prop_change(void *data __UNUSED__,
187 int ev_type __UNUSED__,
190 Ecore_X_Event_Window_Property *event = ev;
192 if (event->win == _root_1st)
194 if (event->atom == _atom[ATOM_E_SCALE])
196 unsigned int val = 1000;
198 if (ecore_x_window_prop_card32_get(event->win,
204 pscale = _elm_config->scale;
205 if (val > 0) _elm_config->scale = (double)val / 1000.0;
206 if (pscale != _elm_config->scale)
213 else if (event->atom == _atom[ATOM_E_FINGER_SIZE])
215 unsigned int val = 1000;
217 if (ecore_x_window_prop_card32_get(event->win,
223 pfinger_size = _elm_config->finger_size;
224 _elm_config->finger_size = val;
225 if (pfinger_size != _elm_config->finger_size)
232 else if (event->atom == _atom[ATOM_E_THEME])
236 val = ecore_x_window_prop_string_get(event->win,
238 eina_stringshare_replace(&_elm_config->theme, val);
241 _elm_theme_parse(NULL, val);
247 else if (event->atom == _atom[ATOM_E_PROFILE])
251 val = ecore_x_window_prop_string_get(event->win,
259 if (strcmp(_elm_profile, val)) changed = 1;
265 if (!_prop_config_get())
270 _elm_config_font_overlay_apply();
276 else if (event->atom == _atom[ATOM_E_FONT_OVERLAY])
278 unsigned int val = 1000;
280 if (ecore_x_window_prop_card32_get(event->win,
287 _elm_config_font_overlay_apply();
291 else if (event->atom == _atom[ATOM_E_CACHE_FLUSH_INTERVAL])
293 unsigned int val = 1000;
295 if (ecore_x_window_prop_card32_get(event->win,
299 int cache_flush_interval;
301 cache_flush_interval = _elm_config->cache_flush_poll_interval;
302 _elm_config->cache_flush_poll_interval = val;
303 if (cache_flush_interval !=
304 _elm_config->cache_flush_poll_interval)
308 else if (event->atom == _atom[ATOM_E_CACHE_FLUSH_ENABLE])
310 unsigned int val = 1000;
312 if (ecore_x_window_prop_card32_get(event->win,
316 _elm_config->cache_flush_enable = !!val;
320 else if (event->atom == _atom[ATOM_E_FONT_CACHE])
322 unsigned int val = 1000;
324 if (ecore_x_window_prop_card32_get(event->win,
330 font_cache = _elm_config->font_cache;
331 _elm_config->font_cache = val;
332 if (font_cache != _elm_config->font_cache)
336 else if (event->atom == _atom[ATOM_E_IMAGE_CACHE])
338 unsigned int val = 1000;
340 if (ecore_x_window_prop_card32_get(event->win,
346 image_cache = _elm_config->image_cache;
347 _elm_config->image_cache = val;
348 if (image_cache != _elm_config->image_cache)
352 else if (event->atom == _atom[ATOM_E_EDJE_FILE_CACHE])
354 unsigned int val = 1000;
356 if (ecore_x_window_prop_card32_get(event->win,
362 edje_file_cache = _elm_config->edje_cache;
363 _elm_config->edje_cache = val;
364 if (edje_file_cache != _elm_config->edje_cache)
368 else if (event->atom == _atom[ATOM_E_EDJE_COLLECTION_CACHE])
370 unsigned int val = 1000;
372 if (ecore_x_window_prop_card32_get(event->win,
376 int edje_collection_cache;
378 edje_collection_cache = _elm_config->edje_collection_cache;
379 _elm_config->edje_collection_cache = val;
380 if (edje_collection_cache !=
381 _elm_config->edje_collection_cache)
385 else if (event->atom == _atom[ATOM_E_THUMBSCROLL_BOUNCE_ENABLE])
387 unsigned int val = 1000;
389 if (ecore_x_window_prop_card32_get(event->win,
393 _elm_config->thumbscroll_bounce_enable = !!val;
396 else if (event->atom == _atom[ATOM_E_THUMBSCROLL_BOUNCE_FRICTION])
398 unsigned int val = 1000;
400 if (ecore_x_window_prop_card32_get(event->win,
405 _elm_config->thumbscroll_bounce_friction =
406 (double)val / 1000.0;
409 else if (event->atom == _atom[ATOM_E_THUMBSCROLL_ENABLE])
411 unsigned int val = 1000;
413 if (ecore_x_window_prop_card32_get(event->win,
417 _elm_config->thumbscroll_enable = !!val;
420 else if (event->atom == _atom[ATOM_E_THUMBSCROLL_THRESHOLD])
422 unsigned int val = 1000;
424 if (ecore_x_window_prop_card32_get(event->win,
428 if (val > 0) _elm_config->thumbscroll_threshold = val;
431 else if (event->atom == _atom[ATOM_E_THUMBSCROLL_MOMENTUM_THRESHOLD])
433 unsigned int val = 1000;
435 if (ecore_x_window_prop_card32_get(event->win,
440 _elm_config->thumbscroll_momentum_threshold =
441 (double)val / 1000.0;
444 else if (event->atom == _atom[ATOM_E_THUMBSCROLL_FRICTION])
446 unsigned int val = 1000;
448 if (ecore_x_window_prop_card32_get(event->win,
453 _elm_config->thumbscroll_friction = (double)val / 1000.0;
456 else if (event->atom == _atom[ATOM_E_THUMBSCROLL_BORDER_FRICTION])
458 unsigned int val = 1000;
460 if (ecore_x_window_prop_card32_get(event->win,
465 _elm_config->thumbscroll_border_friction =
466 (double)val / 1000.0;
469 else if (event->atom == _atom[ATOM_E_THUMBSCROLL_PAGE_SCROLL_FRICTION])
471 unsigned int val = 1000;
473 if (ecore_x_window_prop_card32_get(event->win,
478 _elm_config->page_scroll_friction =
479 (double)val / 1000.0;
482 else if (event->atom ==
483 _atom[ATOM_E_THUMBSCROLL_BRING_IN_SCROLL_FRICTION])
485 unsigned int val = 1000;
487 if (ecore_x_window_prop_card32_get(event->win,
492 _elm_config->bring_in_scroll_friction =
493 (double)val / 1000.0;
496 else if (event->atom ==
497 _atom[ATOM_E_THUMBSCROLL_ZOOM_FRICTION])
499 unsigned int val = 1000;
501 if (ecore_x_window_prop_card32_get(event->win,
506 _elm_config->zoom_friction = (double)val / 1000.0;
509 else if (((_atom_config > 0) && (event->atom == _atom_config)) ||
510 (event->atom == _atom[ATOM_E_CONFIG]))
515 return ECORE_CALLBACK_PASS_ON;
523 Eet_Data_Descriptor_Class eddc;
525 EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Elm_Config);
526 eddc.func.str_direct_alloc = NULL;
527 eddc.func.str_direct_free = NULL;
529 _config_edd = eet_data_descriptor_file_new(&eddc);
532 printf("EEEK! eet_data_descriptor_file_new() failed\n");
536 memset(&eddc, 0, sizeof(eddc)); /* just in case... */
537 EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Elm_Font_Overlay);
538 eddc.func.str_direct_alloc = NULL;
539 eddc.func.str_direct_free = NULL;
541 _config_font_overlay_edd = eet_data_descriptor_stream_new(&eddc);
542 if (!_config_font_overlay_edd)
544 printf("EEEK! eet_data_descriptor_stream_new() failed\n");
545 eet_data_descriptor_free(_config_edd);
548 #define T_INT EET_T_INT
549 #define T_DOUBLE EET_T_DOUBLE
550 #define T_STRING EET_T_STRING
551 #define T_UCHAR EET_T_UCHAR
553 #define T Elm_Font_Overlay
554 #define D _config_font_overlay_edd
555 ELM_CONFIG_VAL(D, T, text_class, EET_T_STRING);
556 ELM_CONFIG_VAL(D, T, font, EET_T_STRING);
557 ELM_CONFIG_VAL(D, T, size, EET_T_INT);
562 #define D _config_edd
563 ELM_CONFIG_VAL(D, T, config_version, T_INT);
564 ELM_CONFIG_VAL(D, T, engine, T_STRING);
565 ELM_CONFIG_VAL(D, T, thumbscroll_enable, T_UCHAR);
566 ELM_CONFIG_VAL(D, T, thumbscroll_threshold, T_INT);
567 ELM_CONFIG_VAL(D, T, thumbscroll_momentum_threshold, T_DOUBLE);
568 ELM_CONFIG_VAL(D, T, thumbscroll_friction, T_DOUBLE);
569 ELM_CONFIG_VAL(D, T, thumbscroll_bounce_friction, T_DOUBLE);
570 ELM_CONFIG_VAL(D, T, thumbscroll_border_friction, T_DOUBLE);
571 ELM_CONFIG_VAL(D, T, page_scroll_friction, T_DOUBLE);
572 ELM_CONFIG_VAL(D, T, bring_in_scroll_friction, T_DOUBLE);
573 ELM_CONFIG_VAL(D, T, zoom_friction, T_DOUBLE);
574 ELM_CONFIG_VAL(D, T, thumbscroll_bounce_enable, T_UCHAR);
575 ELM_CONFIG_VAL(D, T, scale, T_DOUBLE);
576 ELM_CONFIG_VAL(D, T, bgpixmap, T_INT);
577 ELM_CONFIG_VAL(D, T, compositing, T_INT);
578 /* EET_DATA_DESCRIPTOR_ADD_LIST(D, T, "font_dirs", font_dirs, sub_edd); */
579 ELM_CONFIG_LIST(D, T, font_overlays, _config_font_overlay_edd);
580 ELM_CONFIG_VAL(D, T, font_hinting, T_INT);
581 ELM_CONFIG_VAL(D, T, cache_flush_poll_interval, T_INT);
582 ELM_CONFIG_VAL(D, T, cache_flush_enable, T_UCHAR);
583 ELM_CONFIG_VAL(D, T, image_cache, T_INT);
584 ELM_CONFIG_VAL(D, T, font_cache, T_INT);
585 ELM_CONFIG_VAL(D, T, edje_cache, T_INT);
586 ELM_CONFIG_VAL(D, T, edje_collection_cache, T_INT);
587 ELM_CONFIG_VAL(D, T, finger_size, T_INT);
588 ELM_CONFIG_VAL(D, T, fps, T_DOUBLE);
589 ELM_CONFIG_VAL(D, T, theme, T_STRING);
590 ELM_CONFIG_VAL(D, T, modules, T_STRING);
591 ELM_CONFIG_VAL(D, T, tooltip_delay, T_DOUBLE);
592 ELM_CONFIG_VAL(D, T, cursor_engine_only, T_UCHAR);
593 ELM_CONFIG_VAL(D, T, focus_highlight_enable, T_UCHAR);
594 ELM_CONFIG_VAL(D, T, focus_highlight_animate, T_UCHAR);
595 ELM_CONFIG_VAL(D, T, toolbar_shrink_mode, T_INT);
596 ELM_CONFIG_VAL(D, T, fileselector_expand_enable, T_UCHAR);
597 ELM_CONFIG_VAL(D, T, inwin_dialogs_enable, T_UCHAR);
598 ELM_CONFIG_VAL(D, T, icon_size, T_INT);
599 ELM_CONFIG_VAL(D, T, longpress_timeout, T_DOUBLE);
613 eet_data_descriptor_free(_config_edd);
617 if (_config_font_overlay_edd)
619 eet_data_descriptor_free(_config_font_overlay_edd);
620 _config_font_overlay_edd = NULL;
625 _sort_files_cb(const void *f1,
628 return strcmp(f1, f2);
632 _elm_config_current_profile_get(void)
638 _elm_data_dir_snprintf(char *dst,
643 size_t data_dir_len, off;
646 data_dir_len = eina_strlcpy(dst, _elm_data_dir, size);
648 off = data_dir_len + 1;
653 dst[data_dir_len] = '/';
655 off = off + vsnprintf(dst + off, size - off, fmt, ap);
663 _elm_user_dir_snprintf(char *dst,
669 size_t user_dir_len, off;
672 home = getenv("HOME");
676 user_dir_len = eina_str_join_len(dst, size, '/', home, strlen(home),
677 ".elementary", sizeof(".elementary") - 1);
679 off = user_dir_len + 1;
684 dst[user_dir_len] = '/';
686 off = off + vsnprintf(dst + off, size - off, fmt, ap);
694 _elm_config_profile_dir_get(const char *prof,
702 _elm_user_dir_snprintf(buf, sizeof(buf), "config/%s", prof);
704 if (ecore_file_is_dir(buf))
710 snprintf(buf, sizeof(buf), "%s/config/%s", _elm_data_dir, prof);
712 if (ecore_file_is_dir(buf))
719 _elm_config_font_overlays_list(void)
721 return _elm_config->font_overlays;
725 _elm_config_font_overlay_set(const char *text_class,
729 Elm_Font_Overlay *efd;
732 EINA_LIST_FOREACH(_elm_config->font_overlays, l, efd)
734 if (strcmp(efd->text_class, text_class))
737 if (efd->font) eina_stringshare_del(efd->font);
738 efd->font = eina_stringshare_add(font);
740 _elm_config->font_overlays =
741 eina_list_promote_list(_elm_config->font_overlays, l);
745 /* the text class doesn't exist */
746 efd = calloc(1, sizeof(Elm_Font_Overlay));
747 efd->text_class = eina_stringshare_add(text_class);
748 efd->font = eina_stringshare_add(font);
751 _elm_config->font_overlays = eina_list_prepend(_elm_config->font_overlays,
756 _elm_config_font_overlay_remove(const char *text_class)
758 Elm_Font_Overlay *efd;
761 EINA_LIST_FOREACH(_elm_config->font_overlays, l, efd)
763 if (strcmp(efd->text_class, text_class))
766 _elm_config->font_overlays =
767 eina_list_remove_list(_elm_config->font_overlays, l);
768 if (efd->text_class) eina_stringshare_del(efd->text_class);
769 if (efd->font) eina_stringshare_del(efd->font);
777 _elm_config_font_overlay_apply(void)
779 Elm_Font_Overlay *efd;
783 for (i = 0; _elm_text_classes[i].desc; i++)
784 edje_text_class_del(_elm_text_classes[i].name);
786 EINA_LIST_FOREACH(_elm_config->font_overlays, l, efd)
787 edje_text_class_set(efd->text_class, efd->font, efd->size);
791 _elm_config_text_classes_get(void)
793 Eina_List *ret = NULL;
796 for (i = 0; _elm_text_classes[i].desc; i++)
799 tc = malloc(sizeof(*tc));
801 *tc = _elm_text_classes[i];
803 ret = eina_list_append(ret, tc);
810 _elm_config_text_classes_free(Eina_List *l)
814 EINA_LIST_FREE(l, tc)
819 _elm_config_profiles_list(void)
821 const Eina_File_Direct_Info *info;
822 Eina_List *flist = NULL;
823 Eina_Iterator *file_it;
828 len = _elm_user_dir_snprintf(buf, sizeof(buf), "config");
830 file_it = eina_file_direct_ls(buf);
837 len = sizeof(buf) - len;
839 EINA_ITERATOR_FOREACH(file_it, info)
841 if (info->name_length >= len)
844 if (info->type == EINA_FILE_DIR)
847 eina_list_sorted_insert(flist, _sort_files_cb,
848 eina_stringshare_add(info->path +
853 eina_iterator_free(file_it);
856 len = eina_str_join_len(buf, sizeof(buf), '/', _elm_data_dir,
857 strlen(_elm_data_dir), "config",
858 sizeof("config") - 1);
860 file_it = eina_file_direct_ls(buf);
867 len = sizeof(buf) - len;
868 EINA_ITERATOR_FOREACH(file_it, info)
870 if (info->name_length >= len)
880 EINA_LIST_FOREACH(flist, l, tmp)
881 if (!strcmp(info->path + info->name_start, tmp))
886 eina_list_sorted_insert(flist, _sort_files_cb,
887 eina_stringshare_add(info->path +
898 eina_iterator_free(file_it);
901 EINA_LIST_FREE(flist, dir)
902 eina_stringshare_del(dir);
908 _profile_fetch_from_conf(void)
910 char buf[PATH_MAX], *p, *s;
914 _elm_profile = strdup("default");
916 // if env var - use profile without question
917 s = getenv("ELM_PROFILE");
921 _elm_profile = strdup(s);
926 _elm_user_dir_snprintf(buf, sizeof(buf), "config/profile.cfg");
927 ef = eet_open(buf, EET_FILE_MODE_READ);
930 p = eet_read(ef, "config", &len);
934 _elm_profile = malloc(len + 1);
935 memcpy(_elm_profile, p, len);
936 _elm_profile[len] = 0;
945 _elm_data_dir_snprintf(buf, sizeof(buf), "config/profile.cfg");
946 ef = eet_open(buf, EET_FILE_MODE_READ);
949 p = eet_read(ef, "config", &len);
953 _elm_profile = malloc(len + 1);
954 memcpy(_elm_profile, p, len);
955 _elm_profile[len] = 0;
965 Elm_Font_Overlay *fo;
968 if (!_elm_config) return;
969 EINA_LIST_FREE(_elm_config->font_dirs, fontdir)
971 eina_stringshare_del(fontdir);
973 if (_elm_config->engine) eina_stringshare_del(_elm_config->engine);
974 EINA_LIST_FREE(_elm_config->font_overlays, fo)
976 if (fo->text_class) eina_stringshare_del(fo->text_class);
977 if (fo->font) eina_stringshare_del(fo->font);
980 if (_elm_config->theme) eina_stringshare_del(_elm_config->theme);
981 if (_elm_config->modules) eina_stringshare_del(_elm_config->modules);
989 _elm_theme_parse(NULL, _elm_config->theme);
990 ecore_animator_frametime_set(1.0 / _elm_config->fps);
994 _config_sub_apply(void)
996 edje_frametime_set(1.0 / _elm_config->fps);
997 edje_scale_set(_elm_config->scale);
998 if (_elm_config->modules) _elm_module_parse(_elm_config->modules);
1002 _elm_cache_flush_cb(void *data __UNUSED__)
1005 return ECORE_CALLBACK_RENEW;
1008 /* kind of abusing this call right now -- shared between all of those
1009 * properties -- but they are not meant to be called that periodically
1019 EINA_LIST_FOREACH(_elm_win_list, l, win)
1021 Evas *e = evas_object_evas_get(win);
1022 evas_image_cache_set(e, _elm_config->image_cache);
1023 evas_font_cache_set(e, _elm_config->font_cache);
1025 edje_file_cache_set(_elm_config->edje_cache);
1026 edje_collection_cache_set(_elm_config->edje_collection_cache);
1028 if (_elm_cache_flush_poller)
1030 ecore_poller_del(_elm_cache_flush_poller);
1031 _elm_cache_flush_poller = NULL;
1033 if (_elm_config->cache_flush_enable)
1035 if (_elm_config->cache_flush_poll_interval > 0)
1037 _elm_cache_flush_poller =
1038 ecore_poller_add(ECORE_POLLER_CORE,
1039 _elm_config->cache_flush_poll_interval,
1040 _elm_cache_flush_cb, NULL);
1046 _config_user_load(void)
1048 Elm_Config *cfg = NULL;
1052 _elm_user_dir_snprintf(buf, sizeof(buf), "config/%s/base.cfg",
1055 ef = eet_open(buf, EET_FILE_MODE_READ);
1058 cfg = eet_data_read(ef, _config_edd, "config");
1065 _config_system_load(void)
1067 Elm_Config *cfg = NULL;
1071 _elm_data_dir_snprintf(buf, sizeof(buf), "config/%s/base.cfg",
1074 ef = eet_open(buf, EET_FILE_MODE_READ);
1077 cfg = eet_data_read(ef, _config_edd, "config");
1086 _elm_config = _config_user_load();
1089 if (_elm_config->config_version < ELM_CONFIG_VERSION)
1094 /* no user config, fallback for system. No need to check version for
1095 * this one, if it's not the right one, someone screwed up at the time
1096 * of installing it */
1097 _elm_config = _config_system_load();
1098 if (_elm_config) return;
1099 /* FIXME: config load could have failed because of a non-existent
1100 * profile. Fallback to default before moving on */
1102 // config load fail - defaults
1103 /* XXX: do these make sense? Only if it's valid to install the lib
1104 * without the config, but do we want that? */
1105 _elm_config = ELM_NEW(Elm_Config);
1106 _elm_config->config_version = ELM_CONFIG_VERSION;
1107 _elm_config->engine = eina_stringshare_add("software_x11");
1108 _elm_config->thumbscroll_enable = EINA_TRUE;
1109 _elm_config->thumbscroll_threshold = 24;
1110 _elm_config->thumbscroll_momentum_threshold = 100.0;
1111 _elm_config->thumbscroll_friction = 1.0;
1112 _elm_config->thumbscroll_bounce_friction = 0.5;
1113 _elm_config->thumbscroll_bounce_enable = EINA_TRUE;
1114 _elm_config->page_scroll_friction = 0.5;
1115 _elm_config->bring_in_scroll_friction = 0.5;
1116 _elm_config->zoom_friction = 0.5;
1117 _elm_config->thumbscroll_border_friction = 0.5;
1118 _elm_config->scale = 1.0;
1119 _elm_config->bgpixmap = 0;
1120 _elm_config->compositing = 1;
1121 _elm_config->font_hinting = 2;
1122 _elm_config->cache_flush_poll_interval = 512;
1123 _elm_config->cache_flush_enable = EINA_TRUE;
1124 _elm_config->font_dirs = NULL;
1125 _elm_config->image_cache = 4096;
1126 _elm_config->font_cache = 512;
1127 _elm_config->edje_cache = 32;
1128 _elm_config->edje_collection_cache = 64;
1129 _elm_config->finger_size = 40;
1130 _elm_config->fps = 60.0;
1131 _elm_config->theme = eina_stringshare_add("default");
1132 _elm_config->modules = NULL;
1133 _elm_config->tooltip_delay = 1.0;
1134 _elm_config->cursor_engine_only = EINA_TRUE;
1135 _elm_config->focus_highlight_enable = EINA_FALSE;
1136 _elm_config->focus_highlight_animate = EINA_TRUE;
1137 _elm_config->toolbar_shrink_mode = 2;
1138 _elm_config->fileselector_expand_enable = EINA_FALSE;
1139 _elm_config->inwin_dialogs_enable = EINA_FALSE;
1140 _elm_config->icon_size = 32;
1141 _elm_config->longpress_timeout = 1.0;
1145 _elm_config_eet_close_error_get(Eet_File *ef,
1149 const char *erstr = NULL;
1151 err = eet_close(ef);
1154 case EET_ERROR_WRITE_ERROR:
1155 erstr = "An error occurred while saving Elementary's "
1156 "settings to disk. The error could not be "
1157 "deterimined. The file where the error occurred was: "
1158 "%s. This file has been deleted to avoid corrupt data.";
1161 case EET_ERROR_WRITE_ERROR_FILE_TOO_BIG:
1162 erstr = "Elementary's settings files are too big "
1163 "for the file system they are being saved to. "
1164 "This error is very strange as the files should "
1165 "be extremely small. Please check the settings "
1166 "for your home directory. "
1167 "The file where the error occurred was: %s ."
1168 "This file has been deleted to avoid corrupt data.";
1171 case EET_ERROR_WRITE_ERROR_IO_ERROR:
1172 erstr = "An output error occurred when writing the settings "
1173 "files for Elementary. Your disk is having troubles "
1174 "and possibly needs replacement. "
1175 "The file where the error occurred was: %s ."
1176 "This file has been deleted to avoid corrupt data.";
1179 case EET_ERROR_WRITE_ERROR_OUT_OF_SPACE:
1180 erstr = "Elementary cannot write its settings file "
1181 "because it ran out of space to write the file. "
1182 "You have either run out of disk space or have "
1183 "gone over your quota limit. "
1184 "The file where the error occurred was: %s ."
1185 "This file has been deleted to avoid corrupt data.";
1188 case EET_ERROR_WRITE_ERROR_FILE_CLOSED:
1189 erstr = "Elementary unexpectedly had the settings file "
1190 "it was writing closed on it. This is very unusual. "
1191 "The file where the error occurred was: %s "
1192 "This file has been deleted to avoid corrupt data.";
1200 /* delete any partially-written file */
1201 ecore_file_unlink(file);
1202 return strdup(erstr);
1209 _elm_config_profile_save(void)
1211 char buf[4096], buf2[4096];
1217 len = _elm_user_dir_snprintf(buf, sizeof(buf), "config/profile.cfg");
1218 if (len + 1 >= sizeof(buf))
1221 len = _elm_user_dir_snprintf(buf2, sizeof(buf2), "config/profile.cfg.tmp");
1222 if (len + 1 >= sizeof(buf2))
1225 ef = eet_open(buf2, EET_FILE_MODE_WRITE);
1229 ok = eet_write(ef, "config", _elm_profile, strlen(_elm_profile), 0);
1233 err = _elm_config_eet_close_error_get(ef, buf2);
1241 ret = ecore_file_mv(buf2, buf);
1244 ERR("Error saving Elementary's configuration file");
1248 ecore_file_unlink(buf2);
1252 ecore_file_unlink(buf2);
1257 _elm_config_save(void)
1259 char buf[4096], buf2[4096];
1265 len = _elm_user_dir_snprintf(buf, sizeof(buf), "config/%s", _elm_profile);
1266 if (len + 1 >= sizeof(buf))
1269 ok = ecore_file_mkpath(buf);
1272 ERR("Problem acessing Elementary's user configuration directory: %s",
1277 if (!_elm_config_profile_save())
1283 if (len + sizeof("base.cfg") >= sizeof(buf) - len)
1286 memcpy(buf + len, "base.cfg", sizeof("base.cfg"));
1287 len += sizeof("base.cfg") - 1;
1289 if (len + sizeof(".tmp") >= sizeof(buf))
1292 memcpy(buf2, buf, len);
1293 memcpy(buf2 + len, ".tmp", sizeof(".tmp"));
1295 ef = eet_open(buf2, EET_FILE_MODE_WRITE);
1299 ok = eet_data_write(ef, _config_edd, "config", _elm_config, 1);
1303 err = _elm_config_eet_close_error_get(ef, buf2);
1311 ret = ecore_file_mv(buf2, buf);
1314 ERR("Error saving Elementary's configuration file");
1318 ecore_file_unlink(buf2);
1322 ecore_file_unlink(buf2);
1327 _config_update(void)
1331 tcfg = _config_system_load();
1334 /* weird profile or something? We should probably fill
1335 * with hardcoded defaults, or get from default previx */
1338 #define IFCFG(v) if ((_elm_config->config_version & 0xffff) < (v)) {
1339 #define IFCFGELSE } else {
1341 #define COPYVAL(x) do {_elm_config->x = tcfg->x; } while(0)
1342 #define COPYPTR(x) do {_elm_config->x = tcfg->x; tcfg->x = NULL; } while(0)
1343 #define COPYSTR(x) COPYPTR(x)
1345 /* we also need to update for property changes in the root window
1346 * if needed, but that will be dependent on new properties added
1347 * with each version */
1350 COPYVAL(longpress_timeout);
1360 /* after updating user config, we must save */
1369 s = getenv("ELM_ENGINE");
1372 if ((!strcasecmp(s, "x11")) ||
1373 (!strcasecmp(s, "x")) ||
1374 (!strcasecmp(s, "software-x11")) ||
1375 (!strcasecmp(s, "software_x11")))
1376 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_X11);
1377 else if ((!strcasecmp(s, "opengl")) ||
1378 (!strcasecmp(s, "gl")) ||
1379 (!strcasecmp(s, "opengl-x11")) ||
1380 (!strcasecmp(s, "opengl_x11")))
1381 eina_stringshare_replace(&_elm_config->engine, ELM_OPENGL_X11);
1382 else if ((!strcasecmp(s, "x11-8")) ||
1383 (!strcasecmp(s, "x18")) ||
1384 (!strcasecmp(s, "software-8-x11")) ||
1385 (!strcasecmp(s, "software_8_x11")))
1386 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_8_X11);
1387 else if ((!strcasecmp(s, "x11-16")) ||
1388 (!strcasecmp(s, "x16")) ||
1389 (!strcasecmp(s, "software-16-x11")) ||
1390 (!strcasecmp(s, "software_16_x11")))
1391 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_16_X11);
1392 else if ((!strcasecmp(s, "xrender")) ||
1393 (!strcasecmp(s, "xr")) ||
1394 (!strcasecmp(s, "xrender-x11")) ||
1395 (!strcasecmp(s, "xrender_x11")))
1396 eina_stringshare_replace(&_elm_config->engine, ELM_XRENDER_X11);
1397 else if ((!strcasecmp(s, "fb")) ||
1398 (!strcasecmp(s, "software-fb")) ||
1399 (!strcasecmp(s, "software_fb")))
1400 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_FB);
1401 else if ((!strcasecmp(s, "directfb")) ||
1402 (!strcasecmp(s, "dfb")))
1403 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_DIRECTFB);
1404 else if ((!strcasecmp(s, "sdl")) ||
1405 (!strcasecmp(s, "software-sdl")) ||
1406 (!strcasecmp(s, "software_sdl")))
1407 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_SDL);
1408 else if ((!strcasecmp(s, "sdl-16")) ||
1409 (!strcasecmp(s, "software-16-sdl")) ||
1410 (!strcasecmp(s, "software_16_sdl")))
1411 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_16_SDL);
1412 else if ((!strcasecmp(s, "opengl-sdl")) ||
1413 (!strcasecmp(s, "opengl_sdl")) ||
1414 (!strcasecmp(s, "gl-sdl")) ||
1415 (!strcasecmp(s, "gl_sdl")))
1416 eina_stringshare_replace(&_elm_config->engine, ELM_OPENGL_SDL);
1417 else if ((!strcasecmp(s, "gdi")) ||
1418 (!strcasecmp(s, "software-gdi")) ||
1419 (!strcasecmp(s, "software_gdi")))
1420 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_WIN32);
1421 else if ((!strcasecmp(s, "wince-gdi")) ||
1422 (!strcasecmp(s, "software-16-wince-gdi")) ||
1423 (!strcasecmp(s, "software_16_wince_gdi")))
1424 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_16_WINCE);
1427 s = getenv("ELM_THUMBSCROLL_ENABLE");
1428 if (s) _elm_config->thumbscroll_enable = !!atoi(s);
1429 s = getenv("ELM_THUMBSCROLL_THRESHOLD");
1430 if (s) _elm_config->thumbscroll_threshold = atoi(s);
1431 // FIXME: floatformat locale issues here 1.0 vs 1,0 - should just be 1.0
1432 s = getenv("ELM_THUMBSCROLL_MOMENTUM_THRESHOLD");
1433 if (s) _elm_config->thumbscroll_momentum_threshold = atof(s);
1434 s = getenv("ELM_THUMBSCROLL_FRICTION");
1435 if (s) _elm_config->thumbscroll_friction = atof(s);
1436 s = getenv("ELM_THUMBSCROLL_BOUNCE_ENABLE");
1437 if (s) _elm_config->thumbscroll_bounce_enable = !!atoi(s);
1438 s = getenv("ELM_THUMBSCROLL_BOUNCE_FRICTION");
1439 if (s) _elm_config->thumbscroll_bounce_friction = atof(s);
1440 s = getenv("ELM_PAGE_SCROLL_FRICTION");
1441 if (s) _elm_config->page_scroll_friction = atof(s);
1442 s = getenv("ELM_BRING_IN_SCROLL_FRICTION");
1443 if (s) _elm_config->bring_in_scroll_friction = atof(s);
1444 s = getenv("ELM_ZOOM_FRICTION");
1445 if (s) _elm_config->zoom_friction = atof(s);
1446 s = getenv("ELM_THUMBSCROLL_BORDER_FRICTION");
1456 _elm_config->thumbscroll_border_friction = friction;
1458 s = getenv("ELM_THEME");
1459 if (s) eina_stringshare_replace(&_elm_config->theme, s);
1461 s = getenv("ELM_FONT_HINTING");
1464 if (!strcasecmp(s, "none")) _elm_config->font_hinting = 0;
1465 else if (!strcasecmp(s, "auto"))
1466 _elm_config->font_hinting = 1;
1467 else if (!strcasecmp(s, "bytecode"))
1468 _elm_config->font_hinting = 2;
1471 s = getenv("ELM_FONT_PATH");
1477 EINA_LIST_FREE(_elm_config->font_dirs, p)
1479 eina_stringshare_del(p);
1482 buf2 = alloca(strlen(s) + 1);
1487 if ((*p == ':') || (*p == 0))
1492 strncpy(buf2, pp, len);
1494 _elm_config->font_dirs =
1495 eina_list_append(_elm_config->font_dirs,
1496 eina_stringshare_add(buf2));
1509 s = getenv("ELM_IMAGE_CACHE");
1510 if (s) _elm_config->image_cache = atoi(s);
1512 s = getenv("ELM_FONT_CACHE");
1513 if (s) _elm_config->font_cache = atoi(s);
1515 s = getenv("ELM_SCALE");
1516 if (s) _elm_config->scale = atof(s);
1518 _elm_config->finger_size =
1519 (double)_elm_config->finger_size * _elm_config->scale;
1520 s = getenv("ELM_FINGER_SIZE");
1521 if (s) _elm_config->finger_size = atoi(s);
1523 s = getenv("ELM_FPS");
1524 if (s) _elm_config->fps = atof(s);
1525 if (_elm_config->fps < 1.0) _elm_config->fps = 1.0;
1527 s = getenv("ELM_MODULES");
1528 if (s) eina_stringshare_replace(&_elm_config->modules, s);
1530 s = getenv("ELM_TOOLTIP_DELAY");
1533 double delay = atof(s);
1535 _elm_config->tooltip_delay = delay;
1538 s = getenv("ELM_CURSOR_ENGINE_ONLY");
1539 if (s) _elm_config->cursor_engine_only = !!atoi(s);
1541 s = getenv("ELM_FOCUS_HIGHLIGHT_ENABLE");
1542 if (s) _elm_config->focus_highlight_enable = !!atoi(s);
1544 s = getenv("ELM_FOCUS_HIGHLIGHT_ANIMATE");
1545 if (s) _elm_config->focus_highlight_animate = !!atoi(s);
1547 s = getenv("ELM_TOOLBAR_SHRINK_MODE");
1548 if (s) _elm_config->toolbar_shrink_mode = atoi(s);
1550 s = getenv("ELM_FILESELECTOR_EXPAND_ENABLE");
1551 if (s) _elm_config->fileselector_expand_enable = !!atoi(s);
1553 s = getenv("ELM_INWIN_DIALOGS_ENABLE");
1554 if (s) _elm_config->inwin_dialogs_enable = !!atoi(s);
1556 s = getenv("ELM_ICON_SIZE");
1557 if (s) _elm_config->icon_size = atoi(s);
1559 s = getenv("ELM_LONGPRESS_TIMEOUT");
1560 if (s) _elm_config->longpress_timeout = atof(s);
1561 if (_elm_config->longpress_timeout < 0.0)
1562 _elm_config->longpress_timeout = 0.0;
1566 _elm_config_init(void)
1569 _profile_fetch_from_conf();
1573 _elm_config_font_overlay_apply();
1578 _elm_config_sub_init(void)
1580 #define ENGINE_COMPARE(name) (!strcmp(_elm_config->engine, name))
1581 if (ENGINE_COMPARE(ELM_SOFTWARE_X11) ||
1582 ENGINE_COMPARE(ELM_SOFTWARE_16_X11) ||
1583 ENGINE_COMPARE(ELM_XRENDER_X11) ||
1584 ENGINE_COMPARE(ELM_OPENGL_X11))
1585 #undef ENGINE_COMPARE
1587 #ifdef HAVE_ELEMENTARY_X
1588 unsigned int val = 1000;
1590 if (!ecore_x_init(NULL))
1592 ERR("Cannot connect to X11 display. check $DISPLAY variable");
1595 _root_1st = ecore_x_window_root_first_get();
1597 if (!ecore_x_screen_is_composited(0))
1598 _elm_config->compositing = 0;
1600 ecore_x_atoms_get(_atom_names, ATOM_COUNT, _atom);
1601 ecore_x_event_mask_set(_root_1st,
1602 ECORE_X_EVENT_MASK_WINDOW_PROPERTY);
1603 _prop_change_handler = ecore_event_handler_add
1604 (ECORE_X_EVENT_WINDOW_PROPERTY, _prop_change, NULL);
1605 if (!getenv("ELM_SCALE"))
1607 if (ecore_x_window_prop_card32_get(_root_1st,
1608 _atom[ATOM_E_SCALE],
1613 _elm_config->scale = (double)val / 1000.0;
1614 // FIXME: hack until e export finger size too
1615 if (!getenv("ELM_FINGER_SIZE"))
1617 _elm_config->finger_size = 40.0 * _elm_config->scale;
1619 edje_scale_set(_elm_config->scale);
1623 if (!getenv("ELM_FINGER_SIZE"))
1625 if (ecore_x_window_prop_card32_get(_root_1st,
1626 _atom[ATOM_E_FINGER_SIZE],
1631 _elm_config->finger_size = val;
1635 if (!getenv("ELM_THEME"))
1639 s = ecore_x_window_prop_string_get(_root_1st,
1640 _atom[ATOM_E_THEME]);
1643 eina_stringshare_replace(&_elm_config->theme, s);
1644 _elm_theme_parse(NULL, s);
1648 if (!getenv("ELM_PROFILE"))
1652 s = ecore_x_window_prop_string_get(_root_1st,
1653 _atom[ATOM_E_PROFILE]);
1660 if (strcmp(_elm_profile, s)) changed = 1;
1664 if (changed) _prop_config_get();
1669 _config_sub_apply();
1673 _elm_config_reload(void)
1678 _elm_config_font_overlay_apply();
1684 _elm_config_engine_set(const char *engine)
1686 if (_elm_config->engine && strcmp(_elm_config->engine, engine))
1687 eina_stringshare_del(_elm_config->engine);
1689 _elm_config->engine = eina_stringshare_add(engine);
1693 _elm_config_profile_set(const char *profile)
1695 Eina_Bool changed = EINA_FALSE;
1699 if (strcmp(_elm_profile, profile))
1704 _elm_profile = strdup(profile);
1711 _elm_config_font_overlay_apply();
1718 _elm_config_shutdown(void)
1720 #define ENGINE_COMPARE(name) (!strcmp(_elm_config->engine, name))
1721 if (ENGINE_COMPARE(ELM_SOFTWARE_X11) ||
1722 ENGINE_COMPARE(ELM_SOFTWARE_16_X11) ||
1723 ENGINE_COMPARE(ELM_XRENDER_X11) ||
1724 ENGINE_COMPARE(ELM_OPENGL_X11))
1725 #undef ENGINE_COMPARE
1727 #ifdef HAVE_ELEMENTARY_X
1728 ecore_event_handler_del(_prop_change_handler);
1729 _prop_change_handler = NULL;
1736 _elm_profile = NULL;