2 #include "e_actions_intern.h"
5 # include <sys/prctl.h>
8 # include <systemd/sd-daemon.h>
17 t1 = ecore_time_unix_get(); \
18 printf("ESTART: %1.5f [%1.5f] - %s\n", t1 - t0, t1 - t2, x); \
24 TRACE_DS_BEGIN(ESTART: %s, x); \
34 TRACE_DS_MARK(ESTART: %s, x); \
37 static double t0, t1, t2;
45 * i need to make more use of these when i'm baffled as to when something is
48 * void *(*__malloc_hook)(size_t size, const void *caller);
50 * void *(*__realloc_hook)(void *ptr, size_t size, const void *caller);
52 * void *(*__memalign_hook)(size_t alignment, size_t size,
53 * const void *caller);
55 * void (*__free_hook)(void *ptr, const void *caller);
57 * void (*__malloc_initialize_hook)(void);
59 * void (*__after_morecore_hook)(void);
62 static void my_init_hook(void);
63 static void my_free_hook(void *p, const void *caller);
65 static void (*old_free_hook)(void *ptr, const void *caller) = NULL;
66 void (*__free_hook)(void *ptr, const void *caller);
68 void (*__malloc_initialize_hook) (void) = my_init_hook;
72 old_free_hook = __free_hook;
73 __free_hook = my_free_hook;
76 //void *magicfree = NULL;
79 my_free_hook(void *p, const void *caller)
81 __free_hook = old_free_hook;
82 // if ((p) && (p == magicfree))
84 // printf("CAUGHT!!!!! %p ...\n", p);
88 __free_hook = my_free_hook;
92 /* local function prototypes */
93 static void _e_main_shutdown(int errcode);
94 static void _e_main_shutdown_push(int (*func)(void));
95 static void _e_main_parse_arguments(int argc, char **argv);
96 static Eina_Bool _e_main_cb_signal_exit(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev EINA_UNUSED);
97 static Eina_Bool _e_main_cb_signal_hup(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev EINA_UNUSED);
98 static int _e_main_dirs_init(void);
99 static int _e_main_dirs_shutdown(void);
100 static int _e_main_path_init(void);
101 static int _e_main_path_shutdown(void);
102 static int _e_main_screens_init(void);
103 static int _e_main_screens_shutdown(void);
104 static void _e_main_desk_save(void);
105 static void _e_main_desk_restore(void);
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 int _e_main_lvl = 0;
114 static int(*_e_main_shutdown_func[MAX_LEVEL]) (void);
116 static Ecore_Idle_Enterer *_idle_before = NULL;
117 static Ecore_Idle_Enterer *_idle_after = NULL;
119 static Eina_List *hooks = NULL;
121 static int _e_main_hooks_delete = 0;
122 static int _e_main_hooks_walking = 0;
124 static Eina_Inlist *_e_main_hooks[] =
126 [E_MAIN_HOOK_MODULE_LOAD_DONE] = NULL,
127 [E_MAIN_HOOK_E_INFO_READY] = NULL,
128 [E_MAIN_HOOK_POST_CLIENT_IDLER_BEFORE] = NULL
131 /* external variables */
132 E_API Eina_Bool starting = EINA_TRUE;
133 E_API Eina_Bool stopping = EINA_FALSE;
136 _xdg_check_str(const char *env, const char *str)
142 for (p = strstr(env, str); p; p++, p = strstr(p, str))
144 if ((!p[len]) || (p[len] == ':')) return EINA_TRUE;
150 _xdg_data_dirs_augment(void)
153 const char *p = e_prefix_get();
154 char newpath[PATH_MAX], buf[PATH_MAX + PATH_MAX + 200];
158 s = e_util_env_get("XDG_DATA_DIRS");
161 Eina_Bool pfxdata, pfx;
163 pfxdata = !_xdg_check_str(s, e_prefix_data_get());
164 snprintf(newpath, sizeof(newpath), "%s/share", p);
165 pfx = !_xdg_check_str(s, newpath);
168 snprintf(buf, sizeof(buf), "%s%s%s%s%s",
169 pfxdata ? e_prefix_data_get() : "",
174 e_util_env_set("XDG_DATA_DIRS", buf);
180 snprintf(buf, sizeof(buf), "%s:%s/share:/usr/local/share:/usr/share", e_prefix_data_get(), p);
181 e_util_env_set("XDG_DATA_DIRS", buf);
184 s = e_util_env_get("XDG_CONFIG_DIRS");
185 snprintf(newpath, sizeof(newpath), "%s/etc/xdg", p);
188 if (!_xdg_check_str(s, newpath))
190 snprintf(buf, sizeof(buf), "%s:%s", newpath, s);
191 e_util_env_set("XDG_CONFIG_DIRS", buf);
197 snprintf(buf, sizeof(buf), "%s:/etc/xdg", newpath);
198 e_util_env_set("XDG_CONFIG_DIRS", buf);
201 s = e_util_env_get("XDG_RUNTIME_DIR");
208 snprintf(buf, sizeof(buf), "/tmp/xdg-XXXXXX");
210 if (!dir) dir = "/tmp";
213 e_util_env_set("XDG_RUNTIME_DIR", dir);
214 snprintf(buf, sizeof(buf), "%s/.e-deleteme", dir);
215 ecore_file_mkdir(buf);
219 /* set menu prefix so we get our e menu */
220 s = e_util_env_get("XDG_MENU_PREFIX");
224 e_util_env_set("XDG_MENU_PREFIX", "e-");
228 _e_main_subsystem_defer(void *data EINA_UNUSED)
230 TRACE_DS_BEGIN(MAIN:SUBSYSTEMS DEFER);
232 /* try to init delayed subsystems */
234 TRACE_DS_BEGIN(MAIN:DEFERRED INTERNAL SUBSYSTEMS INIT);
236 TSB("[DEFERRED] DPMS Init");
239 e_error_message_show(_("Enlightenment cannot set up dpms.\n"));
242 TSE("[DEFERRED] DPMS Init Done");
243 _e_main_shutdown_push(e_dpms_shutdown);
245 TSB("[DEFERRED] E_Dnd Init");
248 e_error_message_show(_("Enlightenment cannot set up its dnd system.\n"));
251 TSE("[DEFERRED] E_Dnd Init Done");
252 _e_main_shutdown_push(e_dnd_shutdown);
254 TSB("[DEFERRED] E_Scale Init");
257 e_error_message_show(_("Enlightenment cannot set up its scale system.\n"));
260 TSE("[DEFERRED] E_Scale Init Done");
261 _e_main_shutdown_push(e_scale_shutdown);
263 TSB("[DEFERRED] E_Test_Helper Init");
264 e_test_helper_init();
265 _e_main_shutdown_push(e_test_helper_shutdown);
266 TSE("[DEFERRED] E_Test_Helper Done");
268 TSB("[DEFERRED] E_INFO_SERVER Init");
269 e_info_server_init();
270 _e_main_shutdown_push(e_info_server_shutdown);
271 TSE("[DEFERRED] E_INFO_SERVER Done");
274 TRACE_DS_BEGIN(MAIN:DEFERRED COMP JOB);
276 /* try to do deferred job of any subsystems*/
277 TSB("[DEFERRED] Compositor's deferred job");
278 e_comp_deferred_job();
279 TSE("[DEFERRED] Compositor's deferred job Done");
281 if (e_config->use_e_policy)
283 TSB("[DEFERRED] E_Policy's deferred job");
284 e_policy_deferred_job();
285 TSE("[DEFERRED] E_Policy's deferred job Done");
288 TSB("[DEFERRED] E_Module's deferred job");
289 e_module_deferred_job();
290 TSE("[DEFERRED] E_Module's deferred job Done");
294 return ECORE_CALLBACK_DONE;
300 _e_main_shutdown(-1);
301 return ECORE_CALLBACK_DONE;
305 _e_main_deferred_job_schedule(void *d EINA_UNUSED, int type EINA_UNUSED, void *ev EINA_UNUSED)
307 PRCTL("[Winsys] all modules loaded");
308 ecore_idler_add(_e_main_subsystem_defer, NULL);
309 return ECORE_CALLBACK_DONE;
312 /* externally accessible functions */
314 main(int argc, char **argv)
317 struct sigaction action;
320 # ifdef PR_SET_PTRACER
321 # ifdef PR_SET_PTRACER_ANY
322 prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY);
327 #ifdef TIZEN_TEST_GCOV
328 setenv("GCOV_PREFIX", "/tmp", 1);
331 /* for debugging by redirecting stdout & stderr of e to a log file to tail */
332 setvbuf(stdout, NULL, _IONBF, 0);
333 setvbuf(stderr, NULL, _IONBF, 0);
336 t0 = t1 = t2 = ecore_time_unix_get();
337 printf("ESTART(main) %1.5f\n", t0);
339 TRACE_DS_BEGIN(MAIN:BEGIN STARTUP);
340 TSB("Begin Startup");
341 PRCTL("[Winsys] start of main");
343 /* trap deadly bug signals and allow some form of sane recovery */
344 /* or ability to gdb attach and debug at this point - better than your */
345 /* wm/desktop vanishing and not knowing what happened */
347 /* don't install SIGBUS handler */
348 /* Wayland shm sets up a sigbus handler for catching invalid shm region */
349 /* access. If we setup our sigbus handler here, then the wl-shm sigbus */
350 /* handler will not function properly */
351 s = e_util_env_get("NOTIFY_SOCKET");
357 action.sa_sigaction = e_sigseg_act;
358 action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
359 sigemptyset(&action.sa_mask);
360 sigaction(SIGSEGV, &action, NULL);
362 action.sa_sigaction = e_sigill_act;
363 action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
364 sigemptyset(&action.sa_mask);
365 sigaction(SIGILL, &action, NULL);
367 action.sa_sigaction = e_sigfpe_act;
368 action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
369 sigemptyset(&action.sa_mask);
370 sigaction(SIGFPE, &action, NULL);
372 action.sa_sigaction = e_sigabrt_act;
373 action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
374 sigemptyset(&action.sa_mask);
375 sigaction(SIGABRT, &action, NULL);
376 TSE("Signal Trap Done");
382 e_error_message_show(_("Enlightenment cannot initialize Eina!\n"));
385 TSE("Eina Init Done");
386 _e_main_shutdown_push(eina_shutdown);
388 #ifdef OBJECT_HASH_CHECK
389 TSB("E_Object Hash Init");
390 e_object_hash_init();
391 TSE("E_Object Hash Init Done");
397 e_error_message_show(_("Enlightenment could not create a logging domain!\n"));
400 TSE("E_Log Init Done");
401 _e_main_shutdown_push(e_log_shutdown);
403 TSB("Determine Prefix");
404 if (!e_prefix_determine(argv[0]))
407 "ERROR: Enlightenment cannot determine it's installed\n"
408 " prefix from the system or argv[0].\n"
409 " This is because it is not on Linux AND has been\n"
410 " executed strangely. This is unusual.\n");
412 TSE("Determine Prefix Done");
414 TSB("Parse Arguments");
415 _e_main_parse_arguments(argc, argv);
416 TSE("Parse Arguments Done");
418 /*** Initialize Core EFL Libraries We Need ***/
423 e_error_message_show(_("Enlightenment cannot initialize Eet!\n"));
426 TSE("Eet Init Done");
427 _e_main_shutdown_push(eet_shutdown);
429 /* Allow ecore to not load system modules.
430 * Without it ecore_init will block until dbus authentication
431 * and registration are complete.
433 ecore_app_no_system_modules();
438 e_error_message_show(_("Enlightenment cannot initialize Ecore!\n"));
441 TSE("Ecore Init Done");
442 _e_main_shutdown_push(ecore_shutdown);
447 e_error_message_show(_("Enlightenment cannot initialize EIO!\n"));
450 TSE("EIO Init Done");
451 _e_main_shutdown_push(eio_shutdown);
453 TSB("Ecore Event Handlers");
454 if (!ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT,
455 _e_main_cb_signal_exit, NULL))
457 e_error_message_show(_("Enlightenment cannot set up an exit signal handler.\n"
458 "Perhaps you are out of memory?"));
461 if (!ecore_event_handler_add(ECORE_EVENT_SIGNAL_HUP,
462 _e_main_cb_signal_hup, NULL))
464 e_error_message_show(_("Enlightenment cannot set up a HUP signal handler.\n"
465 "Perhaps you are out of memory?"));
468 TSE("Ecore Event Handlers Done");
470 TSB("Ecore_File Init");
471 if (!ecore_file_init())
473 e_error_message_show(_("Enlightenment cannot initialize Ecore_File!\n"));
476 TSE("Ecore_File Init Done");
477 _e_main_shutdown_push(ecore_file_shutdown);
479 TSB("E_Util_File_Monitor Init");
480 e_util_file_monitor_init();
481 TSE("E_Util_File_Monitor Init Done");
482 _e_main_shutdown_push(e_util_file_monitor_shutdown);
484 _idle_before = ecore_idle_enterer_before_add(_e_main_cb_idle_before, NULL);
486 TSB("XDG_DATA_DIRS Init");
487 _xdg_data_dirs_augment();
488 TSE("XDG_DATA_DIRS Init Done");
490 TSB("Ecore_Evas Init");
491 if (!ecore_evas_init())
493 e_error_message_show(_("Enlightenment cannot initialize Ecore_Evas!\n"));
496 TSE("Ecore_Evas Init Done");
501 e_error_message_show(_("Enlightenment cannot initialize Edje!\n"));
504 TSE("Edje Init Done");
505 _e_main_shutdown_push(edje_shutdown);
507 /*** Initialize E Subsystems We Need ***/
512 e_error_message_show(_("Enlightenment cannot set up user home path\n"));
515 TSE("E User Init Done");
516 _e_main_shutdown_push(e_user_shutdown);
518 TSB("E Directories Init");
519 /* setup directories we will be using for configurations storage etc. */
520 if (!_e_main_dirs_init())
522 e_error_message_show(_("Enlightenment cannot create directories in your home directory.\n"
523 "Perhaps you have no home directory or the disk is full?"));
526 TSE("E Directories Init Done");
527 _e_main_shutdown_push(_e_main_dirs_shutdown);
529 TSB("E_Config Init");
530 if (!e_config_init())
532 e_error_message_show(_("Enlightenment cannot set up its config system.\n"));
535 TSE("E_Config Init Done");
536 _e_main_shutdown_push(e_config_shutdown);
541 e_error_message_show(_("Enlightenment cannot set up its environment.\n"));
544 TSE("E_Env Init Done");
545 _e_main_shutdown_push(e_env_shutdown);
547 ecore_exe_run_priority_set(e_config->priority);
550 if (!_e_main_path_init())
552 e_error_message_show(_("Enlightenment cannot set up paths for finding files.\n"
553 "Perhaps you are out of memory?"));
556 TSE("E Paths Init Done");
557 _e_main_shutdown_push(_e_main_path_shutdown);
559 ecore_animator_frametime_set(1.0 / e_config->framerate);
564 e_error_message_show(_("Enlightenment cannot set up its theme system.\n"));
567 TSE("E_Theme Init Done");
568 _e_main_shutdown_push(e_theme_shutdown);
570 TSB("E_Actions Init");
571 if (!e_actions_init())
573 e_error_message_show(_("Enlightenment cannot set up its actions system.\n"));
576 TSE("E_Actions Init Done");
577 _e_main_shutdown_push(e_actions_shutdown);
579 /* these just add event handlers and can't fail
580 * timestamping them is dumb.
582 e_screensaver_preinit();
587 TRACE_DS_BEGIN(MAIN:WAIT /dev/dri/card0);
588 if (e_config->sleep_for_dri)
590 while(access("/dev/dri/card0", F_OK) != 0)
592 struct timespec req, rem;
594 req.tv_nsec = 50000000L;
595 nanosleep(&req, &rem);
603 e_error_message_show(_("Enlightenment cannot set up its msg system."));
606 TSE("E_Msg Init Done");
607 _e_main_shutdown_push(e_msg_shutdown);
609 e_module_event_init();
611 TSB("E_Pointer Init");
612 if (!e_pointer_init())
614 e_error_message_show(_("Enlightenment cannot set up its pointer system.\n"));
617 TSE("E_Pointer Init Done");
618 _e_main_shutdown_push(e_pointer_shutdown);
620 TRACE_DS_BEGIN(MAIN:SCREEN INIT);
622 if (!_e_main_screens_init())
624 e_error_message_show(_("Enlightenment set up window management for all the screens on your system\n"
625 "failed. Perhaps another window manager is running?\n"));
628 TSE("Screens Init Done");
629 _e_main_shutdown_push(_e_main_screens_shutdown);
632 TSB("E_Devicemgr Init");
633 if (!e_devicemgr_init())
635 e_error_message_show(_("Enlightenment cannot set up its device_manager system.\n"));
638 TSE("E_Devicemgr Init Done");
639 _e_main_shutdown_push(e_devicemgr_shutdown);
641 TSB("E_Keyrouter Init");
642 if (!e_keyrouter_init())
644 e_error_message_show(_("Enlightenment cannot set up its keyrouting system.\n"));
647 TSE("E_Keyrouter Init Done");
648 _e_main_shutdown_push(e_keyrouter_shutdown);
650 if (e_config->eom_enable)
655 e_error_message_show(_("Enlightenment cannot set up eom.\n"));
658 TSE("Eom Init Done");
659 _e_main_shutdown_push(e_eom_shutdown);
662 TSB("E_Screensaver Init");
663 if (!e_screensaver_init())
665 e_error_message_show(_("Enlightenment cannot configure the X screensaver.\n"));
668 TSE("E_Screensaver Init Done");
669 _e_main_shutdown_push(e_screensaver_shutdown);
671 TSB("E_Comp Freeze");
673 TSE("E_Comp Freeze Done");
675 TSB("E_Grabinput Init");
676 if (!e_grabinput_init())
678 e_error_message_show(_("Enlightenment cannot set up its grab input handling system.\n"));
681 TSE("E_Grabinput Init Done");
682 _e_main_shutdown_push(e_grabinput_shutdown);
684 TS("E_Gesture Init");
686 _e_main_shutdown_push(e_gesture_shutdown);
688 ecore_event_handler_add(E_EVENT_MODULE_INIT_END, _e_main_deferred_job_schedule, NULL);
690 TSB("E_Module Init");
691 if (!e_module_init())
693 e_error_message_show(_("Enlightenment cannot set up its module system.\n"));
696 TSE("E_Module Init Done");
697 _e_main_shutdown_push(e_module_shutdown);
700 if (!e_mouse_update())
702 e_error_message_show(_("Enlightenment cannot configure the mouse settings.\n"));
705 TSE("E_Mouse Init Done");
710 e_error_message_show(_("Enlightenment cannot initialize the Icon Cache system.\n"));
713 TSE("E_Icon Init Done");
714 _e_main_shutdown_push(e_icon_shutdown);
716 if (e_config->use_e_policy)
718 TSB("E_Policy Init");
719 if (!e_policy_init())
721 e_error_message_show(_("Enlightenment cannot setup policy system!\n"));
724 TSE("E_Policy Init Done");
725 _e_main_shutdown_push(e_policy_shutdown);
728 TSB("E_Process Init");
729 if (!e_process_init())
731 e_error_message_show(_("Enlightenment cannot setup process managing system!\n"));
734 TSE("E_Process Init Done");
735 _e_main_shutdown_push(e_process_shutdown);
737 TSB("E_Security Init");
738 if (!e_security_init())
740 e_error_message_show(_("Enlightenment cannot setup security system!\n"));
743 TSE("E_Security Init Done");
744 _e_main_shutdown_push(e_security_shutdown);
748 TSE("Load Modules Done");
752 TSE("E_Comp Thaw Done");
754 if (e_config->use_thread_max_cpu)
758 cpus = eina_cpu_count();
761 TSM("Set ecore thread max");
762 ecore_thread_max_set(cpus);
766 _idle_after = ecore_idle_enterer_add(_e_main_cb_idle_after, NULL);
768 starting = EINA_FALSE;
770 TSM("MAIN LOOP AT LAST");
772 if (e_config->create_wm_ready)
773 _e_main_create_wm_ready();
778 TSM("[WM] Send start-up completion");
779 sd_notify(0, "READY=1");
781 TSM("[WM] Skip sending start-up completion. (no systemd)");
783 ecore_main_loop_begin();
785 ELOGF("COMP", "STOPPING enlightenment...", NULL);
786 stopping = EINA_TRUE;
789 e_comp_internal_save();
800 _e_main_shutdown(-1);
804 e_main_ts(const char *str)
807 t1 = ecore_time_unix_get();
808 printf("ESTART: %1.5f [%1.5f] - %s\n", t1 - t0, t1 - t2, str);
815 e_main_ts_begin(const char *str)
817 TRACE_DS_BEGIN(ESTART: %s, str);
818 return e_main_ts(str);
822 e_main_ts_end(const char *str)
825 return e_main_ts(str);
828 /* local functions */
830 _e_main_shutdown(int errcode)
836 printf("E: Begin Shutdown Procedure!\n");
838 E_FREE_LIST(hooks, e_main_hook_del);
840 if (_idle_before) ecore_idle_enterer_del(_idle_before);
842 if (_idle_after) ecore_idle_enterer_del(_idle_after);
845 dir = e_util_env_get("XDG_RUNTIME_DIR");
848 char buf_env[PATH_MAX - 12];
849 snprintf(buf_env, sizeof(buf_env), "%s", dir);
850 snprintf(buf, sizeof(buf), "%s/.e-deleteme", buf_env);
851 if (ecore_file_exists(buf)) ecore_file_recursive_rm(buf_env);
854 for (i = (_e_main_lvl - 1); i >= 0; i--)
855 (*_e_main_shutdown_func[i])();
856 #ifdef OBJECT_HASH_CHECK
857 e_object_hash_shutdown();
859 if (errcode < 0) exit(errcode);
863 _e_main_shutdown_push(int (*func)(void))
866 if (_e_main_lvl > MAX_LEVEL)
869 e_error_message_show("WARNING: too many init levels. MAX = %i\n",
873 _e_main_shutdown_func[_e_main_lvl - 1] = func;
877 _e_main_parse_arguments(int argc, char **argv)
881 /* handle some command-line parameters */
882 for (i = 1; i < argc; i++)
884 if ((!strcmp(argv[i], "-profile")) && (i < (argc - 1)))
887 if (!getenv("E_CONF_PROFILE"))
888 e_util_env_set("E_CONF_PROFILE", argv[i]);
890 else if ((!strcmp(argv[i], "-version")) ||
891 (!strcmp(argv[i], "--version")))
893 printf(_("Version: %s\n"), PACKAGE_VERSION);
894 _e_main_shutdown(-1);
896 else if ((!strcmp(argv[i], "-h")) ||
897 (!strcmp(argv[i], "-help")) ||
898 (!strcmp(argv[i], "--help")))
903 "\t-profile CONF_PROFILE\n"
904 "\t\tUse the configuration profile CONF_PROFILE instead of the user selected default or just \"default\".\n"
908 _e_main_shutdown(-1);
914 _e_main_cb_signal_exit(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev EINA_UNUSED)
916 /* called on ctrl-c, kill (pid) (also SIGINT, SIGTERM and SIGQIT) */
917 ecore_main_loop_quit();
918 return ECORE_CALLBACK_RENEW;
922 _e_main_cb_signal_hup(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev EINA_UNUSED)
924 ecore_main_loop_quit();
925 return ECORE_CALLBACK_RENEW;
929 _e_main_dirs_init(void)
931 if(getenv("E_CONF_RO"))
945 base = e_user_dir_get();
946 if (ecore_file_mksubdirs(base, dirs) != sizeof(dirs) / sizeof(dirs[0]) - 1)
948 e_error_message_show("Could not create one of the required "
949 "subdirectories of '%s'\n", base);
957 _e_main_dirs_shutdown(void)
963 _e_main_path_init(void)
967 /* setup data paths */
968 path_data = e_path_new();
971 e_error_message_show("Cannot allocate path for path_data\n");
974 e_prefix_data_concat_static(buf, "data");
975 e_path_default_path_append(path_data, buf);
977 /* setup image paths */
978 path_images = e_path_new();
981 e_error_message_show("Cannot allocate path for path_images\n");
984 e_user_dir_concat_static(buf, "/images");
985 e_path_default_path_append(path_images, buf);
986 e_prefix_data_concat_static(buf, "data/images");
987 e_path_default_path_append(path_images, buf);
989 /* setup font paths */
990 path_fonts = e_path_new();
993 e_error_message_show("Cannot allocate path for path_fonts\n");
996 e_user_dir_concat_static(buf, "/fonts");
997 e_path_default_path_append(path_fonts, buf);
998 e_prefix_data_concat_static(buf, "data/fonts");
999 e_path_default_path_append(path_fonts, buf);
1001 /* setup icon paths */
1002 path_icons = e_path_new();
1005 e_error_message_show("Cannot allocate path for path_icons\n");
1008 e_user_dir_concat_static(buf, "/icons");
1009 e_path_default_path_append(path_icons, buf);
1010 e_prefix_data_concat_static(buf, "data/icons");
1011 e_path_default_path_append(path_icons, buf);
1013 /* setup module paths */
1014 path_modules = e_path_new();
1017 e_error_message_show("Cannot allocate path for path_modules\n");
1020 e_user_dir_concat_static(buf, "/modules");
1021 e_path_default_path_append(path_modules, buf);
1022 snprintf(buf, sizeof(buf), "%s/enlightenment/modules", e_prefix_lib_get());
1023 e_path_default_path_append(path_modules, buf);
1024 /* FIXME: eventually this has to go - moduels should have installers that
1025 * add appropriate install paths (if not installed to user homedir) to
1026 * e's module search dirs
1028 snprintf(buf, sizeof(buf), "%s/enlightenment/modules_extra", e_prefix_lib_get());
1029 e_path_default_path_append(path_modules, buf);
1031 /* setup background paths */
1032 path_backgrounds = e_path_new();
1033 if (!path_backgrounds)
1035 e_error_message_show("Cannot allocate path for path_backgrounds\n");
1038 e_user_dir_concat_static(buf, "/backgrounds");
1039 e_path_default_path_append(path_backgrounds, buf);
1040 e_prefix_data_concat_static(buf, "data/backgrounds");
1041 e_path_default_path_append(path_backgrounds, buf);
1043 path_messages = e_path_new();
1046 e_error_message_show("Cannot allocate path for path_messages\n");
1049 e_user_dir_concat_static(buf, "/locale");
1050 e_path_default_path_append(path_messages, buf);
1051 e_path_default_path_append(path_messages, e_prefix_locale_get());
1057 _e_main_path_shutdown(void)
1061 e_object_del(E_OBJECT(path_data));
1066 e_object_del(E_OBJECT(path_images));
1071 e_object_del(E_OBJECT(path_fonts));
1076 e_object_del(E_OBJECT(path_icons));
1081 e_object_del(E_OBJECT(path_modules));
1082 path_modules = NULL;
1084 if (path_backgrounds)
1086 e_object_del(E_OBJECT(path_backgrounds));
1087 path_backgrounds = NULL;
1091 e_object_del(E_OBJECT(path_messages));
1092 path_messages = NULL;
1098 _e_main_screens_init(void)
1100 TSB("\tscreens: client");
1101 if (!e_client_init()) return 0;
1102 TSE("\tscreens: client Done");
1104 TSB("Compositor Init");
1105 PRCTL("[Winsys] start of compositor init");
1108 e_error_message_show(_("Enlightenment cannot create a compositor.\n"));
1109 _e_main_shutdown(-1);
1111 TSE("Compositor Init Done");
1113 PRCTL("[Winsys] end of compositor init");
1114 _e_main_desk_restore();
1120 _e_main_screens_shutdown(void)
1123 e_client_shutdown();
1125 e_magnifier_shutdown();
1132 _e_main_desk_save(void)
1135 char env[1024], name[1024];
1138 EINA_LIST_FOREACH(e_comp->zones, l, zone)
1140 snprintf(name, sizeof(name), "DESK_%d_%d", 0, zone->num);
1141 snprintf(env, sizeof(env), "%d,%d", zone->desk_x_current, zone->desk_y_current);
1142 e_util_env_set(name, env);
1147 _e_main_desk_restore(void)
1152 E_CLIENT_REVERSE_FOREACH(ec)
1154 zone = e_comp_zone_find_by_ec(ec);
1155 if ((!e_client_util_ignored_get(ec)) && e_desk_has_ec(e_desk_current_get(zone), ec))
1157 ec->want_focus = ec->take_focus = 1;
1164 _e_main_cb_idle_before(void *data EINA_UNUSED)
1166 e_comp_idler_before();
1167 _e_main_hook_call(E_MAIN_HOOK_POST_CLIENT_IDLER_BEFORE, NULL);
1170 return ECORE_CALLBACK_RENEW;
1174 _e_main_cb_idle_after(void *data EINA_UNUSED)
1176 static int first_idle = 1;
1187 return ECORE_CALLBACK_RENEW;
1191 _e_main_create_wm_ready(void)
1193 FILE *_wmready_checker = NULL;
1194 const char *path_wm_ready = "/run/.wm_ready";
1196 if (!e_util_file_realpath_check(path_wm_ready, EINA_TRUE))
1198 WRN("%s is maybe link, so delete it\n", path_wm_ready);
1201 _wmready_checker = fopen(path_wm_ready, "wb");
1202 if (_wmready_checker)
1204 TSM("[WM] WINDOW MANAGER is READY!!!");
1205 PRCTL("[Winsys] WINDOW MANAGER is READY!!!");
1206 fclose(_wmready_checker);
1208 /*TODO: Next lines should be removed. */
1209 FILE *_tmp_wm_ready_checker;
1211 _tmp_wm_ready_checker = fopen(path_wm_ready, "wb");
1213 if (_tmp_wm_ready_checker)
1215 TSM("[WM] temporary wm_ready path is created.");
1216 PRCTL("[Winsys] temporary wm_ready path is created.");
1217 fclose(_tmp_wm_ready_checker);
1221 TSM("[WM] temporary wm_ready path create failed.");
1222 PRCTL("[Winsys] temporary wm_ready path create failed.");
1227 TSM("[WM] WINDOW MANAGER is READY. BUT, failed to create .wm_ready file.");
1228 PRCTL("[Winsys] WINDOW MANAGER is READY. BUT, failed to create .wm_ready file.");
1233 _e_main_hooks_clean(void)
1239 for (x = 0; x < E_MAIN_HOOK_LAST; x++)
1240 EINA_INLIST_FOREACH_SAFE(_e_main_hooks[x], l, mh)
1242 if (!mh->delete_me) continue;
1243 _e_main_hooks[x] = eina_inlist_remove(_e_main_hooks[x],
1244 EINA_INLIST_GET(mh));
1250 _e_main_hook_call(E_Main_Hook_Point hookpoint, void *data EINA_UNUSED)
1254 _e_main_hooks_walking++;
1255 EINA_INLIST_FOREACH(_e_main_hooks[hookpoint], mh)
1257 if (mh->delete_me) continue;
1260 _e_main_hooks_walking--;
1261 if ((_e_main_hooks_walking == 0) && (_e_main_hooks_delete > 0))
1262 _e_main_hooks_clean();
1266 e_main_hook_add(E_Main_Hook_Point hookpoint, E_Main_Hook_Cb func, const void *data)
1270 EINA_SAFETY_ON_TRUE_RETURN_VAL(hookpoint >= E_MAIN_HOOK_LAST, NULL);
1271 mh = E_NEW(E_Main_Hook, 1);
1272 EINA_SAFETY_ON_NULL_RETURN_VAL(mh, NULL);
1273 mh->hookpoint = hookpoint;
1275 mh->data = (void*)data;
1276 _e_main_hooks[hookpoint] = eina_inlist_append(_e_main_hooks[hookpoint],
1277 EINA_INLIST_GET(mh));
1282 e_main_hook_del(E_Main_Hook *mh)
1285 if (_e_main_hooks_walking == 0)
1287 _e_main_hooks[mh->hookpoint] = eina_inlist_remove(_e_main_hooks[mh->hookpoint],
1288 EINA_INLIST_GET(mh));
1292 _e_main_hooks_delete++;
1296 e_main_hook_call(E_Main_Hook_Point hookpoint)
1298 if ((hookpoint < 0) || (hookpoint >= E_MAIN_HOOK_LAST)) return;
1300 _e_main_hook_call(hookpoint, NULL);