3 # include <sys/prctl.h>
12 t1 = ecore_time_unix_get(); \
13 printf("ESTART: %1.5f [%1.5f] - %s\n", t1 - t0, t1 - t2, x); \
16 static double t0, t1, t2;
21 * i need to make more use of these when i'm baffled as to when something is
24 * void *(*__malloc_hook)(size_t size, const void *caller);
26 * void *(*__realloc_hook)(void *ptr, size_t size, const void *caller);
28 * void *(*__memalign_hook)(size_t alignment, size_t size,
29 * const void *caller);
31 * void (*__free_hook)(void *ptr, const void *caller);
33 * void (*__malloc_initialize_hook)(void);
35 * void (*__after_morecore_hook)(void);
38 static void my_init_hook(void);
39 static void my_free_hook(void *p, const void *caller);
41 static void (*old_free_hook)(void *ptr, const void *caller) = NULL;
42 void (*__free_hook)(void *ptr, const void *caller);
44 void (*__malloc_initialize_hook) (void) = my_init_hook;
48 old_free_hook = __free_hook;
49 __free_hook = my_free_hook;
52 //void *magicfree = NULL;
55 my_free_hook(void *p, const void *caller)
57 __free_hook = old_free_hook;
58 // if ((p) && (p == magicfree))
60 // printf("CAUGHT!!!!! %p ...\n", p);
64 __free_hook = my_free_hook;
68 /* local function prototypes */
69 static void _e_main_shutdown(int errcode);
70 static void _e_main_shutdown_push(int (*func)(void));
71 static void _e_main_parse_arguments(int argc, char **argv);
72 static Eina_Bool _e_main_cb_signal_exit(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev EINA_UNUSED);
73 static Eina_Bool _e_main_cb_signal_hup(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev EINA_UNUSED);
74 static Eina_Bool _e_main_cb_signal_user(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev);
75 static int _e_main_dirs_init(void);
76 static int _e_main_dirs_shutdown(void);
77 static int _e_main_path_init(void);
78 static int _e_main_path_shutdown(void);
79 static int _e_main_screens_init(void);
80 static int _e_main_screens_shutdown(void);
81 static void _e_main_desk_save(void);
82 static void _e_main_desk_restore(void);
83 static void _e_main_modules_load(Eina_Bool safe_mode);
84 static Eina_Bool _e_main_cb_idle_before(void *data EINA_UNUSED);
85 static Eina_Bool _e_main_cb_idle_after(void *data EINA_UNUSED);
88 static Eina_Bool really_know = EINA_FALSE;
89 static Eina_Bool inloop = EINA_FALSE;
90 static jmp_buf x_fatal_buff;
92 static int _e_main_lvl = 0;
93 static int(*_e_main_shutdown_func[MAX_LEVEL]) (void);
95 static Ecore_Idle_Enterer *_idle_before = NULL;
96 static Ecore_Idle_Enterer *_idle_after = NULL;
98 static Ecore_Event_Handler *mod_init_end = NULL;
100 /* external variables */
101 E_API Eina_Bool e_precache_end = EINA_FALSE;
102 E_API Eina_Bool x_fatal = EINA_FALSE;
103 E_API Eina_Bool good = EINA_FALSE;
104 E_API Eina_Bool evil = EINA_FALSE;
105 E_API Eina_Bool starting = EINA_TRUE;
106 E_API Eina_Bool stopping = EINA_FALSE;
107 E_API Eina_Bool restart = EINA_FALSE;
108 E_API Eina_Bool e_nopause = EINA_FALSE;
109 EINTERN const char *e_first_frame = NULL;
110 EINTERN double e_first_frame_start_time = -1;
113 _xdg_check_str(const char *env, const char *str)
119 for (p = strstr(env, str); p; p++, p = strstr(p, str))
121 if ((!p[len]) || (p[len] == ':')) return EINA_TRUE;
127 _xdg_data_dirs_augment(void)
130 const char *p = e_prefix_get();
131 char newpath[4096], buf[4096];
135 s = getenv("XDG_DATA_DIRS");
138 Eina_Bool pfxdata, pfx;
140 pfxdata = !_xdg_check_str(s, e_prefix_data_get());
141 snprintf(newpath, sizeof(newpath), "%s/share", p);
142 pfx = !_xdg_check_str(s, newpath);
145 snprintf(buf, sizeof(buf), "%s%s%s%s%s",
146 pfxdata ? e_prefix_data_get() : "",
151 e_util_env_set("XDG_DATA_DIRS", buf);
156 snprintf(buf, sizeof(buf), "%s:%s/share:/usr/local/share:/usr/share", e_prefix_data_get(), p);
157 e_util_env_set("XDG_DATA_DIRS", buf);
160 s = getenv("XDG_CONFIG_DIRS");
161 snprintf(newpath, sizeof(newpath), "%s/etc/xdg", p);
164 if (!_xdg_check_str(s, newpath))
166 snprintf(buf, sizeof(buf), "%s:%s", newpath, s);
167 e_util_env_set("XDG_CONFIG_DIRS", buf);
172 snprintf(buf, sizeof(buf), "%s:/etc/xdg", newpath);
173 e_util_env_set("XDG_CONFIG_DIRS", buf);
176 if (!getenv("XDG_RUNTIME_DIR"))
180 snprintf(buf, sizeof(buf), "/tmp/xdg-XXXXXX");
182 if (!dir) dir = "/tmp";
185 e_util_env_set("XDG_RUNTIME_DIR", dir);
186 snprintf(buf, sizeof(buf), "%s/.e-deleteme", dir);
187 ecore_file_mkdir(buf);
191 /* set menu prefix so we get our e menu */
192 if (!getenv("XDG_MENU_PREFIX"))
194 e_util_env_set("XDG_MENU_PREFIX", "e-");
199 _e_main_subsystem_defer(void *data EINA_UNUSED)
204 TRACE_DS_BEGIN(MAIN:SUBSYSTEMS DEFER);
206 ecore_app_args_get(&argc, &argv);
208 /* try to init delayed subsystems */
210 TRACE_DS_BEGIN(MAIN:DEFFERED EFL INIT);
212 TS("[DEFERRED] Edje Init");
215 e_error_message_show(_("Enlightenment cannot initialize Edje!\n"));
217 _e_main_shutdown(-1);
219 TS("[DEFERRED] Edje Init Done");
220 _e_main_shutdown_push(edje_shutdown);
223 TRACE_DS_BEGIN(MAIN:DEFERRED INTERNAL SUBSYSTEMS INIT);
225 TS("[DEFERRED] Screens Init: win");
228 e_error_message_show(_("Enlightenment cannot setup elementary trap!\n"));
230 _e_main_shutdown(-1);
232 TS("[DEFERRED] Screens Init: win Done");
234 TS("[DEFERRED] E_Dnd Init");
237 e_error_message_show(_("Enlightenment cannot set up its dnd system.\n"));
238 _e_main_shutdown(-1);
240 TS("[DEFERRED] E_Dnd Init Done");
241 _e_main_shutdown_push(e_dnd_shutdown);
243 TS("[DEFERRED] E_Pointer Init");
244 if (!e_pointer_init())
246 e_error_message_show(_("Enlightenment cannot set up its pointer system.\n"));
248 _e_main_shutdown(-1);
251 TS("[DEFERRED] E_Pointer Init Done");
252 _e_main_shutdown_push(e_pointer_shutdown);
254 TS("[DEFERRED] E_Scale Init");
257 e_error_message_show(_("Enlightenment cannot set up its scale system.\n"));
259 _e_main_shutdown(-1);
261 TS("[DEFERRED E_Scale Init Done");
262 _e_main_shutdown_push(e_scale_shutdown);
264 TS("[DEFERRED] E_Test_Helper Init");
265 e_test_helper_init();
266 _e_main_shutdown_push(e_test_helper_shutdown);
267 TS("[DEFERRED] E_Test_Helper Done");
269 TS("[DEFERRED] E_INFO_SERVER Init");
270 e_info_server_init();
271 _e_main_shutdown_push(e_info_server_shutdown);
272 TS("[DEFERRED] E_INFO_SERVER Done");
275 TRACE_DS_BEGIN(MAIN:DEFERRED COMP JOB);
277 /* try to do deferred job of any subsystems*/
278 TS("[DEFERRED] Compositor's deferred job");
279 e_comp_deferred_job();
280 TS("[DEFERRED] Compositor's deferred job Done");
283 TRACE_DS_BEGIN(MAIN:DEFERRED MODULE JOB);
285 TS("[DEFERRED] E_Module's deferred job");
286 e_module_deferred_job();
287 TS("[DEFERRED] E_Module's deferred job Done");
292 return ECORE_CALLBACK_DONE;
296 _e_main_deferred_job_schedule(void *d EINA_UNUSED, int type EINA_UNUSED, void *ev EINA_UNUSED)
298 ecore_idler_add(_e_main_subsystem_defer, NULL);
299 return ECORE_CALLBACK_DONE;
302 /* externally accessible functions */
304 main(int argc, char **argv)
306 Eina_Bool safe_mode = EINA_FALSE;
307 double t = 0.0, tstart = 0.0;
308 char *s = NULL, buff[32];
309 struct sigaction action;
312 # ifdef PR_SET_PTRACER
313 # ifdef PR_SET_PTRACER_ANY
314 prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY);
319 t0 = t1 = t2 = ecore_time_unix_get();
320 printf("ESTART(main) %1.5f\n", t0);
322 TRACE_DS_BEGIN(MAIN:BEGIN STARTUP);
325 /* trap deadly bug signals and allow some form of sane recovery */
326 /* or ability to gdb attach and debug at this point - better than your */
327 /* wm/desktop vanishing and not knowing what happened */
329 /* don't install SIGBUS handler */
330 /* Wayland shm sets up a sigbus handler for catching invalid shm region */
331 /* access. If we setup our sigbus handler here, then the wl-shm sigbus */
332 /* handler will not function properly */
333 if (!getenv("NOTIFY_SOCKET"))
336 action.sa_sigaction = e_sigseg_act;
337 action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
338 sigemptyset(&action.sa_mask);
339 sigaction(SIGSEGV, &action, NULL);
341 action.sa_sigaction = e_sigill_act;
342 action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
343 sigemptyset(&action.sa_mask);
344 sigaction(SIGILL, &action, NULL);
346 action.sa_sigaction = e_sigfpe_act;
347 action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
348 sigemptyset(&action.sa_mask);
349 sigaction(SIGFPE, &action, NULL);
351 action.sa_sigaction = e_sigabrt_act;
352 action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
353 sigemptyset(&action.sa_mask);
354 sigaction(SIGABRT, &action, NULL);
355 TS("Signal Trap Done");
358 t = ecore_time_unix_get();
359 s = getenv("E_START_TIME");
360 if ((s) && (!getenv("E_RESTART_OK")))
363 if ((t - tstart) < 5.0) safe_mode = EINA_TRUE;
366 snprintf(buff, sizeof(buff), "%1.1f", tstart);
367 e_util_env_set("E_START_TIME", buff);
369 if (getenv("E_START_MTRACK"))
370 e_util_env_set("MTRACK", NULL);
374 e_error_message_show(_("Enlightenment cannot initialize Eina!\n"));
375 _e_main_shutdown(-1);
377 TS("Eina Init Done");
378 _e_main_shutdown_push(eina_shutdown);
380 #ifdef OBJECT_HASH_CHECK
381 TS("E_Object Hash Init");
382 e_object_hash_init();
383 TS("E_Object Hash Init Done");
389 e_error_message_show(_("Enlightenment could not create a logging domain!\n"));
390 _e_main_shutdown(-1);
392 TS("E_Log Init Done");
393 _e_main_shutdown_push(e_log_shutdown);
395 TS("Determine Prefix");
396 if (!e_prefix_determine(argv[0]))
399 "ERROR: Enlightenment cannot determine it's installed\n"
400 " prefix from the system or argv[0].\n"
401 " This is because it is not on Linux AND has been\n"
402 " executed strangely. This is unusual.\n");
404 TS("Determine Prefix Done");
406 /* for debugging by redirecting stdout of e to a log file to tail */
407 setvbuf(stdout, NULL, _IONBF, 0);
409 TS("Parse Arguments");
410 _e_main_parse_arguments(argc, argv);
411 TS("Parse Arguments Done");
413 /*** Initialize Core EFL Libraries We Need ***/
418 e_error_message_show(_("Enlightenment cannot initialize Eet!\n"));
419 _e_main_shutdown(-1);
422 _e_main_shutdown_push(eet_shutdown);
424 /* Allow ecore to not load system modules.
425 * Without it ecore_init will block until dbus authentication
426 * and registration are complete.
428 ecore_app_no_system_modules();
433 e_error_message_show(_("Enlightenment cannot initialize Ecore!\n"));
434 _e_main_shutdown(-1);
436 TS("Ecore Init Done");
437 _e_main_shutdown_push(ecore_shutdown);
439 e_first_frame = getenv("E_FIRST_FRAME");
440 if (e_first_frame && e_first_frame[0])
441 e_first_frame_start_time = ecore_time_get();
443 e_first_frame = NULL;
448 e_error_message_show(_("Enlightenment cannot initialize EIO!\n"));
449 _e_main_shutdown(-1);
452 _e_main_shutdown_push(eio_shutdown);
454 ecore_app_args_set(argc, (const char **)argv);
456 TS("Ecore Event Handlers");
457 if (!ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT,
458 _e_main_cb_signal_exit, NULL))
460 e_error_message_show(_("Enlightenment cannot set up an exit signal handler.\n"
461 "Perhaps you are out of memory?"));
462 _e_main_shutdown(-1);
464 if (!ecore_event_handler_add(ECORE_EVENT_SIGNAL_HUP,
465 _e_main_cb_signal_hup, NULL))
467 e_error_message_show(_("Enlightenment cannot set up a HUP signal handler.\n"
468 "Perhaps you are out of memory?"));
469 _e_main_shutdown(-1);
471 if (!ecore_event_handler_add(ECORE_EVENT_SIGNAL_USER,
472 _e_main_cb_signal_user, NULL))
474 e_error_message_show(_("Enlightenment cannot set up a USER signal handler.\n"
475 "Perhaps you are out of memory?"));
476 _e_main_shutdown(-1);
478 TS("Ecore Event Handlers Done");
480 TS("Ecore_File Init");
481 if (!ecore_file_init())
483 e_error_message_show(_("Enlightenment cannot initialize Ecore_File!\n"));
484 _e_main_shutdown(-1);
486 TS("Ecore_File Init Done");
487 _e_main_shutdown_push(ecore_file_shutdown);
489 _idle_before = ecore_idle_enterer_before_add(_e_main_cb_idle_before, NULL);
491 TS("XDG_DATA_DIRS Init");
492 _xdg_data_dirs_augment();
493 TS("XDG_DATA_DIRS Init Done");
495 TS("Ecore_Evas Init");
496 if (!ecore_evas_init())
498 e_error_message_show(_("Enlightenment cannot initialize Ecore_Evas!\n"));
499 _e_main_shutdown(-1);
501 TS("Ecore_Evas Init Done");
503 /* e doesn't sync to compositor - it should be one */
504 ecore_evas_app_comp_sync_set(0);
507 /*** Initialize E Subsystems We Need ***/
509 TS("E Directories Init");
510 /* setup directories we will be using for configurations storage etc. */
511 if (!_e_main_dirs_init())
513 e_error_message_show(_("Enlightenment cannot create directories in your home directory.\n"
514 "Perhaps you have no home directory or the disk is full?"));
515 _e_main_shutdown(-1);
517 TS("E Directories Init Done");
518 _e_main_shutdown_push(_e_main_dirs_shutdown);
521 if (!e_config_init())
523 e_error_message_show(_("Enlightenment cannot set up its config system.\n"));
524 _e_main_shutdown(-1);
526 TS("E_Config Init Done");
527 _e_main_shutdown_push(e_config_shutdown);
532 e_error_message_show(_("Enlightenment cannot set up its environment.\n"));
533 _e_main_shutdown(-1);
535 TS("E_Env Init Done");
536 _e_main_shutdown_push(e_env_shutdown);
538 ecore_exe_run_priority_set(e_config->priority);
541 if (!_e_main_path_init())
543 e_error_message_show(_("Enlightenment cannot set up paths for finding files.\n"
544 "Perhaps you are out of memory?"));
545 _e_main_shutdown(-1);
547 TS("E Paths Init Done");
548 _e_main_shutdown_push(_e_main_path_shutdown);
550 ecore_animator_frametime_set(1.0 / e_config->framerate);
555 e_error_message_show(_("Enlightenment cannot set up its theme system.\n"));
556 _e_main_shutdown(-1);
558 TS("E_Theme Init Done");
559 _e_main_shutdown_push(e_theme_shutdown);
561 e_screensaver_preinit();
563 TS("E_Actions Init");
564 if (!e_actions_init())
566 e_error_message_show(_("Enlightenment cannot set up its actions system.\n"));
567 _e_main_shutdown(-1);
569 TS("E_Actions Init Done");
570 _e_main_shutdown_push(e_actions_shutdown);
572 /* these just add event handlers and can't fail
573 * timestamping them is dumb.
579 TS("E_Screensaver Init");
580 if (!e_screensaver_init())
582 e_error_message_show(_("Enlightenment cannot configure the X screensaver.\n"));
583 _e_main_shutdown(-1);
585 TS("E_Screensaver Init Done");
586 _e_main_shutdown_push(e_screensaver_shutdown);
588 TRACE_DS_BEGIN(MAIN:SCREEN INIT);
590 if (!_e_main_screens_init())
592 e_error_message_show(_("Enlightenment set up window management for all the screens on your system\n"
593 "failed. Perhaps another window manager is running?\n"));
594 _e_main_shutdown(-1);
596 TS("Screens Init Done");
597 _e_main_shutdown_push(_e_main_screens_shutdown);
602 TS("E_Comp Freeze Done");
604 TS("E_Grabinput Init");
605 if (!e_grabinput_init())
607 e_error_message_show(_("Enlightenment cannot set up its grab input handling system.\n"));
608 _e_main_shutdown(-1);
610 TS("E_Grabinput Init Done");
611 _e_main_shutdown_push(e_grabinput_shutdown);
613 ecore_event_handler_add(E_EVENT_MODULE_INIT_END, _e_main_deferred_job_schedule, NULL);
616 if (!e_module_init())
618 e_error_message_show(_("Enlightenment cannot set up its module system.\n"));
619 _e_main_shutdown(-1);
621 TS("E_Module Init Done");
622 _e_main_shutdown_push(e_module_shutdown);
624 TS("E_Remember Init");
625 if (!e_remember_init())
627 e_error_message_show(_("Enlightenment cannot setup remember settings.\n"));
628 _e_main_shutdown(-1);
630 TS("E_Remember Init Done");
631 _e_main_shutdown_push(e_remember_shutdown);
634 if (!e_mouse_update())
636 e_error_message_show(_("Enlightenment cannot configure the mouse settings.\n"));
637 _e_main_shutdown(-1);
639 TS("E_Mouse Init Done");
644 e_error_message_show(_("Enlightenment cannot initialize the Icon Cache system.\n"));
645 _e_main_shutdown(-1);
647 TS("E_Icon Init Done");
648 _e_main_shutdown_push(e_icon_shutdown);
651 _e_main_modules_load(safe_mode);
652 TS("Load Modules Done");
656 TS("E_Comp Thaw Done");
658 _idle_after = ecore_idle_enterer_add(_e_main_cb_idle_after, NULL);
660 starting = EINA_FALSE;
663 e_util_env_set("E_RESTART", "1");
665 TS("MAIN LOOP AT LAST");
668 if (!setjmp(x_fatal_buff))
669 ecore_main_loop_begin();
671 CRI("FATAL: X Died. Connection gone. Abbreviated Shutdown\n");
674 stopping = EINA_TRUE;
677 e_remember_internal_save();
678 e_comp_internal_save();
684 e_util_env_set("E_RESTART_OK", "1");
685 if (getenv("E_START_MTRACK"))
686 e_util_env_set("MTRACK", "track");
696 e_main_ts(const char *str)
699 t1 = ecore_time_unix_get();
700 printf("ESTART: %1.5f [%1.5f] - %s\n", t1 - t0, t1 - t2, str);
706 /* local functions */
708 _e_main_shutdown(int errcode)
714 printf("E: Begin Shutdown Procedure!\n");
716 if (_idle_before) ecore_idle_enterer_del(_idle_before);
718 if (_idle_after) ecore_idle_enterer_del(_idle_after);
721 dir = getenv("XDG_RUNTIME_DIR");
724 char buf_env[PATH_MAX];
725 snprintf(buf_env, sizeof(buf_env), "%s", dir);
726 snprintf(buf, sizeof(buf), "%s/.e-deleteme", buf_env);
727 if (ecore_file_exists(buf)) ecore_file_recursive_rm(buf_env);
729 for (i = (_e_main_lvl - 1); i >= 0; i--)
730 (*_e_main_shutdown_func[i])();
731 #ifdef OBJECT_HASH_CHECK
732 e_object_hash_shutdown();
734 if (errcode < 0) exit(errcode);
738 _e_main_shutdown_push(int (*func)(void))
741 if (_e_main_lvl > MAX_LEVEL)
744 e_error_message_show("WARNING: too many init levels. MAX = %i\n",
748 _e_main_shutdown_func[_e_main_lvl - 1] = func;
752 _e_main_parse_arguments(int argc, char **argv)
757 /* handle some command-line parameters */
758 for (i = 1; i < argc; i++)
760 if ((!strcmp(argv[i], "-display")) && (i < (argc - 1)))
763 e_util_env_set("DISPLAY", argv[i]);
765 else if ((!strcmp(argv[i], "-fake-xinerama-screen")) && (i < (argc - 1)))
770 if (sscanf(argv[i], "%ix%i+%i+%i", &w, &h, &x, &y) == 4)
771 e_xinerama_fake_screen_add(x, y, w, h);
773 else if (!strcmp(argv[i], "-good"))
777 printf("LA LA LA\n");
779 else if (!strcmp(argv[i], "-evil"))
783 printf("MUHAHAHAHHAHAHAHAHA\n");
785 else if (!strcmp(argv[i], "-psychotic"))
789 printf("MUHAHALALALALALALALA\n");
791 else if ((!strcmp(argv[i], "-profile")) && (i < (argc - 1)))
794 if (!getenv("E_CONF_PROFILE"))
795 e_util_env_set("E_CONF_PROFILE", argv[i]);
797 else if (!strcmp(argv[i], "-i-really-know-what-i-am-doing-and-accept-full-responsibility-for-it"))
798 really_know = EINA_TRUE;
799 else if (!strcmp(argv[i], "-nopause"))
800 e_nopause = EINA_TRUE;
801 else if ((!strcmp(argv[i], "-version")) ||
802 (!strcmp(argv[i], "--version")))
804 printf(_("Version: %s\n"), PACKAGE_VERSION);
805 _e_main_shutdown(-1);
807 else if ((!strcmp(argv[i], "-h")) ||
808 (!strcmp(argv[i], "-help")) ||
809 (!strcmp(argv[i], "--help")))
814 "\t-display DISPLAY\n"
815 "\t\tConnect to display named DISPLAY.\n"
816 "\t\tEG: -display :1.0\n"
817 "\t-fake-xinerama-screen WxH+X+Y\n"
818 "\t\tAdd a FAKE xinerama screen (instead of the real ones)\n"
819 "\t\tgiven the geometry. Add as many as you like. They all\n"
820 "\t\treplace the real xinerama screens, if any. This can\n"
821 "\t\tbe used to simulate xinerama.\n"
822 "\t\tEG: -fake-xinerama-screen 800x600+0+0 -fake-xinerama-screen 800x600+800+0\n"
823 "\t-profile CONF_PROFILE\n"
824 "\t\tUse the configuration profile CONF_PROFILE instead of the user selected default or just \"default\".\n"
830 "\t\tBe psychotic.\n"
831 "\t-i-really-know-what-i-am-doing-and-accept-full-responsibility-for-it\n"
832 "\t\tIf you need this help, you don't need this option.\n"
836 _e_main_shutdown(-1);
840 /* fix up DISPLAY to be :N.0 if no .screen is in it */
841 s = getenv("DISPLAY");
846 if (!(p = strrchr(s, ':')))
848 snprintf(buff, sizeof(buff), "%s:0.0", s);
849 e_util_env_set("DISPLAY", buff);
853 if (!strrchr(p, '.'))
855 snprintf(buff, sizeof(buff), "%s.0", s);
856 e_util_env_set("DISPLAY", buff);
861 /* we want to have been launched by enlightenment_start. there is a very */
862 /* good reason we want to have been launched this way, thus check */
863 if (!getenv("E_START"))
865 e_error_message_show(_("You are executing enlightenment directly. This is\n"
866 "bad. Please do not execute the \"enlightenment\"\n"
867 "binary. Use the \"enlightenment_start\" launcher. It\n"
868 "will handle setting up environment variables, paths,\n"
869 "and launching any other required services etc.\n"
870 "before enlightenment itself begins running.\n"));
871 _e_main_shutdown(-1);
876 _e_main_cb_x_fatal(void *data EINA_UNUSED)
878 e_error_message_show("Lost X Connection.\n");
879 ecore_main_loop_quit();
883 if (inloop) longjmp(x_fatal_buff, -99);
888 _e_main_cb_signal_exit(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev EINA_UNUSED)
890 /* called on ctrl-c, kill (pid) (also SIGINT, SIGTERM and SIGQIT) */
891 //e_sys_action_do(E_SYS_EXIT, NULL);
892 return ECORE_CALLBACK_RENEW;
896 _e_main_cb_signal_hup(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev EINA_UNUSED)
898 //e_sys_action_do(E_SYS_RESTART, NULL);
899 return ECORE_CALLBACK_RENEW;
903 _e_main_cb_signal_user(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev)
905 Ecore_Event_Signal_User *e = ev;
909 // E_Action *a = e_action_find("configuration");
910 // if ((a) && (a->func.go)) a->func.go(NULL, NULL);
912 else if (e->number == 2)
914 // comp module has its own handler for this for enabling/disabling fps debug
916 return ECORE_CALLBACK_RENEW;
921 _e_main_dirs_init(void)
932 base = e_user_dir_get();
933 if (ecore_file_mksubdirs(base, dirs) != sizeof(dirs) / sizeof(dirs[0]) - 1)
935 e_error_message_show("Could not create one of the required "
936 "subdirectories of '%s'\n", base);
944 _e_main_dirs_shutdown(void)
950 _e_main_path_init(void)
954 /* setup data paths */
955 path_data = e_path_new();
958 e_error_message_show("Cannot allocate path for path_data\n");
961 e_prefix_data_concat_static(buf, "data");
962 e_path_default_path_append(path_data, buf);
964 /* setup image paths */
965 path_images = e_path_new();
968 e_error_message_show("Cannot allocate path for path_images\n");
971 e_user_dir_concat_static(buf, "/images");
972 e_path_default_path_append(path_images, buf);
973 e_prefix_data_concat_static(buf, "data/images");
974 e_path_default_path_append(path_images, buf);
976 /* setup font paths */
977 path_fonts = e_path_new();
980 e_error_message_show("Cannot allocate path for path_fonts\n");
983 e_user_dir_concat_static(buf, "/fonts");
984 e_path_default_path_append(path_fonts, buf);
985 e_prefix_data_concat_static(buf, "data/fonts");
986 e_path_default_path_append(path_fonts, buf);
988 /* setup icon paths */
989 path_icons = e_path_new();
992 e_error_message_show("Cannot allocate path for path_icons\n");
995 e_user_dir_concat_static(buf, "/icons");
996 e_path_default_path_append(path_icons, buf);
997 e_prefix_data_concat_static(buf, "data/icons");
998 e_path_default_path_append(path_icons, buf);
1000 /* setup module paths */
1001 path_modules = e_path_new();
1004 e_error_message_show("Cannot allocate path for path_modules\n");
1007 e_user_dir_concat_static(buf, "/modules");
1008 e_path_default_path_append(path_modules, buf);
1009 snprintf(buf, sizeof(buf), "%s/enlightenment/modules", e_prefix_lib_get());
1010 e_path_default_path_append(path_modules, buf);
1011 /* FIXME: eventually this has to go - moduels should have installers that
1012 * add appropriate install paths (if not installed to user homedir) to
1013 * e's module search dirs
1015 snprintf(buf, sizeof(buf), "%s/enlightenment/modules_extra", e_prefix_lib_get());
1016 e_path_default_path_append(path_modules, buf);
1018 /* setup background paths */
1019 path_backgrounds = e_path_new();
1020 if (!path_backgrounds)
1022 e_error_message_show("Cannot allocate path for path_backgrounds\n");
1025 e_user_dir_concat_static(buf, "/backgrounds");
1026 e_path_default_path_append(path_backgrounds, buf);
1027 e_prefix_data_concat_static(buf, "data/backgrounds");
1028 e_path_default_path_append(path_backgrounds, buf);
1030 path_messages = e_path_new();
1033 e_error_message_show("Cannot allocate path for path_messages\n");
1036 e_user_dir_concat_static(buf, "/locale");
1037 e_path_default_path_append(path_messages, buf);
1038 e_path_default_path_append(path_messages, e_prefix_locale_get());
1044 _e_main_path_shutdown(void)
1048 e_object_del(E_OBJECT(path_data));
1053 e_object_del(E_OBJECT(path_images));
1058 e_object_del(E_OBJECT(path_fonts));
1063 e_object_del(E_OBJECT(path_icons));
1068 e_object_del(E_OBJECT(path_modules));
1069 path_modules = NULL;
1071 if (path_backgrounds)
1073 e_object_del(E_OBJECT(path_backgrounds));
1074 path_backgrounds = NULL;
1078 e_object_del(E_OBJECT(path_messages));
1079 path_messages = NULL;
1085 _e_main_screens_init(void)
1087 TS("\tscreens: client");
1088 if (!e_client_init()) return 0;
1090 TS("Compositor Init");
1093 e_error_message_show(_("Enlightenment cannot create a compositor.\n"));
1094 _e_main_shutdown(-1);
1097 _e_main_desk_restore();
1103 _e_main_screens_shutdown(void)
1107 e_client_shutdown();
1116 _e_main_desk_save(void)
1119 char env[1024], name[1024];
1122 EINA_LIST_FOREACH(e_comp->zones, l, zone)
1124 snprintf(name, sizeof(name), "DESK_%d_%d", 0, zone->num);
1125 snprintf(env, sizeof(env), "%d,%d", zone->desk_x_current, zone->desk_y_current);
1126 e_util_env_set(name, env);
1131 _e_main_desk_restore(void)
1139 EINA_LIST_FOREACH(e_comp->zones, l, zone)
1145 snprintf(name, sizeof(name), "DESK_%d_%d", 0, zone->num);
1148 snprintf(buf_e, sizeof(buf_e), "%s", env);
1149 if (!sscanf(buf_e, "%d,%d", &desk_x, &desk_y)) continue;
1150 desk = e_desk_at_xy_get(zone, desk_x, desk_y);
1151 if (!desk) continue;
1155 E_CLIENT_REVERSE_FOREACH(ec)
1156 if ((!e_client_util_ignored_get(ec)) && e_client_util_desk_visible(ec, e_desk_current_get(ec->zone)))
1158 ec->want_focus = ec->take_focus = 1;
1164 _e_main_modules_load_after(void *d EINA_UNUSED, int type EINA_UNUSED, void *ev EINA_UNUSED)
1166 E_FREE_FUNC(mod_init_end, ecore_event_handler_del);
1167 return ECORE_CALLBACK_RENEW;
1171 _e_main_modules_load(Eina_Bool safe_mode)
1174 e_module_all_load();
1180 crashmodule = getenv("E_MODULE_LOAD");
1181 if (crashmodule) m = e_module_new(crashmodule);
1183 if ((crashmodule) && (m))
1185 e_module_disable(m);
1186 e_object_del(E_OBJECT(m));
1188 e_error_message_show
1189 (_("Enlightenment crashed early on start and has<br>"
1190 "been restarted. There was an error loading the<br>"
1191 "module named: %s. This module has been disabled<br>"
1192 "and will not be loaded."), crashmodule);
1194 (_("Enlightenment crashed early on start and has been restarted"),
1195 _("Enlightenment crashed early on start and has been restarted.<br>"
1196 "There was an error loading the module named: %s<br><br>"
1197 "This module has been disabled and will not be loaded."), crashmodule);
1198 e_module_all_load();
1202 e_error_message_show
1203 (_("Enlightenment crashed early on start and has<br>"
1204 "been restarted. All modules have been disabled<br>"
1205 "and will not be loaded to help remove any problem<br>"
1206 "modules from your configuration. The module<br>"
1207 "configuration dialog should let you select your<br>"
1208 "modules again.\n"));
1210 (_("Enlightenment crashed early on start and has been restarted"),
1211 _("Enlightenment crashed early on start and has been restarted.<br>"
1212 "All modules have been disabled and will not be loaded to help<br>"
1213 "remove any problem modules from your configuration.<br><br>"
1214 "The module configuration dialog should let you select your<br>"
1217 mod_init_end = ecore_event_handler_add(E_EVENT_MODULE_INIT_END, _e_main_modules_load_after, NULL);
1222 _e_main_cb_idle_before(void *data EINA_UNUSED)
1224 e_client_idler_before();
1225 e_pointer_idler_before();
1227 return ECORE_CALLBACK_RENEW;
1231 _e_main_cb_idle_after(void *data EINA_UNUSED)
1233 static int first_idle = 1;
1238 #ifdef E_RELEASE_BUILD
1243 e_precache_end = EINA_TRUE;
1246 if (first_idle++ < 60)
1250 e_precache_end = EINA_TRUE;
1254 return ECORE_CALLBACK_RENEW;