3 # include <sys/prctl.h>
6 # include <systemd/sd-daemon.h>
15 t1 = ecore_time_unix_get(); \
16 printf("ESTART: %1.5f [%1.5f] - %s\n", t1 - t0, t1 - t2, x); \
22 TRACE_DS_BEGIN(ESTART: %s, x); \
32 TRACE_DS_MARK(ESTART: %s, x); \
35 static double t0, t1, t2;
43 * i need to make more use of these when i'm baffled as to when something is
46 * void *(*__malloc_hook)(size_t size, const void *caller);
48 * void *(*__realloc_hook)(void *ptr, size_t size, const void *caller);
50 * void *(*__memalign_hook)(size_t alignment, size_t size,
51 * const void *caller);
53 * void (*__free_hook)(void *ptr, const void *caller);
55 * void (*__malloc_initialize_hook)(void);
57 * void (*__after_morecore_hook)(void);
60 static void my_init_hook(void);
61 static void my_free_hook(void *p, const void *caller);
63 static void (*old_free_hook)(void *ptr, const void *caller) = NULL;
64 void (*__free_hook)(void *ptr, const void *caller);
66 void (*__malloc_initialize_hook) (void) = my_init_hook;
70 old_free_hook = __free_hook;
71 __free_hook = my_free_hook;
74 //void *magicfree = NULL;
77 my_free_hook(void *p, const void *caller)
79 __free_hook = old_free_hook;
80 // if ((p) && (p == magicfree))
82 // printf("CAUGHT!!!!! %p ...\n", p);
86 __free_hook = my_free_hook;
90 /* local function prototypes */
91 static void _e_main_shutdown(int errcode);
92 static void _e_main_shutdown_push(int (*func)(void));
93 static void _e_main_parse_arguments(int argc, char **argv);
94 static Eina_Bool _e_main_cb_signal_exit(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev EINA_UNUSED);
95 static Eina_Bool _e_main_cb_signal_hup(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev EINA_UNUSED);
96 static Eina_Bool _e_main_cb_signal_user(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev);
97 static int _e_main_dirs_init(void);
98 static int _e_main_dirs_shutdown(void);
99 static int _e_main_path_init(void);
100 static int _e_main_path_shutdown(void);
101 static int _e_main_screens_init(void);
102 static int _e_main_screens_shutdown(void);
103 static void _e_main_desk_save(void);
104 static void _e_main_desk_restore(void);
105 static void _e_main_modules_load(Eina_Bool safe_mode);
106 static Eina_Bool _e_main_cb_idle_before(void *data EINA_UNUSED);
107 static Eina_Bool _e_main_cb_idle_after(void *data EINA_UNUSED);
108 static void _e_main_create_wm_ready(void);
109 static void _e_main_hooks_clean(void);
110 static void _e_main_hook_call(E_Main_Hook_Point hookpoint, void *data EINA_UNUSED);
112 /* local variables */
113 static Eina_Bool really_know = EINA_FALSE;
114 static Eina_Bool inloop = EINA_FALSE;
116 static int _e_main_lvl = 0;
117 static int(*_e_main_shutdown_func[MAX_LEVEL]) (void);
119 static Ecore_Idle_Enterer *_idle_before = NULL;
120 static Ecore_Idle_Enterer *_idle_after = NULL;
122 static Ecore_Event_Handler *mod_init_end = NULL;
124 static Eina_List *hooks = NULL;
126 static int _e_main_hooks_delete = 0;
127 static int _e_main_hooks_walking = 0;
129 static Eina_Inlist *_e_main_hooks[] =
131 [E_MAIN_HOOK_MODULE_LOAD_DONE] = NULL,
132 [E_MAIN_HOOK_E_INFO_READY] = NULL
135 /* external variables */
136 E_API Eina_Bool e_precache_end = EINA_FALSE;
137 E_API Eina_Bool good = EINA_FALSE;
138 E_API Eina_Bool evil = EINA_FALSE;
139 E_API Eina_Bool starting = EINA_TRUE;
140 E_API Eina_Bool stopping = EINA_FALSE;
141 E_API Eina_Bool restart = EINA_FALSE;
142 E_API Eina_Bool e_nopause = EINA_FALSE;
143 EINTERN const char *e_first_frame = NULL;
144 EINTERN double e_first_frame_start_time = -1;
147 _xdg_check_str(const char *env, const char *str)
153 for (p = strstr(env, str); p; p++, p = strstr(p, str))
155 if ((!p[len]) || (p[len] == ':')) return EINA_TRUE;
161 _xdg_data_dirs_augment(void)
164 const char *p = e_prefix_get();
165 char newpath[4096], buf[4096];
169 s = getenv("XDG_DATA_DIRS");
172 Eina_Bool pfxdata, pfx;
174 pfxdata = !_xdg_check_str(s, e_prefix_data_get());
175 snprintf(newpath, sizeof(newpath), "%s/share", p);
176 pfx = !_xdg_check_str(s, newpath);
179 snprintf(buf, sizeof(buf), "%s%s%s%s%s",
180 pfxdata ? e_prefix_data_get() : "",
185 e_util_env_set("XDG_DATA_DIRS", buf);
190 snprintf(buf, sizeof(buf), "%s:%s/share:/usr/local/share:/usr/share", e_prefix_data_get(), p);
191 e_util_env_set("XDG_DATA_DIRS", buf);
194 s = getenv("XDG_CONFIG_DIRS");
195 snprintf(newpath, sizeof(newpath), "%s/etc/xdg", p);
198 if (!_xdg_check_str(s, newpath))
200 snprintf(buf, sizeof(buf), "%s:%s", newpath, s);
201 e_util_env_set("XDG_CONFIG_DIRS", buf);
206 snprintf(buf, sizeof(buf), "%s:/etc/xdg", newpath);
207 e_util_env_set("XDG_CONFIG_DIRS", buf);
210 if (!getenv("XDG_RUNTIME_DIR"))
214 snprintf(buf, sizeof(buf), "/tmp/xdg-XXXXXX");
216 if (!dir) dir = "/tmp";
219 e_util_env_set("XDG_RUNTIME_DIR", dir);
220 snprintf(buf, sizeof(buf), "%s/.e-deleteme", dir);
221 ecore_file_mkdir(buf);
225 /* set menu prefix so we get our e menu */
226 if (!getenv("XDG_MENU_PREFIX"))
228 e_util_env_set("XDG_MENU_PREFIX", "e-");
233 _e_main_subsystem_defer(void *data EINA_UNUSED)
238 TRACE_DS_BEGIN(MAIN:SUBSYSTEMS DEFER);
240 ecore_app_args_get(&argc, &argv);
242 /* try to init delayed subsystems */
244 TRACE_DS_BEGIN(MAIN:DEFERRED INTERNAL SUBSYSTEMS INIT);
246 TSB("[DEFERRED] DPMS Init");
249 e_error_message_show(_("Enlightenment cannot set up dpms.\n"));
252 TSE("[DEFERRED] DPMS Init Done");
253 _e_main_shutdown_push(e_dpms_shutdown);
255 TSB("[DEFERRED] Screens Init: win");
258 e_error_message_show(_("Enlightenment cannot setup elementary trap!\n"));
261 TSE("[DEFERRED] Screens Init: win Done");
263 TSB("[DEFERRED] E_Dnd Init");
266 e_error_message_show(_("Enlightenment cannot set up its dnd system.\n"));
269 TSE("[DEFERRED] E_Dnd Init Done");
270 _e_main_shutdown_push(e_dnd_shutdown);
272 TSB("[DEFERRED] E_Scale Init");
275 e_error_message_show(_("Enlightenment cannot set up its scale system.\n"));
278 TSE("[DEFERRED] E_Scale Init Done");
279 _e_main_shutdown_push(e_scale_shutdown);
281 TSB("[DEFERRED] E_Test_Helper Init");
282 e_test_helper_init();
283 _e_main_shutdown_push(e_test_helper_shutdown);
284 TSE("[DEFERRED] E_Test_Helper Done");
286 TSB("[DEFERRED] E_INFO_SERVER Init");
287 e_info_server_init();
288 _e_main_shutdown_push(e_info_server_shutdown);
289 TSE("[DEFERRED] E_INFO_SERVER Done");
292 TRACE_DS_BEGIN(MAIN:DEFERRED COMP JOB);
294 /* try to do deferred job of any subsystems*/
295 TSB("[DEFERRED] Compositor's deferred job");
296 e_comp_deferred_job();
297 TSE("[DEFERRED] Compositor's deferred job Done");
299 if (e_config->use_e_policy)
301 TSB("[DEFERRED] E_Policy's deferred job");
302 e_policy_deferred_job();
303 TSE("[DEFERRED] E_Policy's deferred job Done");
306 TSB("[DEFERRED] E_Module's deferred job");
307 e_module_deferred_job();
308 TSE("[DEFERRED] E_Module's deferred job Done");
312 return ECORE_CALLBACK_DONE;
318 _e_main_shutdown(-1);
319 return ECORE_CALLBACK_DONE;
323 _e_main_deferred_job_schedule(void *d EINA_UNUSED, int type EINA_UNUSED, void *ev EINA_UNUSED)
325 PRCTL("[Winsys] all modules loaded");
326 ecore_idler_add(_e_main_subsystem_defer, NULL);
327 return ECORE_CALLBACK_DONE;
330 /* externally accessible functions */
332 main(int argc, char **argv)
334 Eina_Bool safe_mode = EINA_FALSE;
335 double t = 0.0, tstart = 0.0;
336 char *s = NULL, buff[32];
337 struct sigaction action;
340 # ifdef PR_SET_PTRACER
341 # ifdef PR_SET_PTRACER_ANY
342 prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY);
347 t0 = t1 = t2 = ecore_time_unix_get();
348 printf("ESTART(main) %1.5f\n", t0);
350 TRACE_DS_BEGIN(MAIN:BEGIN STARTUP);
351 TSB("Begin Startup");
352 PRCTL("[Winsys] start of main");
354 /* trap deadly bug signals and allow some form of sane recovery */
355 /* or ability to gdb attach and debug at this point - better than your */
356 /* wm/desktop vanishing and not knowing what happened */
358 /* don't install SIGBUS handler */
359 /* Wayland shm sets up a sigbus handler for catching invalid shm region */
360 /* access. If we setup our sigbus handler here, then the wl-shm sigbus */
361 /* handler will not function properly */
362 if (!getenv("NOTIFY_SOCKET"))
365 action.sa_sigaction = e_sigseg_act;
366 action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
367 sigemptyset(&action.sa_mask);
368 sigaction(SIGSEGV, &action, NULL);
370 action.sa_sigaction = e_sigill_act;
371 action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
372 sigemptyset(&action.sa_mask);
373 sigaction(SIGILL, &action, NULL);
375 action.sa_sigaction = e_sigfpe_act;
376 action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
377 sigemptyset(&action.sa_mask);
378 sigaction(SIGFPE, &action, NULL);
380 action.sa_sigaction = e_sigabrt_act;
381 action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
382 sigemptyset(&action.sa_mask);
383 sigaction(SIGABRT, &action, NULL);
384 TSE("Signal Trap Done");
387 t = ecore_time_unix_get();
388 s = getenv("E_START_TIME");
389 if ((s) && (!getenv("E_RESTART_OK")))
392 if ((t - tstart) < 5.0) safe_mode = EINA_TRUE;
395 snprintf(buff, sizeof(buff), "%1.1f", tstart);
396 e_util_env_set("E_START_TIME", buff);
398 if (getenv("E_START_MTRACK"))
399 e_util_env_set("MTRACK", NULL);
403 e_error_message_show(_("Enlightenment cannot initialize Eina!\n"));
406 TSE("Eina Init Done");
407 _e_main_shutdown_push(eina_shutdown);
409 #ifdef OBJECT_HASH_CHECK
410 TSB("E_Object Hash Init");
411 e_object_hash_init();
412 TSE("E_Object Hash Init Done");
418 e_error_message_show(_("Enlightenment could not create a logging domain!\n"));
421 TSE("E_Log Init Done");
422 _e_main_shutdown_push(e_log_shutdown);
424 TSB("Determine Prefix");
425 if (!e_prefix_determine(argv[0]))
428 "ERROR: Enlightenment cannot determine it's installed\n"
429 " prefix from the system or argv[0].\n"
430 " This is because it is not on Linux AND has been\n"
431 " executed strangely. This is unusual.\n");
433 TSE("Determine Prefix Done");
435 /* for debugging by redirecting stdout of e to a log file to tail */
436 setvbuf(stdout, NULL, _IONBF, 0);
438 TSB("Parse Arguments");
439 _e_main_parse_arguments(argc, argv);
440 TSE("Parse Arguments Done");
442 /*** Initialize Core EFL Libraries We Need ***/
447 e_error_message_show(_("Enlightenment cannot initialize Eet!\n"));
450 TSE("Eet Init Done");
451 _e_main_shutdown_push(eet_shutdown);
453 /* Allow ecore to not load system modules.
454 * Without it ecore_init will block until dbus authentication
455 * and registration are complete.
457 ecore_app_no_system_modules();
462 e_error_message_show(_("Enlightenment cannot initialize Ecore!\n"));
465 TSE("Ecore Init Done");
466 _e_main_shutdown_push(ecore_shutdown);
468 e_first_frame = getenv("E_FIRST_FRAME");
469 if (e_first_frame && e_first_frame[0])
470 e_first_frame_start_time = ecore_time_get();
472 e_first_frame = NULL;
477 e_error_message_show(_("Enlightenment cannot initialize EIO!\n"));
480 TSE("EIO Init Done");
481 _e_main_shutdown_push(eio_shutdown);
483 ecore_app_args_set(argc, (const char **)argv);
485 TSB("Ecore Event Handlers");
486 if (!ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT,
487 _e_main_cb_signal_exit, NULL))
489 e_error_message_show(_("Enlightenment cannot set up an exit signal handler.\n"
490 "Perhaps you are out of memory?"));
493 if (!ecore_event_handler_add(ECORE_EVENT_SIGNAL_HUP,
494 _e_main_cb_signal_hup, NULL))
496 e_error_message_show(_("Enlightenment cannot set up a HUP signal handler.\n"
497 "Perhaps you are out of memory?"));
500 if (!ecore_event_handler_add(ECORE_EVENT_SIGNAL_USER,
501 _e_main_cb_signal_user, NULL))
503 e_error_message_show(_("Enlightenment cannot set up a USER signal handler.\n"
504 "Perhaps you are out of memory?"));
507 TSE("Ecore Event Handlers Done");
509 TSB("Ecore_File Init");
510 if (!ecore_file_init())
512 e_error_message_show(_("Enlightenment cannot initialize Ecore_File!\n"));
515 TSE("Ecore_File Init Done");
516 _e_main_shutdown_push(ecore_file_shutdown);
518 _idle_before = ecore_idle_enterer_before_add(_e_main_cb_idle_before, NULL);
520 TSB("XDG_DATA_DIRS Init");
521 _xdg_data_dirs_augment();
522 TSE("XDG_DATA_DIRS Init Done");
524 TSB("Ecore_Evas Init");
525 if (!ecore_evas_init())
527 e_error_message_show(_("Enlightenment cannot initialize Ecore_Evas!\n"));
530 TSE("Ecore_Evas Init Done");
532 /* e doesn't sync to compositor - it should be one */
533 ecore_evas_app_comp_sync_set(0);
538 e_error_message_show(_("Enlightenment cannot initialize Edje!\n"));
541 TSE("Edje Init Done");
542 _e_main_shutdown_push(edje_shutdown);
544 /*** Initialize E Subsystems We Need ***/
546 TSB("E Directories Init");
547 /* setup directories we will be using for configurations storage etc. */
548 if (!_e_main_dirs_init())
550 e_error_message_show(_("Enlightenment cannot create directories in your home directory.\n"
551 "Perhaps you have no home directory or the disk is full?"));
554 TSE("E Directories Init Done");
555 _e_main_shutdown_push(_e_main_dirs_shutdown);
557 TSB("E_Config Init");
558 if (!e_config_init())
560 e_error_message_show(_("Enlightenment cannot set up its config system.\n"));
563 TSE("E_Config Init Done");
564 _e_main_shutdown_push(e_config_shutdown);
569 e_error_message_show(_("Enlightenment cannot set up its environment.\n"));
572 TSE("E_Env Init Done");
573 _e_main_shutdown_push(e_env_shutdown);
575 ecore_exe_run_priority_set(e_config->priority);
578 if (!_e_main_path_init())
580 e_error_message_show(_("Enlightenment cannot set up paths for finding files.\n"
581 "Perhaps you are out of memory?"));
584 TSE("E Paths Init Done");
585 _e_main_shutdown_push(_e_main_path_shutdown);
587 ecore_animator_frametime_set(1.0 / e_config->framerate);
592 e_error_message_show(_("Enlightenment cannot set up its theme system.\n"));
595 TSE("E_Theme Init Done");
596 _e_main_shutdown_push(e_theme_shutdown);
598 TSB("E_Actions Init");
599 if (!e_actions_init())
601 e_error_message_show(_("Enlightenment cannot set up its actions system.\n"));
604 TSE("E_Actions Init Done");
605 _e_main_shutdown_push(e_actions_shutdown);
607 /* these just add event handlers and can't fail
608 * timestamping them is dumb.
610 e_screensaver_preinit();
615 TRACE_DS_BEGIN(MAIN:WAIT /dev/dri/card0);
616 if (e_config->sleep_for_dri)
618 while(access("/dev/dri/card0", F_OK) != 0)
620 struct timespec req, rem;
622 req.tv_nsec = 50000000L;
623 nanosleep(&req, &rem);
628 e_module_event_init();
630 TSB("E_Pointer Init");
631 if (!e_pointer_init())
633 e_error_message_show(_("Enlightenment cannot set up its pointer system.\n"));
636 TSE("E_Pointer Init Done");
637 _e_main_shutdown_push(e_pointer_shutdown);
639 TRACE_DS_BEGIN(MAIN:SCREEN INIT);
641 if (!_e_main_screens_init())
643 e_error_message_show(_("Enlightenment set up window management for all the screens on your system\n"
644 "failed. Perhaps another window manager is running?\n"));
647 TSE("Screens Init Done");
648 _e_main_shutdown_push(_e_main_screens_shutdown);
651 if (e_config->eom_enable)
656 e_error_message_show(_("Enlightenment cannot set up eom.\n"));
659 TSE("Eom Init Done");
660 _e_main_shutdown_push(e_eom_shutdown);
663 TSB("E_Screensaver Init");
664 if (!e_screensaver_init())
666 e_error_message_show(_("Enlightenment cannot configure the X screensaver.\n"));
669 TSE("E_Screensaver Init Done");
670 _e_main_shutdown_push(e_screensaver_shutdown);
672 TSB("E_Comp Freeze");
674 TSE("E_Comp Freeze Done");
676 TSB("E_Grabinput Init");
677 if (!e_grabinput_init())
679 e_error_message_show(_("Enlightenment cannot set up its grab input handling system.\n"));
682 TSE("E_Grabinput Init Done");
683 _e_main_shutdown_push(e_grabinput_shutdown);
685 TS("E_Gesture Init");
687 _e_main_shutdown_push(e_gesture_shutdown);
689 ecore_event_handler_add(E_EVENT_MODULE_INIT_END, _e_main_deferred_job_schedule, NULL);
691 TSB("E_Module Init");
692 if (!e_module_init())
694 e_error_message_show(_("Enlightenment cannot set up its module system.\n"));
697 TSE("E_Module Init Done");
698 _e_main_shutdown_push(e_module_shutdown);
701 if (!e_mouse_update())
703 e_error_message_show(_("Enlightenment cannot configure the mouse settings.\n"));
706 TSE("E_Mouse Init Done");
711 e_error_message_show(_("Enlightenment cannot initialize the Icon Cache system.\n"));
714 TSE("E_Icon Init Done");
715 _e_main_shutdown_push(e_icon_shutdown);
717 if (e_config->use_e_policy)
719 TSB("E_Policy Init");
720 if (!e_policy_init())
722 e_error_message_show(_("Enlightenment cannot setup policy system!\n"));
725 TSE("E_Policy Init Done");
726 _e_main_shutdown_push(e_policy_shutdown);
729 TSB("E_Process Init");
730 if (!e_process_init())
732 e_error_message_show(_("Enlightenment cannot setup process managing system!\n"));
735 TSE("E_Process Init Done");
736 _e_main_shutdown_push(e_process_shutdown);
738 TSB("E_Security Init");
739 if (!e_security_init())
741 e_error_message_show(_("Enlightenment cannot setup security system!\n"));
744 TSE("E_Security Init Done");
745 _e_main_shutdown_push(e_security_shutdown);
748 _e_main_modules_load(safe_mode);
749 TSE("Load Modules Done");
753 TSE("E_Comp Thaw Done");
755 _idle_after = ecore_idle_enterer_add(_e_main_cb_idle_after, NULL);
757 starting = EINA_FALSE;
760 e_util_env_set("E_RESTART", "1");
762 TSM("MAIN LOOP AT LAST");
764 if (e_config->create_wm_ready)
765 _e_main_create_wm_ready();
770 TSM("[WM] Send start-up completion");
771 sd_notify(0, "READY=1");
773 TSM("[WM] Skip sending start-up completion. (no systemd)");
775 ecore_main_loop_begin();
779 ELOGF("COMP", "STOPPING enlightenment...", NULL, NULL);
780 stopping = EINA_TRUE;
783 e_comp_internal_save();
789 e_util_env_set("E_RESTART_OK", "1");
790 if (getenv("E_START_MTRACK"))
791 e_util_env_set("MTRACK", "track");
802 _e_main_shutdown(-1);
806 e_main_ts(const char *str)
809 t1 = ecore_time_unix_get();
810 printf("ESTART: %1.5f [%1.5f] - %s\n", t1 - t0, t1 - t2, str);
817 e_main_ts_begin(const char *str)
819 TRACE_DS_BEGIN(ESTART: %s, str);
820 return e_main_ts(str);
824 e_main_ts_end(const char *str)
827 return e_main_ts(str);
830 /* local functions */
832 _e_main_shutdown(int errcode)
838 printf("E: Begin Shutdown Procedure!\n");
840 E_FREE_LIST(hooks, e_main_hook_del);
842 if (_idle_before) ecore_idle_enterer_del(_idle_before);
844 if (_idle_after) ecore_idle_enterer_del(_idle_after);
847 dir = getenv("XDG_RUNTIME_DIR");
850 char buf_env[PATH_MAX];
851 snprintf(buf_env, sizeof(buf_env), "%s", dir);
852 snprintf(buf, sizeof(buf), "%s/.e-deleteme", buf_env);
853 if (ecore_file_exists(buf)) ecore_file_recursive_rm(buf_env);
855 for (i = (_e_main_lvl - 1); i >= 0; i--)
856 (*_e_main_shutdown_func[i])();
857 #ifdef OBJECT_HASH_CHECK
858 e_object_hash_shutdown();
860 if (errcode < 0) exit(errcode);
864 _e_main_shutdown_push(int (*func)(void))
867 if (_e_main_lvl > MAX_LEVEL)
870 e_error_message_show("WARNING: too many init levels. MAX = %i\n",
874 _e_main_shutdown_func[_e_main_lvl - 1] = func;
878 _e_main_parse_arguments(int argc, char **argv)
882 /* handle some command-line parameters */
883 for (i = 1; i < argc; i++)
885 if (!strcmp(argv[i], "-good"))
889 printf("LA LA LA\n");
891 else if (!strcmp(argv[i], "-evil"))
895 printf("MUHAHAHAHHAHAHAHAHA\n");
897 else if (!strcmp(argv[i], "-psychotic"))
901 printf("MUHAHALALALALALALALA\n");
903 else if ((!strcmp(argv[i], "-profile")) && (i < (argc - 1)))
906 if (!getenv("E_CONF_PROFILE"))
907 e_util_env_set("E_CONF_PROFILE", argv[i]);
909 else if (!strcmp(argv[i], "-i-really-know-what-i-am-doing-and-accept-full-responsibility-for-it"))
910 really_know = EINA_TRUE;
911 else if (!strcmp(argv[i], "-nopause"))
912 e_nopause = EINA_TRUE;
913 else if ((!strcmp(argv[i], "-version")) ||
914 (!strcmp(argv[i], "--version")))
916 printf(_("Version: %s\n"), PACKAGE_VERSION);
917 _e_main_shutdown(-1);
919 else if ((!strcmp(argv[i], "-h")) ||
920 (!strcmp(argv[i], "-help")) ||
921 (!strcmp(argv[i], "--help")))
926 "\t-display DISPLAY\n"
927 "\t\tConnect to display named DISPLAY.\n"
928 "\t\tEG: -display :1.0\n"
929 "\t-fake-xinerama-screen WxH+X+Y\n"
930 "\t\tAdd a FAKE xinerama screen (instead of the real ones)\n"
931 "\t\tgiven the geometry. Add as many as you like. They all\n"
932 "\t\treplace the real xinerama screens, if any. This can\n"
933 "\t\tbe used to simulate xinerama.\n"
934 "\t\tEG: -fake-xinerama-screen 800x600+0+0 -fake-xinerama-screen 800x600+800+0\n"
935 "\t-profile CONF_PROFILE\n"
936 "\t\tUse the configuration profile CONF_PROFILE instead of the user selected default or just \"default\".\n"
942 "\t\tBe psychotic.\n"
943 "\t-i-really-know-what-i-am-doing-and-accept-full-responsibility-for-it\n"
944 "\t\tIf you need this help, you don't need this option.\n"
948 _e_main_shutdown(-1);
954 _e_main_cb_signal_exit(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev EINA_UNUSED)
956 /* called on ctrl-c, kill (pid) (also SIGINT, SIGTERM and SIGQIT) */
957 ecore_main_loop_quit();
958 return ECORE_CALLBACK_RENEW;
962 _e_main_cb_signal_hup(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev EINA_UNUSED)
965 ecore_main_loop_quit();
966 return ECORE_CALLBACK_RENEW;
970 _e_main_cb_signal_user(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev)
972 Ecore_Event_Signal_User *e = ev;
976 // E_Action *a = e_action_find("configuration");
977 // if ((a) && (a->func.go)) a->func.go(NULL, NULL);
979 else if (e->number == 2)
981 // comp module has its own handler for this for enabling/disabling fps debug
983 return ECORE_CALLBACK_RENEW;
988 _e_main_dirs_init(void)
990 if(getenv("E_CONF_RO"))
1004 base = e_user_dir_get();
1005 if (ecore_file_mksubdirs(base, dirs) != sizeof(dirs) / sizeof(dirs[0]) - 1)
1007 e_error_message_show("Could not create one of the required "
1008 "subdirectories of '%s'\n", base);
1016 _e_main_dirs_shutdown(void)
1022 _e_main_path_init(void)
1026 /* setup data paths */
1027 path_data = e_path_new();
1030 e_error_message_show("Cannot allocate path for path_data\n");
1033 e_prefix_data_concat_static(buf, "data");
1034 e_path_default_path_append(path_data, buf);
1036 /* setup image paths */
1037 path_images = e_path_new();
1040 e_error_message_show("Cannot allocate path for path_images\n");
1043 e_user_dir_concat_static(buf, "/images");
1044 e_path_default_path_append(path_images, buf);
1045 e_prefix_data_concat_static(buf, "data/images");
1046 e_path_default_path_append(path_images, buf);
1048 /* setup font paths */
1049 path_fonts = e_path_new();
1052 e_error_message_show("Cannot allocate path for path_fonts\n");
1055 e_user_dir_concat_static(buf, "/fonts");
1056 e_path_default_path_append(path_fonts, buf);
1057 e_prefix_data_concat_static(buf, "data/fonts");
1058 e_path_default_path_append(path_fonts, buf);
1060 /* setup icon paths */
1061 path_icons = e_path_new();
1064 e_error_message_show("Cannot allocate path for path_icons\n");
1067 e_user_dir_concat_static(buf, "/icons");
1068 e_path_default_path_append(path_icons, buf);
1069 e_prefix_data_concat_static(buf, "data/icons");
1070 e_path_default_path_append(path_icons, buf);
1072 /* setup module paths */
1073 path_modules = e_path_new();
1076 e_error_message_show("Cannot allocate path for path_modules\n");
1079 e_user_dir_concat_static(buf, "/modules");
1080 e_path_default_path_append(path_modules, buf);
1081 snprintf(buf, sizeof(buf), "%s/enlightenment/modules", e_prefix_lib_get());
1082 e_path_default_path_append(path_modules, buf);
1083 /* FIXME: eventually this has to go - moduels should have installers that
1084 * add appropriate install paths (if not installed to user homedir) to
1085 * e's module search dirs
1087 snprintf(buf, sizeof(buf), "%s/enlightenment/modules_extra", e_prefix_lib_get());
1088 e_path_default_path_append(path_modules, buf);
1090 /* setup background paths */
1091 path_backgrounds = e_path_new();
1092 if (!path_backgrounds)
1094 e_error_message_show("Cannot allocate path for path_backgrounds\n");
1097 e_user_dir_concat_static(buf, "/backgrounds");
1098 e_path_default_path_append(path_backgrounds, buf);
1099 e_prefix_data_concat_static(buf, "data/backgrounds");
1100 e_path_default_path_append(path_backgrounds, buf);
1102 path_messages = e_path_new();
1105 e_error_message_show("Cannot allocate path for path_messages\n");
1108 e_user_dir_concat_static(buf, "/locale");
1109 e_path_default_path_append(path_messages, buf);
1110 e_path_default_path_append(path_messages, e_prefix_locale_get());
1116 _e_main_path_shutdown(void)
1120 e_object_del(E_OBJECT(path_data));
1125 e_object_del(E_OBJECT(path_images));
1130 e_object_del(E_OBJECT(path_fonts));
1135 e_object_del(E_OBJECT(path_icons));
1140 e_object_del(E_OBJECT(path_modules));
1141 path_modules = NULL;
1143 if (path_backgrounds)
1145 e_object_del(E_OBJECT(path_backgrounds));
1146 path_backgrounds = NULL;
1150 e_object_del(E_OBJECT(path_messages));
1151 path_messages = NULL;
1157 _e_main_screens_init(void)
1159 TSB("\tscreens: client");
1160 if (!e_client_init()) return 0;
1161 TSE("\tscreens: client Done");
1163 TSB("Compositor Init");
1164 PRCTL("[Winsys] start of compositor init");
1167 e_error_message_show(_("Enlightenment cannot create a compositor.\n"));
1168 _e_main_shutdown(-1);
1170 TSE("Compositor Init Done");
1172 PRCTL("[Winsys] end of compositor init");
1173 _e_main_desk_restore();
1179 _e_main_screens_shutdown(void)
1183 e_client_shutdown();
1192 _e_main_desk_save(void)
1195 char env[1024], name[1024];
1198 EINA_LIST_FOREACH(e_comp->zones, l, zone)
1200 snprintf(name, sizeof(name), "DESK_%d_%d", 0, zone->num);
1201 snprintf(env, sizeof(env), "%d,%d", zone->desk_x_current, zone->desk_y_current);
1202 e_util_env_set(name, env);
1207 _e_main_desk_restore(void)
1211 E_CLIENT_REVERSE_FOREACH(ec)
1212 if ((!e_client_util_ignored_get(ec)) && e_client_util_desk_visible(ec, e_desk_current_get(ec->zone)))
1214 ec->want_focus = ec->take_focus = 1;
1220 _e_main_modules_load_after(void *d EINA_UNUSED, int type EINA_UNUSED, void *ev EINA_UNUSED)
1222 E_FREE_FUNC(mod_init_end, ecore_event_handler_del);
1223 return ECORE_CALLBACK_RENEW;
1227 _e_main_modules_load(Eina_Bool safe_mode)
1230 e_module_all_load();
1236 crashmodule = getenv("E_MODULE_LOAD");
1237 if (crashmodule) m = e_module_new(crashmodule);
1239 if ((crashmodule) && (m))
1241 e_module_disable(m);
1242 e_object_del(E_OBJECT(m));
1244 e_error_message_show
1245 (_("Enlightenment crashed early on start and has<br>"
1246 "been restarted. There was an error loading the<br>"
1247 "module named: %s. This module has been disabled<br>"
1248 "and will not be loaded."), crashmodule);
1250 (_("Enlightenment crashed early on start and has been restarted"),
1251 _("Enlightenment crashed early on start and has been restarted.<br>"
1252 "There was an error loading the module named: %s<br><br>"
1253 "This module has been disabled and will not be loaded."), crashmodule);
1254 e_module_all_load();
1258 e_error_message_show
1259 (_("Enlightenment crashed early on start and has<br>"
1260 "been restarted. All modules have been disabled<br>"
1261 "and will not be loaded to help remove any problem<br>"
1262 "modules from your configuration. The module<br>"
1263 "configuration dialog should let you select your<br>"
1264 "modules again.\n"));
1266 (_("Enlightenment crashed early on start and has been restarted"),
1267 _("Enlightenment crashed early on start and has been restarted.<br>"
1268 "All modules have been disabled and will not be loaded to help<br>"
1269 "remove any problem modules from your configuration.<br><br>"
1270 "The module configuration dialog should let you select your<br>"
1273 mod_init_end = ecore_event_handler_add(E_EVENT_MODULE_INIT_END, _e_main_modules_load_after, NULL);
1278 _e_main_cb_idle_before(void *data EINA_UNUSED)
1280 e_client_idler_before();
1282 return ECORE_CALLBACK_RENEW;
1286 _e_main_cb_idle_after(void *data EINA_UNUSED)
1288 static int first_idle = 1;
1293 #ifdef E_RELEASE_BUILD
1298 e_precache_end = EINA_TRUE;
1301 if (first_idle++ < 60)
1305 e_precache_end = EINA_TRUE;
1309 return ECORE_CALLBACK_RENEW;
1313 _e_main_create_wm_ready(void)
1315 FILE *_wmready_checker = NULL;
1316 const char *path_wm_ready = "/run/.wm_ready";
1318 if (!e_util_file_realpath_check(path_wm_ready, EINA_TRUE))
1320 WRN("%s is maybe link, so delete it\n", path_wm_ready);
1323 _wmready_checker = fopen(path_wm_ready, "wb");
1324 if (_wmready_checker)
1326 TSM("[WM] WINDOW MANAGER is READY!!!");
1327 PRCTL("[Winsys] WINDOW MANAGER is READY!!!");
1328 fclose(_wmready_checker);
1330 /*TODO: Next lines should be removed. */
1331 FILE *_tmp_wm_ready_checker;
1333 _tmp_wm_ready_checker = fopen(path_wm_ready, "wb");
1335 if (_tmp_wm_ready_checker)
1337 TSM("[WM] temporary wm_ready path is created.");
1338 PRCTL("[Winsys] temporary wm_ready path is created.");
1339 fclose(_tmp_wm_ready_checker);
1343 TSM("[WM] temporary wm_ready path create failed.");
1344 PRCTL("[Winsys] temporary wm_ready path create failed.");
1349 TSM("[WM] WINDOW MANAGER is READY. BUT, failed to create .wm_ready file.");
1350 PRCTL("[Winsys] WINDOW MANAGER is READY. BUT, failed to create .wm_ready file.");
1355 _e_main_hooks_clean(void)
1361 for (x = 0; x < E_MAIN_HOOK_LAST; x++)
1362 EINA_INLIST_FOREACH_SAFE(_e_main_hooks[x], l, mh)
1364 if (!mh->delete_me) continue;
1365 _e_main_hooks[x] = eina_inlist_remove(_e_main_hooks[x],
1366 EINA_INLIST_GET(mh));
1372 _e_main_hook_call(E_Main_Hook_Point hookpoint, void *data EINA_UNUSED)
1376 _e_main_hooks_walking++;
1377 EINA_INLIST_FOREACH(_e_main_hooks[hookpoint], mh)
1379 if (mh->delete_me) continue;
1382 _e_main_hooks_walking--;
1383 if ((_e_main_hooks_walking == 0) && (_e_main_hooks_delete > 0))
1384 _e_main_hooks_clean();
1388 e_main_hook_add(E_Main_Hook_Point hookpoint, E_Main_Hook_Cb func, const void *data)
1392 EINA_SAFETY_ON_TRUE_RETURN_VAL(hookpoint >= E_MAIN_HOOK_LAST, NULL);
1393 mh = E_NEW(E_Main_Hook, 1);
1394 EINA_SAFETY_ON_NULL_RETURN_VAL(mh, NULL);
1395 mh->hookpoint = hookpoint;
1397 mh->data = (void*)data;
1398 _e_main_hooks[hookpoint] = eina_inlist_append(_e_main_hooks[hookpoint],
1399 EINA_INLIST_GET(mh));
1404 e_main_hook_del(E_Main_Hook *mh)
1407 if (_e_main_hooks_walking == 0)
1409 _e_main_hooks[mh->hookpoint] = eina_inlist_remove(_e_main_hooks[mh->hookpoint],
1410 EINA_INLIST_GET(mh));
1414 _e_main_hooks_delete++;
1418 e_main_hook_call(E_Main_Hook_Point hookpoint)
1420 if ((hookpoint < 0) || (hookpoint >= E_MAIN_HOOK_LAST)) return;
1422 _e_main_hook_call(hookpoint, NULL);