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