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