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