Merge branch 'master' of 165.213.180.234:slp/pkgs/e/elementary
[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 Elm_Config *_elm_config = NULL;
13 char *_elm_profile = NULL;
14 static Eet_Data_Descriptor *_config_edd = NULL;
15
16 static void _desc_init(void);
17 static void _desc_shutdown(void);
18 static void _profile_get(void);
19 static void _config_free(void);
20 static void _config_apply(void);
21 static Elm_Config * _config_user_load(void);
22 static Elm_Config * _config_system_load(void);
23 static void _config_load(void);
24 static void _config_update(void);
25 static void _env_get(void);
26
27 #ifdef HAVE_ELEMENTARY_X
28 static Ecore_Event_Handler *_prop_change_handler = NULL;
29 static Ecore_X_Window _root_1st = 0;
30 #define ATOM_COUNT 8
31 static Ecore_X_Atom _atom[ATOM_COUNT];
32 static Ecore_X_Atom _atom_config = 0;
33 static Ecore_X_Atom _atom_config_specific = 0;
34 static const char *_atom_names[ATOM_COUNT] =
35 {
36      "ENLIGHTENMENT_SCALE",
37      "ENLIGHTENMENT_FINGER_SIZE",
38      "ENLIGHTENMENT_THEME",
39      "ENLIGHTENMENT_PROFILE",
40      "ENLIGHTENMENT_CONFIG",
41      "ENLIGHTENMENT_INPUT_PANEL",
42      "ENLIGHTENMENT_AUTOCAPITAL_ALLOW",
43      "ENLIGHTENMENT_AUTOPERIOD_ALLOW",
44 };
45 #define ATOM_E_SCALE 0
46 #define ATOM_E_FINGER_SIZE 1
47 #define ATOM_E_THEME 2
48 #define ATOM_E_PROFILE 3
49 #define ATOM_E_CONFIG 4
50 #define ATOM_E_INPUT_PANEL 5
51 #define ATOM_E_AUTOCAPITAL_ALLOW 6
52 #define ATOM_E_AUTOPERIOD_ALLOW 7
53
54 static Eina_Bool _prop_config_get(void);
55 static Eina_Bool _prop_change(void *data __UNUSED__, int ev_type __UNUSED__, void *ev);
56
57 static Eina_Bool
58 _prop_config_get(void)
59 {
60    int size = 0;
61    Ecore_X_Atom atom;
62    char buf[512];
63    unsigned char *data = NULL;
64    Elm_Config *config_data;
65
66    snprintf(buf, sizeof(buf), "ENLIGHTENMENT_CONFIG_%s", _elm_profile);
67    atom = ecore_x_atom_get(buf);
68    _atom_config = atom;
69    if (!ecore_x_window_prop_property_get(_root_1st,
70                                          atom, _atom[ATOM_E_CONFIG], 
71                                          8, &data, &size))
72      {
73         if (!ecore_x_window_prop_property_get(_root_1st, 
74                                               _atom[ATOM_E_CONFIG], 
75                                               _atom[ATOM_E_CONFIG], 
76                                               8, &data, &size))
77           return EINA_FALSE;
78         else
79           _atom_config = _atom[ATOM_E_CONFIG];
80      }
81    else
82      _atom_config = atom;
83    if (size < 1)
84      {
85         free(data);
86         return EINA_FALSE;
87      }
88    config_data = eet_data_descriptor_decode(_config_edd, data, size);
89    free(data);
90    if (!config_data) return EINA_FALSE;
91  /* What do we do on version mismatch when someone changes the
92  * config in the rootwindow? */
93  /* Most obvious case, new version and we are still linked to
94  * whatever was there before, we just ignore until user restarts us */
95  if (config_data->config_version > ELM_CONFIG_VERSION)
96  return EINA_TRUE;
97 /* What in the case the version is older? Do we even support those
98 * cases or we only check for equality above? */
99    _config_free();
100    _elm_config = config_data;
101    _config_apply();
102    _elm_rescale();
103    return EINA_TRUE;
104 }
105
106 static Eina_Bool
107 _prop_change(void *data __UNUSED__, int ev_type __UNUSED__, void *ev)
108 {
109    Ecore_X_Event_Window_Property *event = ev;
110
111    if (event->win == _root_1st)
112      {
113         if (event->atom == _atom[ATOM_E_SCALE])
114           {
115              unsigned int val = 1000;
116
117              if (ecore_x_window_prop_card32_get(event->win,
118                                                 event->atom,
119                                                 &val, 1) > 0)
120                {
121                   double pscale;
122
123                   pscale = _elm_config->scale;
124                   if (val > 0) _elm_config->scale = (double)val / 1000.0;
125                   if (pscale != _elm_config->scale) _elm_rescale();
126                }
127           }
128         else if (event->atom == _atom[ATOM_E_FINGER_SIZE])
129           {
130              unsigned int val = 1000;
131
132              if (ecore_x_window_prop_card32_get(event->win,
133                                                 event->atom,
134                                                 &val, 1) > 0)
135                {
136                   int pfinger_size;
137
138                   pfinger_size = _elm_config->finger_size;
139                   _elm_config->finger_size = val;
140                   if (pfinger_size != _elm_config->finger_size) _elm_rescale();
141                }
142           }
143         else if (event->atom == _atom[ATOM_E_THEME])
144           {
145              char *val = NULL;
146
147              val = ecore_x_window_prop_string_get(event->win,
148                                                   event->atom);
149              eina_stringshare_replace(&_elm_config->theme, val);
150              if (val)
151                {
152                   _elm_theme_parse(NULL, val);
153                   free(val);
154                   _elm_rescale();
155                }
156           }
157         else if (event->atom == _atom[ATOM_E_PROFILE])
158           {
159              char *val = NULL;
160
161              val = ecore_x_window_prop_string_get(event->win,
162                                                   event->atom);
163              if (val)
164                {
165                   int changed = 0;
166
167                   if (_elm_profile)
168                     {
169                        if (strcmp(_elm_profile, val)) changed = 1;
170                        free(_elm_profile);
171                     }
172                   _elm_profile = val;
173                   if (changed)
174                     {
175                        if (!_prop_config_get())
176                          {
177                             _config_free();
178                             _config_load();
179                             _config_apply();
180                             _elm_rescale();
181                          }
182                     }
183                }
184           }
185         else if (event->atom == _atom[ATOM_E_INPUT_PANEL])
186           {
187              unsigned int val = 0;
188
189              if (ecore_x_window_prop_card32_get(event->win,
190                                                 event->atom,
191                                                 &val, 1) > 0)
192                {
193                    int input_panel_enable;
194
195                    input_panel_enable = _elm_config->input_panel_enable;
196                    _elm_config->input_panel_enable = val;
197                    if (input_panel_enable != _elm_config->input_panel_enable) 
198                      {
199                         edje_input_panel_enabled_set(_elm_config->input_panel_enable);
200                      }
201                }
202           }
203         else if (event->atom == _atom[ATOM_E_AUTOCAPITAL_ALLOW])
204           {
205              unsigned int val = 0;
206
207              if (ecore_x_window_prop_card32_get(event->win,
208                                                 event->atom,
209                                                 &val, 1) > 0)
210                {
211                    int autocapital_allow;
212
213                    autocapital_allow = _elm_config->autocapital_allow;
214                    _elm_config->autocapital_allow = val;
215                    if (autocapital_allow != _elm_config->autocapital_allow) 
216                      {
217                         edje_autocapitalization_allow_set(_elm_config->autocapital_allow);
218                      }
219                }
220           }             
221         else if (event->atom == _atom[ATOM_E_AUTOPERIOD_ALLOW])
222           {
223              unsigned int val = 0;
224
225              if (ecore_x_window_prop_card32_get(event->win,
226                                                 event->atom,
227                                                 &val, 1) > 0)
228                {
229                   int autoperiod_allow;
230
231                   autoperiod_allow = _elm_config->autoperiod_allow;
232                   _elm_config->autoperiod_allow = val;
233                   if (autoperiod_allow != _elm_config->autoperiod_allow) 
234                     {
235                        edje_autoperiod_allow_set(_elm_config->autoperiod_allow);
236                     }
237                }
238           }
239         else if (((_atom_config > 0) && (event->atom == _atom_config)) ||
240                  (event->atom == _atom[ATOM_E_CONFIG]))
241           {
242              _prop_config_get();
243           }
244      }
245
246    return ECORE_CALLBACK_PASS_ON;
247 }
248 #endif
249
250 static void
251 _desc_init(void)
252 {
253    Eet_Data_Descriptor_Class eddc;
254    
255    EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Elm_Config);
256    eddc.func.str_direct_alloc = NULL;
257    eddc.func.str_direct_free = NULL;
258    
259    _config_edd = eet_data_descriptor_file_new(&eddc);
260    if (!_config_edd)
261      {
262         printf("EEEK! eet_data_descriptor_file_new() failed\n");
263         return;
264      }
265    EET_DATA_DESCRIPTOR_ADD_BASIC(_config_edd, Elm_Config, "config_version", config_version, EET_T_INT);
266    EET_DATA_DESCRIPTOR_ADD_BASIC(_config_edd, Elm_Config, "engine", engine, EET_T_INT);
267    EET_DATA_DESCRIPTOR_ADD_BASIC(_config_edd, Elm_Config, "thumbscroll_enable", thumbscroll_enable, EET_T_INT);
268    EET_DATA_DESCRIPTOR_ADD_BASIC(_config_edd, Elm_Config, "thumbscroll_threshhold", thumbscroll_threshhold, EET_T_INT);
269    EET_DATA_DESCRIPTOR_ADD_BASIC(_config_edd, Elm_Config, "thumbscroll_momentum_threshhold", thumbscroll_momentum_threshhold, EET_T_DOUBLE);
270    EET_DATA_DESCRIPTOR_ADD_BASIC(_config_edd, Elm_Config, "thumbscroll_friction", thumbscroll_friction, EET_T_DOUBLE);
271    EET_DATA_DESCRIPTOR_ADD_BASIC(_config_edd, Elm_Config, "thumbscroll_bounce_friction", thumbscroll_bounce_friction, EET_T_DOUBLE);
272    EET_DATA_DESCRIPTOR_ADD_BASIC(_config_edd, Elm_Config, "page_scroll_friction", page_scroll_friction, EET_T_DOUBLE);
273    EET_DATA_DESCRIPTOR_ADD_BASIC(_config_edd, Elm_Config, "bring_in_scroll_friction", bring_in_scroll_friction, EET_T_DOUBLE);
274    EET_DATA_DESCRIPTOR_ADD_BASIC(_config_edd, Elm_Config, "zoom_friction", zoom_friction, EET_T_DOUBLE);
275    EET_DATA_DESCRIPTOR_ADD_BASIC(_config_edd, Elm_Config, "thumbscroll_bounce_enable", thumbscroll_bounce_enable, EET_T_INT);
276    EET_DATA_DESCRIPTOR_ADD_BASIC(_config_edd, Elm_Config, "scale", scale, EET_T_DOUBLE);
277    EET_DATA_DESCRIPTOR_ADD_BASIC(_config_edd, Elm_Config, "bgpixmap", bgpixmap, EET_T_INT);
278    EET_DATA_DESCRIPTOR_ADD_BASIC(_config_edd, Elm_Config, "compositing", compositing, EET_T_INT);
279    // EET_DATA_DESCRIPTOR_ADD_LIST(_config_edd, Elm_Config, "font_dirs", font_dirs, sub_edd);
280    EET_DATA_DESCRIPTOR_ADD_BASIC(_config_edd, Elm_Config, "font_hinting", font_hinting, EET_T_INT);
281    EET_DATA_DESCRIPTOR_ADD_BASIC(_config_edd, Elm_Config, "image_cache", image_cache, EET_T_INT);
282    EET_DATA_DESCRIPTOR_ADD_BASIC(_config_edd, Elm_Config, "font_cache", font_cache, EET_T_INT);
283    EET_DATA_DESCRIPTOR_ADD_BASIC(_config_edd, Elm_Config, "finger_size", finger_size, EET_T_INT);
284    EET_DATA_DESCRIPTOR_ADD_BASIC(_config_edd, Elm_Config, "fps", fps, EET_T_DOUBLE);
285    EET_DATA_DESCRIPTOR_ADD_BASIC(_config_edd, Elm_Config, "theme", theme, EET_T_STRING);
286    EET_DATA_DESCRIPTOR_ADD_BASIC(_config_edd, Elm_Config, "modules", modules, EET_T_STRING);
287    EET_DATA_DESCRIPTOR_ADD_BASIC(_config_edd, Elm_Config, "password_show_last_character", password_show_last_character, EET_T_INT);
288    EET_DATA_DESCRIPTOR_ADD_BASIC(_config_edd, Elm_Config, "longpress_timeout", longpress_timeout, EET_T_DOUBLE);
289 }
290
291 static void
292 _desc_shutdown(void)
293 {
294    if (!_config_edd) return;
295    eet_data_descriptor_free(_config_edd);
296    _config_edd = NULL;
297 }
298
299 static void
300 _profile_get(void)
301 {
302    Eet_File *ef = NULL;
303    const char *home = NULL;
304    char buf[PATH_MAX], *p, *s;
305    int len = 0;
306
307    _elm_profile = strdup("default");
308    
309    // if env var - use profile without question
310    s = getenv("ELM_PROFILE");
311    if (s)
312      {
313         free(_elm_profile);
314         _elm_profile = strdup(s);
315         return;
316      }
317    
318    home = getenv("HOME");
319    if (!home) home = "/";
320    
321    // usser profile
322    snprintf(buf, sizeof(buf), "%s/.elementary/config/profile.cfg", home);
323    ef = eet_open(buf, EET_FILE_MODE_READ);
324    if (ef)
325      {
326         p = eet_read(ef, "config", &len);
327         if (p)
328           {
329              free(_elm_profile);
330              _elm_profile = malloc(len + 1);
331              memcpy(_elm_profile, p, len);
332              _elm_profile[len] = 0;
333              free(p);
334           }
335         eet_close(ef);
336         if (!p) ef = NULL;
337      }
338    if (ef) return;
339    
340    // system profile
341    snprintf(buf, sizeof(buf), "%s/config/profile.cfg", _elm_data_dir);
342    ef = eet_open(buf, EET_FILE_MODE_READ);
343    if (ef)
344      {
345         p = eet_read(ef, "config", &len);
346         if (p)
347           {
348              free(_elm_profile);
349              _elm_profile = malloc(len + 1);
350              memcpy(_elm_profile, p, len);
351              _elm_profile[len] = 0;
352              free(p);
353           }
354         eet_close(ef);
355      }
356 }
357
358 static void
359 _config_free(void)
360 {
361    const char *fontdir;
362    
363    if (!_elm_config) return;
364    EINA_LIST_FREE(_elm_config->font_dirs, fontdir)
365      {
366         eina_stringshare_del(fontdir);
367      }
368    if (_elm_config->theme) eina_stringshare_del(_elm_config->theme);
369    if (_elm_config->modules) eina_stringshare_del(_elm_config->modules);
370    free(_elm_config);
371    _elm_config = NULL;
372 }
373
374 static void
375 _config_apply(void)
376 {
377    _elm_theme_parse(NULL, _elm_config->theme);
378    ecore_animator_frametime_set(1.0 / _elm_config->fps);
379 }
380
381 static void
382 _config_sub_apply(void)
383 {
384    edje_frametime_set(1.0 / _elm_config->fps);
385    edje_scale_set(_elm_config->scale);
386    if (_elm_config->modules) _elm_module_parse(_elm_config->modules);
387    edje_input_panel_enabled_set(_elm_config->input_panel_enable);
388    edje_autocapitalization_allow_set(_elm_config->autocapital_allow);
389    edje_autoperiod_allow_set(_elm_config->autoperiod_allow);
390 }
391
392 static Elm_Config *
393 _config_user_load(void)
394 {
395    Elm_Config *cfg = NULL;
396    Eet_File *ef;
397    char buf[PATH_MAX];
398    const char *home;
399
400    home = getenv("HOME");
401    if (!home) home = "";
402
403    snprintf(buf, sizeof(buf), "%s/.elementary/config/%s/base.cfg", home,
404             _elm_profile);
405    ef = eet_open(buf, EET_FILE_MODE_READ);
406    if (ef)
407      {
408         cfg = eet_data_read(ef, _config_edd, "config");
409         eet_close(ef);
410      }
411    return cfg;
412 }
413
414 static Elm_Config *
415 _config_system_load(void)
416 {
417    Elm_Config *cfg = NULL;
418    Eet_File *ef;
419    char buf[PATH_MAX];
420
421    snprintf(buf, sizeof(buf), "%s/config/%s/base.cfg", _elm_data_dir,
422             _elm_profile);
423    ef = eet_open(buf, EET_FILE_MODE_READ);
424    if (ef)
425      {
426         cfg = eet_data_read(ef, _config_edd, "config");
427         eet_close(ef);
428      }
429    return cfg;
430 }
431
432
433 static void
434 _config_load(void)
435 {
436    _elm_config = _config_user_load();
437    
438    
439    // user config
440    if (_elm_config)
441      {
442         if (_elm_config->config_version < ELM_CONFIG_VERSION)
443           _config_update();
444         return;
445      }
446
447    /* no user config, fallback for system. No need to check version for
448     * this one, if it's not the right one, someone screwed up at the time
449     * of installing it */
450    _elm_config = _config_system_load();
451    if (_elm_config) return;
452    /* FIXME: config load could have failed because of a non-existent
453     * profile. Fallback to default before moving on */
454
455    // config load fail - defaults
456    /* XXX: do these make sense? Only if it's valid to install the lib
457     * without the config, but do we want that? */
458    _elm_config = ELM_NEW(Elm_Config);
459    _elm_config->config_version = ELM_CONFIG_VERSION;
460    _elm_config->engine = ELM_SOFTWARE_X11;
461    _elm_config->thumbscroll_enable = 1;
462    _elm_config->thumbscroll_threshhold = 24;
463    _elm_config->thumbscroll_momentum_threshhold = 100.0;
464    _elm_config->thumbscroll_friction = 1.0;
465    _elm_config->thumbscroll_bounce_friction = 0.5;
466    _elm_config->page_scroll_friction = 0.5;
467    _elm_config->bring_in_scroll_friction = 0.5;
468    _elm_config->zoom_friction = 0.5;
469    _elm_config->thumbscroll_bounce_enable = 1;
470    _elm_config->scale = 1.0;
471    _elm_config->bgpixmap = 0;
472    _elm_config->font_hinting = 2;
473    _elm_config->font_dirs = NULL;
474    _elm_config->image_cache = 4096;
475    _elm_config->font_cache = 512;
476    _elm_config->finger_size = 40;
477    _elm_config->compositing = 1;
478    _elm_config->fps = 60.0;
479    _elm_config->theme = eina_stringshare_add("default");
480    _elm_config->modules = NULL;
481    _elm_config->password_show_last_character = 0;
482    _elm_config->longpress_timeout = 1.0;
483 }
484 static void
485 _config_update(void)
486 {
487    Elm_Config *tcfg;
488    tcfg = _config_system_load();
489    if (!tcfg)
490      {
491         return;
492      }
493 #define IFCFG(v) if ((_elm_config->config_version & 0xffff) < (v)) {
494 #define IFCFGELSE } else {
495 #define IFCFGEND }
496 #define COPYVAL(x) do {_elm_config->x = tcfg->x;} while(0)
497 #define COPYPTR(x) do {_elm_config->x = tcfg->x; tcfg->x = NULL; } while(0)
498 #define COPYSTR(x) COPYPTR(x)
499
500    /* we also need to update for property changes in the root window
501     * if needed, but that will be dependant on new properties added
502     * with each version */
503
504    /* nothing here, just an example */
505    /*
506    IFCFG(0x0002);
507    COPYVAL(some_value);
508    IFCFGEND;
509    */
510
511 #undef COPYSTR
512 #undef COPYPTR
513 #undef COPYVAL
514 #undef IFCFGEND
515 #undef IFCFGELSE
516 #undef IFCFG
517
518    /* after updating user config, we must save */
519 }
520
521 static void
522 _env_get(void)
523 {
524    char *s;
525    
526    s = getenv("ELM_ENGINE");
527    if (s)
528      {
529         if ((!strcasecmp(s, "x11")) ||
530             (!strcasecmp(s, "x")) ||
531             (!strcasecmp(s, "software-x11")) ||
532             (!strcasecmp(s, "software_x11")))
533           _elm_config->engine = ELM_SOFTWARE_X11;
534         else if ((!strcasecmp(s, "x11-16")) ||
535                  (!strcasecmp(s, "x16")) ||
536                  (!strcasecmp(s, "software-16-x11")) ||
537                  (!strcasecmp(s, "software_16_x11")))
538           _elm_config->engine = ELM_SOFTWARE_16_X11;
539         else if ((!strcasecmp(s, "xrender")) ||
540                  (!strcasecmp(s, "xr")) ||
541                  (!strcasecmp(s, "xrender-x11")) ||
542                  (!strcasecmp(s, "xrender_x11")))
543           _elm_config->engine = ELM_XRENDER_X11;
544         else if ((!strcasecmp(s, "fb")) ||
545                  (!strcasecmp(s, "software-fb")) ||
546                  (!strcasecmp(s, "software_fb")))
547           _elm_config->engine = ELM_SOFTWARE_FB;
548         else if ((!strcasecmp(s, "directfb")) ||
549                  (!strcasecmp(s, "dfb")))
550           _elm_config->engine = ELM_SOFTWARE_DIRECTFB;
551         else if ((!strcasecmp(s, "sdl")) ||
552                  (!strcasecmp(s, "software-sdl")) ||
553                  (!strcasecmp(s, "software_sdl")))
554           _elm_config->engine = ELM_SOFTWARE_SDL;
555         else if ((!strcasecmp(s, "sdl-16")) ||
556                  (!strcasecmp(s, "software-16-sdl")) ||
557                  (!strcasecmp(s, "software_16_sdl")))
558           _elm_config->engine = ELM_SOFTWARE_16_SDL;
559         else if ((!strcasecmp(s, "opengl")) ||
560                  (!strcasecmp(s, "gl")) ||
561                  (!strcasecmp(s, "opengl-x11")) ||
562                  (!strcasecmp(s, "opengl_x11")))
563           _elm_config->engine = ELM_OPENGL_X11;
564         else if ((!strcasecmp(s, "opengl-sdl")) ||
565                  (!strcasecmp(s, "opengl_sdl")) ||
566                  (!strcasecmp(s, "gl-sdl")) ||
567                  (!strcasecmp(s, "gl_sdl")))
568           _elm_config->engine = ELM_OPENGL_SDL;
569         else if ((!strcasecmp(s, "gdi")) ||
570                  (!strcasecmp(s, "software-gdi")) ||
571                  (!strcasecmp(s, "software_gdi")))
572           _elm_config->engine = ELM_SOFTWARE_WIN32;
573         else if ((!strcasecmp(s, "wince-gdi")) ||
574                  (!strcasecmp(s, "software-16-wince-gdi")) ||
575                  (!strcasecmp(s, "software_16_wince_gdi")))
576           _elm_config->engine = ELM_SOFTWARE_16_WINCE;
577      }
578
579    s = getenv("ELM_THUMBSCROLL_ENABLE");
580    if (s) _elm_config->thumbscroll_enable = atoi(s);
581    s = getenv("ELM_THUMBSCROLL_THRESHOLD");
582    if (s) _elm_config->thumbscroll_threshhold = atoi(s);
583    // FIXME: floatformat locale issues here 1.0 vs 1,0 - should just be 1.0
584    s = getenv("ELM_THUMBSCROLL_MOMENTUM_THRESHOLD");
585    if (s) _elm_config->thumbscroll_momentum_threshhold = atof(s);
586    s = getenv("ELM_THUMBSCROLL_FRICTION");
587    if (s) _elm_config->thumbscroll_friction = atof(s);
588    s = getenv("ELM_PAGE_SCROLL_FRICTION");
589    if (s) _elm_config->page_scroll_friction = atof(s);
590    s = getenv("ELM_BRING_IN_SCROLL_FRICTION");
591    if (s) _elm_config->bring_in_scroll_friction = atof(s);
592    s = getenv("ELM_ZOOM_FRICTION");
593    if (s) _elm_config->zoom_friction = atof(s);
594    s = getenv("ELM_THUMBSCROLL_BOUNCE_FRICTION");
595    if (s) _elm_config->thumbscroll_bounce_friction = atof(s);
596
597    s = getenv("ELM_THEME");
598    if (s) eina_stringshare_replace(&_elm_config->theme, s);
599
600    s = getenv("ELM_FONT_HINTING");
601    if (s)
602      {
603         if      (!strcasecmp(s, "none"))     _elm_config->font_hinting = 0;
604         else if (!strcasecmp(s, "auto"))     _elm_config->font_hinting = 1;
605         else if (!strcasecmp(s, "bytecode")) _elm_config->font_hinting = 2;
606      }
607
608    s = getenv("ELM_FONT_PATH");
609    if (s)
610      {
611         const char *p, *pp;
612         char *buf2;
613
614         EINA_LIST_FREE(_elm_config->font_dirs, p)
615           {
616              eina_stringshare_del(p);
617           }
618         
619         buf2 = alloca(strlen(s) + 1);
620         p = s;
621         pp = p;
622         for (;;)
623           {
624              if ((*p == ':') || (*p == 0))
625                {
626                   int len;
627
628                   len = p - pp;
629                   strncpy(buf2, pp, len);
630                   buf2[len] = 0;
631                   _elm_config->font_dirs = 
632                     eina_list_append(_elm_config->font_dirs, 
633                                      eina_stringshare_add(buf2));
634                   if (*p == 0) break;
635                   p++;
636                   pp = p;
637                }
638              else
639                {
640                   if (*p == 0) break;
641                   p++;
642                }
643           }
644      }
645
646    s = getenv("ELM_IMAGE_CACHE");
647    if (s) _elm_config->image_cache = atoi(s);
648
649    s = getenv("ELM_FONT_CACHE");
650    if (s) _elm_config->font_cache = atoi(s);
651
652    s = getenv("ELM_SCALE");
653    if (s) _elm_config->scale = atof(s);
654    
655    _elm_config->finger_size = (double)_elm_config->finger_size * _elm_config->scale;
656    s = getenv("ELM_FINGER_SIZE");
657    if (s) _elm_config->finger_size = atoi(s);
658
659    s = getenv("ELM_PASSWORD_SHOW_LAST_CHARACTER");
660    if (s) _elm_config->password_show_last_character = atoi(s);
661
662    s = getenv("ELM_FPS");
663    if (s) _elm_config->fps = atof(s);
664    if (_elm_config->fps < 1.0) _elm_config->fps = 1.0;
665
666    s = getenv("ELM_MODULES");
667    if (s) eina_stringshare_replace(&_elm_config->modules, s);
668
669    s = getenv("ELM_INPUT_PANEL");
670    if (s) _elm_config->input_panel_enable = atoi(s);
671
672    s = getenv("ELM_LONGPRESS_TIMEOUT");
673    if (s) _elm_config->longpress_timeout = atof(s);
674    if (_elm_config->longpress_timeout < 0.0) _elm_config->longpress_timeout = 0.0;
675 }
676
677 void
678 _elm_config_init(void)
679 {
680    _desc_init();
681    _profile_get();
682    _config_load();
683 }
684
685 void
686 _elm_config_sub_init(void)
687 {
688    _env_get();
689    _config_apply();
690    if ((_elm_config->engine == ELM_SOFTWARE_X11) ||
691        (_elm_config->engine == ELM_SOFTWARE_16_X11) ||
692        (_elm_config->engine == ELM_XRENDER_X11) ||
693        (_elm_config->engine == ELM_OPENGL_X11))
694      {
695 #ifdef HAVE_ELEMENTARY_X
696         unsigned int val = 1000;
697
698         if (!ecore_x_init(NULL))
699           {
700              ERR("Cannot connect to X11 display. check $DISPLAY variable");
701              exit(1);
702           }
703         _root_1st = ecore_x_window_root_first_get();
704         
705         if (!ecore_x_screen_is_composited(0))
706           _elm_config->compositing = 0;
707
708         ecore_x_atoms_get(_atom_names, ATOM_COUNT, _atom);
709         ecore_x_event_mask_set(_root_1st,
710                                ECORE_X_EVENT_MASK_WINDOW_PROPERTY);
711         _prop_change_handler = ecore_event_handler_add
712           (ECORE_X_EVENT_WINDOW_PROPERTY, _prop_change, NULL);
713         if (!getenv("ELM_SCALE"))
714           {
715              if (ecore_x_window_prop_card32_get(_root_1st,
716                                                 _atom[ATOM_E_SCALE],
717                                                 &val, 1) > 0)
718                {
719                   if (val > 0)
720                     {
721                        _elm_config->scale = (double)val / 1000.0;
722                        // FIXME: hack until e export finger size too
723                        if (!getenv("ELM_FINGER_SIZE"))
724                          _elm_config->finger_size = 40.0 * _elm_config->scale;
725                        edje_scale_set(_elm_config->scale);
726                     }
727                }
728           }
729         if (!getenv("ELM_FINGER_SIZE"))
730           {
731              if (ecore_x_window_prop_card32_get(_root_1st,
732                                                 _atom[ATOM_E_FINGER_SIZE],
733                                                 &val, 1) > 0)
734                {
735                   if (val > 0)
736                     {
737                        _elm_config->finger_size = val;
738                     }
739                }
740           }
741         if (!getenv("ELM_THEME"))
742           {
743              char *s;
744              
745              s = ecore_x_window_prop_string_get(_root_1st,
746                                                 _atom[ATOM_E_THEME]);
747              if (s)
748                {
749                   eina_stringshare_replace(&_elm_config->theme, s);
750                   _elm_theme_parse(NULL, s);
751                   free(s);
752                }
753           }
754         if (!getenv("ELM_PROFILE"))
755           {
756              char *s;
757              
758              s = ecore_x_window_prop_string_get(_root_1st,
759                                                 _atom[ATOM_E_PROFILE]);
760              if (s)
761                {
762                   int changed = 0;
763                   
764                   if (_elm_profile)
765                     {
766                        if (strcmp(_elm_profile, s)) changed = 1;
767                        free(_elm_profile);
768                     }
769                   _elm_profile = s;
770                   if (changed) _prop_config_get();
771                }
772           }
773         if (!getenv("ELM_INPUT_PANEL"))
774           {
775              if (ecore_x_window_prop_card32_get(_root_1st,
776                                                 _atom[ATOM_E_INPUT_PANEL],
777                                                 &val, 1) > 0)
778                {
779                   if (val > 0)
780                     {
781                        _elm_config->input_panel_enable = val;
782                        edje_input_panel_enabled_set(_elm_config->input_panel_enable);
783                     }
784                }
785           }
786         if (ecore_x_window_prop_card32_get(_root_1st,
787                                            _atom[ATOM_E_AUTOCAPITAL_ALLOW],
788                                            &val, 1) > 0)
789           {
790              if (val > 0)
791                {
792                   _elm_config->autocapital_allow = val;
793                   edje_autocapitalization_allow_set(_elm_config->autocapital_allow);
794                }
795           }
796         if (ecore_x_window_prop_card32_get(_root_1st,
797                                            _atom[ATOM_E_AUTOPERIOD_ALLOW],
798                                            &val, 1) > 0)
799           {
800              if (val > 0)
801                {
802                   _elm_config->autoperiod_allow = val;
803                   edje_autoperiod_allow_set(_elm_config->autoperiod_allow);
804                }
805           }
806 #endif
807       }
808    _config_sub_apply();
809 }
810
811 void
812 _elm_config_shutdown(void)
813 {
814    if ((_elm_config->engine == ELM_SOFTWARE_X11) ||
815        (_elm_config->engine == ELM_SOFTWARE_16_X11) ||
816        (_elm_config->engine == ELM_XRENDER_X11) ||
817        (_elm_config->engine == ELM_OPENGL_X11) ||
818        (_elm_config->engine == ELM_SOFTWARE_SDL) ||
819        (_elm_config->engine == ELM_SOFTWARE_16_SDL) ||
820        (_elm_config->engine == ELM_OPENGL_SDL) ||
821        (_elm_config->engine == ELM_SOFTWARE_WIN32) ||
822        (_elm_config->engine == ELM_SOFTWARE_16_WINCE))
823      {
824 #ifdef HAVE_ELEMENTARY_X
825         ecore_event_handler_del(_prop_change_handler);
826         _prop_change_handler = NULL;
827 #endif
828      }
829    _config_free();
830    if (_elm_profile)
831      {
832         free(_elm_profile);
833         _elm_profile = NULL;
834      }
835    _desc_shutdown();
836 }
837
838 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/