b72cab0fdb046c23faf17b7bf051dbd85f9f5e2f
[framework/uifw/elementary.git] / src / lib / elm_config.c
1 #ifdef HAVE_CONFIG_H
2 # include "elementary_config.h"
3 #endif
4
5 #ifdef HAVE_EVIL
6 # include <Evil.h>
7 #endif
8
9 #include <Elementary.h>
10 #include "elm_priv.h"
11
12 EAPI int ELM_EVENT_CONFIG_ALL_CHANGED = 0;
13
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;
18 const char *_elm_preferred_engine = NULL;
19
20 static Ecore_Poller *_elm_cache_flush_poller = NULL;
21
22 const char *_elm_engines[] = {
23    "software_x11",
24    "fb",
25    "directfb",
26    "software_16_x11",
27    "software_8_x11",
28    "xrender_x11",
29    "opengl_x11",
30    "software_gdi",
31    "software_16_wince_gdi",
32    "sdl",
33    "software_16_sdl",
34    "opengl_sdl",
35    "buffer",
36    "ews",
37    "opengl_cocoa",
38    "psl1ght",
39    "wayland_shm",
40    "wayland_egl",
41    NULL
42 };
43
44 /* whenever you want to add a new text class support into Elementary,
45    declare it both here and in the (default) theme */
46 static const Elm_Text_Class _elm_text_classes[] = {
47    {"button", "Button Labels"},
48    {"label", "Text Labels"},
49    {"entry", "Text Entries"},
50    {"title_bar", "Title Bar"},
51    {"list_item", "List Items"},
52    {"grid_item", "Grid Items"},
53    {"toolbar_item", "Toolbar Items"},
54    {"menu_item", "Menu Items"},
55    {NULL, NULL}
56 };
57
58 static void        _desc_init(void);
59 static void        _desc_shutdown(void);
60 static void        _profile_fetch_from_conf(void);
61 static void        _config_free(void);
62 static void        _config_apply(void);
63 static Elm_Config *_config_user_load(void);
64 static Elm_Config *_config_system_load(void);
65 static void        _config_load(void);
66 static void        _config_update(void);
67 static void        _env_get(void);
68 static size_t      _elm_data_dir_snprintf(char       *dst,
69                                           size_t      size,
70                                           const char *fmt, ...)
71                                           EINA_PRINTF(3, 4);
72 static size_t _elm_user_dir_snprintf(char       *dst,
73                                      size_t      size,
74                                      const char *fmt, ...)
75                                      EINA_PRINTF(3, 4);
76
77 #define ELM_CONFIG_VAL(edd, type, member, dtype) \
78   EET_DATA_DESCRIPTOR_ADD_BASIC(edd, type, #member, member, dtype)
79 #define ELM_CONFIG_LIST(edd, type, member, eddtype) \
80   EET_DATA_DESCRIPTOR_ADD_LIST(edd, type, #member, member, eddtype)
81
82 #ifdef HAVE_ELEMENTARY_X
83 static Ecore_Event_Handler *_prop_change_handler = NULL;
84 static Ecore_Timer *_prop_all_update_timer = NULL;
85 static Ecore_Timer *_prop_change_delay_timer = NULL;
86 static Ecore_X_Window _root_1st = 0;
87 #define ATOM_COUNT 2
88 static Ecore_X_Atom _atom[ATOM_COUNT];
89 static Ecore_X_Atom _atom_config = 0;
90 static const char *_atom_names[ATOM_COUNT] =
91 {
92    "ELM_PROFILE",
93    "ELM_CONFIG"
94 };
95 #define ATOM_E_PROFILE                              0
96 #define ATOM_E_CONFIG                               1
97
98 static Eina_Bool _prop_all_update_cb(void *data __UNUSED__);
99 static Eina_Bool _prop_config_get(void);
100 static void      _prop_config_set(void);
101 static Eina_Bool _prop_change(void *data  __UNUSED__,
102                               int ev_type __UNUSED__,
103                               void       *ev);
104
105 static Eina_Bool
106 _prop_all_update_cb(void *data __UNUSED__)
107 {
108    _prop_config_set();
109    ecore_x_window_prop_string_set(_root_1st, _atom[ATOM_E_PROFILE],
110                                   _elm_profile);
111    _prop_all_update_timer = NULL;
112    return EINA_FALSE;
113 }
114
115 static Eina_Bool
116 _prop_config_get(void)
117 {
118    int size = 0;
119    Ecore_X_Atom atom;
120    char buf[512];
121    unsigned char *data = NULL;
122    Elm_Config *config_data;
123
124    snprintf(buf, sizeof(buf), "ELM_CONFIG_%s", _elm_profile);
125    atom = ecore_x_atom_get(buf);
126    _atom_config = atom;
127    if (!ecore_x_window_prop_property_get(_root_1st,
128                                          atom, _atom[ATOM_E_CONFIG],
129                                          8, &data, &size))
130      {
131         if (!ecore_x_window_prop_property_get(_root_1st,
132                                               _atom[ATOM_E_CONFIG],
133                                               _atom[ATOM_E_CONFIG],
134                                               8, &data, &size))
135           return EINA_FALSE;
136         else
137           _atom_config = _atom[ATOM_E_CONFIG];
138      }
139    else
140      _atom_config = atom;
141    if (size < 1)
142      {
143         free(data);
144         return EINA_FALSE;
145      }
146    config_data = eet_data_descriptor_decode(_config_edd, data, size);
147    free(data);
148    if (!config_data) return EINA_FALSE;
149
150    /* What do we do on version mismatch when someone changes the
151     * config in the rootwindow? */
152    /* Most obvious case, new version and we are still linked to
153     * whatever was there before, we just ignore until user restarts us */
154    if (config_data->config_version > ELM_CONFIG_VERSION)
155      return EINA_TRUE;
156    /* What in the case the version is older? Do we even support those
157     * cases or we only check for equality above? */
158
159    _config_free();
160    _elm_config = config_data;
161    _config_apply();
162    _elm_config_font_overlay_apply();
163    _elm_rescale();
164    _elm_recache();
165    ecore_event_add(ELM_EVENT_CONFIG_ALL_CHANGED, NULL, NULL, NULL);
166    return EINA_TRUE;
167 }
168
169 static void
170 _prop_config_set(void)
171 {
172    unsigned char *config_data = NULL;
173    int size = 0;
174
175    config_data = eet_data_descriptor_encode(_config_edd, _elm_config, &size);
176    if (config_data)
177      {
178         Ecore_X_Atom atom;
179         char buf[512];
180
181         snprintf(buf, sizeof(buf), "ELM_CONFIG_%s", _elm_profile);
182         atom = ecore_x_atom_get(buf);
183         _atom_config = atom;
184
185         ecore_x_window_prop_property_set(_root_1st, _atom_config,
186                                          _atom[ATOM_E_CONFIG], 8,
187                                          config_data, size);
188         free(config_data);
189      }
190 }
191
192 static Eina_Bool
193 _prop_change_delay_cb(void *data __UNUSED__)
194 {
195    char *s;
196
197    s = ecore_x_window_prop_string_get(_root_1st, _atom[ATOM_E_PROFILE]);
198    if (s)
199      {
200         if (_elm_profile) free(_elm_profile);
201         _elm_profile = s;
202      }
203    _prop_config_get();
204    _prop_change_delay_timer = NULL;
205    return EINA_FALSE;
206 }
207
208 static Eina_Bool
209 _prop_change(void *data  __UNUSED__,
210              int ev_type __UNUSED__,
211              void       *ev)
212 {
213    Ecore_X_Event_Window_Property *event = ev;
214
215    if (event->win == _root_1st)
216      {
217         if (event->atom == _atom[ATOM_E_PROFILE])
218           {
219              if (_prop_change_delay_timer) ecore_timer_del(_prop_change_delay_timer);
220              _prop_change_delay_timer = ecore_timer_add(0.1, _prop_change_delay_cb, NULL);
221           }
222         else if (((_atom_config > 0) && (event->atom == _atom_config)) ||
223                  (event->atom == _atom[ATOM_E_CONFIG]))
224           {
225              if (_prop_change_delay_timer) ecore_timer_del(_prop_change_delay_timer);
226              _prop_change_delay_timer = ecore_timer_add(0.1, _prop_change_delay_cb, NULL);
227           }
228      }
229    return ECORE_CALLBACK_PASS_ON;
230 }
231
232 #endif
233
234 static void
235 _desc_init(void)
236 {
237    Eet_Data_Descriptor_Class eddc;
238
239    EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Elm_Config);
240    eddc.func.str_direct_alloc = NULL;
241    eddc.func.str_direct_free = NULL;
242
243    _config_edd = eet_data_descriptor_file_new(&eddc);
244    if (!_config_edd)
245      {
246         printf("EEEK! eet_data_descriptor_file_new() failed\n");
247         return;
248      }
249
250    memset(&eddc, 0, sizeof(eddc)); /* just in case... */
251    EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Elm_Font_Overlay);
252    eddc.func.str_direct_alloc = NULL;
253    eddc.func.str_direct_free = NULL;
254
255    _config_font_overlay_edd = eet_data_descriptor_stream_new(&eddc);
256    if (!_config_font_overlay_edd)
257      {
258         printf("EEEK! eet_data_descriptor_stream_new() failed\n");
259         eet_data_descriptor_free(_config_edd);
260         return;
261      }
262 #define T_INT    EET_T_INT
263 #define T_DOUBLE EET_T_DOUBLE
264 #define T_STRING EET_T_STRING
265 #define T_UCHAR  EET_T_UCHAR
266
267 #define T        Elm_Font_Overlay
268 #define D        _config_font_overlay_edd
269    ELM_CONFIG_VAL(D, T, text_class, EET_T_STRING);
270    ELM_CONFIG_VAL(D, T, font, EET_T_STRING);
271    ELM_CONFIG_VAL(D, T, size, EET_T_INT);
272 #undef T
273 #undef D
274
275 #define T Elm_Config
276 #define D _config_edd
277    ELM_CONFIG_VAL(D, T, config_version, T_INT);
278    ELM_CONFIG_VAL(D, T, engine, T_STRING);
279    ELM_CONFIG_VAL(D, T, vsync, T_UCHAR);
280    ELM_CONFIG_VAL(D, T, thumbscroll_enable, T_UCHAR);
281    ELM_CONFIG_VAL(D, T, thumbscroll_threshold, T_INT);
282    ELM_CONFIG_VAL(D, T, thumbscroll_momentum_threshold, T_DOUBLE);
283    ELM_CONFIG_VAL(D, T, thumbscroll_friction, T_DOUBLE);
284    ELM_CONFIG_VAL(D, T, thumbscroll_bounce_friction, T_DOUBLE);
285    ELM_CONFIG_VAL(D, T, thumbscroll_border_friction, T_DOUBLE);
286    ELM_CONFIG_VAL(D, T, thumbscroll_sensitivity_friction, T_DOUBLE);
287    ELM_CONFIG_VAL(D, T, page_scroll_friction, T_DOUBLE);
288    ELM_CONFIG_VAL(D, T, bring_in_scroll_friction, T_DOUBLE);
289    ELM_CONFIG_VAL(D, T, zoom_friction, T_DOUBLE);
290    ELM_CONFIG_VAL(D, T, thumbscroll_bounce_enable, T_UCHAR);
291    ELM_CONFIG_VAL(D, T, scroll_smooth_time_interval, T_DOUBLE);
292    ELM_CONFIG_VAL(D, T, scroll_smooth_amount, T_DOUBLE);
293    ELM_CONFIG_VAL(D, T, scroll_smooth_history_weight, T_DOUBLE);
294    ELM_CONFIG_VAL(D, T, scroll_smooth_future_time, T_DOUBLE);
295    ELM_CONFIG_VAL(D, T, scroll_smooth_time_window, T_DOUBLE);
296    ELM_CONFIG_VAL(D, T, scale, T_DOUBLE);
297    ELM_CONFIG_VAL(D, T, bgpixmap, T_INT);
298    ELM_CONFIG_VAL(D, T, compositing, T_INT);
299    /* EET_DATA_DESCRIPTOR_ADD_LIST(D, T, "font_dirs", font_dirs, sub_edd); */
300    ELM_CONFIG_LIST(D, T, font_overlays, _config_font_overlay_edd);
301    ELM_CONFIG_VAL(D, T, font_hinting, T_INT);
302    ELM_CONFIG_VAL(D, T, cache_flush_poll_interval, T_INT);
303    ELM_CONFIG_VAL(D, T, cache_flush_enable, T_UCHAR);
304    ELM_CONFIG_VAL(D, T, image_cache, T_INT);
305    ELM_CONFIG_VAL(D, T, font_cache, T_INT);
306    ELM_CONFIG_VAL(D, T, edje_cache, T_INT);
307    ELM_CONFIG_VAL(D, T, edje_collection_cache, T_INT);
308    ELM_CONFIG_VAL(D, T, finger_size, T_INT);
309    ELM_CONFIG_VAL(D, T, fps, T_DOUBLE);
310    ELM_CONFIG_VAL(D, T, theme, T_STRING);
311    ELM_CONFIG_VAL(D, T, modules, T_STRING);
312    ELM_CONFIG_VAL(D, T, tooltip_delay, T_DOUBLE);
313    ELM_CONFIG_VAL(D, T, cursor_engine_only, T_UCHAR);
314    ELM_CONFIG_VAL(D, T, focus_highlight_enable, T_UCHAR);
315    ELM_CONFIG_VAL(D, T, focus_highlight_animate, T_UCHAR);
316    ELM_CONFIG_VAL(D, T, toolbar_shrink_mode, T_INT);
317    ELM_CONFIG_VAL(D, T, fileselector_expand_enable, T_UCHAR);
318    ELM_CONFIG_VAL(D, T, inwin_dialogs_enable, T_UCHAR);
319    ELM_CONFIG_VAL(D, T, icon_size, T_INT);
320    ELM_CONFIG_VAL(D, T, longpress_timeout, T_DOUBLE);
321    ELM_CONFIG_VAL(D, T, effect_enable, T_UCHAR);
322    ELM_CONFIG_VAL(D, T, desktop_entry, T_UCHAR);
323    ELM_CONFIG_VAL(D, T, password_show_last, T_UCHAR);
324    ELM_CONFIG_VAL(D, T, password_show_last_timeout, T_DOUBLE);
325    ELM_CONFIG_VAL(D, T, glayer_zoom_finger_enable, T_UCHAR);
326    ELM_CONFIG_VAL(D, T, glayer_zoom_finger_factor, T_DOUBLE);
327    ELM_CONFIG_VAL(D, T, glayer_zoom_wheel_factor, T_DOUBLE);
328    ELM_CONFIG_VAL(D, T, glayer_zoom_distance_tolerance, T_DOUBLE);
329    ELM_CONFIG_VAL(D, T, glayer_rotate_finger_enable, T_UCHAR);
330    ELM_CONFIG_VAL(D, T, glayer_rotate_angular_tolerance, T_DOUBLE);
331    ELM_CONFIG_VAL(D, T, glayer_line_min_length, T_DOUBLE);
332    ELM_CONFIG_VAL(D, T, glayer_line_distance_tolerance, T_DOUBLE);
333    ELM_CONFIG_VAL(D, T, glayer_line_angular_tolerance, T_DOUBLE);
334    ELM_CONFIG_VAL(D, T, glayer_flick_time_limit_ms, T_INT);
335    ELM_CONFIG_VAL(D, T, glayer_long_tap_start_timeout, T_DOUBLE);
336    ELM_CONFIG_VAL(D, T, access_mode, T_INT);
337    ELM_CONFIG_VAL(D, T, glayer_continues_enable, T_UCHAR);
338    ELM_CONFIG_VAL(D, T, week_start, T_INT);
339    ELM_CONFIG_VAL(D, T, weekend_start, T_INT);
340    ELM_CONFIG_VAL(D, T, weekend_len, T_INT);
341 #undef T
342 #undef D
343 #undef T_INT
344 #undef T_DOUBLE
345 #undef T_STRING
346 #undef T_UCHAR
347 }
348
349 static void
350 _desc_shutdown(void)
351 {
352    if (_config_edd)
353      {
354         eet_data_descriptor_free(_config_edd);
355         _config_edd = NULL;
356      }
357
358    if (_config_font_overlay_edd)
359      {
360         eet_data_descriptor_free(_config_font_overlay_edd);
361         _config_font_overlay_edd = NULL;
362      }
363 }
364
365 static int
366 _sort_files_cb(const void *f1,
367                const void *f2)
368 {
369    return strcmp(f1, f2);
370 }
371
372 const char *
373 _elm_config_current_profile_get(void)
374 {
375    return _elm_profile;
376 }
377
378 static size_t
379 _elm_data_dir_snprintf(char       *dst,
380                        size_t      size,
381                        const char *fmt,
382                        ...)
383 {
384    size_t data_dir_len, off;
385    va_list ap;
386
387    data_dir_len = eina_strlcpy(dst, _elm_data_dir, size);
388
389    off = data_dir_len + 1;
390    if (off >= size)
391      goto end;
392
393    va_start(ap, fmt);
394    dst[data_dir_len] = '/';
395
396    off = off + vsnprintf(dst + off, size - off, fmt, ap);
397    va_end(ap);
398
399 end:
400    return off;
401 }
402
403 static size_t
404 _elm_user_dir_snprintf(char       *dst,
405                        size_t      size,
406                        const char *fmt,
407                        ...)
408 {
409    const char *home;
410    size_t user_dir_len, off;
411    va_list ap;
412
413 #ifdef _WIN32
414    home = evil_homedir_get();
415 #else
416    home = getenv("HOME");
417 #endif
418    if (!home)
419      home = "/";
420
421    user_dir_len = eina_str_join_len(dst, size, '/', home, strlen(home),
422                                     ELEMENTARY_BASE_DIR, sizeof(ELEMENTARY_BASE_DIR) - 1);
423
424    off = user_dir_len + 1;
425    if (off >= size)
426      goto end;
427
428    va_start(ap, fmt);
429    dst[user_dir_len] = '/';
430
431    off = off + vsnprintf(dst + off, size - off, fmt, ap);
432    va_end(ap);
433
434 end:
435    return off;
436 }
437
438 const char *
439 _elm_config_profile_dir_get(const char *prof,
440                             Eina_Bool   is_user)
441 {
442    char buf[PATH_MAX];
443
444    if (!is_user)
445      goto not_user;
446
447    _elm_user_dir_snprintf(buf, sizeof(buf), "config/%s", prof);
448
449    if (ecore_file_is_dir(buf))
450      return strdup(buf);
451
452    return NULL;
453
454 not_user:
455    snprintf(buf, sizeof(buf), "%s/config/%s", _elm_data_dir, prof);
456
457    if (ecore_file_is_dir(buf))
458      return strdup(buf);
459
460    return NULL;
461 }
462
463 Eina_List *
464 _elm_config_font_overlays_list(void)
465 {
466    return _elm_config->font_overlays;
467 }
468
469 void
470 _elm_config_font_overlay_set(const char    *text_class,
471                              const char    *font,
472                              Evas_Font_Size size)
473 {
474    Elm_Font_Overlay *efd;
475    Eina_List *l;
476
477    EINA_LIST_FOREACH(_elm_config->font_overlays, l, efd)
478      {
479         if (strcmp(efd->text_class, text_class))
480           continue;
481
482         if (efd->font) eina_stringshare_del(efd->font);
483         efd->font = eina_stringshare_add(font);
484         efd->size = size;
485         _elm_config->font_overlays =
486           eina_list_promote_list(_elm_config->font_overlays, l);
487         return;
488      }
489
490    /* the text class doesn't exist */
491    efd = calloc(1, sizeof(Elm_Font_Overlay));
492    efd->text_class = eina_stringshare_add(text_class);
493    efd->font = eina_stringshare_add(font);
494    efd->size = size;
495
496    _elm_config->font_overlays = eina_list_prepend(_elm_config->font_overlays,
497                                                   efd);
498 }
499
500 void
501 _elm_config_font_overlay_remove(const char *text_class)
502 {
503    Elm_Font_Overlay *efd;
504    Eina_List *l;
505
506    EINA_LIST_FOREACH(_elm_config->font_overlays, l, efd)
507      {
508         if (strcmp(efd->text_class, text_class))
509           continue;
510
511         _elm_config->font_overlays =
512           eina_list_remove_list(_elm_config->font_overlays, l);
513         if (efd->text_class) eina_stringshare_del(efd->text_class);
514         if (efd->font) eina_stringshare_del(efd->font);
515         free(efd);
516
517         return;
518      }
519 }
520
521 void
522 _elm_config_font_overlay_apply(void)
523 {
524    Elm_Font_Overlay *efd;
525    Eina_List *l;
526    int i;
527
528    for (i = 0; _elm_text_classes[i].desc; i++)
529      edje_text_class_del(_elm_text_classes[i].name);
530
531    EINA_LIST_FOREACH(_elm_config->font_overlays, l, efd)
532      edje_text_class_set(efd->text_class, efd->font, efd->size);
533 }
534
535 Eina_List *
536 _elm_config_text_classes_get(void)
537 {
538    Eina_List *ret = NULL;
539    int i;
540
541    for (i = 0; _elm_text_classes[i].desc; i++)
542      {
543         Elm_Text_Class *tc;
544         tc = malloc(sizeof(*tc));
545         if (!tc) continue;
546
547         *tc = _elm_text_classes[i];
548
549         ret = eina_list_append(ret, tc);
550      }
551
552    return ret;
553 }
554
555 void
556 _elm_config_text_classes_free(Eina_List *l)
557 {
558    Elm_Text_Class *tc;
559
560    EINA_LIST_FREE(l, tc)
561      free(tc);
562 }
563
564 Eina_List *
565 _elm_config_profiles_list(void)
566 {
567    Eina_File_Direct_Info *info;
568    Eina_List *flist = NULL;
569    Eina_Iterator *file_it;
570    char buf[PATH_MAX];
571    const char *dir;
572    size_t len;
573
574    len = _elm_user_dir_snprintf(buf, sizeof(buf), "config");
575
576    file_it = eina_file_direct_ls(buf);
577    if (!file_it)
578      goto sys;
579
580    buf[len] = '/';
581    len++;
582
583    len = sizeof(buf) - len;
584
585    EINA_ITERATOR_FOREACH(file_it, info)
586      {
587         Eina_Stat st;
588
589         if (eina_file_statat(eina_iterator_container_get(file_it), info, &st))
590           {
591              ERR("this is bad.");
592              continue;
593           }
594         if (info->name_length >= len)
595           continue;
596
597         if (info->type == EINA_FILE_DIR)
598           {
599              flist =
600                eina_list_sorted_insert(flist, _sort_files_cb,
601                                        eina_stringshare_add(info->path +
602                                                             info->name_start));
603           }
604      }
605
606    eina_iterator_free(file_it);
607
608 sys:
609    len = eina_str_join_len(buf, sizeof(buf), '/', _elm_data_dir,
610                            strlen(_elm_data_dir), "config",
611                            sizeof("config") - 1);
612
613    file_it = eina_file_direct_ls(buf);
614    if (!file_it)
615      goto list_free;
616
617    buf[len] = '/';
618    len++;
619
620    len = sizeof(buf) - len;
621    EINA_ITERATOR_FOREACH(file_it, info)
622      {
623         if (info->name_length >= len)
624           continue;
625
626         switch (info->type)
627           {
628            case EINA_FILE_DIR:
629            {
630               const Eina_List *l;
631               const char *tmp;
632
633               EINA_LIST_FOREACH(flist, l, tmp)
634                 if (!strcmp(info->path + info->name_start, tmp))
635                   break;
636
637               if (!l)
638                 flist =
639                   eina_list_sorted_insert(flist, _sort_files_cb,
640                                           eina_stringshare_add(info->path +
641                                                                info->name_start));
642            }
643            break;
644
645            default:
646              continue;
647           }
648      }
649    eina_iterator_free(file_it);
650    return flist;
651
652 list_free:
653    EINA_LIST_FREE(flist, dir)
654      eina_stringshare_del(dir);
655
656    return NULL;
657 }
658
659 static void
660 _profile_fetch_from_conf(void)
661 {
662    char buf[PATH_MAX], *p, *s;
663    Eet_File *ef = NULL;
664    int len = 0;
665
666    _elm_profile = strdup("default");
667
668    // if env var - use profile without question
669    s = getenv("ELM_PROFILE");
670    if (s)
671      {
672         free(_elm_profile);
673         _elm_profile = strdup(s);
674         return;
675      }
676
677    // user profile
678    _elm_user_dir_snprintf(buf, sizeof(buf), "config/profile.cfg");
679    ef = eet_open(buf, EET_FILE_MODE_READ);
680    if (ef)
681      {
682         p = eet_read(ef, "config", &len);
683         if (p)
684           {
685              free(_elm_profile);
686              _elm_profile = malloc(len + 1);
687              memcpy(_elm_profile, p, len);
688              _elm_profile[len] = 0;
689              free(p);
690           }
691         eet_close(ef);
692         if (!p) ef = NULL;
693      }
694    if (ef) return;
695
696    // system profile
697    _elm_data_dir_snprintf(buf, sizeof(buf), "config/profile.cfg");
698    ef = eet_open(buf, EET_FILE_MODE_READ);
699    if (ef)
700      {
701         p = eet_read(ef, "config", &len);
702         if (p)
703           {
704              free(_elm_profile);
705              _elm_profile = malloc(len + 1);
706              memcpy(_elm_profile, p, len);
707              _elm_profile[len] = 0;
708              free(p);
709           }
710         eet_close(ef);
711      }
712 }
713
714 static void
715 _config_free(void)
716 {
717    Elm_Font_Overlay *fo;
718    const char *fontdir;
719
720    if (!_elm_config) return;
721    EINA_LIST_FREE(_elm_config->font_dirs, fontdir)
722      {
723         eina_stringshare_del(fontdir);
724      }
725    if (_elm_config->engine) eina_stringshare_del(_elm_config->engine);
726    EINA_LIST_FREE(_elm_config->font_overlays, fo)
727      {
728         if (fo->text_class) eina_stringshare_del(fo->text_class);
729         if (fo->font) eina_stringshare_del(fo->font);
730         free(fo);
731      }
732    if (_elm_config->theme) eina_stringshare_del(_elm_config->theme);
733    if (_elm_config->modules) eina_stringshare_del(_elm_config->modules);
734    free(_elm_config);
735    _elm_config = NULL;
736 }
737
738 static void
739 _config_apply(void)
740 {
741    _elm_theme_parse(NULL, _elm_config->theme);
742    ecore_animator_frametime_set(1.0 / _elm_config->fps);
743 }
744
745 static void
746 _config_sub_apply(void)
747 {
748    edje_frametime_set(1.0 / _elm_config->fps);
749    edje_scale_set(_elm_config->scale);
750    edje_password_show_last_set(_elm_config->password_show_last);
751    edje_password_show_last_timeout_set(_elm_config->password_show_last_timeout);
752    if (_elm_config->modules) _elm_module_parse(_elm_config->modules);
753 }
754
755 static Eina_Bool
756 _elm_cache_flush_cb(void *data __UNUSED__)
757 {
758    elm_cache_all_flush();
759    return ECORE_CALLBACK_RENEW;
760 }
761
762 /* kind of abusing this call right now -- shared between all of those
763  * properties -- but they are not meant to be called that periodically
764  * anyway */
765 void
766 _elm_recache(void)
767 {
768    Eina_List *l;
769    Evas_Object *win;
770
771    elm_cache_all_flush();
772
773    EINA_LIST_FOREACH(_elm_win_list, l, win)
774      {
775         Evas *e = evas_object_evas_get(win);
776         evas_image_cache_set(e, _elm_config->image_cache * 1024);
777         evas_font_cache_set(e, _elm_config->font_cache * 1024);
778      }
779    edje_file_cache_set(_elm_config->edje_cache);
780    edje_collection_cache_set(_elm_config->edje_collection_cache);
781
782    if (_elm_cache_flush_poller)
783      {
784         ecore_poller_del(_elm_cache_flush_poller);
785         _elm_cache_flush_poller = NULL;
786      }
787    if (_elm_config->cache_flush_enable)
788      {
789         if (_elm_config->cache_flush_poll_interval > 0)
790           {
791              _elm_cache_flush_poller =
792                 ecore_poller_add(ECORE_POLLER_CORE,
793                                  _elm_config->cache_flush_poll_interval,
794                                  _elm_cache_flush_cb, NULL);
795           }
796      }
797 }
798
799 static Elm_Config *
800 _config_user_load(void)
801 {
802    Elm_Config *cfg = NULL;
803    Eet_File *ef;
804    char buf[PATH_MAX];
805
806    _elm_user_dir_snprintf(buf, sizeof(buf), "config/%s/base.cfg",
807                           _elm_profile);
808
809    ef = eet_open(buf, EET_FILE_MODE_READ);
810    if (ef)
811      {
812         cfg = eet_data_read(ef, _config_edd, "config");
813         eet_close(ef);
814      }
815    return cfg;
816 }
817
818 static Elm_Config *
819 _config_system_load(void)
820 {
821    Elm_Config *cfg = NULL;
822    Eet_File *ef;
823    char buf[PATH_MAX];
824
825    _elm_data_dir_snprintf(buf, sizeof(buf), "config/%s/base.cfg",
826                           _elm_profile);
827
828    ef = eet_open(buf, EET_FILE_MODE_READ);
829    if (ef)
830      {
831         cfg = eet_data_read(ef, _config_edd, "config");
832         eet_close(ef);
833      }
834    return cfg;
835 }
836
837 static void
838 _config_load(void)
839 {
840    _elm_config = _config_user_load();
841    if (_elm_config)
842      {
843         if (_elm_config->config_version < ELM_CONFIG_VERSION)
844           _config_update();
845         return;
846      }
847
848    /* no user config, fallback for system. No need to check version for
849     * this one, if it's not the right one, someone screwed up at the time
850     * of installing it */
851    _elm_config = _config_system_load();
852    if (_elm_config) return;
853    /* FIXME: config load could have failed because of a non-existent
854     * profile. Fallback to default before moving on */
855
856    // config load fail - defaults
857    // why are these here? well if they are, it means you can make a gui
858    // config recovery app i guess...
859    _elm_config = ELM_NEW(Elm_Config);
860    _elm_config->config_version = ELM_CONFIG_VERSION;
861    _elm_config->engine = eina_stringshare_add("software_x11");
862    _elm_config->vsync = 0;
863    _elm_config->thumbscroll_enable = EINA_TRUE;
864    _elm_config->thumbscroll_threshold = 24;
865    _elm_config->thumbscroll_momentum_threshold = 100.0;
866    _elm_config->thumbscroll_friction = 1.0;
867    _elm_config->thumbscroll_bounce_friction = 0.5;
868    _elm_config->thumbscroll_bounce_enable = EINA_TRUE;
869    _elm_config->page_scroll_friction = 0.5;
870    _elm_config->bring_in_scroll_friction = 0.5;
871    _elm_config->zoom_friction = 0.5;
872    _elm_config->thumbscroll_border_friction = 0.5;
873    _elm_config->thumbscroll_sensitivity_friction = 0.25; // magic number! just trial and error shows this makes it behave "nicer" and not run off at high speed all the time
874    _elm_config->scroll_smooth_time_interval = 0.008;
875    _elm_config->scroll_smooth_amount = 1.0;
876    _elm_config->scroll_smooth_history_weight = 0.3;
877    _elm_config->scroll_smooth_future_time = 0.0;
878    _elm_config->scroll_smooth_time_window = 0.2;
879    _elm_config->scale = 1.0;
880    _elm_config->bgpixmap = 0;
881    _elm_config->compositing = 1;
882    _elm_config->font_hinting = 2;
883    _elm_config->cache_flush_poll_interval = 512;
884    _elm_config->cache_flush_enable = EINA_TRUE;
885    _elm_config->font_dirs = NULL;
886    _elm_config->image_cache = 4096;
887    _elm_config->font_cache = 512;
888    _elm_config->edje_cache = 32;
889    _elm_config->edje_collection_cache = 64;
890    _elm_config->finger_size = 40;
891    _elm_config->fps = 60.0;
892    _elm_config->theme = eina_stringshare_add("default");
893    _elm_config->modules = NULL;
894    _elm_config->tooltip_delay = 1.0;
895    _elm_config->cursor_engine_only = EINA_TRUE;
896    _elm_config->focus_highlight_enable = EINA_FALSE;
897    _elm_config->focus_highlight_animate = EINA_TRUE;
898    _elm_config->toolbar_shrink_mode = 2;
899    _elm_config->fileselector_expand_enable = EINA_FALSE;
900    _elm_config->inwin_dialogs_enable = EINA_FALSE;
901    _elm_config->icon_size = 32;
902    _elm_config->longpress_timeout = 1.0;
903    _elm_config->effect_enable = EINA_TRUE;
904    _elm_config->desktop_entry = EINA_FALSE;
905    _elm_config->is_mirrored = EINA_FALSE; /* Read sys value in env_get() */
906    _elm_config->password_show_last = EINA_FALSE;
907    _elm_config->password_show_last_timeout = 2.0;
908    _elm_config->glayer_zoom_finger_enable = EINA_TRUE;
909    _elm_config->glayer_zoom_finger_factor = 1.0;
910    _elm_config->glayer_zoom_wheel_factor = 0.05;
911    _elm_config->glayer_zoom_distance_tolerance = 1.0; /* 1 times elm_finger_size_get() */
912    _elm_config->glayer_rotate_finger_enable = EINA_TRUE;
913    _elm_config->glayer_rotate_angular_tolerance = 2.0; /* 2 DEG */
914    _elm_config->glayer_line_min_length = 1.0;         /* 1 times elm_finger_size_get() */
915    _elm_config->glayer_line_distance_tolerance = 3.0; /* 3 times elm_finger_size_get() */
916    _elm_config->glayer_line_angular_tolerance = 20.0; /* 20 DEG */
917    _elm_config->glayer_flick_time_limit_ms = 120;              /* ms to finish flick */
918    _elm_config->glayer_long_tap_start_timeout = 1.2;   /* 1.2 second to start long-tap */
919    _elm_config->glayer_continues_enable = EINA_TRUE;      /* Continue gestures default */
920    _elm_config->week_start = 1; /* monday */
921    _elm_config->weekend_start = 6; /* saturday */
922    _elm_config->weekend_len = 2;
923 }
924
925 static const char *
926 _elm_config_eet_close_error_get(Eet_File *ef,
927                                 char     *file)
928 {
929    Eet_Error err;
930    const char *erstr = NULL;
931
932    err = eet_close(ef);
933    switch (err)
934      {
935       case EET_ERROR_WRITE_ERROR:
936         erstr = "An error occurred while saving Elementary's "
937                 "settings to disk. The error could not be "
938                 "deterimined. The file where the error occurred was: "
939                 "%s. This file has been deleted to avoid corrupt data.";
940         break;
941
942       case EET_ERROR_WRITE_ERROR_FILE_TOO_BIG:
943         erstr = "Elementary's settings files are too big "
944                 "for the file system they are being saved to. "
945                 "This error is very strange as the files should "
946                 "be extremely small. Please check the settings "
947                 "for your home directory. "
948                 "The file where the error occurred was: %s ."
949                 "This file has been deleted to avoid corrupt data.";
950         break;
951
952       case EET_ERROR_WRITE_ERROR_IO_ERROR:
953         erstr = "An output error occurred when writing the settings "
954                 "files for Elementary. Your disk is having troubles "
955                 "and possibly needs replacement. "
956                 "The file where the error occurred was: %s ."
957                 "This file has been deleted to avoid corrupt data.";
958         break;
959
960       case EET_ERROR_WRITE_ERROR_OUT_OF_SPACE:
961         erstr = "Elementary cannot write its settings file "
962                 "because it ran out of space to write the file. "
963                 "You have either run out of disk space or have "
964                 "gone over your quota limit. "
965                 "The file where the error occurred was: %s ."
966                 "This file has been deleted to avoid corrupt data.";
967         break;
968
969       case EET_ERROR_WRITE_ERROR_FILE_CLOSED:
970         erstr = "Elementary unexpectedly had the settings file "
971                 "it was writing closed on it. This is very unusual. "
972                 "The file where the error occurred was: %s "
973                 "This file has been deleted to avoid corrupt data.";
974         break;
975
976       default:
977         break;
978      }
979    if (erstr)
980      {
981         /* delete any partially-written file */
982          ecore_file_unlink(file);
983          return strdup(erstr);
984      }
985
986    return NULL;
987 }
988
989 static Eina_Bool
990 _elm_config_profile_save(void)
991 {
992    char buf[4096], buf2[4096];
993    int ok = 0, ret;
994    const char *err;
995    Eet_File *ef;
996    size_t len;
997
998    len = _elm_user_dir_snprintf(buf, sizeof(buf), "config/profile.cfg");
999    if (len + 1 >= sizeof(buf))
1000      return EINA_FALSE;
1001
1002    len = _elm_user_dir_snprintf(buf2, sizeof(buf2), "config/profile.cfg.tmp");
1003    if (len + 1 >= sizeof(buf2))
1004      return EINA_FALSE;
1005
1006    ef = eet_open(buf2, EET_FILE_MODE_WRITE);
1007    if (!ef)
1008      return EINA_FALSE;
1009
1010    ok = eet_write(ef, "config", _elm_profile, strlen(_elm_profile), 0);
1011    if (!ok)
1012      goto err;
1013
1014    err = _elm_config_eet_close_error_get(ef, buf2);
1015    if (err)
1016      {
1017         ERR("%s", err);
1018         free((void *)err);
1019         goto err;
1020      }
1021
1022    ret = ecore_file_mv(buf2, buf);
1023    if (!ret)
1024      {
1025         ERR("Error saving Elementary's configuration file");
1026         goto err;
1027      }
1028
1029    ecore_file_unlink(buf2);
1030    return EINA_TRUE;
1031
1032 err:
1033    ecore_file_unlink(buf2);
1034    return EINA_FALSE;
1035 }
1036
1037 Eina_Bool
1038 _elm_config_save(void)
1039 {
1040    char buf[4096], buf2[4096];
1041    int ok = 0, ret;
1042    const char *err;
1043    Eet_File *ef;
1044    size_t len;
1045
1046    len = _elm_user_dir_snprintf(buf, sizeof(buf), "config/%s", _elm_profile);
1047    if (len + 1 >= sizeof(buf))
1048      return EINA_FALSE;
1049
1050    ok = ecore_file_mkpath(buf);
1051    if (!ok)
1052      {
1053         ERR("Problem accessing Elementary's user configuration directory: %s",
1054             buf);
1055         return EINA_FALSE;
1056      }
1057
1058    if (!_elm_config_profile_save())
1059      return EINA_FALSE;
1060
1061    buf[len] = '/';
1062    len++;
1063
1064    if (len + sizeof("base.cfg") >= sizeof(buf) - len)
1065      return EINA_FALSE;
1066
1067    memcpy(buf + len, "base.cfg", sizeof("base.cfg"));
1068    len += sizeof("base.cfg") - 1;
1069
1070    if (len + sizeof(".tmp") >= sizeof(buf))
1071      return EINA_FALSE;
1072
1073    memcpy(buf2, buf, len);
1074    memcpy(buf2 + len, ".tmp", sizeof(".tmp"));
1075
1076    ef = eet_open(buf2, EET_FILE_MODE_WRITE);
1077    if (!ef)
1078      return EINA_FALSE;
1079
1080    ok = eet_data_write(ef, _config_edd, "config", _elm_config, 1);
1081    if (!ok)
1082      goto err;
1083
1084    err = _elm_config_eet_close_error_get(ef, buf2);
1085    if (err)
1086      {
1087         ERR("%s", err);
1088         free((void *)err);
1089         goto err;
1090      }
1091
1092    ret = ecore_file_mv(buf2, buf);
1093    if (!ret)
1094      {
1095         ERR("Error saving Elementary's configuration file");
1096         goto err;
1097      }
1098
1099    ecore_file_unlink(buf2);
1100    return EINA_TRUE;
1101
1102 err:
1103    ecore_file_unlink(buf2);
1104    return EINA_FALSE;
1105 }
1106
1107 static void
1108 _config_update(void)
1109 {
1110    Elm_Config *tcfg;
1111
1112    tcfg = _config_system_load();
1113    if (!tcfg)
1114      {
1115         /* weird profile or something? We should probably fill
1116          * with hardcoded defaults, or get from default previx */
1117           return;
1118      }
1119 #define IFCFG(v)   if ((_elm_config->config_version & 0xffff) < (v)) {
1120 #define IFCFGELSE } else {
1121 #define IFCFGEND  }
1122 #define COPYVAL(x) do {_elm_config->x = tcfg->x; } while(0)
1123 #define COPYPTR(x) do {_elm_config->x = tcfg->x; tcfg->x = NULL; } while(0)
1124 #define COPYSTR(x) COPYPTR(x)
1125
1126      /* we also need to update for property changes in the root window
1127       * if needed, but that will be dependent on new properties added
1128       * with each version */
1129
1130      IFCFG(0x0003);
1131      COPYVAL(longpress_timeout);
1132      IFCFGEND;
1133
1134 #undef COPYSTR
1135 #undef COPYPTR
1136 #undef COPYVAL
1137 #undef IFCFGEND
1138 #undef IFCFGELSE
1139 #undef IFCFG
1140
1141      /* after updating user config, we must save */
1142 }
1143
1144 static void
1145 _env_get(void)
1146 {
1147    char *s;
1148    double friction;
1149
1150    s = getenv("ELM_ENGINE");
1151    if (s)
1152      {
1153         if ((!strcasecmp(s, "x11")) ||
1154             (!strcasecmp(s, "x")) ||
1155             (!strcasecmp(s, "software-x11")) ||
1156             (!strcasecmp(s, "software_x11")))
1157           eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_X11);
1158         else if ((!strcasecmp(s, "opengl")) ||
1159                  (!strcasecmp(s, "gl")) ||
1160                  (!strcasecmp(s, "opengl-x11")) ||
1161                  (!strcasecmp(s, "opengl_x11")))
1162           eina_stringshare_replace(&_elm_config->engine, ELM_OPENGL_X11);
1163         else if ((!strcasecmp(s, "x11-8")) ||
1164                  (!strcasecmp(s, "x8")) ||
1165                  (!strcasecmp(s, "software-8-x11")) ||
1166                  (!strcasecmp(s, "software_8_x11")))
1167           eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_8_X11);
1168         else if ((!strcasecmp(s, "x11-16")) ||
1169                  (!strcasecmp(s, "x16")) ||
1170                  (!strcasecmp(s, "software-16-x11")) ||
1171                  (!strcasecmp(s, "software_16_x11")))
1172           eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_16_X11);
1173 /*
1174         else if ((!strcasecmp(s, "xrender")) ||
1175                  (!strcasecmp(s, "xr")) ||
1176                  (!strcasecmp(s, "xrender-x11")) ||
1177                  (!strcasecmp(s, "xrender_x11")))
1178           eina_stringshare_replace(&_elm_config->engine, ELM_XRENDER_X11);
1179  */
1180         else if ((!strcasecmp(s, "fb")) ||
1181                  (!strcasecmp(s, "software-fb")) ||
1182                  (!strcasecmp(s, "software_fb")))
1183           eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_FB);
1184         else if ((!strcasecmp(s, "directfb")) ||
1185                  (!strcasecmp(s, "dfb")))
1186           eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_DIRECTFB);
1187         else if ((!strcasecmp(s, "psl1ght")))
1188           eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_PSL1GHT);
1189         else if ((!strcasecmp(s, "sdl")) ||
1190                  (!strcasecmp(s, "software-sdl")) ||
1191                  (!strcasecmp(s, "software_sdl")))
1192           eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_SDL);
1193         else if ((!strcasecmp(s, "sdl-16")) ||
1194                  (!strcasecmp(s, "software-16-sdl")) ||
1195                  (!strcasecmp(s, "software_16_sdl")))
1196           eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_16_SDL);
1197         else if ((!strcasecmp(s, "opengl-sdl")) ||
1198                  (!strcasecmp(s, "opengl_sdl")) ||
1199                  (!strcasecmp(s, "gl-sdl")) ||
1200                  (!strcasecmp(s, "gl_sdl")))
1201           eina_stringshare_replace(&_elm_config->engine, ELM_OPENGL_SDL);
1202         else if ((!strcasecmp(s, "opengl-cocoa")) ||
1203                  (!strcasecmp(s, "opengl_cocoa")) ||
1204                  (!strcasecmp(s, "gl-cocoa")) ||
1205                  (!strcasecmp(s, "gl_cocoa")))
1206           eina_stringshare_replace(&_elm_config->engine, ELM_OPENGL_COCOA);
1207         else if ((!strcasecmp(s, "gdi")) ||
1208                  (!strcasecmp(s, "software-gdi")) ||
1209                  (!strcasecmp(s, "software_gdi")))
1210           eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_WIN32);
1211         else if ((!strcasecmp(s, "wince-gdi")) ||
1212                  (!strcasecmp(s, "software-16-wince-gdi")) ||
1213                  (!strcasecmp(s, "software_16_wince_gdi")))
1214           eina_stringshare_replace(&_elm_config->engine, ELM_SOFTWARE_16_WINCE);
1215         else if (!strcasecmp(s, "buffer"))
1216           eina_stringshare_replace(&_elm_config->engine, ELM_BUFFER);
1217         else if ((!strncmp(s, "shot:", 5)))
1218           eina_stringshare_replace(&_elm_config->engine, s);
1219         else if ((!strcasecmp(s, "ews")))
1220           eina_stringshare_replace(&_elm_config->engine, ELM_EWS);
1221         else if ((!strcasecmp(s, "wayland_shm")))
1222           eina_stringshare_replace(&_elm_config->engine, ELM_WAYLAND_SHM);
1223         else if ((!strcasecmp(s, "wayland_egl")))
1224           eina_stringshare_replace(&_elm_config->engine, ELM_WAYLAND_EGL);
1225         else
1226           ERR("Unknown engine '%s'.", s);
1227      }
1228
1229    s = getenv("ELM_VSYNC");
1230    if (s) _elm_config->vsync = !!atoi(s);
1231
1232    s = getenv("ELM_THUMBSCROLL_ENABLE");
1233    if (s) _elm_config->thumbscroll_enable = !!atoi(s);
1234    s = getenv("ELM_THUMBSCROLL_THRESHOLD");
1235    if (s) _elm_config->thumbscroll_threshold = atoi(s);
1236    // FIXME: floatformat locale issues here 1.0 vs 1,0 - should just be 1.0
1237    s = getenv("ELM_THUMBSCROLL_MOMENTUM_THRESHOLD");
1238    if (s) _elm_config->thumbscroll_momentum_threshold = atof(s);
1239    s = getenv("ELM_THUMBSCROLL_FRICTION");
1240    if (s) _elm_config->thumbscroll_friction = atof(s);
1241    s = getenv("ELM_THUMBSCROLL_BOUNCE_ENABLE");
1242    if (s) _elm_config->thumbscroll_bounce_enable = !!atoi(s);
1243    s = getenv("ELM_THUMBSCROLL_BOUNCE_FRICTION");
1244    if (s) _elm_config->thumbscroll_bounce_friction = atof(s);
1245    s = getenv("ELM_PAGE_SCROLL_FRICTION");
1246    if (s) _elm_config->page_scroll_friction = atof(s);
1247    s = getenv("ELM_BRING_IN_SCROLL_FRICTION");
1248    if (s) _elm_config->bring_in_scroll_friction = atof(s);
1249    s = getenv("ELM_ZOOM_FRICTION");
1250    if (s) _elm_config->zoom_friction = atof(s);
1251    s = getenv("ELM_THUMBSCROLL_BORDER_FRICTION");
1252    if (s)
1253      {
1254         friction = atof(s);
1255         if (friction < 0.0)
1256           friction = 0.0;
1257
1258         if (friction > 1.0)
1259           friction = 1.0;
1260
1261         _elm_config->thumbscroll_border_friction = friction;
1262      }
1263    s = getenv("ELM_THUMBSCROLL_SENSITIVITY_FRICTION");
1264    if (s)
1265      {
1266         friction = atof(s);
1267         if (friction < 0.1)
1268           friction = 0.1;
1269
1270         if (friction > 1.0)
1271           friction = 1.0;
1272
1273         _elm_config->thumbscroll_sensitivity_friction = friction;
1274      }
1275    s = getenv("ELM_SCROLL_SMOOTH_TIME_INTERVAL");
1276    if (s) _elm_config->scroll_smooth_time_interval = atof(s);
1277    s = getenv("ELM_SCROLL_SMOOTH_AMOUNT");
1278    if (s) _elm_config->scroll_smooth_amount = atof(s);
1279    s = getenv("ELM_SCROLL_SMOOTH_HISTORY_WEIGHT");
1280    if (s) _elm_config->scroll_smooth_history_weight = atof(s);
1281    s = getenv("ELM_SCROLL_SMOOTH_FUTURE_TIME");
1282    if (s) _elm_config->scroll_smooth_future_time = atof(s);
1283    s = getenv("ELM_SCROLL_SMOOTH_TIME_WINDOW");
1284    if (s) _elm_config->scroll_smooth_time_window = atof(s);
1285    s = getenv("ELM_THEME");
1286    if (s) eina_stringshare_replace(&_elm_config->theme, s);
1287
1288    s = getenv("ELM_FONT_HINTING");
1289    if (s)
1290      {
1291         if      (!strcasecmp(s, "none")) _elm_config->font_hinting = 0;
1292         else if (!strcasecmp(s, "auto"))
1293           _elm_config->font_hinting = 1;
1294         else if (!strcasecmp(s, "bytecode"))
1295           _elm_config->font_hinting = 2;
1296      }
1297
1298    s = getenv("ELM_FONT_PATH");
1299    if (s)
1300      {
1301         const char *p, *pp;
1302         char *buf2;
1303
1304         EINA_LIST_FREE(_elm_config->font_dirs, p)
1305           {
1306              eina_stringshare_del(p);
1307           }
1308
1309         buf2 = alloca(strlen(s) + 1);
1310         p = s;
1311         pp = p;
1312         for (;; )
1313           {
1314              if ((*p == ':') || (*p == 0))
1315                {
1316                   int len;
1317
1318                   len = p - pp;
1319                   strncpy(buf2, pp, len);
1320                   buf2[len] = 0;
1321                   _elm_config->font_dirs =
1322                     eina_list_append(_elm_config->font_dirs,
1323                                      eina_stringshare_add(buf2));
1324                   if (*p == 0) break;
1325                   p++;
1326                   pp = p;
1327                }
1328              else
1329                {
1330                   if (*p == 0) break;
1331                   p++;
1332                }
1333           }
1334      }
1335
1336    s = getenv("ELM_IMAGE_CACHE");
1337    if (s) _elm_config->image_cache = atoi(s);
1338
1339    s = getenv("ELM_FONT_CACHE");
1340    if (s) _elm_config->font_cache = atoi(s);
1341
1342    s = getenv("ELM_SCALE");
1343    if (s) _elm_config->scale = atof(s);
1344
1345    s = getenv("ELM_FINGER_SIZE");
1346    if (s) _elm_config->finger_size = atoi(s);
1347
1348    s = getenv("ELM_PASSWORD_SHOW_LAST");
1349    if (s) _elm_config->password_show_last = !!atoi(s);
1350
1351    s = getenv("ELM_PASSWORD_SHOW_LAST_TIMEOUT");
1352    if (s)
1353      {
1354         double pw_show_last_timeout = atof(s);
1355         if (pw_show_last_timeout >= 0.0)
1356           _elm_config->password_show_last_timeout = pw_show_last_timeout;
1357      }
1358
1359    s = getenv("ELM_FPS");
1360    if (s) _elm_config->fps = atof(s);
1361    if (_elm_config->fps < 1.0) _elm_config->fps = 1.0;
1362
1363    s = getenv("ELM_MODULES");
1364    if (s) eina_stringshare_replace(&_elm_config->modules, s);
1365
1366    /* Get RTL orientation from system */
1367    setlocale(LC_ALL, "");
1368    bindtextdomain(PACKAGE, LOCALE_DIR);
1369    _elm_config->is_mirrored = !strcmp(E_("default:LTR"), "default:RTL");
1370
1371    s = getenv("ELM_TOOLTIP_DELAY");
1372    if (s)
1373      {
1374         double delay = atof(s);
1375         if (delay >= 0.0)
1376           _elm_config->tooltip_delay = delay;
1377      }
1378
1379    s = getenv("ELM_CURSOR_ENGINE_ONLY");
1380    if (s) _elm_config->cursor_engine_only = !!atoi(s);
1381
1382    s = getenv("ELM_FOCUS_HIGHLIGHT_ENABLE");
1383    if (s) _elm_config->focus_highlight_enable = !!atoi(s);
1384
1385    s = getenv("ELM_FOCUS_HIGHLIGHT_ANIMATE");
1386    if (s) _elm_config->focus_highlight_animate = !!atoi(s);
1387
1388    s = getenv("ELM_TOOLBAR_SHRINK_MODE");
1389    if (s) _elm_config->toolbar_shrink_mode = atoi(s);
1390
1391    s = getenv("ELM_FILESELECTOR_EXPAND_ENABLE");
1392    if (s) _elm_config->fileselector_expand_enable = !!atoi(s);
1393
1394    s = getenv("ELM_INWIN_DIALOGS_ENABLE");
1395    if (s) _elm_config->inwin_dialogs_enable = !!atoi(s);
1396
1397    s = getenv("ELM_ICON_SIZE");
1398    if (s) _elm_config->icon_size = atoi(s);
1399
1400    s = getenv("ELM_LONGPRESS_TIMEOUT");
1401    if (s) _elm_config->longpress_timeout = atof(s);
1402    if (_elm_config->longpress_timeout < 0.0)
1403      _elm_config->longpress_timeout = 0.0;
1404
1405    s = getenv("ELM_EFFECT_ENABLE");
1406    if (s) _elm_config->effect_enable = !!atoi(s);
1407
1408    s = getenv("ELM_DESKTOP_ENTRY");
1409    if (s) _elm_config->desktop_entry = !!atoi(s);
1410    s = getenv("ELM_ACCESS_MODE");
1411    if (s) _elm_config->access_mode = ELM_ACCESS_MODE_ON;
1412 }
1413
1414 EAPI Eina_Bool
1415 elm_config_mirrored_get(void)
1416 {
1417    return _elm_config->is_mirrored;
1418 }
1419
1420 EAPI void
1421 elm_config_mirrored_set(Eina_Bool mirrored)
1422 {
1423    _elm_config->is_mirrored = mirrored;
1424    _elm_rescale();
1425 }
1426
1427 EAPI Eina_Bool
1428 elm_config_cursor_engine_only_get(void)
1429 {
1430    return _elm_config->cursor_engine_only;
1431 }
1432
1433 EAPI void
1434 elm_config_cursor_engine_only_set(Eina_Bool engine_only)
1435 {
1436    engine_only = !!engine_only;
1437    _elm_config->cursor_engine_only = engine_only;
1438 }
1439
1440 EINA_DEPRECATED EAPI double
1441 elm_tooltip_delay_get(void)
1442 {
1443    return elm_config_tooltip_delay_get();
1444 }
1445
1446 EINA_DEPRECATED EAPI Eina_Bool
1447 elm_tooltip_delay_set(double delay)
1448 {
1449    elm_config_tooltip_delay_set(delay);
1450    return EINA_TRUE;
1451 }
1452
1453 EAPI double
1454 elm_config_tooltip_delay_get(void)
1455 {
1456    return _elm_config->tooltip_delay;
1457 }
1458
1459 EAPI void
1460 elm_config_tooltip_delay_set(double delay)
1461 {
1462    if (delay < 0.0) return;
1463    _elm_config->tooltip_delay = delay;
1464 }
1465
1466 EAPI double
1467 elm_scale_get(void)
1468 {
1469    return elm_config_scale_get();
1470 }
1471
1472 EAPI double
1473 elm_config_scale_get(void)
1474 {
1475    return _elm_config->scale;
1476 }
1477
1478 EAPI void
1479 elm_scale_set(double scale)
1480 {
1481         elm_config_scale_set(scale);
1482 }
1483
1484 EAPI void
1485 elm_config_scale_set(double scale)
1486 {
1487    if (_elm_config->scale == scale) return;
1488    _elm_config->scale = scale;
1489    _elm_rescale();
1490 }
1491
1492 EAPI Eina_Bool
1493 elm_config_password_show_last_get(void)
1494 {
1495    return _elm_config->password_show_last;
1496 }
1497
1498 EAPI void
1499 elm_config_password_show_last_set(Eina_Bool password_show_last)
1500 {
1501    if (_elm_config->password_show_last == password_show_last) return;
1502    _elm_config->password_show_last = password_show_last;
1503    edje_password_show_last_set(_elm_config->password_show_last);
1504 }
1505
1506 EAPI double
1507 elm_config_password_show_last_timeout_get(void)
1508 {
1509    return _elm_config->password_show_last_timeout;
1510 }
1511
1512 EAPI void
1513 elm_config_password_show_last_timeout_set(double password_show_last_timeout)
1514 {
1515    if (_elm_config->password_show_last_timeout == password_show_last_timeout) return;
1516    _elm_config->password_show_last_timeout = password_show_last_timeout;
1517    edje_password_show_last_timeout_set(_elm_config->password_show_last_timeout);
1518 }
1519
1520 EAPI Eina_Bool
1521 elm_config_save(void)
1522 {
1523    return _elm_config_save();
1524 }
1525
1526 EAPI void
1527 elm_config_reload(void)
1528 {
1529    _elm_config_reload();
1530 }
1531
1532 EAPI const char *
1533 elm_config_profile_get(void)
1534 {
1535    return _elm_config_current_profile_get();
1536 }
1537
1538 EAPI const char *
1539 elm_config_profile_dir_get(const char *profile,
1540                     Eina_Bool   is_user)
1541 {
1542    return _elm_config_profile_dir_get(profile, is_user);
1543 }
1544
1545 EAPI void
1546 elm_config_profile_dir_free(const char *p_dir)
1547 {
1548    free((void *)p_dir);
1549 }
1550
1551 EAPI Eina_List *
1552 elm_config_profile_list_get(void)
1553 {
1554    return _elm_config_profiles_list();
1555 }
1556
1557 EAPI void
1558 elm_config_profile_list_free(Eina_List *l)
1559 {
1560    const char *dir;
1561
1562    EINA_LIST_FREE(l, dir)
1563      eina_stringshare_del(dir);
1564 }
1565
1566 EAPI void
1567 elm_config_profile_set(const char *profile)
1568 {
1569    EINA_SAFETY_ON_NULL_RETURN(profile);
1570    _elm_config_profile_set(profile);
1571 }
1572
1573 EAPI const char *
1574 elm_config_engine_get(void)
1575 {
1576    return _elm_config->engine;
1577 }
1578
1579 EAPI void
1580 elm_config_engine_set(const char *engine)
1581 {
1582    EINA_SAFETY_ON_NULL_RETURN(engine);
1583
1584    _elm_config_engine_set(engine);
1585 }
1586
1587 EAPI Eina_List *
1588 elm_config_text_classes_list_get(void)
1589 {
1590    return _elm_config_text_classes_get();
1591 }
1592
1593 EAPI void
1594 elm_config_text_classes_list_free(Eina_List *list)
1595 {
1596    _elm_config_text_classes_free(list);
1597 }
1598
1599 EAPI const Eina_List *
1600 elm_config_font_overlay_list_get(void)
1601 {
1602    return _elm_config_font_overlays_list();
1603 }
1604
1605 EAPI void
1606 elm_config_font_overlay_set(const char    *text_class,
1607                      const char    *font,
1608                      Evas_Font_Size size)
1609 {
1610    EINA_SAFETY_ON_NULL_RETURN(text_class);
1611    _elm_config_font_overlay_set(text_class, font, size);
1612 }
1613
1614 EAPI void
1615 elm_config_font_overlay_unset(const char *text_class)
1616 {
1617    EINA_SAFETY_ON_NULL_RETURN(text_class);
1618    _elm_config_font_overlay_remove(text_class);
1619 }
1620
1621 EAPI void
1622 elm_config_font_overlay_apply(void)
1623 {
1624    _elm_config_font_overlay_apply();
1625 }
1626 // WRAPPER:: will be removed soon.
1627 EAPI Evas_Coord
1628 elm_finger_size_get(void)
1629 {
1630    return elm_config_finger_size_get();
1631 }
1632
1633 EAPI Evas_Coord
1634 elm_config_finger_size_get(void)
1635 {
1636    return _elm_config->finger_size;
1637 }
1638
1639 // WRAPPER:: will be removed soon.
1640 EAPI void
1641 elm_finger_size_set(Evas_Coord size)
1642 {
1643    elm_config_finger_size_set(size);
1644 }
1645
1646 EAPI void
1647 elm_config_finger_size_set(Evas_Coord size)
1648 {
1649    if (_elm_config->finger_size == size) return;
1650    _elm_config->finger_size = size;
1651    _elm_rescale();
1652 }
1653
1654 EAPI int
1655 elm_config_cache_flush_interval_get(void)
1656 {
1657    return _elm_config->cache_flush_poll_interval;
1658 }
1659
1660 EAPI void
1661 elm_config_cache_flush_interval_set(int size)
1662 {
1663    if (_elm_config->cache_flush_poll_interval == size) return;
1664    _elm_config->cache_flush_poll_interval = size;
1665
1666    _elm_recache();
1667 }
1668
1669 EAPI Eina_Bool
1670 elm_config_cache_flush_enabled_get(void)
1671 {
1672    return _elm_config->cache_flush_enable;
1673 }
1674
1675 EAPI void
1676 elm_config_cache_flush_enabled_set(Eina_Bool enabled)
1677 {
1678    enabled = !!enabled;
1679    if (_elm_config->cache_flush_enable == enabled) return;
1680    _elm_config->cache_flush_enable = enabled;
1681
1682    _elm_recache();
1683 }
1684
1685 EINA_DEPRECATED EAPI int
1686 elm_font_cache_get(void)
1687 {
1688    return elm_config_cache_font_cache_size_get();
1689 }
1690
1691 EAPI int
1692 elm_config_cache_font_cache_size_get(void)
1693 {
1694    return _elm_config->font_cache;
1695 }
1696
1697 EINA_DEPRECATED EAPI void
1698 elm_font_cache_set(int size)
1699 {
1700    elm_config_cache_font_cache_size_set(size);
1701 }
1702
1703 EAPI void 
1704 elm_config_cache_font_cache_size_set(int size)
1705 {
1706    if (_elm_config->font_cache == size) return;
1707    _elm_config->font_cache = size;
1708
1709    _elm_recache();
1710 }
1711
1712 EINA_DEPRECATED EAPI int
1713 elm_image_cache_get(void)
1714 {
1715    return elm_config_cache_image_cache_size_get();
1716 }
1717
1718 EAPI int
1719 elm_config_cache_image_cache_size_get(void)
1720 {
1721    return _elm_config->image_cache;
1722 }
1723
1724 EINA_DEPRECATED EAPI void
1725 elm_image_cache_set(int size)
1726 {
1727    elm_config_cache_image_cache_size_set(size);
1728 }
1729
1730 EAPI void
1731 elm_config_cache_image_cache_size_set(int size)
1732 {
1733    if (_elm_config->image_cache == size) return;
1734    _elm_config->image_cache = size;
1735
1736    _elm_recache();
1737 }
1738
1739 EINA_DEPRECATED EAPI int
1740 elm_edje_file_cache_get(void)
1741 {
1742    return elm_config_cache_edje_file_cache_size_get();
1743 }
1744
1745 EAPI int
1746 elm_config_cache_edje_file_cache_size_get()
1747 {
1748    return _elm_config->edje_cache;
1749 }
1750
1751 EINA_DEPRECATED EAPI void
1752 elm_edje_file_cache_set(int size)
1753 {
1754    elm_config_cache_edje_file_cache_size_set(size);
1755 }
1756
1757 EAPI void
1758 elm_config_cache_edje_file_cache_size_set(int size)
1759 {
1760    if (_elm_config->edje_cache == size) return;
1761    _elm_config->edje_cache = size;
1762
1763    _elm_recache();
1764 }
1765
1766 EINA_DEPRECATED EAPI int
1767 elm_edje_collection_cache_get(void)
1768 {
1769    return elm_config_cache_edje_collection_cache_size_get();
1770 }
1771
1772 EAPI int
1773 elm_config_cache_edje_collection_cache_size_get(void)
1774 {
1775    return _elm_config->edje_collection_cache;
1776 }
1777
1778 EINA_DEPRECATED EAPI void
1779 elm_edje_collection_cache_set(int size)
1780 {
1781    elm_config_cache_edje_collection_cache_size_set(size);
1782 }
1783
1784 EAPI void
1785 elm_config_cache_edje_collection_cache_size_set(int size)
1786 {
1787    if (_elm_config->edje_collection_cache == size) return;
1788    _elm_config->edje_collection_cache = size;
1789
1790    _elm_recache();
1791 }
1792
1793 EAPI Eina_Bool
1794 elm_config_focus_highlight_enabled_get(void)
1795 {
1796    return _elm_config->focus_highlight_enable;
1797 }
1798
1799 EAPI void
1800 elm_config_focus_highlight_enabled_set(Eina_Bool enable)
1801 {
1802    _elm_config->focus_highlight_enable = !!enable;
1803 }
1804
1805 EAPI Eina_Bool
1806 elm_config_focus_highlight_animate_get(void)
1807 {
1808    return _elm_config->focus_highlight_animate;
1809 }
1810
1811 EAPI void
1812 elm_config_focus_highlight_animate_set(Eina_Bool animate)
1813 {
1814    _elm_config->focus_highlight_animate = !!animate;
1815 }
1816
1817 EAPI Eina_Bool
1818 elm_config_scroll_bounce_enabled_get(void)
1819 {
1820    return _elm_config->thumbscroll_bounce_enable;
1821 }
1822
1823 EAPI void
1824 elm_config_scroll_bounce_enabled_set(Eina_Bool enabled)
1825 {
1826    _elm_config->thumbscroll_bounce_enable = enabled;
1827 }
1828
1829 EAPI double
1830 elm_config_scroll_bounce_friction_get(void)
1831 {
1832    return _elm_config->thumbscroll_bounce_friction;
1833 }
1834
1835 EAPI void
1836 elm_config_scroll_bounce_friction_set(double friction)
1837 {
1838    _elm_config->thumbscroll_bounce_friction = friction;
1839 }
1840
1841 EAPI double
1842 elm_config_scroll_page_scroll_friction_get(void)
1843 {
1844    return _elm_config->page_scroll_friction;
1845 }
1846
1847 EAPI void
1848 elm_config_scroll_page_scroll_friction_set(double friction)
1849 {
1850    _elm_config->page_scroll_friction = friction;
1851 }
1852
1853 EAPI double
1854 elm_config_scroll_bring_in_scroll_friction_get(void)
1855 {
1856    return _elm_config->bring_in_scroll_friction;
1857 }
1858
1859 EAPI void
1860 elm_config_scroll_bring_in_scroll_friction_set(double friction)
1861 {
1862    _elm_config->bring_in_scroll_friction = friction;
1863 }
1864
1865 EAPI double
1866 elm_config_scroll_zoom_friction_get(void)
1867 {
1868    return _elm_config->zoom_friction;
1869 }
1870
1871 EAPI void
1872 elm_config_scroll_zoom_friction_set(double friction)
1873 {
1874    _elm_config->zoom_friction = friction;
1875 }
1876
1877 EAPI Eina_Bool
1878 elm_config_scroll_thumbscroll_enabled_get(void)
1879 {
1880    return _elm_config->thumbscroll_enable;
1881 }
1882
1883 EAPI void
1884 elm_config_scroll_thumbscroll_enabled_set(Eina_Bool enabled)
1885 {
1886    _elm_config->thumbscroll_enable = enabled;
1887 }
1888
1889 EAPI unsigned int
1890 elm_config_scroll_thumbscroll_threshold_get(void)
1891 {
1892    return _elm_config->thumbscroll_threshold;
1893 }
1894
1895 EAPI void
1896 elm_config_scroll_thumbscroll_threshold_set(unsigned int threshold)
1897 {
1898    _elm_config->thumbscroll_threshold = threshold;
1899 }
1900
1901 EAPI double
1902 elm_config_scroll_thumbscroll_momentum_threshold_get(void)
1903 {
1904    return _elm_config->thumbscroll_momentum_threshold;
1905 }
1906
1907 EAPI void
1908 elm_config_scroll_thumbscroll_momentum_threshold_set(double threshold)
1909 {
1910    _elm_config->thumbscroll_momentum_threshold = threshold;
1911 }
1912
1913 EAPI double
1914 elm_config_scroll_thumbscroll_friction_get(void)
1915 {
1916    return _elm_config->thumbscroll_friction;
1917 }
1918
1919 EAPI void
1920 elm_config_scroll_thumbscroll_friction_set(double friction)
1921 {
1922    _elm_config->thumbscroll_friction = friction;
1923 }
1924
1925 EAPI double
1926 elm_config_scroll_thumbscroll_border_friction_get(void)
1927 {
1928    return _elm_config->thumbscroll_border_friction;
1929 }
1930
1931 EAPI void
1932 elm_config_scroll_thumbscroll_border_friction_set(double friction)
1933 {
1934    if (friction < 0.0) friction = 0.0;
1935    if (friction > 1.0) friction = 1.0;
1936    _elm_config->thumbscroll_friction = friction;
1937 }
1938
1939 EAPI double
1940 elm_config_scroll_thumbscroll_sensitivity_friction_get(void)
1941 {
1942    return _elm_config->thumbscroll_sensitivity_friction;
1943 }
1944
1945 EAPI void
1946 elm_config_scroll_thumbscroll_sensitivity_friction_set(double friction)
1947 {
1948    if (friction < 0.1) friction = 0.1;
1949    if (friction > 1.0) friction = 1.0;
1950    _elm_config->thumbscroll_friction = friction;
1951 }
1952
1953 EAPI void
1954 elm_config_longpress_timeout_set(double longpress_timeout)
1955 {
1956    _elm_config->longpress_timeout = longpress_timeout;
1957 }
1958
1959 EAPI double
1960 elm_config_longpress_timeout_get(void)
1961 {
1962    return _elm_config->longpress_timeout;
1963 }
1964
1965 EAPI void
1966 elm_config_all_flush(void)
1967 {
1968 #ifdef HAVE_ELEMENTARY_X
1969    if (_prop_all_update_timer) ecore_timer_del(_prop_all_update_timer);
1970    _prop_all_update_timer = ecore_timer_add(0.1, _prop_all_update_cb, NULL);
1971 #endif
1972 }
1973
1974 static void
1975 _translation_init()
1976 {
1977 #ifdef ENABLE_NLS
1978    const char *cur_dom = textdomain(NULL);
1979    const char *trans_comment = gettext("");
1980    const char *msg_locale = setlocale(LC_MESSAGES, NULL);
1981
1982    /* Same concept as what glib does:
1983     * We shouldn't translate if there are no translations for the
1984     * application in the current locale + domain. (Unless locale is
1985     * en_/C where translating only parts of the interface make some
1986     * sense).
1987     */
1988    _elm_config->translate = !(strcmp (cur_dom, "messages") &&
1989          !*trans_comment && strncmp (msg_locale, "en_", 3) &&
1990          strcmp (msg_locale, "C"));
1991 #endif
1992 }
1993
1994 void
1995 _elm_config_init(void)
1996 {
1997    if (!ELM_EVENT_CONFIG_ALL_CHANGED)
1998       ELM_EVENT_CONFIG_ALL_CHANGED = ecore_event_type_new();
1999    _desc_init();
2000    _profile_fetch_from_conf();
2001    _config_load();
2002    if (_elm_preferred_engine) eina_stringshare_del(_elm_preferred_engine);
2003    if (_elm_config->engine)
2004      _elm_preferred_engine = eina_stringshare_add(_elm_config->engine);
2005    else
2006      _elm_preferred_engine = NULL;
2007    _translation_init();
2008    _env_get();
2009    _config_apply();
2010    _elm_config_font_overlay_apply();
2011    _elm_recache();
2012 }
2013
2014 void
2015 _elm_config_sub_shutdown(void)
2016 {
2017 #define ENGINE_COMPARE(name) (!strcmp(_elm_config->engine, name))
2018    if (ENGINE_COMPARE(ELM_SOFTWARE_X11) ||
2019        ENGINE_COMPARE(ELM_SOFTWARE_16_X11) ||
2020        ENGINE_COMPARE(ELM_XRENDER_X11) ||
2021        ENGINE_COMPARE(ELM_OPENGL_X11) ||
2022        ENGINE_COMPARE(ELM_OPENGL_COCOA))
2023 #undef ENGINE_COMPARE
2024      {
2025 #ifdef HAVE_ELEMENTARY_X
2026         ecore_x_disconnect();
2027 #endif
2028      }
2029 }
2030
2031 void
2032 _elm_config_sub_init(void)
2033 {
2034 #define ENGINE_COMPARE(name) (!strcmp(_elm_config->engine, name))
2035    if (ENGINE_COMPARE(ELM_SOFTWARE_X11) ||
2036        ENGINE_COMPARE(ELM_SOFTWARE_16_X11) ||
2037        ENGINE_COMPARE(ELM_XRENDER_X11) ||
2038        ENGINE_COMPARE(ELM_OPENGL_X11) ||
2039        ENGINE_COMPARE(ELM_OPENGL_COCOA))
2040 #undef ENGINE_COMPARE
2041      {
2042 #ifdef HAVE_ELEMENTARY_X
2043         if (!ecore_x_init(NULL))
2044           {
2045              ERR("Cannot connect to X11 display. check $DISPLAY variable");
2046              exit(1);
2047           }
2048         _root_1st = ecore_x_window_root_first_get();
2049
2050         if (!ecore_x_screen_is_composited(0))
2051           _elm_config->compositing = 0;
2052
2053         ecore_x_atoms_get(_atom_names, ATOM_COUNT, _atom);
2054         ecore_x_event_mask_set(_root_1st,
2055                                ECORE_X_EVENT_MASK_WINDOW_PROPERTY);
2056         _prop_change_handler = ecore_event_handler_add
2057             (ECORE_X_EVENT_WINDOW_PROPERTY, _prop_change, NULL);
2058         if (!getenv("ELM_PROFILE"))
2059           {
2060              char *s;
2061
2062              s = ecore_x_window_prop_string_get(_root_1st,
2063                                                 _atom[ATOM_E_PROFILE]);
2064              if (s)
2065                {
2066                   int changed = 0;
2067
2068                   if (_elm_profile)
2069                     {
2070                        if (strcmp(_elm_profile, s)) changed = 1;
2071                        free(_elm_profile);
2072                     }
2073                   _elm_profile = s;
2074                   if (changed) _prop_config_get();
2075                }
2076           }
2077 #endif
2078      }
2079    _config_sub_apply();
2080 }
2081
2082 void
2083 _elm_config_reload(void)
2084 {
2085    _config_free();
2086    _config_load();
2087    _config_apply();
2088    _elm_config_font_overlay_apply();
2089    _elm_rescale();
2090    _elm_recache();
2091 }
2092
2093 void
2094 _elm_config_engine_set(const char *engine)
2095 {
2096    if (_elm_config->engine && strcmp(_elm_config->engine, engine))
2097      eina_stringshare_del(_elm_config->engine);
2098
2099    _elm_config->engine = eina_stringshare_add(engine);
2100 }
2101
2102 EAPI const char *
2103 elm_config_preferred_engine_get(void)
2104 {
2105    return _elm_preferred_engine;
2106 }
2107
2108 EAPI void
2109 elm_config_preferred_engine_set(const char *engine)
2110 {
2111    if (engine)
2112      eina_stringshare_replace(&(_elm_preferred_engine), engine);
2113    else
2114      {
2115         if (_elm_preferred_engine) eina_stringshare_del(_elm_preferred_engine);
2116         _elm_preferred_engine = eina_stringshare_add(_elm_config->engine);
2117      }
2118 }
2119
2120 void
2121 _elm_config_profile_set(const char *profile)
2122 {
2123    Eina_Bool changed = EINA_FALSE;
2124
2125    if (_elm_profile)
2126      {
2127         if (strcmp(_elm_profile, profile))
2128           changed = 1;
2129         free(_elm_profile);
2130      }
2131
2132    _elm_profile = strdup(profile);
2133
2134    if (changed)
2135      {
2136         _config_free();
2137         _config_load();
2138         _config_apply();
2139         _elm_config_font_overlay_apply();
2140         _elm_rescale();
2141         _elm_recache();
2142      }
2143 }
2144
2145 void
2146 _elm_config_shutdown(void)
2147 {
2148 #ifdef HAVE_ELEMENTARY_X
2149    if (_prop_all_update_timer)
2150      {
2151         ecore_timer_del(_prop_all_update_timer);
2152         _prop_all_update_timer = NULL;
2153         _prop_all_update_cb(NULL);
2154      }
2155    if (_prop_change_delay_timer) ecore_timer_del(_prop_change_delay_timer);
2156    _prop_change_delay_timer = NULL;
2157 #endif
2158
2159 #define ENGINE_COMPARE(name) (!strcmp(_elm_config->engine, name))
2160    if (ENGINE_COMPARE(ELM_SOFTWARE_X11) ||
2161        ENGINE_COMPARE(ELM_SOFTWARE_16_X11) ||
2162        ENGINE_COMPARE(ELM_XRENDER_X11) ||
2163        ENGINE_COMPARE(ELM_OPENGL_X11))
2164 #undef ENGINE_COMPARE
2165      {
2166 #ifdef HAVE_ELEMENTARY_X
2167         ecore_event_handler_del(_prop_change_handler);
2168         _prop_change_handler = NULL;
2169 #endif
2170      }
2171    _config_free();
2172    if (_elm_preferred_engine)
2173      {
2174         eina_stringshare_del(_elm_preferred_engine);
2175         _elm_preferred_engine = NULL;
2176      }
2177    if (_elm_profile)
2178      {
2179         free(_elm_profile);
2180         _elm_profile = NULL;
2181      }
2182    _desc_shutdown();
2183 }
2184