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