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,
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,
452 _elm_config->thumbscroll_friction = (double)val / 1000.0;
455 else if (event->atom == _atom[ATOM_E_THUMBSCROLL_BORDER_FRICTION])
457 unsigned int val = 1000;
459 if (ecore_x_window_prop_card32_get(event->win,
463 _elm_config->thumbscroll_border_friction =
464 (double)val / 1000.0;
467 else if (event->atom == _atom[ATOM_E_THUMBSCROLL_PAGE_SCROLL_FRICTION])
469 unsigned int val = 1000;
471 if (ecore_x_window_prop_card32_get(event->win,
475 _elm_config->page_scroll_friction =
476 (double)val / 1000.0;
479 else if (event->atom ==
480 _atom[ATOM_E_THUMBSCROLL_BRING_IN_SCROLL_FRICTION])
482 unsigned int val = 1000;
484 if (ecore_x_window_prop_card32_get(event->win,
488 _elm_config->bring_in_scroll_friction =
489 (double)val / 1000.0;
492 else if (event->atom ==
493 _atom[ATOM_E_THUMBSCROLL_ZOOM_FRICTION])
495 unsigned int val = 1000;
497 if (ecore_x_window_prop_card32_get(event->win,
501 _elm_config->zoom_friction = (double)val / 1000.0;
504 else if (((_atom_config > 0) && (event->atom == _atom_config)) ||
505 (event->atom == _atom[ATOM_E_CONFIG]))
510 return ECORE_CALLBACK_PASS_ON;
518 Eet_Data_Descriptor_Class eddc;
520 EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Elm_Config);
521 eddc.func.str_direct_alloc = NULL;
522 eddc.func.str_direct_free = NULL;
524 _config_edd = eet_data_descriptor_file_new(&eddc);
527 printf("EEEK! eet_data_descriptor_file_new() failed\n");
531 memset(&eddc, 0, sizeof(eddc)); /* just in case... */
532 EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Elm_Font_Overlay);
533 eddc.func.str_direct_alloc = NULL;
534 eddc.func.str_direct_free = NULL;
536 _config_font_overlay_edd = eet_data_descriptor_stream_new(&eddc);
537 if (!_config_font_overlay_edd)
539 printf("EEEK! eet_data_descriptor_stream_new() failed\n");
540 eet_data_descriptor_free(_config_edd);
543 #define T_INT EET_T_INT
544 #define T_DOUBLE EET_T_DOUBLE
545 #define T_STRING EET_T_STRING
546 #define T_UCHAR EET_T_UCHAR
548 #define T Elm_Font_Overlay
549 #define D _config_font_overlay_edd
550 ELM_CONFIG_VAL(D, T, text_class, EET_T_STRING);
551 ELM_CONFIG_VAL(D, T, font, EET_T_STRING);
552 ELM_CONFIG_VAL(D, T, size, EET_T_INT);
557 #define D _config_edd
558 ELM_CONFIG_VAL(D, T, config_version, T_INT);
559 ELM_CONFIG_VAL(D, T, engine, T_STRING);
560 ELM_CONFIG_VAL(D, T, vsync, T_UCHAR);
561 ELM_CONFIG_VAL(D, T, thumbscroll_enable, T_UCHAR);
562 ELM_CONFIG_VAL(D, T, thumbscroll_threshold, T_INT);
563 ELM_CONFIG_VAL(D, T, thumbscroll_momentum_threshold, T_DOUBLE);
564 ELM_CONFIG_VAL(D, T, thumbscroll_friction, T_DOUBLE);
565 ELM_CONFIG_VAL(D, T, thumbscroll_bounce_friction, T_DOUBLE);
566 ELM_CONFIG_VAL(D, T, thumbscroll_border_friction, T_DOUBLE);
567 ELM_CONFIG_VAL(D, T, page_scroll_friction, T_DOUBLE);
568 ELM_CONFIG_VAL(D, T, bring_in_scroll_friction, T_DOUBLE);
569 ELM_CONFIG_VAL(D, T, zoom_friction, T_DOUBLE);
570 ELM_CONFIG_VAL(D, T, thumbscroll_bounce_enable, T_UCHAR);
571 ELM_CONFIG_VAL(D, T, scale, T_DOUBLE);
572 ELM_CONFIG_VAL(D, T, bgpixmap, T_INT);
573 ELM_CONFIG_VAL(D, T, compositing, T_INT);
574 /* EET_DATA_DESCRIPTOR_ADD_LIST(D, T, "font_dirs", font_dirs, sub_edd); */
575 ELM_CONFIG_LIST(D, T, font_overlays, _config_font_overlay_edd);
576 ELM_CONFIG_VAL(D, T, font_hinting, T_INT);
577 ELM_CONFIG_VAL(D, T, cache_flush_poll_interval, T_INT);
578 ELM_CONFIG_VAL(D, T, cache_flush_enable, T_UCHAR);
579 ELM_CONFIG_VAL(D, T, image_cache, T_INT);
580 ELM_CONFIG_VAL(D, T, font_cache, T_INT);
581 ELM_CONFIG_VAL(D, T, edje_cache, T_INT);
582 ELM_CONFIG_VAL(D, T, edje_collection_cache, T_INT);
583 ELM_CONFIG_VAL(D, T, finger_size, T_INT);
584 ELM_CONFIG_VAL(D, T, fps, T_DOUBLE);
585 ELM_CONFIG_VAL(D, T, theme, T_STRING);
586 ELM_CONFIG_VAL(D, T, modules, T_STRING);
587 ELM_CONFIG_VAL(D, T, tooltip_delay, T_DOUBLE);
588 ELM_CONFIG_VAL(D, T, cursor_engine_only, T_UCHAR);
589 ELM_CONFIG_VAL(D, T, focus_highlight_enable, T_UCHAR);
590 ELM_CONFIG_VAL(D, T, focus_highlight_animate, T_UCHAR);
591 ELM_CONFIG_VAL(D, T, toolbar_shrink_mode, T_INT);
592 ELM_CONFIG_VAL(D, T, fileselector_expand_enable, T_UCHAR);
593 ELM_CONFIG_VAL(D, T, inwin_dialogs_enable, T_UCHAR);
594 ELM_CONFIG_VAL(D, T, icon_size, T_INT);
595 ELM_CONFIG_VAL(D, T, longpress_timeout, T_DOUBLE);
596 ELM_CONFIG_VAL(D, T, effect_enable, T_UCHAR);
597 ELM_CONFIG_VAL(D, T, desktop_entry, T_UCHAR);
611 eet_data_descriptor_free(_config_edd);
615 if (_config_font_overlay_edd)
617 eet_data_descriptor_free(_config_font_overlay_edd);
618 _config_font_overlay_edd = NULL;
623 _sort_files_cb(const void *f1,
626 return strcmp(f1, f2);
630 _elm_config_current_profile_get(void)
636 _elm_data_dir_snprintf(char *dst,
641 size_t data_dir_len, off;
644 data_dir_len = eina_strlcpy(dst, _elm_data_dir, size);
646 off = data_dir_len + 1;
651 dst[data_dir_len] = '/';
653 off = off + vsnprintf(dst + off, size - off, fmt, ap);
661 _elm_user_dir_snprintf(char *dst,
667 size_t user_dir_len, off;
671 home = evil_homedir_get();
673 home = getenv("HOME");
678 user_dir_len = eina_str_join_len(dst, size, '/', home, strlen(home),
679 ".elementary", sizeof(".elementary") - 1);
681 off = user_dir_len + 1;
686 dst[user_dir_len] = '/';
688 off = off + vsnprintf(dst + off, size - off, fmt, ap);
696 _elm_config_profile_dir_get(const char *prof,
704 _elm_user_dir_snprintf(buf, sizeof(buf), "config/%s", prof);
706 if (ecore_file_is_dir(buf))
712 snprintf(buf, sizeof(buf), "%s/config/%s", _elm_data_dir, prof);
714 if (ecore_file_is_dir(buf))
721 _elm_config_font_overlays_list(void)
723 return _elm_config->font_overlays;
727 _elm_config_font_overlay_set(const char *text_class,
731 Elm_Font_Overlay *efd;
734 EINA_LIST_FOREACH(_elm_config->font_overlays, l, efd)
736 if (strcmp(efd->text_class, text_class))
739 if (efd->font) eina_stringshare_del(efd->font);
740 efd->font = eina_stringshare_add(font);
742 _elm_config->font_overlays =
743 eina_list_promote_list(_elm_config->font_overlays, l);
747 /* the text class doesn't exist */
748 efd = calloc(1, sizeof(Elm_Font_Overlay));
749 efd->text_class = eina_stringshare_add(text_class);
750 efd->font = eina_stringshare_add(font);
753 _elm_config->font_overlays = eina_list_prepend(_elm_config->font_overlays,
758 _elm_config_font_overlay_remove(const char *text_class)
760 Elm_Font_Overlay *efd;
763 EINA_LIST_FOREACH(_elm_config->font_overlays, l, efd)
765 if (strcmp(efd->text_class, text_class))
768 _elm_config->font_overlays =
769 eina_list_remove_list(_elm_config->font_overlays, l);
770 if (efd->text_class) eina_stringshare_del(efd->text_class);
771 if (efd->font) eina_stringshare_del(efd->font);
779 _elm_config_font_overlay_apply(void)
781 Elm_Font_Overlay *efd;
785 for (i = 0; _elm_text_classes[i].desc; i++)
786 edje_text_class_del(_elm_text_classes[i].name);
788 EINA_LIST_FOREACH(_elm_config->font_overlays, l, efd)
789 edje_text_class_set(efd->text_class, efd->font, efd->size);
793 _elm_config_text_classes_get(void)
795 Eina_List *ret = NULL;
798 for (i = 0; _elm_text_classes[i].desc; i++)
801 tc = malloc(sizeof(*tc));
803 *tc = _elm_text_classes[i];
805 ret = eina_list_append(ret, tc);
812 _elm_config_text_classes_free(Eina_List *l)
816 EINA_LIST_FREE(l, tc)
821 _elm_config_profiles_list(void)
823 const Eina_File_Direct_Info *info;
824 Eina_List *flist = NULL;
825 Eina_Iterator *file_it;
830 len = _elm_user_dir_snprintf(buf, sizeof(buf), "config");
832 file_it = eina_file_direct_ls(buf);
839 len = sizeof(buf) - len;
841 EINA_ITERATOR_FOREACH(file_it, info)
843 if (info->name_length >= len)
846 if (info->type == EINA_FILE_DIR)
849 eina_list_sorted_insert(flist, _sort_files_cb,
850 eina_stringshare_add(info->path +
855 eina_iterator_free(file_it);
858 len = eina_str_join_len(buf, sizeof(buf), '/', _elm_data_dir,
859 strlen(_elm_data_dir), "config",
860 sizeof("config") - 1);
862 file_it = eina_file_direct_ls(buf);
869 len = sizeof(buf) - len;
870 EINA_ITERATOR_FOREACH(file_it, info)
872 if (info->name_length >= len)
882 EINA_LIST_FOREACH(flist, l, tmp)
883 if (!strcmp(info->path + info->name_start, tmp))
888 eina_list_sorted_insert(flist, _sort_files_cb,
889 eina_stringshare_add(info->path +
900 eina_iterator_free(file_it);
903 EINA_LIST_FREE(flist, dir)
904 eina_stringshare_del(dir);
910 _profile_fetch_from_conf(void)
912 char buf[PATH_MAX], *p, *s;
916 _elm_profile = strdup("default");
918 // if env var - use profile without question
919 s = getenv("ELM_PROFILE");
923 _elm_profile = strdup(s);
928 _elm_user_dir_snprintf(buf, sizeof(buf), "config/profile.cfg");
929 ef = eet_open(buf, EET_FILE_MODE_READ);
932 p = eet_read(ef, "config", &len);
936 _elm_profile = malloc(len + 1);
937 memcpy(_elm_profile, p, len);
938 _elm_profile[len] = 0;
947 _elm_data_dir_snprintf(buf, sizeof(buf), "config/profile.cfg");
948 ef = eet_open(buf, EET_FILE_MODE_READ);
951 p = eet_read(ef, "config", &len);
955 _elm_profile = malloc(len + 1);
956 memcpy(_elm_profile, p, len);
957 _elm_profile[len] = 0;
967 Elm_Font_Overlay *fo;
970 if (!_elm_config) return;
971 EINA_LIST_FREE(_elm_config->font_dirs, fontdir)
973 eina_stringshare_del(fontdir);
975 if (_elm_config->engine) eina_stringshare_del(_elm_config->engine);
976 EINA_LIST_FREE(_elm_config->font_overlays, fo)
978 if (fo->text_class) eina_stringshare_del(fo->text_class);
979 if (fo->font) eina_stringshare_del(fo->font);
982 if (_elm_config->theme) eina_stringshare_del(_elm_config->theme);
983 if (_elm_config->modules) eina_stringshare_del(_elm_config->modules);
991 _elm_theme_parse(NULL, _elm_config->theme);
992 ecore_animator_frametime_set(1.0 / _elm_config->fps);
996 _config_sub_apply(void)
998 edje_frametime_set(1.0 / _elm_config->fps);
999 edje_scale_set(_elm_config->scale);
1000 if (_elm_config->modules) _elm_module_parse(_elm_config->modules);
1004 _elm_cache_flush_cb(void *data __UNUSED__)
1007 return ECORE_CALLBACK_RENEW;
1010 /* kind of abusing this call right now -- shared between all of those
1011 * properties -- but they are not meant to be called that periodically
1021 EINA_LIST_FOREACH(_elm_win_list, l, win)
1023 Evas *e = evas_object_evas_get(win);
1024 evas_image_cache_set(e, _elm_config->image_cache * 1024);
1025 evas_font_cache_set(e, _elm_config->font_cache * 1024);
1027 edje_file_cache_set(_elm_config->edje_cache);
1028 edje_collection_cache_set(_elm_config->edje_collection_cache);
1030 if (_elm_cache_flush_poller)
1032 ecore_poller_del(_elm_cache_flush_poller);
1033 _elm_cache_flush_poller = NULL;
1035 if (_elm_config->cache_flush_enable)
1037 if (_elm_config->cache_flush_poll_interval > 0)
1039 _elm_cache_flush_poller =
1040 ecore_poller_add(ECORE_POLLER_CORE,
1041 _elm_config->cache_flush_poll_interval,
1042 _elm_cache_flush_cb, NULL);
1048 _config_user_load(void)
1050 Elm_Config *cfg = NULL;
1054 _elm_user_dir_snprintf(buf, sizeof(buf), "config/%s/base.cfg",
1057 ef = eet_open(buf, EET_FILE_MODE_READ);
1060 cfg = eet_data_read(ef, _config_edd, "config");
1067 _config_system_load(void)
1069 Elm_Config *cfg = NULL;
1073 _elm_data_dir_snprintf(buf, sizeof(buf), "config/%s/base.cfg",
1076 ef = eet_open(buf, EET_FILE_MODE_READ);
1079 cfg = eet_data_read(ef, _config_edd, "config");
1088 _elm_config = _config_user_load();
1091 if (_elm_config->config_version < ELM_CONFIG_VERSION)
1096 /* no user config, fallback for system. No need to check version for
1097 * this one, if it's not the right one, someone screwed up at the time
1098 * of installing it */
1099 _elm_config = _config_system_load();
1100 if (_elm_config) return;
1101 /* FIXME: config load could have failed because of a non-existent
1102 * profile. Fallback to default before moving on */
1104 // config load fail - defaults
1105 /* XXX: do these make sense? Only if it's valid to install the lib
1106 * without the config, but do we want that? */
1107 _elm_config = ELM_NEW(Elm_Config);
1108 _elm_config->config_version = ELM_CONFIG_VERSION;
1109 _elm_config->engine = eina_stringshare_add("software_x11");
1110 _elm_config->vsync = 0;
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->tooltip_delay = 1.0;
1137 _elm_config->cursor_engine_only = EINA_TRUE;
1138 _elm_config->focus_highlight_enable = EINA_FALSE;
1139 _elm_config->focus_highlight_animate = EINA_TRUE;
1140 _elm_config->toolbar_shrink_mode = 2;
1141 _elm_config->fileselector_expand_enable = EINA_FALSE;
1142 _elm_config->inwin_dialogs_enable = EINA_FALSE;
1143 _elm_config->icon_size = 32;
1144 _elm_config->longpress_timeout = 1.0;
1145 _elm_config->effect_enable = EINA_TRUE;
1146 _elm_config->desktop_entry = EINA_FALSE;
1148 _elm_config->is_mirrored = EINA_FALSE; /* Read sys value in env_get() */
1152 _elm_config_eet_close_error_get(Eet_File *ef,
1156 const char *erstr = NULL;
1158 err = eet_close(ef);
1161 case EET_ERROR_WRITE_ERROR:
1162 erstr = "An error occurred while saving Elementary's "
1163 "settings to disk. The error could not be "
1164 "deterimined. The file where the error occurred was: "
1165 "%s. This file has been deleted to avoid corrupt data.";
1168 case EET_ERROR_WRITE_ERROR_FILE_TOO_BIG:
1169 erstr = "Elementary's settings files are too big "
1170 "for the file system they are being saved to. "
1171 "This error is very strange as the files should "
1172 "be extremely small. Please check the settings "
1173 "for your home directory. "
1174 "The file where the error occurred was: %s ."
1175 "This file has been deleted to avoid corrupt data.";
1178 case EET_ERROR_WRITE_ERROR_IO_ERROR:
1179 erstr = "An output error occurred when writing the settings "
1180 "files for Elementary. Your disk is having troubles "
1181 "and possibly needs replacement. "
1182 "The file where the error occurred was: %s ."
1183 "This file has been deleted to avoid corrupt data.";
1186 case EET_ERROR_WRITE_ERROR_OUT_OF_SPACE:
1187 erstr = "Elementary cannot write its settings file "
1188 "because it ran out of space to write the file. "
1189 "You have either run out of disk space or have "
1190 "gone over your quota limit. "
1191 "The file where the error occurred was: %s ."
1192 "This file has been deleted to avoid corrupt data.";
1195 case EET_ERROR_WRITE_ERROR_FILE_CLOSED:
1196 erstr = "Elementary unexpectedly had the settings file "
1197 "it was writing closed on it. This is very unusual. "
1198 "The file where the error occurred was: %s "
1199 "This file has been deleted to avoid corrupt data.";
1207 /* delete any partially-written file */
1208 ecore_file_unlink(file);
1209 return strdup(erstr);
1216 _elm_config_profile_save(void)
1218 char buf[4096], buf2[4096];
1224 len = _elm_user_dir_snprintf(buf, sizeof(buf), "config/profile.cfg");
1225 if (len + 1 >= sizeof(buf))
1228 len = _elm_user_dir_snprintf(buf2, sizeof(buf2), "config/profile.cfg.tmp");
1229 if (len + 1 >= sizeof(buf2))
1232 ef = eet_open(buf2, EET_FILE_MODE_WRITE);
1236 ok = eet_write(ef, "config", _elm_profile, strlen(_elm_profile), 0);
1240 err = _elm_config_eet_close_error_get(ef, buf2);
1248 ret = ecore_file_mv(buf2, buf);
1251 ERR("Error saving Elementary's configuration file");
1255 ecore_file_unlink(buf2);
1259 ecore_file_unlink(buf2);
1264 _elm_config_save(void)
1266 char buf[4096], buf2[4096];
1272 len = _elm_user_dir_snprintf(buf, sizeof(buf), "config/%s", _elm_profile);
1273 if (len + 1 >= sizeof(buf))
1276 ok = ecore_file_mkpath(buf);
1279 ERR("Problem acessing Elementary's user configuration directory: %s",
1284 if (!_elm_config_profile_save())
1290 if (len + sizeof("base.cfg") >= sizeof(buf) - len)
1293 memcpy(buf + len, "base.cfg", sizeof("base.cfg"));
1294 len += sizeof("base.cfg") - 1;
1296 if (len + sizeof(".tmp") >= sizeof(buf))
1299 memcpy(buf2, buf, len);
1300 memcpy(buf2 + len, ".tmp", sizeof(".tmp"));
1302 ef = eet_open(buf2, EET_FILE_MODE_WRITE);
1306 ok = eet_data_write(ef, _config_edd, "config", _elm_config, 1);
1310 err = _elm_config_eet_close_error_get(ef, buf2);
1318 ret = ecore_file_mv(buf2, buf);
1321 ERR("Error saving Elementary's configuration file");
1325 ecore_file_unlink(buf2);
1329 ecore_file_unlink(buf2);
1334 _config_update(void)
1338 tcfg = _config_system_load();
1341 /* weird profile or something? We should probably fill
1342 * with hardcoded defaults, or get from default previx */
1345 #define IFCFG(v) if ((_elm_config->config_version & 0xffff) < (v)) {
1346 #define IFCFGELSE } else {
1348 #define COPYVAL(x) do {_elm_config->x = tcfg->x; } while(0)
1349 #define COPYPTR(x) do {_elm_config->x = tcfg->x; tcfg->x = NULL; } while(0)
1350 #define COPYSTR(x) COPYPTR(x)
1352 /* we also need to update for property changes in the root window
1353 * if needed, but that will be dependent on new properties added
1354 * with each version */
1357 COPYVAL(longpress_timeout);
1367 /* after updating user config, we must save */
1376 s = getenv("ELM_ENGINE");
1379 if ((!strcasecmp(s, "x11")) ||
1380 (!strcasecmp(s, "x")) ||
1381 (!strcasecmp(s, "software-x11")) ||
1382 (!strcasecmp(s, "software_x11")))
1383 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_X11);
1384 else if ((!strcasecmp(s, "opengl")) ||
1385 (!strcasecmp(s, "gl")) ||
1386 (!strcasecmp(s, "opengl-x11")) ||
1387 (!strcasecmp(s, "opengl_x11")))
1388 eina_stringshare_replace(&_elm_config->engine, ELM_OPENGL_X11);
1389 else if ((!strcasecmp(s, "x11-8")) ||
1390 (!strcasecmp(s, "x8")) ||
1391 (!strcasecmp(s, "software-8-x11")) ||
1392 (!strcasecmp(s, "software_8_x11")))
1393 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_8_X11);
1394 else if ((!strcasecmp(s, "x11-16")) ||
1395 (!strcasecmp(s, "x16")) ||
1396 (!strcasecmp(s, "software-16-x11")) ||
1397 (!strcasecmp(s, "software_16_x11")))
1398 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_16_X11);
1400 else if ((!strcasecmp(s, "xrender")) ||
1401 (!strcasecmp(s, "xr")) ||
1402 (!strcasecmp(s, "xrender-x11")) ||
1403 (!strcasecmp(s, "xrender_x11")))
1404 eina_stringshare_replace(&_elm_config->engine, ELM_XRENDER_X11);
1406 else if ((!strcasecmp(s, "fb")) ||
1407 (!strcasecmp(s, "software-fb")) ||
1408 (!strcasecmp(s, "software_fb")))
1409 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_FB);
1410 else if ((!strcasecmp(s, "directfb")) ||
1411 (!strcasecmp(s, "dfb")))
1412 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_DIRECTFB);
1413 else if ((!strcasecmp(s, "sdl")) ||
1414 (!strcasecmp(s, "software-sdl")) ||
1415 (!strcasecmp(s, "software_sdl")))
1416 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_SDL);
1417 else if ((!strcasecmp(s, "sdl-16")) ||
1418 (!strcasecmp(s, "software-16-sdl")) ||
1419 (!strcasecmp(s, "software_16_sdl")))
1420 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_16_SDL);
1421 else if ((!strcasecmp(s, "opengl-sdl")) ||
1422 (!strcasecmp(s, "opengl_sdl")) ||
1423 (!strcasecmp(s, "gl-sdl")) ||
1424 (!strcasecmp(s, "gl_sdl")))
1425 eina_stringshare_replace(&_elm_config->engine, ELM_OPENGL_SDL);
1426 else if ((!strcasecmp(s, "gdi")) ||
1427 (!strcasecmp(s, "software-gdi")) ||
1428 (!strcasecmp(s, "software_gdi")))
1429 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_WIN32);
1430 else if ((!strcasecmp(s, "wince-gdi")) ||
1431 (!strcasecmp(s, "software-16-wince-gdi")) ||
1432 (!strcasecmp(s, "software_16_wince_gdi")))
1433 eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_16_WINCE);
1434 else if ((!strncmp(s, "shot:", 5)))
1435 eina_stringshare_replace(&_elm_config->engine, s);
1438 s = getenv("ELM_VSYNC");
1439 if (s) _elm_config->vsync = !!atoi(s);
1441 s = getenv("ELM_THUMBSCROLL_ENABLE");
1442 if (s) _elm_config->thumbscroll_enable = !!atoi(s);
1443 s = getenv("ELM_THUMBSCROLL_THRESHOLD");
1444 if (s) _elm_config->thumbscroll_threshold = atoi(s);
1445 // FIXME: floatformat locale issues here 1.0 vs 1,0 - should just be 1.0
1446 s = getenv("ELM_THUMBSCROLL_MOMENTUM_THRESHOLD");
1447 if (s) _elm_config->thumbscroll_momentum_threshold = atof(s);
1448 s = getenv("ELM_THUMBSCROLL_FRICTION");
1449 if (s) _elm_config->thumbscroll_friction = atof(s);
1450 s = getenv("ELM_THUMBSCROLL_BOUNCE_ENABLE");
1451 if (s) _elm_config->thumbscroll_bounce_enable = !!atoi(s);
1452 s = getenv("ELM_THUMBSCROLL_BOUNCE_FRICTION");
1453 if (s) _elm_config->thumbscroll_bounce_friction = atof(s);
1454 s = getenv("ELM_PAGE_SCROLL_FRICTION");
1455 if (s) _elm_config->page_scroll_friction = atof(s);
1456 s = getenv("ELM_BRING_IN_SCROLL_FRICTION");
1457 if (s) _elm_config->bring_in_scroll_friction = atof(s);
1458 s = getenv("ELM_ZOOM_FRICTION");
1459 if (s) _elm_config->zoom_friction = atof(s);
1460 s = getenv("ELM_THUMBSCROLL_BORDER_FRICTION");
1470 _elm_config->thumbscroll_border_friction = friction;
1472 s = getenv("ELM_THEME");
1473 if (s) eina_stringshare_replace(&_elm_config->theme, s);
1475 s = getenv("ELM_FONT_HINTING");
1478 if (!strcasecmp(s, "none")) _elm_config->font_hinting = 0;
1479 else if (!strcasecmp(s, "auto"))
1480 _elm_config->font_hinting = 1;
1481 else if (!strcasecmp(s, "bytecode"))
1482 _elm_config->font_hinting = 2;
1485 s = getenv("ELM_FONT_PATH");
1491 EINA_LIST_FREE(_elm_config->font_dirs, p)
1493 eina_stringshare_del(p);
1496 buf2 = alloca(strlen(s) + 1);
1501 if ((*p == ':') || (*p == 0))
1506 strncpy(buf2, pp, len);
1508 _elm_config->font_dirs =
1509 eina_list_append(_elm_config->font_dirs,
1510 eina_stringshare_add(buf2));
1523 s = getenv("ELM_IMAGE_CACHE");
1524 if (s) _elm_config->image_cache = atoi(s);
1526 s = getenv("ELM_FONT_CACHE");
1527 if (s) _elm_config->font_cache = atoi(s);
1529 s = getenv("ELM_SCALE");
1530 if (s) _elm_config->scale = atof(s);
1532 _elm_config->finger_size =
1533 (double)_elm_config->finger_size * _elm_config->scale;
1534 s = getenv("ELM_FINGER_SIZE");
1535 if (s) _elm_config->finger_size = atoi(s);
1537 s = getenv("ELM_FPS");
1538 if (s) _elm_config->fps = atof(s);
1539 if (_elm_config->fps < 1.0) _elm_config->fps = 1.0;
1541 s = getenv("ELM_MODULES");
1542 if (s) eina_stringshare_replace(&_elm_config->modules, s);
1544 /* Get RTL orientation from system */
1545 setlocale(LC_ALL, "");
1546 bindtextdomain(PACKAGE, LOCALE_DIR);
1547 _elm_config->is_mirrored = !strcmp(E_("default:LTR"), "default:RTL");
1549 s = getenv("ELM_TOOLTIP_DELAY");
1552 double delay = atof(s);
1554 _elm_config->tooltip_delay = delay;
1557 s = getenv("ELM_CURSOR_ENGINE_ONLY");
1558 if (s) _elm_config->cursor_engine_only = !!atoi(s);
1560 s = getenv("ELM_FOCUS_HIGHLIGHT_ENABLE");
1561 if (s) _elm_config->focus_highlight_enable = !!atoi(s);
1563 s = getenv("ELM_FOCUS_HIGHLIGHT_ANIMATE");
1564 if (s) _elm_config->focus_highlight_animate = !!atoi(s);
1566 s = getenv("ELM_TOOLBAR_SHRINK_MODE");
1567 if (s) _elm_config->toolbar_shrink_mode = atoi(s);
1569 s = getenv("ELM_FILESELECTOR_EXPAND_ENABLE");
1570 if (s) _elm_config->fileselector_expand_enable = !!atoi(s);
1572 s = getenv("ELM_INWIN_DIALOGS_ENABLE");
1573 if (s) _elm_config->inwin_dialogs_enable = !!atoi(s);
1575 s = getenv("ELM_ICON_SIZE");
1576 if (s) _elm_config->icon_size = atoi(s);
1578 s = getenv("ELM_LONGPRESS_TIMEOUT");
1579 if (s) _elm_config->longpress_timeout = atof(s);
1580 if (_elm_config->longpress_timeout < 0.0)
1581 _elm_config->longpress_timeout = 0.0;
1583 s = getenv("ELM_EFFECT_ENABLE");
1584 if (s) _elm_config->effect_enable = !!atoi(s);
1586 s = getenv("ELM_DESKTOP_ENTRY");
1587 if (s) _elm_config->desktop_entry = !!atoi(s);
1591 * Get the system mirrored mode. This determines the default mirrored mode
1594 * @return EINA_TRUE if mirrored is set, EINA_FALSE otherwise
1597 elm_mirrored_get(void)
1599 return _elm_config->is_mirrored;
1603 * Set the system mirrored mode. This determines the default mirrored mode
1606 * @param mirrored EINA_TRUE to set mirrored mode, EINA_FALSE to unset it.
1609 elm_mirrored_set(Eina_Bool mirrored)
1611 _elm_config->is_mirrored = mirrored;
1616 _elm_config_init(void)
1619 _profile_fetch_from_conf();
1623 _elm_config_font_overlay_apply();
1628 _elm_config_sub_init(void)
1630 #define ENGINE_COMPARE(name) (!strcmp(_elm_config->engine, name))
1631 if (ENGINE_COMPARE(ELM_SOFTWARE_X11) ||
1632 ENGINE_COMPARE(ELM_SOFTWARE_16_X11) ||
1633 ENGINE_COMPARE(ELM_XRENDER_X11) ||
1634 ENGINE_COMPARE(ELM_OPENGL_X11))
1635 #undef ENGINE_COMPARE
1637 #ifdef HAVE_ELEMENTARY_X
1638 unsigned int val = 1000;
1640 if (!ecore_x_init(NULL))
1642 ERR("Cannot connect to X11 display. check $DISPLAY variable");
1645 _root_1st = ecore_x_window_root_first_get();
1647 if (!ecore_x_screen_is_composited(0))
1648 _elm_config->compositing = 0;
1650 ecore_x_atoms_get(_atom_names, ATOM_COUNT, _atom);
1651 ecore_x_event_mask_set(_root_1st,
1652 ECORE_X_EVENT_MASK_WINDOW_PROPERTY);
1653 _prop_change_handler = ecore_event_handler_add
1654 (ECORE_X_EVENT_WINDOW_PROPERTY, _prop_change, NULL);
1655 if (!getenv("ELM_SCALE"))
1657 if (ecore_x_window_prop_card32_get(_root_1st,
1658 _atom[ATOM_E_SCALE],
1663 _elm_config->scale = (double)val / 1000.0;
1664 // FIXME: hack until e export finger size too
1665 if (!getenv("ELM_FINGER_SIZE"))
1667 _elm_config->finger_size = 40.0 * _elm_config->scale;
1669 edje_scale_set(_elm_config->scale);
1673 if (!getenv("ELM_FINGER_SIZE"))
1675 if (ecore_x_window_prop_card32_get(_root_1st,
1676 _atom[ATOM_E_FINGER_SIZE],
1681 _elm_config->finger_size = val;
1685 if (!getenv("ELM_THEME"))
1689 s = ecore_x_window_prop_string_get(_root_1st,
1690 _atom[ATOM_E_THEME]);
1693 eina_stringshare_replace(&_elm_config->theme, s);
1694 _elm_theme_parse(NULL, s);
1698 if (!getenv("ELM_PROFILE"))
1702 s = ecore_x_window_prop_string_get(_root_1st,
1703 _atom[ATOM_E_PROFILE]);
1710 if (strcmp(_elm_profile, s)) changed = 1;
1714 if (changed) _prop_config_get();
1719 _config_sub_apply();
1723 _elm_config_reload(void)
1728 _elm_config_font_overlay_apply();
1734 _elm_config_engine_set(const char *engine)
1736 if (_elm_config->engine && strcmp(_elm_config->engine, engine))
1737 eina_stringshare_del(_elm_config->engine);
1739 _elm_config->engine = eina_stringshare_add(engine);
1743 _elm_config_profile_set(const char *profile)
1745 Eina_Bool changed = EINA_FALSE;
1749 if (strcmp(_elm_profile, profile))
1754 _elm_profile = strdup(profile);
1761 _elm_config_font_overlay_apply();
1768 _elm_config_shutdown(void)
1770 #define ENGINE_COMPARE(name) (!strcmp(_elm_config->engine, name))
1771 if (ENGINE_COMPARE(ELM_SOFTWARE_X11) ||
1772 ENGINE_COMPARE(ELM_SOFTWARE_16_X11) ||
1773 ENGINE_COMPARE(ELM_XRENDER_X11) ||
1774 ENGINE_COMPARE(ELM_OPENGL_X11))
1775 #undef ENGINE_COMPARE
1777 #ifdef HAVE_ELEMENTARY_X
1778 ecore_event_handler_del(_prop_change_handler);
1779 _prop_change_handler = NULL;
1786 _elm_profile = NULL;