quick-init: delayed to init edje, efreet, e_pointer
[platform/upstream/enlightenment.git] / src / bin / e_main.c
1 #include "e.h"
2 #ifdef __linux__
3 # include <sys/prctl.h>
4 #endif
5
6 #define MAX_LEVEL 80
7
8 #define TS_DO
9 #ifdef TS_DO
10 # define TS(x)                                                    \
11   {                                                               \
12      t1 = ecore_time_unix_get();                                  \
13      printf("ESTART: %1.5f [%1.5f] - %s\n", t1 - t0, t1 - t2, x); \
14      t2 = t1;                                                     \
15   }
16 static double t0, t1, t2;
17 #else
18 # define TS(x)
19 #endif
20
21 /*
22  * i need to make more use of these when i'm baffled as to when something is
23  * up. other hooks:
24  *
25  *      void *(*__malloc_hook)(size_t size, const void *caller);
26  *
27  *      void *(*__realloc_hook)(void *ptr, size_t size, const void *caller);
28  *
29  *      void *(*__memalign_hook)(size_t alignment, size_t size,
30  *                               const void *caller);
31  *
32  *      void (*__free_hook)(void *ptr, const void *caller);
33  *
34  *      void (*__malloc_initialize_hook)(void);
35  *
36  *      void (*__after_morecore_hook)(void);
37  *
38
39    static void my_init_hook(void);
40    static void my_free_hook(void *p, const void *caller);
41
42    static void (*old_free_hook)(void *ptr, const void *caller) = NULL;
43    void (*__free_hook)(void *ptr, const void *caller);
44
45    void (*__malloc_initialize_hook) (void) = my_init_hook;
46    static void
47    my_init_hook(void)
48    {
49    old_free_hook = __free_hook;
50    __free_hook = my_free_hook;
51    }
52
53    //void *magicfree = NULL;
54
55    static void
56    my_free_hook(void *p, const void *caller)
57    {
58    __free_hook = old_free_hook;
59    //   if ((p) && (p == magicfree))
60    //     {
61    //   printf("CAUGHT!!!!! %p ...\n", p);
62    //   abort();
63    //     }
64    free(p);
65    __free_hook = my_free_hook;
66    }
67  */
68
69 /* local function prototypes */
70 static void      _e_main_shutdown(int errcode);
71 static void      _e_main_shutdown_push(int (*func)(void));
72 static void      _e_main_parse_arguments(int argc, char **argv);
73 static Eina_Bool _e_main_cb_signal_exit(void *data __UNUSED__, int ev_type __UNUSED__, void *ev __UNUSED__);
74 static Eina_Bool _e_main_cb_signal_hup(void *data __UNUSED__, int ev_type __UNUSED__, void *ev __UNUSED__);
75 static Eina_Bool _e_main_cb_signal_user(void *data __UNUSED__, int ev_type __UNUSED__, void *ev);
76 static int       _e_main_dirs_init(void);
77 static int       _e_main_dirs_shutdown(void);
78 static int       _e_main_path_init(void);
79 static int       _e_main_path_shutdown(void);
80 static void      _e_main_test_formats(void);
81 static int       _e_main_screens_init(void);
82 static int       _e_main_screens_shutdown(void);
83 static void      _e_main_desk_save(void);
84 static void      _e_main_desk_restore(void);
85 static void      _e_main_efreet_paths_init(void);
86 static void      _e_main_modules_load(Eina_Bool safe_mode);
87 static Eina_Bool _e_main_cb_idle_before(void *data __UNUSED__);
88 static Eina_Bool _e_main_cb_idle_after(void *data __UNUSED__);
89 static Eina_Bool _e_main_cb_startup_fake_end(void *data __UNUSED__);
90
91 /* local variables */
92 static Eina_Bool really_know = EINA_FALSE;
93 static Eina_Bool locked = EINA_FALSE;
94 static Eina_Bool inloop = EINA_FALSE;
95 static jmp_buf x_fatal_buff;
96
97 static int _e_main_lvl = 0;
98 static int(*_e_main_shutdown_func[MAX_LEVEL]) (void);
99
100 static Ecore_Idle_Enterer *_idle_before = NULL;
101 static Ecore_Idle_Enterer *_idle_after = NULL;
102
103 static Ecore_Event_Handler *mod_init_end = NULL;
104
105 /* external variables */
106 EAPI Eina_Bool e_precache_end = EINA_FALSE;
107 EAPI Eina_Bool x_fatal = EINA_FALSE;
108 EAPI Eina_Bool good = EINA_FALSE;
109 EAPI Eina_Bool evil = EINA_FALSE;
110 EAPI Eina_Bool starting = EINA_TRUE;
111 EAPI Eina_Bool stopping = EINA_FALSE;
112 EAPI Eina_Bool restart = EINA_FALSE;
113 EAPI Eina_Bool e_nopause = EINA_FALSE;
114 EINTERN const char *e_first_frame = NULL;
115 EINTERN double e_first_frame_start_time = -1;
116
117 static Eina_Bool
118 _xdg_check_str(const char *env, const char *str)
119 {
120    const char *p;
121    size_t len;
122
123    len = strlen(str);
124    for (p = strstr(env, str); p; p++, p = strstr(p, str))
125      {
126         if ((!p[len]) || (p[len] == ':')) return EINA_TRUE;
127      }
128    return EINA_FALSE;
129 }
130
131 static void
132 _xdg_data_dirs_augment(void)
133 {
134    const char *s;
135    const char *p = e_prefix_get();
136    char newpath[4096], buf[4096];
137
138    if (!p) return;
139
140    s = getenv("XDG_DATA_DIRS");
141    if (s)
142      {
143         Eina_Bool pfxdata, pfx;
144
145         pfxdata = !_xdg_check_str(s, e_prefix_data_get());
146         snprintf(newpath, sizeof(newpath), "%s/share", p);
147         pfx = !_xdg_check_str(s, newpath);
148         if (pfxdata || pfx)
149           {
150              snprintf(buf, sizeof(buf), "%s%s%s%s%s",
151                pfxdata ? e_prefix_data_get() : "",
152                pfxdata ? ":" : "",
153                pfx ? newpath : "",
154                pfx ? ":" : "",
155                s);
156              e_util_env_set("XDG_DATA_DIRS", buf);
157           }
158      }
159    else
160      {
161         snprintf(buf, sizeof(buf), "%s:%s/share:/usr/local/share:/usr/share", e_prefix_data_get(), p);
162         e_util_env_set("XDG_DATA_DIRS", buf);
163      }
164
165    s = getenv("XDG_CONFIG_DIRS");
166    snprintf(newpath, sizeof(newpath), "%s/etc/xdg", p);
167    if (s)
168      {
169         if (!_xdg_check_str(s, newpath))
170           {
171              snprintf(buf, sizeof(buf), "%s:%s", newpath, s);
172              e_util_env_set("XDG_CONFIG_DIRS", buf);
173           }
174      }
175    else
176      {
177         snprintf(buf, sizeof(buf), "%s:/etc/xdg", newpath);
178         e_util_env_set("XDG_CONFIG_DIRS", buf);
179      }
180
181    if (!getenv("XDG_RUNTIME_DIR"))
182      {
183         const char *dir;
184
185         snprintf(buf, sizeof(buf), "/tmp/xdg-XXXXXX");
186         dir = mkdtemp(buf);
187         if (!dir) dir = "/tmp";
188         else
189           {
190              e_util_env_set("XDG_RUNTIME_DIR", dir);
191              snprintf(buf, sizeof(buf), "%s/.e-deleteme", dir);
192              ecore_file_mkdir(buf);
193           }
194      }
195
196    /* set menu prefix so we get our e menu */
197    if (!getenv("XDG_MENU_PREFIX"))
198      {
199         e_util_env_set("XDG_MENU_PREFIX", "e-");
200      }
201 }
202
203 #ifndef ENABLE_QUICK_INIT
204 static Eina_Bool
205 _e_main_shelf_init_job(void *data EINA_UNUSED)
206 {
207    e_shelf_config_update();
208    return ECORE_CALLBACK_CANCEL;
209 }
210 #else
211 static Eina_Bool
212 _e_main_subsystem_defer(void *data EINA_UNUSED)
213 {
214    int argc;
215    char **argv;
216
217    ecore_app_args_get(&argc, &argv);
218
219    /* try to init delayed subsystems */
220    TS("[DEFERRED] Elementary Init");
221    if (!elm_init(argc, argv))
222      {
223         e_error_message_show(_("Enlightenment cannot initialize Elementary!\n"));
224         _e_main_shutdown(-1);
225      }
226    TS("[DEFERRED] Elementary Init Done");
227
228    TS("[DEFERRED] Edje Init");
229    if (!edje_init())
230      {
231         e_error_message_show(_("Enlightenment cannot initialize Edje!\n"));
232         _e_main_shutdown(-1);
233      }
234    TS("[DEFERRED] Edje Init Done");
235    _e_main_shutdown_push(edje_shutdown);
236
237    TS("[DEFERRED] Efreet Init");
238    if (!efreet_init())
239      {
240         e_error_message_show(_("Enlightenment cannot initialize the FDO desktop system.\n"
241                                "Perhaps you lack permissions on ~/.cache/efreet or are\n"
242                                "out of memory or disk space?"));
243         _e_main_shutdown(-1);
244      }
245    TS("[DEFERRED] Efreet Init Done");
246    _e_main_shutdown_push(efreet_shutdown);
247
248    TS("[DEFERRED] Screens Init: win");
249    if (!e_win_init())
250      {
251         e_error_message_show(_("Enlightenment cannot setup elementary trap!\n"));
252         _e_main_shutdown(-1);
253      }
254    TS("[DEFERRED] Screens Init: win Done");
255
256    TS("[DEFERRED] E_Pointer Init");
257    if (!e_pointer_init())
258      {
259         e_error_message_show(_("Enlightenment cannot set up its pointer system.\n"));
260         _e_main_shutdown(-1);
261      }
262
263    TS("[DEFERRED] E_Pointer Init Done");
264    _e_main_shutdown_push(e_pointer_shutdown);
265
266    TS("[DEFERRED] E_Scale Init");
267    if (!e_scale_init())
268      {
269         e_error_message_show(_("Enlightenment cannot set up its scale system.\n"));
270         _e_main_shutdown(-1);
271      }
272    TS("[DEFERRED E_Scale Init Done");
273    _e_main_shutdown_push(e_scale_shutdown);
274
275    TS("[DEFERRED] Efreet Paths");
276    _e_main_efreet_paths_init();
277    TS("[DEFERRED] Efreet Paths Done");
278
279    TS("[DEFERRED] E_Test_Helper Init");
280    e_test_helper_init();
281    _e_main_shutdown_push(e_test_helper_shutdown);
282    TS("[DEFERRED] E_Test_Helper Done");
283
284    TS("[DEFERRED] E_INFO_SERVER Init");
285    e_info_server_init();
286    _e_main_shutdown_push(e_info_server_shutdown);
287    TS("[DEFERRED] E_INFO_SERVER Done");
288
289    /* try to do deferred job of any subsystems*/
290    TS("[DEFERRED] Compositor's deferred job");
291    e_comp_deferred_job();
292    TS("[DEFERRED] Compositor's deferred job Done");
293
294    TS("[DEFERRED] E_Module's deferred job");
295    e_module_deferred_job();
296    TS("[DEFERRED] E_Module's deferred job Done");
297
298    return ECORE_CALLBACK_DONE;
299 }
300
301 static Eina_Bool
302 _e_main_deferred_job_schedule(void *d EINA_UNUSED, int type EINA_UNUSED, void *ev EINA_UNUSED)
303 {
304    ecore_idler_add(_e_main_subsystem_defer, NULL);
305    return ECORE_CALLBACK_DONE;
306 }
307
308 #endif
309
310 /* externally accessible functions */
311 int
312 main(int argc, char **argv)
313 {
314    Eina_Bool nostartup = EINA_FALSE;
315    Eina_Bool safe_mode = EINA_FALSE;
316    Eina_Bool after_restart = EINA_FALSE;
317    Eina_Bool waslocked = EINA_FALSE;
318    double t = 0.0, tstart = 0.0;
319    char *s = NULL, buff[32];
320    struct sigaction action;
321
322 #ifdef __linux__
323 # ifdef PR_SET_PTRACER
324 #  ifdef PR_SET_PTRACER_ANY
325    prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY);
326 #  endif
327 # endif
328 #endif
329    
330 #ifdef TS_DO
331    t0 = t1 = t2 = ecore_time_unix_get();
332 #endif
333    TS("Begin Startup");
334
335    /* trap deadly bug signals and allow some form of sane recovery */
336    /* or ability to gdb attach and debug at this point - better than your */
337    /* wm/desktop vanishing and not knowing what happened */
338    if (!getenv("NOTIFY_SOCKET"))
339      {
340         TS("Signal Trap");
341         action.sa_sigaction = e_sigseg_act;
342         action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
343         sigemptyset(&action.sa_mask);
344         sigaction(SIGSEGV, &action, NULL);
345
346         action.sa_sigaction = e_sigill_act;
347         action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
348         sigemptyset(&action.sa_mask);
349         sigaction(SIGILL, &action, NULL);
350
351         action.sa_sigaction = e_sigfpe_act;
352         action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
353         sigemptyset(&action.sa_mask);
354         sigaction(SIGFPE, &action, NULL);
355
356 #ifndef HAVE_WAYLAND_ONLY
357         action.sa_sigaction = e_sigbus_act;
358         action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
359         sigemptyset(&action.sa_mask);
360         sigaction(SIGBUS, &action, NULL);
361 #endif
362
363         action.sa_sigaction = e_sigabrt_act;
364         action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
365         sigemptyset(&action.sa_mask);
366         sigaction(SIGABRT, &action, NULL);
367         TS("Signal Trap Done");
368      }
369
370    t = ecore_time_unix_get();
371    s = getenv("E_START_TIME");
372    if ((s) && (!getenv("E_RESTART_OK")))
373      {
374         tstart = atof(s);
375         if ((t - tstart) < 5.0) safe_mode = EINA_TRUE;
376      }
377    tstart = t;
378    snprintf(buff, sizeof(buff), "%1.1f", tstart);
379    e_util_env_set("E_START_TIME", buff);
380
381    if (getenv("E_START_MTRACK"))
382      e_util_env_set("MTRACK", NULL);
383    TS("Eina Init");
384    if (!eina_init())
385      {
386         e_error_message_show(_("Enlightenment cannot initialize Eina!\n"));
387         _e_main_shutdown(-1);
388      }
389    _e_main_shutdown_push(eina_shutdown);
390 #ifdef OBJECT_HASH_CHECK
391    e_object_hash_init();
392 #endif
393    if (!e_log_init())
394      {
395         e_error_message_show(_("Enlightenment could not create a logging domain!\n"));
396         _e_main_shutdown(-1);
397      }
398 #ifdef TS_DO
399 #undef TS
400 # define TS(x)                                                    \
401   {                                                               \
402      t1 = ecore_time_unix_get();                                  \
403      printf("ESTART: %1.5f [%1.5f] - %s\n", t1 - t0, t1 - t2, x); \
404      t2 = t1;                                                     \
405   }
406 #endif
407    TS("Eina Init Done");
408    _e_main_shutdown_push(e_log_shutdown);
409
410    TS("Determine Prefix");
411    if (!e_prefix_determine(argv[0]))
412      {
413         fprintf(stderr,
414                 "ERROR: Enlightenment cannot determine it's installed\n"
415                 "       prefix from the system or argv[0].\n"
416                 "       This is because it is not on Linux AND has been\n"
417                 "       executed strangely. This is unusual.\n");
418      }
419    TS("Determine Prefix Done");
420
421    /* for debugging by redirecting stdout of e to a log file to tail */
422    setvbuf(stdout, NULL, _IONBF, 0);
423
424    TS("Environment Variables");
425    if (getenv("E_RESTART")) after_restart = EINA_TRUE;
426    if (getenv("DESKTOP_STARTUP_ID"))
427      e_util_env_set("DESKTOP_STARTUP_ID", NULL);
428    e_util_env_set("E_RESTART_OK", NULL);
429    e_util_env_set("PANTS", "ON");
430    e_util_env_set("DESKTOP", "Enlightenment-0.17.0");
431    TS("Environment Variables Done");
432
433    TS("Parse Arguments");
434    _e_main_parse_arguments(argc, argv);
435    TS("Parse Arguments Done");
436
437    /*** Initialize Core EFL Libraries We Need ***/
438
439    TS("Eet Init");
440    if (!eet_init())
441      {
442         e_error_message_show(_("Enlightenment cannot initialize Eet!\n"));
443         _e_main_shutdown(-1);
444      }
445    TS("Eet Init Done");
446    _e_main_shutdown_push(eet_shutdown);
447
448    TS("Ecore Init");
449    if (!ecore_init())
450      {
451         e_error_message_show(_("Enlightenment cannot initialize Ecore!\n"));
452         _e_main_shutdown(-1);
453      }
454    TS("Ecore Init Done");
455    _e_main_shutdown_push(ecore_shutdown);
456
457    e_first_frame = getenv("E_FIRST_FRAME");
458    if (e_first_frame && (!e_first_frame[0]))
459      e_first_frame = NULL;
460    else
461      e_first_frame_start_time = ecore_time_get();
462
463    TS("EIO Init");
464    if (!eio_init())
465      {
466         e_error_message_show(_("Enlightenment cannot initialize EIO!\n"));
467         _e_main_shutdown(-1);
468      }
469    TS("EIO Init Done");
470    _e_main_shutdown_push(eio_shutdown);
471
472    ecore_app_args_set(argc, (const char **)argv);
473
474    TS("Ecore Event Handlers");
475    if (!ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT,
476                                 _e_main_cb_signal_exit, NULL))
477      {
478         e_error_message_show(_("Enlightenment cannot set up an exit signal handler.\n"
479                                "Perhaps you are out of memory?"));
480         _e_main_shutdown(-1);
481      }
482    if (!ecore_event_handler_add(ECORE_EVENT_SIGNAL_HUP,
483                                 _e_main_cb_signal_hup, NULL))
484      {
485         e_error_message_show(_("Enlightenment cannot set up a HUP signal handler.\n"
486                                "Perhaps you are out of memory?"));
487         _e_main_shutdown(-1);
488      }
489    if (!ecore_event_handler_add(ECORE_EVENT_SIGNAL_USER,
490                                 _e_main_cb_signal_user, NULL))
491      {
492         e_error_message_show(_("Enlightenment cannot set up a USER signal handler.\n"
493                                "Perhaps you are out of memory?"));
494         _e_main_shutdown(-1);
495      }
496    TS("Ecore Event Handlers Done");
497
498    TS("Ecore_File Init");
499    if (!ecore_file_init())
500      {
501         e_error_message_show(_("Enlightenment cannot initialize Ecore_File!\n"));
502         _e_main_shutdown(-1);
503      }
504    TS("Ecore_File Init Done");
505    _e_main_shutdown_push(ecore_file_shutdown);
506
507 #ifndef ENABLE_QUICK_INIT
508    TS("Ecore_Con Init");
509    if (!ecore_con_init())
510      {
511         e_error_message_show(_("Enlightenment cannot initialize Ecore_Con!\n"));
512         _e_main_shutdown(-1);
513      }
514    TS("Ecore_Con Init Done");
515    _e_main_shutdown_push(ecore_con_shutdown);
516
517    TS("Ecore_Ipc Init");
518    if (!ecore_ipc_init())
519      {
520         e_error_message_show(_("Enlightenment cannot initialize Ecore_Ipc!\n"));
521         _e_main_shutdown(-1);
522      }
523    TS("Ecore_Ipc Init Done");
524    _e_main_shutdown_push(ecore_ipc_shutdown);
525
526    _idle_before = ecore_idle_enterer_before_add(_e_main_cb_idle_before, NULL);
527
528    _xdg_data_dirs_augment();
529
530    TS("Ecore_Evas Init");
531    if (!ecore_evas_init())
532      {
533         e_error_message_show(_("Enlightenment cannot initialize Ecore_Evas!\n"));
534         _e_main_shutdown(-1);
535      }
536    TS("Ecore_Evas Init Done");
537 //   _e_main_shutdown_push(ecore_evas_shutdown);
538
539    TS("Elementary Init");
540    if (!elm_init(argc, argv))
541      {
542         e_error_message_show(_("Enlightenment cannot initialize Elementary!\n"));
543         _e_main_shutdown(-1);
544      }
545    TS("Elementary Init Done");
546    //_e_main_shutdown_push(elm_shutdown);
547
548    TS("Emotion Init");
549    if (!emotion_init())
550      {
551         e_error_message_show(_("Enlightenment cannot initialize Emotion!\n"));
552         _e_main_shutdown(-1);
553      }
554    TS("Emotion Init Done");
555    _e_main_shutdown_push((void *)emotion_shutdown);
556
557    /* e doesn't sync to compositor - it should be one */
558    ecore_evas_app_comp_sync_set(0);
559
560    TS("Ecore_Evas Engine Check");
561 #ifdef HAVE_WAYLAND_ONLY
562    if (!ecore_evas_engine_type_supported_get(ECORE_EVAS_ENGINE_WAYLAND_SHM))
563      {
564         e_error_message_show(_("Enlightenment found ecore_evas doesn't support the Wayland SHM\n"
565                                "rendering in Evas. Please check your installation of Evas and\n"
566                                 "Ecore and check they support the Wayland SHM rendering engine."));
567         _e_main_shutdown(-1);
568      }
569 #else
570    if (!ecore_evas_engine_type_supported_get(ECORE_EVAS_ENGINE_SOFTWARE_XCB))
571      {
572         if (!ecore_evas_engine_type_supported_get(ECORE_EVAS_ENGINE_SOFTWARE_XLIB))
573           {
574              e_error_message_show(_("Enlightenment found ecore_evas doesn't support the Software X11\n"
575                                     "rendering in Evas. Please check your installation of Evas and\n"
576                                     "Ecore and check they support the Software X11 rendering engine."));
577              _e_main_shutdown(-1);
578           }
579      }
580 #endif
581    if (!ecore_evas_engine_type_supported_get(ECORE_EVAS_ENGINE_SOFTWARE_BUFFER))
582      {
583         e_error_message_show(_("Enlightenment found ecore_evas doesn't support the Software Buffer\n"
584                                "rendering in Evas. Please check your installation of Evas and\n"
585                                "Ecore and check they support the Software Buffer rendering engine."));
586         _e_main_shutdown(-1);
587      }
588    TS("Ecore_Evas Engine Check Done");
589
590    TS("Edje Init");
591    if (!edje_init())
592      {
593         e_error_message_show(_("Enlightenment cannot initialize Edje!\n"));
594         _e_main_shutdown(-1);
595      }
596    TS("Edje Init Done");
597    _e_main_shutdown_push(edje_shutdown);
598    edje_freeze();
599
600    /*** Initialize E Subsystems We Need ***/
601
602    TS("E Intl Init");
603    if (!e_intl_init())
604      {
605         e_error_message_show(_("Enlightenment cannot initialize E_Intl!\n"));
606         _e_main_shutdown(-1);
607      }
608    TS("E Intl Init Done");
609    _e_main_shutdown_push(e_intl_shutdown);
610
611 #ifndef HAVE_WAYLAND_ONLY
612    /* init white box of death alert */
613    TS("E_Alert Init");
614    if (!e_alert_init())
615      {
616         e_error_message_show(_("Enlightenment cannot initialize its emergency alert system.\n"
617                                "Have you set your DISPLAY variable?"));
618         _e_main_shutdown(-1);
619      }
620    TS("E_Alert Init Done");
621    _e_main_shutdown_push(e_alert_shutdown);
622 #endif
623
624    TS("E_Configure Init");
625    e_configure_init();
626    TS("E_Configure Init Done");
627
628    TS("E Directories Init");
629    /* setup directories we will be using for configurations storage etc. */
630    if (!_e_main_dirs_init())
631      {
632         e_error_message_show(_("Enlightenment cannot create directories in your home directory.\n"
633                                "Perhaps you have no home directory or the disk is full?"));
634         _e_main_shutdown(-1);
635      }
636    TS("E Directories Init Done");
637    _e_main_shutdown_push(_e_main_dirs_shutdown);
638
639    TS("E_Filereg Init");
640    if (!e_filereg_init())
641      {
642         e_error_message_show(_("Enlightenment cannot set up its file registry system.\n"));
643         _e_main_shutdown(-1);
644      }
645    TS("E_Filereg Init Done");
646    _e_main_shutdown_push(e_filereg_shutdown);
647
648    TS("E_Config Init");
649    if (!e_config_init())
650      {
651         e_error_message_show(_("Enlightenment cannot set up its config system.\n"));
652         _e_main_shutdown(-1);
653      }
654    TS("E_Config Init Done");
655    _e_main_shutdown_push(e_config_shutdown);
656
657    TS("E_Env Init");
658    if (!e_env_init())
659      {
660         e_error_message_show(_("Enlightenment cannot set up its environment.\n"));
661         _e_main_shutdown(-1);
662      }
663    TS("E_Env Init Done");
664    _e_main_shutdown_push(e_env_shutdown);
665
666    efreet_desktop_environment_set(e_config->desktop_environment);
667    e_util_env_set("E_ICON_THEME", e_config->icon_theme);
668    ecore_exe_run_priority_set(e_config->priority);
669    locked |= e_config->desklock_start_locked;
670
671    s = getenv("E_DESKLOCK_LOCKED");
672    if ((s) && (!strcmp(s, "locked"))) waslocked = EINA_TRUE;
673
674    TS("E Paths Init");
675    if (!_e_main_path_init())
676      {
677         e_error_message_show(_("Enlightenment cannot set up paths for finding files.\n"
678                                "Perhaps you are out of memory?"));
679         _e_main_shutdown(-1);
680      }
681    TS("E Paths Init Done");
682    _e_main_shutdown_push(_e_main_path_shutdown);
683
684    TS("E_Ipc Init");
685    if (!e_ipc_init()) _e_main_shutdown(-1);
686    TS("E_Ipc Init Done");
687    _e_main_shutdown_push(e_ipc_shutdown);
688
689    edje_frametime_set(1.0 / e_config->framerate);
690
691    TS("E_Font Init");
692    if (!e_font_init())
693      {
694         e_error_message_show(_("Enlightenment cannot set up its font system.\n"));
695         _e_main_shutdown(-1);
696      }
697    TS("E_Font Init Done");
698    _e_main_shutdown_push(e_font_shutdown);
699
700    TS("E_Font Apply");
701    e_font_apply();
702    TS("E_Font Apply Done");
703
704    TS("E_Theme Init");
705    if (!e_theme_init())
706      {
707         e_error_message_show(_("Enlightenment cannot set up its theme system.\n"));
708         _e_main_shutdown(-1);
709      }
710    TS("E_Theme Init Done");
711    _e_main_shutdown_push(e_theme_shutdown);
712
713    TS("E_Moveresize Init");
714    e_moveresize_init();
715    TS("E_Moveresize Init Done");
716    _e_main_shutdown_push(e_moveresize_shutdown);
717
718    if (e_config->show_splash)
719      e_init_status_set(_("Setup Message Bus"));
720    TS("E_Msgbus Init");
721    if (e_msgbus_init())
722      _e_main_shutdown_push(e_msgbus_shutdown);
723    TS("E_Msgbus Init Done");
724
725    TS("Efreet Init");
726    if (!efreet_init())
727      {
728         e_error_message_show(_("Enlightenment cannot initialize the FDO desktop system.\n"
729                                "Perhaps you lack permissions on ~/.cache/efreet or are\n"
730                                "out of memory or disk space?"));
731         _e_main_shutdown(-1);
732      }
733    TS("Efreet Init Done");
734    _e_main_shutdown_push(efreet_shutdown);
735
736    if (e_config->show_splash)
737      e_init_status_set(_("Starting International Support"));
738    TS("E_Intl Post Init");
739    if (!e_intl_post_init())
740      {
741         e_error_message_show(_("Enlightenment cannot set up its intl system.\n"));
742         _e_main_shutdown(-1);
743      }
744    TS("E_Intl Post Init Done");
745    _e_main_shutdown_push(e_intl_post_shutdown);
746
747    e_screensaver_preinit();
748
749    if (e_config->show_splash)
750      e_init_status_set(_("Setup Actions"));
751    TS("E_Actions Init");
752    if (!e_actions_init())
753      {
754         e_error_message_show(_("Enlightenment cannot set up its actions system.\n"));
755         _e_main_shutdown(-1);
756      }
757    TS("E_Actions Init Done");
758    _e_main_shutdown_push(e_actions_shutdown);
759
760    /* these just add event handlers and can't fail
761     * timestamping them is dumb.
762     */
763    e_zone_init();
764    e_desk_init();
765    e_exehist_init();
766
767    if (e_config->show_splash)
768      e_init_status_set(_("Setup Powersave Modes"));
769    TS("E_Powersave Init");
770    if (!e_powersave_init())
771      {
772         e_error_message_show(_("Enlightenment cannot set up its powersave modes.\n"));
773         _e_main_shutdown(-1);
774      }
775    TS("E_Powersave Init Done");
776    _e_main_shutdown_push(e_powersave_shutdown);
777
778    if (e_config->show_splash)
779      e_init_status_set(_("Setup Screensaver"));
780    TS("E_Screensaver Init");
781    if (!e_screensaver_init())
782      {
783         e_error_message_show(_("Enlightenment cannot configure the X screensaver.\n"));
784         _e_main_shutdown(-1);
785      }
786    TS("E_Screensaver Init Done");
787    _e_main_shutdown_push(e_screensaver_shutdown);
788
789    if (e_config->show_splash)
790      e_init_status_set(_("Setup Screens"));
791    TS("Screens Init");
792    if (!_e_main_screens_init())
793      {
794         e_error_message_show(_("Enlightenment set up window management for all the screens on your system\n"
795                                "failed. Perhaps another window manager is running?\n"));
796         _e_main_shutdown(-1);
797      }
798    TS("Screens Init Done");
799    _e_main_shutdown_push(_e_main_screens_shutdown);
800    e_screensaver_force_update();
801
802    TS("E_Pointer Init");
803    if (!e_pointer_init())
804      {
805         e_error_message_show(_("Enlightenment cannot set up its pointer system.\n"));
806         _e_main_shutdown(-1);
807      }
808    TS("E_Pointer Init Done");
809    _e_main_shutdown_push(e_pointer_shutdown);
810    e_menu_init();
811
812    TS("E_Scale Init");
813    if (!e_scale_init())
814      {
815         e_error_message_show(_("Enlightenment cannot set up its scale system.\n"));
816         _e_main_shutdown(-1);
817      }
818    TS("E_Scale Init Done");
819    _e_main_shutdown_push(e_scale_shutdown);
820
821    if (e_config->show_splash)
822      {
823         TS("E_Splash Init");
824         if (!e_init_init())
825           {
826              e_error_message_show(_("Enlightenment cannot set up its init screen.\n"));
827              _e_main_shutdown(-1);
828           }
829         TS("E_Splash Init Done");
830         _e_main_shutdown_push(e_init_shutdown);
831      }
832    if (!((!e_config->show_splash) || (after_restart)))
833      e_init_show();
834
835    if (!really_know)
836      {
837         TS("Test File Format Support");
838         _e_main_test_formats();
839         TS("Test File Format Support Done");
840      }
841    else
842      {
843         efreet_icon_extension_add(".svg");
844         efreet_icon_extension_add(".jpg");
845         efreet_icon_extension_add(".png");
846         efreet_icon_extension_add(".edj");
847      }
848
849    if (e_config->show_splash)
850      e_init_status_set(_("Setup ACPI"));
851    TS("E_Acpi Init");
852    e_acpi_init();
853    TS("E_Acpi Init Done");
854    _e_main_shutdown_push(e_acpi_shutdown);
855
856    if (e_config->show_splash)
857      e_init_status_set(_("Setup Backlight"));
858    TS("E_Backlight Init");
859    if (!e_backlight_init())
860      {
861         e_error_message_show(_("Enlightenment cannot configure the backlight.\n"));
862         _e_main_shutdown(-1);
863      }
864    TS("E_Backlight Init Done");
865
866    if (e_config->show_splash)
867      e_init_status_set(_("Setup DPMS"));
868    TS("E_Dpms Init");
869    if (!e_dpms_init())
870      {
871         e_error_message_show(_("Enlightenment cannot configure the DPMS settings.\n"));
872         _e_main_shutdown(-1);
873      }
874    TS("E_Dpms Init Done");
875    _e_main_shutdown_push(e_dpms_shutdown);
876
877    if (e_config->show_splash)
878      e_init_status_set(_("Setup Desklock"));
879    TS("E_Desklock Init");
880    if (!e_desklock_init())
881      {
882         e_error_message_show(_("Enlightenment cannot set up its desk locking system.\n"));
883         _e_main_shutdown(-1);
884      }
885    TS("E_Desklock Init Done");
886    _e_main_shutdown_push(e_desklock_shutdown);
887
888    if (waslocked || (locked && ((!after_restart) || (!getenv("E_DESKLOCK_UNLOCKED")))))
889      e_desklock_show(EINA_TRUE);
890
891    if (e_config->show_splash)
892      e_init_status_set(_("Setup Paths"));
893    TS("Efreet Paths");
894    _e_main_efreet_paths_init();
895    TS("Efreet Paths Done");
896
897    if (e_config->show_splash)
898      e_init_status_set(_("Setup System Controls"));
899    TS("E_Sys Init");
900    if (!e_sys_init())
901      {
902         e_error_message_show(_("Enlightenment cannot initialize the System Command system.\n"));
903         _e_main_shutdown(-1);
904      }
905    TS("E_Sys Init Done");
906    _e_main_shutdown_push(e_sys_shutdown);
907
908    if (e_config->show_splash)
909      e_init_status_set(_("Setup Execution System"));
910    TS("E_Exec Init");
911    if (!e_exec_init())
912      {
913         e_error_message_show(_("Enlightenment cannot set up its exec system.\n"));
914         _e_main_shutdown(-1);
915      }
916    TS("E_Exec Init Done");
917
918    TS("E_Comp Freeze");
919    e_comp_all_freeze();
920    TS("E_Comp Freeze Done");
921
922    if (e_config->show_splash)
923      e_init_status_set(_("Setup Filemanager"));
924    TS("E_Fm2 Init");
925    if (!e_fm2_init())
926      {
927         e_error_message_show(_("Enlightenment cannot initialize the File manager.\n"));
928         _e_main_shutdown(-1);
929      }
930    TS("E_Fm2 Init Done");
931    _e_main_shutdown_push(e_fm2_shutdown);
932
933    if (e_config->show_splash)
934      e_init_status_set(_("Setup Message System"));
935    TS("E_Msg Init");
936    if (!e_msg_init())
937      {
938         e_error_message_show(_("Enlightenment cannot set up its msg system.\n"));
939         _e_main_shutdown(-1);
940      }
941    TS("E_Msg Init Done");
942    _e_main_shutdown_push(e_msg_shutdown);
943
944    if (e_config->show_splash)
945      e_init_status_set(_("Setup Grab Input Handling"));
946    TS("E_Grabinput Init");
947    if (!e_grabinput_init())
948      {
949         e_error_message_show(_("Enlightenment cannot set up its grab input handling system.\n"));
950         _e_main_shutdown(-1);
951      }
952    TS("E_Grabinput Init Done");
953    _e_main_shutdown_push(e_grabinput_shutdown);
954
955    if (e_config->show_splash)
956      e_init_status_set(_("Setup Modules"));
957    TS("E_Module Init");
958    if (!e_module_init())
959      {
960         e_error_message_show(_("Enlightenment cannot set up its module system.\n"));
961         _e_main_shutdown(-1);
962      }
963    TS("E_Module Init Done");
964    _e_main_shutdown_push(e_module_shutdown);
965
966    if (e_config->show_splash)
967      e_init_status_set(_("Setup Remembers"));
968    TS("E_Remember Init");
969    if (!e_remember_init(after_restart ? E_STARTUP_RESTART : E_STARTUP_START))
970      {
971         e_error_message_show(_("Enlightenment cannot setup remember settings.\n"));
972         _e_main_shutdown(-1);
973      }
974    TS("E_Remember Init Done");
975    _e_main_shutdown_push(e_remember_shutdown);
976
977    if (e_config->show_splash)
978      e_init_status_set(_("Setup Color Classes"));
979    TS("E_Color_Class Init");
980    if (!e_color_class_init())
981      {
982         e_error_message_show(_("Enlightenment cannot set up its color class system.\n"));
983         _e_main_shutdown(-1);
984      }
985    TS("E_Color_Class Init Done");
986    _e_main_shutdown_push(e_color_class_shutdown);
987
988    if (e_config->show_splash)
989      e_init_status_set(_("Setup Gadcon"));
990    TS("E_Gadcon Init");
991    if (!e_gadcon_init())
992      {
993         e_error_message_show(_("Enlightenment cannot set up its gadget control system.\n"));
994         _e_main_shutdown(-1);
995      }
996    TS("E_Gadcon Init Done");
997    _e_main_shutdown_push(e_gadcon_shutdown);
998
999    if (e_config->show_splash)
1000      e_init_status_set(_("Setup Toolbars"));
1001    TS("E_Toolbar Init");
1002    if (!e_toolbar_init())
1003      {
1004         e_error_message_show(_("Enlightenment cannot set up its toolbars.\n"));
1005         _e_main_shutdown(-1);
1006      }
1007    TS("E_Toolbar Init Done");
1008    _e_main_shutdown_push(e_toolbar_shutdown);
1009
1010    if (e_config->show_splash)
1011      e_init_status_set(_("Setup Wallpaper"));
1012    TS("E_Bg Init");
1013    if (!e_bg_init())
1014      {
1015         e_error_message_show(_("Enlightenment cannot set up its desktop background system.\n"));
1016         _e_main_shutdown(-1);
1017      }
1018    TS("E_Bg Init Done");
1019    _e_main_shutdown_push(e_bg_shutdown);
1020
1021    if (e_config->show_splash)
1022      e_init_status_set(_("Setup Mouse"));
1023    TS("E_Mouse Init");
1024    if (!e_mouse_update())
1025      {
1026         e_error_message_show(_("Enlightenment cannot configure the mouse settings.\n"));
1027         _e_main_shutdown(-1);
1028      }
1029    TS("E_Mouse Init Done");
1030
1031    if (e_config->show_splash)
1032      e_init_status_set(_("Setup Bindings"));
1033    TS("E_Bindings Init");
1034    if (!e_bindings_init())
1035      {
1036         e_error_message_show(_("Enlightenment cannot set up its bindings system.\n"));
1037         _e_main_shutdown(-1);
1038      }
1039    TS("E_Bindings Init Done");
1040    _e_main_shutdown_push(e_bindings_shutdown);
1041
1042    if (e_config->show_splash)
1043      e_init_status_set(_("Setup Thumbnailer"));
1044    TS("E_Thumb Init");
1045    if (!e_thumb_init())
1046      {
1047         e_error_message_show(_("Enlightenment cannot initialize the Thumbnailing system.\n"));
1048         _e_main_shutdown(-1);
1049      }
1050    TS("E_Thumb Init Done");
1051    _e_main_shutdown_push(e_thumb_shutdown);
1052
1053    TS("E_Icon Init");
1054    if (!e_icon_init())
1055      {
1056         e_error_message_show(_("Enlightenment cannot initialize the Icon Cache system.\n"));
1057         _e_main_shutdown(-1);
1058      }
1059    TS("E_Icon Init Done");
1060    _e_main_shutdown_push(e_icon_shutdown);
1061
1062    TS("E_Update Init");
1063    if (!e_update_init())
1064      {
1065         e_error_message_show(_("Enlightenment cannot initialize the Update system.\n"));
1066         _e_main_shutdown(-1);
1067      }
1068    TS("E_Update Init Done");
1069    _e_main_shutdown_push(e_update_shutdown);
1070
1071    if (e_config->show_splash)
1072      e_init_status_set(_("Setup Desktop Environment"));
1073    TS("E_Deskenv Init");
1074    if (!e_deskenv_init())
1075      {
1076         e_error_message_show(_("Enlightenment cannot initialize its desktop environment.\n"));
1077         _e_main_shutdown(-1);
1078      }
1079    TS("E_Deskenv Init Done");
1080    _e_main_shutdown_push(e_deskenv_shutdown);
1081
1082    if (e_config->show_splash)
1083      e_init_status_set(_("Setup File Ordering"));
1084    TS("E_Order Init");
1085    if (!e_order_init())
1086      {
1087         e_error_message_show(_("Enlightenment cannot set up its order file system.\n"));
1088         _e_main_shutdown(-1);
1089      }
1090    TS("E_Order Init Done");
1091    _e_main_shutdown_push(e_order_shutdown);
1092
1093    TS("E_Manager Keys Grab");
1094    e_managers_keys_grab();
1095    TS("E_Manager Keys Grab Done");
1096
1097    if (e_config->show_splash)
1098      e_init_status_set(_("Load Modules"));
1099    TS("Load Modules");
1100    _e_main_modules_load(safe_mode);
1101    TS("Load Modules Done");
1102
1103    TS("Run Startup Apps");
1104    if (!nostartup)
1105      {
1106         if (after_restart)
1107           e_startup(E_STARTUP_RESTART);
1108         else
1109           e_startup(E_STARTUP_START);
1110      }
1111    TS("Run Startup Apps Done");
1112
1113    if (e_config->show_splash && (!after_restart))
1114      ecore_timer_add(2.0, _e_main_cb_startup_fake_end, NULL);
1115
1116    TS("E_Comp Thaw");
1117    e_comp_all_thaw();
1118    TS("E_Comp Thaw Done");
1119
1120    TS("E_Test Init");
1121    e_test();
1122    TS("E_Test Done");
1123
1124    TS("E_Test_Helper Init");
1125    e_test_helper_init();
1126    _e_main_shutdown_push(e_test_helper_shutdown);
1127    TS("E_Test_Helper Done");
1128
1129    TS("E_Info_Server Init");
1130    e_info_server_init();
1131    _e_main_shutdown_push(e_info_server_shutdown);
1132    TS("E_Info_Server Done");
1133
1134    if (e_config->show_splash)
1135      e_init_status_set(_("Setup Shelves"));
1136    TS("E_Shelf Init");
1137    if (!e_shelf_init())
1138      {
1139         e_error_message_show(_("Enlightenment cannot set up its module system.\n"));
1140         _e_main_shutdown(-1);
1141      }
1142    TS("E_Shelf Init Done");
1143
1144    ecore_idle_enterer_before_add(_e_main_shelf_init_job, NULL);
1145 #else
1146    _idle_before = ecore_idle_enterer_before_add(_e_main_cb_idle_before, NULL);
1147
1148    _xdg_data_dirs_augment();
1149
1150    TS("Ecore_Evas Init");
1151    if (!ecore_evas_init())
1152      {
1153         e_error_message_show(_("Enlightenment cannot initialize Ecore_Evas!\n"));
1154         _e_main_shutdown(-1);
1155      }
1156    TS("Ecore_Evas Init Done");
1157
1158    /* e doesn't sync to compositor - it should be one */
1159    ecore_evas_app_comp_sync_set(0);
1160
1161    TS("Ecore_Evas Engine Check");
1162 #ifdef HAVE_WAYLAND_ONLY
1163    if (!ecore_evas_engine_type_supported_get(ECORE_EVAS_ENGINE_WAYLAND_SHM))
1164      {
1165         e_error_message_show(_("Enlightenment found ecore_evas doesn't support the Wayland SHM\n"
1166                                "rendering in Evas. Please check your installation of Evas and\n"
1167                                 "Ecore and check they support the Wayland SHM rendering engine."));
1168         _e_main_shutdown(-1);
1169      }
1170 #else
1171    if (!ecore_evas_engine_type_supported_get(ECORE_EVAS_ENGINE_SOFTWARE_XCB))
1172      {
1173         if (!ecore_evas_engine_type_supported_get(ECORE_EVAS_ENGINE_SOFTWARE_XLIB))
1174           {
1175              e_error_message_show(_("Enlightenment found ecore_evas doesn't support the Software X11\n"
1176                                     "rendering in Evas. Please check your installation of Evas and\n"
1177                                     "Ecore and check they support the Software X11 rendering engine."));
1178              _e_main_shutdown(-1);
1179           }
1180      }
1181 #endif
1182    if (!ecore_evas_engine_type_supported_get(ECORE_EVAS_ENGINE_SOFTWARE_BUFFER))
1183      {
1184         e_error_message_show(_("Enlightenment found ecore_evas doesn't support the Software Buffer\n"
1185                                "rendering in Evas. Please check your installation of Evas and\n"
1186                                "Ecore and check they support the Software Buffer rendering engine."));
1187         _e_main_shutdown(-1);
1188      }
1189    TS("Ecore_Evas Engine Check Done");
1190
1191    /*** Initialize E Subsystems We Need ***/
1192
1193    TS("E Directories Init");
1194    /* setup directories we will be using for configurations storage etc. */
1195    if (!_e_main_dirs_init())
1196      {
1197         e_error_message_show(_("Enlightenment cannot create directories in your home directory.\n"
1198                                "Perhaps you have no home directory or the disk is full?"));
1199         _e_main_shutdown(-1);
1200      }
1201    TS("E Directories Init Done");
1202    _e_main_shutdown_push(_e_main_dirs_shutdown);
1203
1204    TS("E_Config Init");
1205    if (!e_config_init())
1206      {
1207         e_error_message_show(_("Enlightenment cannot set up its config system.\n"));
1208         _e_main_shutdown(-1);
1209      }
1210    TS("E_Config Init Done");
1211    _e_main_shutdown_push(e_config_shutdown);
1212
1213    TS("E_Env Init");
1214    if (!e_env_init())
1215      {
1216         e_error_message_show(_("Enlightenment cannot set up its environment.\n"));
1217         _e_main_shutdown(-1);
1218      }
1219    TS("E_Env Init Done");
1220    _e_main_shutdown_push(e_env_shutdown);
1221
1222    efreet_desktop_environment_set(e_config->desktop_environment);
1223    e_util_env_set("E_ICON_THEME", e_config->icon_theme);
1224    ecore_exe_run_priority_set(e_config->priority);
1225    locked |= e_config->desklock_start_locked;
1226
1227    s = getenv("E_DESKLOCK_LOCKED");
1228    if ((s) && (!strcmp(s, "locked"))) waslocked = EINA_TRUE;
1229
1230    TS("E Paths Init");
1231    if (!_e_main_path_init())
1232      {
1233         e_error_message_show(_("Enlightenment cannot set up paths for finding files.\n"
1234                                "Perhaps you are out of memory?"));
1235         _e_main_shutdown(-1);
1236      }
1237    TS("E Paths Init Done");
1238    _e_main_shutdown_push(_e_main_path_shutdown);
1239
1240    ecore_animator_frametime_set(1.0 / e_config->framerate);
1241
1242    TS("E_Font Init");
1243    if (!e_font_init())
1244      {
1245         e_error_message_show(_("Enlightenment cannot set up its font system.\n"));
1246         _e_main_shutdown(-1);
1247      }
1248    TS("E_Font Init Done");
1249    _e_main_shutdown_push(e_font_shutdown);
1250
1251    TS("E_Font Apply");
1252    e_font_apply();
1253    TS("E_Font Apply Done");
1254
1255    TS("E_Theme Init");
1256    if (!e_theme_init())
1257      {
1258         e_error_message_show(_("Enlightenment cannot set up its theme system.\n"));
1259         _e_main_shutdown(-1);
1260      }
1261    TS("E_Theme Init Done");
1262    _e_main_shutdown_push(e_theme_shutdown);
1263
1264    TS("E_Moveresize Init");
1265    e_moveresize_init();
1266    TS("E_Moveresize Init Done");
1267    _e_main_shutdown_push(e_moveresize_shutdown);
1268
1269    e_screensaver_preinit();
1270
1271    if (e_config->show_splash)
1272      e_init_status_set(_("Setup Actions"));
1273    TS("E_Actions Init");
1274    if (!e_actions_init())
1275      {
1276         e_error_message_show(_("Enlightenment cannot set up its actions system.\n"));
1277         _e_main_shutdown(-1);
1278      }
1279    TS("E_Actions Init Done");
1280    _e_main_shutdown_push(e_actions_shutdown);
1281
1282    /* these just add event handlers and can't fail
1283     * timestamping them is dumb.
1284     */
1285    e_zone_init();
1286    e_desk_init();
1287    e_exehist_init();
1288
1289    if (e_config->show_splash)
1290      e_init_status_set(_("Setup Powersave Modes"));
1291    TS("E_Powersave Init");
1292    if (!e_powersave_init())
1293      {
1294         e_error_message_show(_("Enlightenment cannot set up its powersave modes.\n"));
1295         _e_main_shutdown(-1);
1296      }
1297    TS("E_Powersave Init Done");
1298    _e_main_shutdown_push(e_powersave_shutdown);
1299
1300    if (e_config->show_splash)
1301      e_init_status_set(_("Setup Screensaver"));
1302    TS("E_Screensaver Init");
1303    if (!e_screensaver_init())
1304      {
1305         e_error_message_show(_("Enlightenment cannot configure the X screensaver.\n"));
1306         _e_main_shutdown(-1);
1307      }
1308    TS("E_Screensaver Init Done");
1309    _e_main_shutdown_push(e_screensaver_shutdown);
1310
1311    if (e_config->show_splash)
1312      e_init_status_set(_("Setup Screens"));
1313    TS("Screens Init");
1314    if (!_e_main_screens_init())
1315      {
1316         e_error_message_show(_("Enlightenment set up window management for all the screens on your system\n"
1317                                "failed. Perhaps another window manager is running?\n"));
1318         _e_main_shutdown(-1);
1319      }
1320    TS("Screens Init Done");
1321    _e_main_shutdown_push(_e_main_screens_shutdown);
1322    e_screensaver_force_update();
1323
1324    if (e_config->show_splash)
1325      e_init_status_set(_("Setup System Controls"));
1326    TS("E_Sys Init");
1327    if (!e_sys_init())
1328      {
1329         e_error_message_show(_("Enlightenment cannot initialize the System Command system.\n"));
1330         _e_main_shutdown(-1);
1331      }
1332    TS("E_Sys Init Done");
1333    _e_main_shutdown_push(e_sys_shutdown);
1334
1335    TS("E_Comp Freeze");
1336    e_comp_all_freeze();
1337    TS("E_Comp Freeze Done");
1338
1339    if (e_config->show_splash)
1340      e_init_status_set(_("Setup Grab Input Handling"));
1341    TS("E_Grabinput Init");
1342    if (!e_grabinput_init())
1343      {
1344         e_error_message_show(_("Enlightenment cannot set up its grab input handling system.\n"));
1345         _e_main_shutdown(-1);
1346      }
1347    TS("E_Grabinput Init Done");
1348    _e_main_shutdown_push(e_grabinput_shutdown);
1349
1350    ecore_event_handler_add(E_EVENT_MODULE_INIT_END, _e_main_deferred_job_schedule, NULL);
1351
1352    if (e_config->show_splash)
1353      e_init_status_set(_("Setup Modules"));
1354    TS("E_Module Init");
1355    if (!e_module_init())
1356      {
1357         e_error_message_show(_("Enlightenment cannot set up its module system.\n"));
1358         _e_main_shutdown(-1);
1359      }
1360    TS("E_Module Init Done");
1361    _e_main_shutdown_push(e_module_shutdown);
1362
1363    if (e_config->show_splash)
1364      e_init_status_set(_("Setup Remembers"));
1365    TS("E_Remember Init");
1366    if (!e_remember_init(after_restart ? E_STARTUP_RESTART : E_STARTUP_START))
1367      {
1368         e_error_message_show(_("Enlightenment cannot setup remember settings.\n"));
1369         _e_main_shutdown(-1);
1370      }
1371    TS("E_Remember Init Done");
1372    _e_main_shutdown_push(e_remember_shutdown);
1373
1374    if (e_config->show_splash)
1375      e_init_status_set(_("Setup Mouse"));
1376    TS("E_Mouse Init");
1377    if (!e_mouse_update())
1378      {
1379         e_error_message_show(_("Enlightenment cannot configure the mouse settings.\n"));
1380         _e_main_shutdown(-1);
1381      }
1382    TS("E_Mouse Init Done");
1383
1384    if (e_config->show_splash)
1385      e_init_status_set(_("Setup Bindings"));
1386    TS("E_Bindings Init");
1387    if (!e_bindings_init())
1388      {
1389         e_error_message_show(_("Enlightenment cannot set up its bindings system.\n"));
1390         _e_main_shutdown(-1);
1391      }
1392    TS("E_Bindings Init Done");
1393    _e_main_shutdown_push(e_bindings_shutdown);
1394
1395    TS("E_Icon Init");
1396    if (!e_icon_init())
1397      {
1398         e_error_message_show(_("Enlightenment cannot initialize the Icon Cache system.\n"));
1399         _e_main_shutdown(-1);
1400      }
1401    TS("E_Icon Init Done");
1402    _e_main_shutdown_push(e_icon_shutdown);
1403
1404    TS("E_Manager Keys Grab");
1405    e_managers_keys_grab();
1406    TS("E_Manager Keys Grab Done");
1407
1408    if (e_config->show_splash)
1409      e_init_status_set(_("Load Modules"));
1410    TS("Load Modules");
1411    _e_main_modules_load(safe_mode);
1412    TS("Load Modules Done");
1413
1414    if (e_config->show_splash && (!after_restart))
1415      ecore_timer_add(2.0, _e_main_cb_startup_fake_end, NULL);
1416
1417    TS("E_Comp Thaw");
1418    e_comp_all_thaw();
1419    TS("E_Comp Thaw Done");
1420 #endif
1421
1422    _idle_after = ecore_idle_enterer_add(_e_main_cb_idle_after, NULL);
1423
1424    if (e_config->show_splash)
1425      e_init_status_set(_("Almost Done"));
1426
1427    starting = EINA_FALSE;
1428    inloop = EINA_TRUE;
1429
1430    e_util_env_set("E_RESTART", "1");
1431
1432    TS("MAIN LOOP AT LAST");
1433    if (!setjmp(x_fatal_buff))
1434      ecore_main_loop_begin();
1435    else
1436      CRI("FATAL: X Died. Connection gone. Abbreviated Shutdown\n");
1437
1438    inloop = EINA_FALSE;
1439    stopping = EINA_TRUE;
1440
1441    //if (!x_fatal) e_canvas_idle_flush();
1442
1443    e_config_save_flush();
1444    _e_main_desk_save();
1445    e_remember_internal_save();
1446    e_comp_internal_save();
1447
1448    _e_main_shutdown(0);
1449
1450    if (restart)
1451      {
1452         e_util_env_set("E_RESTART_OK", "1");
1453         if (getenv("E_START_MTRACK"))
1454           e_util_env_set("MTRACK", "track");
1455         ecore_app_restart();
1456      }
1457
1458    e_prefix_shutdown();
1459
1460    return 0;
1461 }
1462
1463 EAPI double
1464 e_main_ts(const char *str)
1465 {
1466    double ret;
1467    t1 = ecore_time_unix_get();
1468    printf("ESTART: %1.5f [%1.5f] - %s\n", t1 - t0, t1 - t2, str);
1469    ret = t1 - t2;
1470    t2 = t1;
1471    return ret;
1472 }
1473
1474 /* local functions */
1475 static void
1476 _e_main_shutdown(int errcode)
1477 {
1478    int i = 0;
1479    char buf[PATH_MAX];
1480    const char *dir;
1481
1482    printf("E: Begin Shutdown Procedure!\n");
1483
1484    if (_idle_before) ecore_idle_enterer_del(_idle_before);
1485    _idle_before = NULL;
1486    if (_idle_after) ecore_idle_enterer_del(_idle_after);
1487    _idle_after = NULL;
1488
1489    dir = getenv("XDG_RUNTIME_DIR");
1490    if (dir)
1491      {
1492         char buf_env[PATH_MAX];
1493         snprintf(buf_env, sizeof(buf_env), "%s", dir);
1494         snprintf(buf, sizeof(buf), "%s/.e-deleteme", buf_env);
1495         if (ecore_file_exists(buf)) ecore_file_recursive_rm(buf_env);
1496      }
1497    for (i = (_e_main_lvl - 1); i >= 0; i--)
1498      (*_e_main_shutdown_func[i])();
1499 #ifdef OBJECT_HASH_CHECK
1500    e_object_hash_shutdown();
1501 #endif
1502    if (errcode < 0) exit(errcode);
1503 }
1504
1505 static void
1506 _e_main_shutdown_push(int (*func)(void))
1507 {
1508    _e_main_lvl++;
1509    if (_e_main_lvl > MAX_LEVEL)
1510      {
1511         _e_main_lvl--;
1512         e_error_message_show("WARNING: too many init levels. MAX = %i\n",
1513                              MAX_LEVEL);
1514         return;
1515      }
1516    _e_main_shutdown_func[_e_main_lvl - 1] = func;
1517 }
1518
1519 static void
1520 _e_main_parse_arguments(int argc, char **argv)
1521 {
1522    char *s = NULL;
1523    int i = 0;
1524
1525    /* handle some command-line parameters */
1526    for (i = 1; i < argc; i++)
1527      {
1528         if ((!strcmp(argv[i], "-display")) && (i < (argc - 1)))
1529           {
1530              i++;
1531              e_util_env_set("DISPLAY", argv[i]);
1532           }
1533         else if ((!strcmp(argv[i], "-fake-xinerama-screen")) && (i < (argc - 1)))
1534           {
1535              int x, y, w, h;
1536
1537              i++;
1538              if (sscanf(argv[i], "%ix%i+%i+%i", &w, &h, &x, &y) == 4)
1539                e_xinerama_fake_screen_add(x, y, w, h);
1540           }
1541         else if (!strcmp(argv[i], "-good"))
1542           {
1543              good = EINA_TRUE;
1544              evil = EINA_FALSE;
1545              printf("LA LA LA\n");
1546           }
1547         else if (!strcmp(argv[i], "-evil"))
1548           {
1549              good = EINA_FALSE;
1550              evil = EINA_TRUE;
1551              printf("MUHAHAHAHHAHAHAHAHA\n");
1552           }
1553         else if (!strcmp(argv[i], "-psychotic"))
1554           {
1555              good = EINA_TRUE;
1556              evil = EINA_TRUE;
1557              printf("MUHAHALALALALALALALA\n");
1558           }
1559         else if ((!strcmp(argv[i], "-profile")) && (i < (argc - 1)))
1560           {
1561              i++;
1562              if (!getenv("E_CONF_PROFILE"))
1563                e_util_env_set("E_CONF_PROFILE", argv[i]);
1564           }
1565         else if (!strcmp(argv[i], "-i-really-know-what-i-am-doing-and-accept-full-responsibility-for-it"))
1566           really_know = EINA_TRUE;
1567         else if (!strcmp(argv[i], "-locked"))
1568           locked = EINA_TRUE;
1569         else if (!strcmp(argv[i], "-nopause"))
1570           e_nopause = EINA_TRUE;
1571         else if ((!strcmp(argv[i], "-h")) ||
1572                  (!strcmp(argv[i], "-help")) ||
1573                  (!strcmp(argv[i], "--help")))
1574           {
1575              printf
1576                (_(
1577                  "Options:\n"
1578                  "\t-display DISPLAY\n"
1579                  "\t\tConnect to display named DISPLAY.\n"
1580                  "\t\tEG: -display :1.0\n"
1581                  "\t-fake-xinerama-screen WxH+X+Y\n"
1582                  "\t\tAdd a FAKE xinerama screen (instead of the real ones)\n"
1583                  "\t\tgiven the geometry. Add as many as you like. They all\n"
1584                  "\t\treplace the real xinerama screens, if any. This can\n"
1585                  "\t\tbe used to simulate xinerama.\n"
1586                  "\t\tEG: -fake-xinerama-screen 800x600+0+0 -fake-xinerama-screen 800x600+800+0\n"
1587                  "\t-profile CONF_PROFILE\n"
1588                  "\t\tUse the configuration profile CONF_PROFILE instead of the user selected default or just \"default\".\n"
1589                  "\t-good\n"
1590                  "\t\tBe good.\n"
1591                  "\t-evil\n"
1592                  "\t\tBe evil.\n"
1593                  "\t-psychotic\n"
1594                  "\t\tBe psychotic.\n"
1595                  "\t-locked\n"
1596                  "\t\tStart with desklock on, so password will be asked.\n"
1597                  "\t-i-really-know-what-i-am-doing-and-accept-full-responsibility-for-it\n"
1598                  "\t\tIf you need this help, you don't need this option.\n"
1599                  )
1600                );
1601              _e_main_shutdown(-1);
1602           }
1603      }
1604
1605    /* fix up DISPLAY to be :N.0 if no .screen is in it */
1606    s = getenv("DISPLAY");
1607    if (s)
1608      {
1609         char *p, buff[4096];
1610
1611         if (!(p = strrchr(s, ':')))
1612           {
1613              snprintf(buff, sizeof(buff), "%s:0.0", s);
1614              e_util_env_set("DISPLAY", buff);
1615           }
1616         else
1617           {
1618              if (!strrchr(p, '.'))
1619                {
1620                   snprintf(buff, sizeof(buff), "%s.0", s);
1621                   e_util_env_set("DISPLAY", buff);
1622                }
1623           }
1624      }
1625
1626    /* we want to have been launched by enlightenment_start. there is a very */
1627    /* good reason we want to have been launched this way, thus check */
1628    if (!getenv("E_START"))
1629      {
1630         e_error_message_show(_("You are executing enlightenment directly. This is\n"
1631                                "bad. Please do not execute the \"enlightenment\"\n"
1632                                "binary. Use the \"enlightenment_start\" launcher. It\n"
1633                                "will handle setting up environment variables, paths,\n"
1634                                "and launching any other required services etc.\n"
1635                                "before enlightenment itself begins running.\n"));
1636         _e_main_shutdown(-1);
1637      }
1638 }
1639
1640 EINTERN void
1641 _e_main_cb_x_fatal(void *data __UNUSED__)
1642 {
1643    e_error_message_show("Lost X Connection.\n");
1644    ecore_main_loop_quit();
1645    if (!x_fatal)
1646      {
1647         x_fatal = EINA_TRUE;
1648         if (inloop) longjmp(x_fatal_buff, -99);
1649      }
1650 }
1651
1652 static Eina_Bool
1653 _e_main_cb_signal_exit(void *data __UNUSED__, int ev_type __UNUSED__, void *ev __UNUSED__)
1654 {
1655    /* called on ctrl-c, kill (pid) (also SIGINT, SIGTERM and SIGQIT) */
1656    e_sys_action_do(E_SYS_EXIT, NULL);
1657    return ECORE_CALLBACK_RENEW;
1658 }
1659
1660 static Eina_Bool
1661 _e_main_cb_signal_hup(void *data __UNUSED__, int ev_type __UNUSED__, void *ev __UNUSED__)
1662 {
1663    e_sys_action_do(E_SYS_RESTART, NULL);
1664    return ECORE_CALLBACK_RENEW;
1665 }
1666
1667 static Eina_Bool
1668 _e_main_cb_signal_user(void *data __UNUSED__, int ev_type __UNUSED__, void *ev)
1669 {
1670    Ecore_Event_Signal_User *e = ev;
1671
1672    if (e->number == 1)
1673      {
1674 //        E_Action *a = e_action_find("configuration");
1675 //        if ((a) && (a->func.go)) a->func.go(NULL, NULL);
1676      }
1677    else if (e->number == 2)
1678      {
1679         // comp module has its own handler for this for enabling/disabling fps debug
1680      }
1681    return ECORE_CALLBACK_RENEW;
1682
1683 }
1684
1685 static int
1686 _e_main_dirs_init(void)
1687 {
1688    const char *base;
1689    const char *dirs[] =
1690    {
1691       "images",
1692       "fonts",
1693       "themes",
1694       "icons",
1695       "backgrounds",
1696       "applications",
1697       "applications/menu",
1698       "applications/menu/favorite",
1699       "applications/menu/all",
1700       "applications/bar",
1701       "applications/bar/default",
1702       "applications/startup",
1703       "applications/restart",
1704       "applications/trash",
1705       "applications/desk-lock",
1706       "applications/desk-unlock",
1707       "modules",
1708       "config",
1709       "locale",
1710       "input_methods",
1711       NULL
1712    };
1713
1714    base = e_user_dir_get();
1715    if (ecore_file_mksubdirs(base, dirs) != sizeof(dirs) / sizeof(dirs[0]) - 1)
1716      {
1717         e_error_message_show("Could not create one of the required "
1718                              "subdirectories of '%s'\n", base);
1719         return 0;
1720      }
1721
1722    return 1;
1723 }
1724
1725 static int
1726 _e_main_dirs_shutdown(void)
1727 {
1728    return 1;
1729 }
1730
1731 static int
1732 _e_main_path_init(void)
1733 {
1734    char buf[PATH_MAX];
1735
1736    /* setup data paths */
1737    path_data = e_path_new();
1738    if (!path_data)
1739      {
1740         e_error_message_show("Cannot allocate path for path_data\n");
1741         return 0;
1742      }
1743    e_prefix_data_concat_static(buf, "data");
1744    e_path_default_path_append(path_data, buf);
1745    e_path_user_path_set(path_data, &(e_config->path_append_data));
1746
1747    /* setup image paths */
1748    path_images = e_path_new();
1749    if (!path_images)
1750      {
1751         e_error_message_show("Cannot allocate path for path_images\n");
1752         return 0;
1753      }
1754    e_user_dir_concat_static(buf, "/images");
1755    e_path_default_path_append(path_images, buf);
1756    e_prefix_data_concat_static(buf, "data/images");
1757    e_path_default_path_append(path_images, buf);
1758    e_path_user_path_set(path_images, &(e_config->path_append_images));
1759
1760    /* setup font paths */
1761    path_fonts = e_path_new();
1762    if (!path_fonts)
1763      {
1764         e_error_message_show("Cannot allocate path for path_fonts\n");
1765         return 0;
1766      }
1767    e_user_dir_concat_static(buf, "/fonts");
1768    e_path_default_path_append(path_fonts, buf);
1769    e_prefix_data_concat_static(buf, "data/fonts");
1770    e_path_default_path_append(path_fonts, buf);
1771    e_path_user_path_set(path_fonts, &(e_config->path_append_fonts));
1772
1773    /* setup icon paths */
1774    path_icons = e_path_new();
1775    if (!path_icons)
1776      {
1777         e_error_message_show("Cannot allocate path for path_icons\n");
1778         return 0;
1779      }
1780    e_user_dir_concat_static(buf, "/icons");
1781    e_path_default_path_append(path_icons, buf);
1782    e_prefix_data_concat_static(buf, "data/icons");
1783    e_path_default_path_append(path_icons, buf);
1784    e_path_user_path_set(path_icons, &(e_config->path_append_icons));
1785
1786    /* setup module paths */
1787    path_modules = e_path_new();
1788    if (!path_modules)
1789      {
1790         e_error_message_show("Cannot allocate path for path_modules\n");
1791         return 0;
1792      }
1793    e_user_dir_concat_static(buf, "/modules");
1794    e_path_default_path_append(path_modules, buf);
1795    snprintf(buf, sizeof(buf), "%s/enlightenment/modules", e_prefix_lib_get());
1796    e_path_default_path_append(path_modules, buf);
1797    /* FIXME: eventually this has to go - moduels should have installers that
1798     * add appropriate install paths (if not installed to user homedir) to
1799     * e's module search dirs
1800     */
1801    snprintf(buf, sizeof(buf), "%s/enlightenment/modules_extra", e_prefix_lib_get());
1802    e_path_default_path_append(path_modules, buf);
1803    e_path_user_path_set(path_modules, &(e_config->path_append_modules));
1804
1805    /* setup background paths */
1806    path_backgrounds = e_path_new();
1807    if (!path_backgrounds)
1808      {
1809         e_error_message_show("Cannot allocate path for path_backgrounds\n");
1810         return 0;
1811      }
1812    e_user_dir_concat_static(buf, "/backgrounds");
1813    e_path_default_path_append(path_backgrounds, buf);
1814    e_prefix_data_concat_static(buf, "data/backgrounds");
1815    e_path_default_path_append(path_backgrounds, buf);
1816    e_path_user_path_set(path_backgrounds, &(e_config->path_append_backgrounds));
1817
1818    path_messages = e_path_new();
1819    if (!path_messages)
1820      {
1821         e_error_message_show("Cannot allocate path for path_messages\n");
1822         return 0;
1823      }
1824    e_user_dir_concat_static(buf, "/locale");
1825    e_path_default_path_append(path_messages, buf);
1826    e_path_default_path_append(path_messages, e_prefix_locale_get());
1827    e_path_user_path_set(path_messages, &(e_config->path_append_messages));
1828
1829    return 1;
1830 }
1831
1832 static int
1833 _e_main_path_shutdown(void)
1834 {
1835    if (path_data)
1836      {
1837         e_object_del(E_OBJECT(path_data));
1838         path_data = NULL;
1839      }
1840    if (path_images)
1841      {
1842         e_object_del(E_OBJECT(path_images));
1843         path_images = NULL;
1844      }
1845    if (path_fonts)
1846      {
1847         e_object_del(E_OBJECT(path_fonts));
1848         path_fonts = NULL;
1849      }
1850    if (path_icons)
1851      {
1852         e_object_del(E_OBJECT(path_icons));
1853         path_icons = NULL;
1854      }
1855    if (path_modules)
1856      {
1857         e_object_del(E_OBJECT(path_modules));
1858         path_modules = NULL;
1859      }
1860    if (path_backgrounds)
1861      {
1862         e_object_del(E_OBJECT(path_backgrounds));
1863         path_backgrounds = NULL;
1864      }
1865    if (path_messages)
1866      {
1867         e_object_del(E_OBJECT(path_messages));
1868         path_messages = NULL;
1869      }
1870    return 1;
1871 }
1872
1873 static void
1874 _e_main_test_formats(void)
1875 {
1876    Evas *evas;
1877    Ecore_Evas *ee;
1878    Evas_Object *im, *txt;
1879    Evas_Coord tw, th;
1880    char buff[PATH_MAX];
1881
1882    if (e_config->show_splash)
1883      e_init_status_set(_("Testing Format Support"));
1884
1885    if (!(ee = ecore_evas_buffer_new(1, 1)))
1886      {
1887         e_error_message_show(_("Enlightenment found Evas can't create a buffer canvas. Please check\n"
1888                                "Evas has Software Buffer engine support.\n"));
1889         _e_main_shutdown(-1);
1890      }
1891    evas = ecore_evas_get(ee);
1892    im = evas_object_image_add(evas);
1893
1894    e_prefix_data_concat_static(buff, "data/images/test.svg");
1895    evas_object_image_file_set(im, buff, NULL);
1896    if (evas_object_image_load_error_get(im) != EVAS_LOAD_ERROR_NONE)
1897      {
1898         e_error_message_show(_("Enlightenment found Evas can't load SVG files. "
1899                                "Check Evas has SVG loader support.\n"));
1900      }
1901    else
1902      efreet_icon_extension_add(".svg");
1903
1904    e_prefix_data_concat_static(buff, "data/images/test.jpg");
1905    evas_object_image_file_set(im, buff, NULL);
1906    if (evas_object_image_load_error_get(im) != EVAS_LOAD_ERROR_NONE)
1907      {
1908         e_error_message_show(_("Enlightenment found Evas can't load JPEG files. "
1909                                "Check Evas has JPEG loader support.\n"));
1910         _e_main_shutdown(-1);
1911      }
1912    efreet_icon_extension_add(".jpg");
1913
1914    e_prefix_data_concat_static(buff, "data/images/test.png");
1915    evas_object_image_file_set(im, buff, NULL);
1916    if (evas_object_image_load_error_get(im) != EVAS_LOAD_ERROR_NONE)
1917      {
1918         e_error_message_show(_("Enlightenment found Evas can't load PNG files. "
1919                                "Check Evas has PNG loader support.\n"));
1920         _e_main_shutdown(-1);
1921      }
1922    efreet_icon_extension_add(".png");
1923
1924    e_prefix_data_concat_static(buff, "data/images/test.edj");
1925    evas_object_image_file_set(im, buff, "images/0");
1926    if (evas_object_image_load_error_get(im) != EVAS_LOAD_ERROR_NONE)
1927      {
1928         e_error_message_show(_("Enlightenment found Evas can't load EET files. "
1929                                "Check Evas has EET loader support.\n"));
1930         _e_main_shutdown(-1);
1931      }
1932    efreet_icon_extension_add(".edj");
1933
1934    evas_object_del(im);
1935
1936    txt = evas_object_text_add(evas);
1937    evas_object_text_font_set(txt, "Sans", 10);
1938    evas_object_text_text_set(txt, "Hello");
1939    evas_object_geometry_get(txt, NULL, NULL, &tw, &th);
1940    if ((tw <= 0) && (th <= 0))
1941      {
1942         e_error_message_show(_("Enlightenment found Evas can't load the 'Sans' font. Check Evas has fontconfig\n"
1943                                "support and system fontconfig defines a 'Sans' font.\n"));
1944         _e_main_shutdown(-1);
1945      }
1946    evas_object_del(txt);
1947    ecore_evas_free(ee);
1948 }
1949
1950 static int
1951 _e_main_screens_init(void)
1952 {
1953    TS("\tscreens: manager");
1954    if (!e_manager_init()) return 0;
1955
1956    TS("\tscreens: client");
1957    if (!e_client_init()) return 0;
1958 #ifndef ENABLE_QUICK_INIT
1959    TS("\tscreens: win");
1960    if (!e_win_init()) return 0;
1961 #endif
1962 #ifndef HAVE_WAYLAND_ONLY
1963    TS("E_Xkb Init");
1964    if (!e_xkb_init())
1965      {
1966         e_error_message_show(_("Enlightenment cannot setup XKB Keyboard layouts.\n"));
1967         _e_main_shutdown(-1);
1968      }
1969    TS("E_Xkb Init Done");
1970 #endif
1971
1972    TS("Compositor Init");
1973    if (!e_comp_init())
1974      {
1975         e_error_message_show(_("Enlightenment cannot create a compositor.\n"));
1976         _e_main_shutdown(-1);
1977      }
1978
1979    _e_main_desk_restore();
1980
1981 #ifndef HAVE_WAYLAND_ONLY
1982    if (e_config->show_splash)
1983      e_init_status_set(_("Setup DND"));
1984    TS("E_Dnd Init");
1985    if (!e_dnd_init())
1986      {
1987         e_error_message_show(_("Enlightenment cannot set up its dnd system.\n"));
1988         _e_main_shutdown(-1);
1989      }
1990    TS("E_Dnd Init Done");
1991    _e_main_shutdown_push(e_dnd_shutdown);
1992 #endif
1993
1994    return 1;
1995 }
1996
1997 static int
1998 _e_main_screens_shutdown(void)
1999 {
2000    e_win_shutdown();
2001    e_menu_shutdown();
2002    e_shelf_shutdown();
2003    e_comp_shutdown();
2004    e_client_shutdown();
2005    e_exehist_shutdown();
2006    e_backlight_shutdown();
2007    e_exec_shutdown();
2008
2009    e_desk_shutdown();
2010    e_zone_shutdown();
2011    e_manager_shutdown();
2012    return 1;
2013 }
2014
2015 static void
2016 _e_main_desk_save(void)
2017 {
2018    const Eina_List *l;
2019    char env[1024], name[1024];
2020    E_Zone *zone;
2021
2022    EINA_LIST_FOREACH(e_comp->zones, l, zone)
2023      {
2024         snprintf(name, sizeof(name), "DESK_%d_%d", e_comp->num, zone->num);
2025         snprintf(env, sizeof(env), "%d,%d", zone->desk_x_current, zone->desk_y_current);
2026         e_util_env_set(name, env);
2027      }
2028 }
2029
2030 static void
2031 _e_main_desk_restore(void)
2032 {
2033    const Eina_List *l;
2034    E_Zone *zone;
2035    const char *env;
2036    char name[1024];
2037
2038    EINA_LIST_FOREACH(e_comp->zones, l, zone)
2039      {
2040         E_Desk *desk;
2041         int desk_x, desk_y;
2042         char buf_e[64];
2043
2044         snprintf(name, sizeof(name), "DESK_%d_%d", e_comp->num, zone->num);
2045         env = getenv(name);
2046         if (!env) continue;
2047         snprintf(buf_e, sizeof(buf_e), "%s", env);
2048         if (!sscanf(buf_e, "%d,%d", &desk_x, &desk_y)) continue;
2049         desk = e_desk_at_xy_get(zone, desk_x, desk_y);
2050         if (!desk) continue;
2051         e_desk_show(desk);
2052      }
2053 }
2054
2055 static void
2056 _e_main_efreet_paths_init(void)
2057 {
2058    Eina_List **list;
2059
2060    if ((list = efreet_icon_extra_list_get()))
2061      {
2062         char buff[PATH_MAX];
2063
2064         e_user_dir_concat_static(buff, "icons");
2065         *list = eina_list_prepend(*list, (void *)eina_stringshare_add(buff));
2066         e_prefix_data_concat_static(buff, "data/icons");
2067         *list = eina_list_prepend(*list, (void *)eina_stringshare_add(buff));
2068      }
2069 }
2070
2071 static Eina_Bool
2072 _e_main_modules_load_after(void *d EINA_UNUSED, int type EINA_UNUSED, void *ev EINA_UNUSED)
2073 {
2074    e_int_config_modules(NULL, NULL);
2075    E_FREE_FUNC(mod_init_end, ecore_event_handler_del);
2076    return ECORE_CALLBACK_RENEW;
2077 }
2078
2079 static void
2080 _e_main_modules_load(Eina_Bool safe_mode)
2081 {
2082    if (!safe_mode)
2083      e_module_all_load();
2084    else
2085      {
2086         E_Module *m;
2087         char *crashmodule;
2088
2089         crashmodule = getenv("E_MODULE_LOAD");
2090         if (crashmodule) m = e_module_new(crashmodule);
2091
2092         if ((crashmodule) && (m))
2093           {
2094              e_module_disable(m);
2095              e_object_del(E_OBJECT(m));
2096
2097              e_error_message_show
2098                (_("Enlightenment crashed early on start and has<br>"
2099                   "been restarted. There was an error loading the<br>"
2100                   "module named: %s. This module has been disabled<br>"
2101                   "and will not be loaded."), crashmodule);
2102              e_util_dialog_show
2103                (_("Enlightenment crashed early on start and has been restarted"),
2104                _("Enlightenment crashed early on start and has been restarted.<br>"
2105                  "There was an error loading the module named: %s<br><br>"
2106                  "This module has been disabled and will not be loaded."), crashmodule);
2107              e_module_all_load();
2108           }
2109         else
2110           {
2111              e_error_message_show
2112                (_("Enlightenment crashed early on start and has<br>"
2113                   "been restarted. All modules have been disabled<br>"
2114                   "and will not be loaded to help remove any problem<br>"
2115                   "modules from your configuration. The module<br>"
2116                   "configuration dialog should let you select your<br>"
2117                   "modules again.\n"));
2118              e_util_dialog_show
2119                (_("Enlightenment crashed early on start and has been restarted"),
2120                _("Enlightenment crashed early on start and has been restarted.<br>"
2121                  "All modules have been disabled and will not be loaded to help<br>"
2122                  "remove any problem modules from your configuration.<br><br>"
2123                  "The module configuration dialog should let you select your<br>"
2124                  "modules again."));
2125           }
2126         mod_init_end = ecore_event_handler_add(E_EVENT_MODULE_INIT_END, _e_main_modules_load_after, NULL);
2127      }
2128 }
2129
2130 static Eina_Bool
2131 _e_main_cb_idle_before(void *data __UNUSED__)
2132 {
2133    e_menu_idler_before();
2134    e_client_idler_before();
2135    e_pointer_idler_before();
2136    edje_thaw();
2137    return ECORE_CALLBACK_RENEW;
2138 }
2139
2140 static Eina_Bool
2141 _e_main_cb_idle_after(void *data __UNUSED__)
2142 {
2143    static int first_idle = 1;
2144
2145    eet_clearcache();
2146    edje_freeze();
2147
2148 #ifdef E_RELEASE_BUILD
2149    if (first_idle)
2150      {
2151         TS("SLEEP");
2152         first_idle = 0;
2153         e_precache_end = EINA_TRUE;
2154      }
2155 #else
2156    if (first_idle++ < 60)
2157      {
2158         TS("SLEEP");
2159         if (!first_idle)
2160           e_precache_end = EINA_TRUE;
2161      }
2162 #endif
2163
2164    return ECORE_CALLBACK_RENEW;
2165 }
2166
2167 static Eina_Bool
2168 _e_main_cb_startup_fake_end(void *data __UNUSED__)
2169 {
2170    e_init_hide();
2171    return ECORE_CALLBACK_CANCEL;
2172 }